@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * The main designating function for modifying profiles. Loads up info, determins what to do, etc. |
@@ -30,18 +31,21 @@ discard block |
||
| 30 | 31 | global $smcFunc; |
| 31 | 32 | |
| 32 | 33 | // Don't reload this as we may have processed error strings. |
| 33 | - if (empty($post_errors)) |
|
| 34 | - loadLanguage('Profile+Drafts'); |
|
| 34 | + if (empty($post_errors)) { |
|
| 35 | + loadLanguage('Profile+Drafts'); |
|
| 36 | + } |
|
| 35 | 37 | loadTemplate('Profile'); |
| 36 | 38 | |
| 37 | 39 | require_once($sourcedir . '/Subs-Menu.php'); |
| 38 | 40 | |
| 39 | 41 | // Did we get the user by name... |
| 40 | - if (isset($_REQUEST['user'])) |
|
| 41 | - $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 42 | + if (isset($_REQUEST['user'])) { |
|
| 43 | + $memberResult = loadMemberData($_REQUEST['user'], true, 'profile'); |
|
| 44 | + } |
|
| 42 | 45 | // ... or by id_member? |
| 43 | - elseif (!empty($_REQUEST['u'])) |
|
| 44 | - $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 46 | + elseif (!empty($_REQUEST['u'])) { |
|
| 47 | + $memberResult = loadMemberData((int) $_REQUEST['u'], false, 'profile'); |
|
| 48 | + } |
|
| 45 | 49 | // If it was just ?action=profile, edit your own profile, but only if you're not a guest. |
| 46 | 50 | else |
| 47 | 51 | { |
@@ -51,8 +55,9 @@ discard block |
||
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | // Check if loadMemberData() has returned a valid result. |
| 54 | - if (!$memberResult) |
|
| 55 | - fatal_lang_error('not_a_user', false, 404); |
|
| 58 | + if (!$memberResult) { |
|
| 59 | + fatal_lang_error('not_a_user', false, 404); |
|
| 60 | + } |
|
| 56 | 61 | |
| 57 | 62 | // If all went well, we have a valid member ID! |
| 58 | 63 | list ($memID) = $memberResult; |
@@ -68,8 +73,9 @@ discard block |
||
| 68 | 73 | |
| 69 | 74 | // Group management isn't actually a permission. But we need it to be for this, so we need a phantom permission. |
| 70 | 75 | // And we care about what the current user can do, not what the user whose profile it is. |
| 71 | - if ($user_info['mod_cache']['gq'] != '0=1') |
|
| 72 | - $user_info['permissions'][] = 'approve_group_requests'; |
|
| 76 | + if ($user_info['mod_cache']['gq'] != '0=1') { |
|
| 77 | + $user_info['permissions'][] = 'approve_group_requests'; |
|
| 78 | + } |
|
| 73 | 79 | |
| 74 | 80 | // If paid subscriptions are enabled, make sure we actually have at least one subscription available... |
| 75 | 81 | $context['subs_available'] = false; |
@@ -437,21 +443,25 @@ discard block |
||
| 437 | 443 | foreach ($section['areas'] as $area_id => $area) |
| 438 | 444 | { |
| 439 | 445 | // If it said no permissions that meant it wasn't valid! |
| 440 | - if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) |
|
| 441 | - $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 446 | + if (empty($area['permission'][$context['user']['is_owner'] ? 'own' : 'any'])) { |
|
| 447 | + $profile_areas[$section_id]['areas'][$area_id]['enabled'] = false; |
|
| 448 | + } |
|
| 442 | 449 | // Otherwise pick the right set. |
| 443 | - else |
|
| 444 | - $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 450 | + else { |
|
| 451 | + $profile_areas[$section_id]['areas'][$area_id]['permission'] = $area['permission'][$context['user']['is_owner'] ? 'own' : 'any']; |
|
| 452 | + } |
|
| 445 | 453 | |
| 446 | 454 | // Password required in most cases |
| 447 | - if (!empty($area['password'])) |
|
| 448 | - $context['password_areas'][] = $area_id; |
|
| 455 | + if (!empty($area['password'])) { |
|
| 456 | + $context['password_areas'][] = $area_id; |
|
| 457 | + } |
|
| 449 | 458 | } |
| 450 | 459 | } |
| 451 | 460 | |
| 452 | 461 | // Is there an updated message to show? |
| 453 | - if (isset($_GET['updated'])) |
|
| 454 | - $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 462 | + if (isset($_GET['updated'])) { |
|
| 463 | + $context['profile_updated'] = $txt['profile_updated_own']; |
|
| 464 | + } |
|
| 455 | 465 | |
| 456 | 466 | // Set a few options for the menu. |
| 457 | 467 | $menuOptions = array( |
@@ -466,8 +476,9 @@ discard block |
||
| 466 | 476 | $profile_include_data = createMenu($profile_areas, $menuOptions); |
| 467 | 477 | |
| 468 | 478 | // No menu means no access. |
| 469 | - if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) |
|
| 470 | - fatal_lang_error('no_access', false); |
|
| 479 | + if (!$profile_include_data && (!$user_info['is_guest'] || validateSession())) { |
|
| 480 | + fatal_lang_error('no_access', false); |
|
| 481 | + } |
|
| 471 | 482 | |
| 472 | 483 | // Make a note of the Unique ID for this menu. |
| 473 | 484 | $context['profile_menu_id'] = $context['max_menu_id']; |
@@ -493,8 +504,9 @@ discard block |
||
| 493 | 504 | if ($current_area == $area_id) |
| 494 | 505 | { |
| 495 | 506 | // This can't happen - but is a security check. |
| 496 | - if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) |
|
| 497 | - fatal_lang_error('no_access', false); |
|
| 507 | + if ((isset($section['enabled']) && $section['enabled'] == false) || (isset($area['enabled']) && $area['enabled'] == false)) { |
|
| 508 | + fatal_lang_error('no_access', false); |
|
| 509 | + } |
|
| 498 | 510 | |
| 499 | 511 | // Are we saving data in a valid area? |
| 500 | 512 | if (isset($area['sc']) && (isset($_REQUEST['save']) || $context['do_preview'])) |
@@ -513,12 +525,14 @@ discard block |
||
| 513 | 525 | } |
| 514 | 526 | |
| 515 | 527 | // Does this require session validating? |
| 516 | - if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) |
|
| 517 | - $security_checks['validate'] = true; |
|
| 528 | + if (!empty($area['validate']) || (isset($_REQUEST['save']) && !$context['user']['is_owner'])) { |
|
| 529 | + $security_checks['validate'] = true; |
|
| 530 | + } |
|
| 518 | 531 | |
| 519 | 532 | // Permissions for good measure. |
| 520 | - if (!empty($profile_include_data['permission'])) |
|
| 521 | - $security_checks['permission'] = $profile_include_data['permission']; |
|
| 533 | + if (!empty($profile_include_data['permission'])) { |
|
| 534 | + $security_checks['permission'] = $profile_include_data['permission']; |
|
| 535 | + } |
|
| 522 | 536 | |
| 523 | 537 | // Either way got something. |
| 524 | 538 | $found_area = true; |
@@ -527,21 +541,26 @@ discard block |
||
| 527 | 541 | } |
| 528 | 542 | |
| 529 | 543 | // Oh dear, some serious security lapse is going on here... we'll put a stop to that! |
| 530 | - if (!$found_area) |
|
| 531 | - fatal_lang_error('no_access', false); |
|
| 544 | + if (!$found_area) { |
|
| 545 | + fatal_lang_error('no_access', false); |
|
| 546 | + } |
|
| 532 | 547 | |
| 533 | 548 | // Release this now. |
| 534 | 549 | unset($profile_areas); |
| 535 | 550 | |
| 536 | 551 | // Now the context is setup have we got any security checks to carry out additional to that above? |
| 537 | - if (isset($security_checks['session'])) |
|
| 538 | - checkSession($security_checks['session']); |
|
| 539 | - if (isset($security_checks['validate'])) |
|
| 540 | - validateSession(); |
|
| 541 | - if (isset($security_checks['validateToken'])) |
|
| 542 | - validateToken($token_name, $token_type); |
|
| 543 | - if (isset($security_checks['permission'])) |
|
| 544 | - isAllowedTo($security_checks['permission']); |
|
| 552 | + if (isset($security_checks['session'])) { |
|
| 553 | + checkSession($security_checks['session']); |
|
| 554 | + } |
|
| 555 | + if (isset($security_checks['validate'])) { |
|
| 556 | + validateSession(); |
|
| 557 | + } |
|
| 558 | + if (isset($security_checks['validateToken'])) { |
|
| 559 | + validateToken($token_name, $token_type); |
|
| 560 | + } |
|
| 561 | + if (isset($security_checks['permission'])) { |
|
| 562 | + isAllowedTo($security_checks['permission']); |
|
| 563 | + } |
|
| 545 | 564 | |
| 546 | 565 | // Create a token if needed. |
| 547 | 566 | if (isset($security_checks['needsToken']) || isset($security_checks['validateToken'])) |
@@ -551,8 +570,9 @@ discard block |
||
| 551 | 570 | } |
| 552 | 571 | |
| 553 | 572 | // File to include? |
| 554 | - if (isset($profile_include_data['file'])) |
|
| 555 | - require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 573 | + if (isset($profile_include_data['file'])) { |
|
| 574 | + require_once($sourcedir . '/' . $profile_include_data['file']); |
|
| 575 | + } |
|
| 556 | 576 | |
| 557 | 577 | // Build the link tree. |
| 558 | 578 | $context['linktree'][] = array( |
@@ -560,17 +580,19 @@ discard block |
||
| 560 | 580 | 'name' => sprintf($txt['profile_of_username'], $context['member']['name']), |
| 561 | 581 | ); |
| 562 | 582 | |
| 563 | - if (!empty($profile_include_data['label'])) |
|
| 564 | - $context['linktree'][] = array( |
|
| 583 | + if (!empty($profile_include_data['label'])) { |
|
| 584 | + $context['linktree'][] = array( |
|
| 565 | 585 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'], |
| 566 | 586 | 'name' => $profile_include_data['label'], |
| 567 | 587 | ); |
| 588 | + } |
|
| 568 | 589 | |
| 569 | - if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) |
|
| 570 | - $context['linktree'][] = array( |
|
| 590 | + if (!empty($profile_include_data['current_subsection']) && $profile_include_data['subsections'][$profile_include_data['current_subsection']][0] != $profile_include_data['label']) { |
|
| 591 | + $context['linktree'][] = array( |
|
| 571 | 592 | 'url' => $scripturl . '?action=profile' . ($memID != $user_info['id'] ? ';u=' . $memID : '') . ';area=' . $profile_include_data['current_area'] . ';sa=' . $profile_include_data['current_subsection'], |
| 572 | 593 | 'name' => $profile_include_data['subsections'][$profile_include_data['current_subsection']][0], |
| 573 | 594 | ); |
| 595 | + } |
|
| 574 | 596 | |
| 575 | 597 | // Set the template for this area and add the profile layer. |
| 576 | 598 | $context['sub_template'] = $profile_include_data['function']; |
@@ -596,12 +618,14 @@ discard block |
||
| 596 | 618 | if ($check_password) |
| 597 | 619 | { |
| 598 | 620 | // Check to ensure we're forcing SSL for authentication |
| 599 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 600 | - fatal_lang_error('login_ssl_required'); |
|
| 621 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 622 | + fatal_lang_error('login_ssl_required'); |
|
| 623 | + } |
|
| 601 | 624 | |
| 602 | 625 | // You didn't even enter a password! |
| 603 | - if (trim($_POST['oldpasswrd']) == '') |
|
| 604 | - $post_errors[] = 'no_password'; |
|
| 626 | + if (trim($_POST['oldpasswrd']) == '') { |
|
| 627 | + $post_errors[] = 'no_password'; |
|
| 628 | + } |
|
| 605 | 629 | |
| 606 | 630 | // Since the password got modified due to all the $_POST cleaning, lets undo it so we can get the correct password |
| 607 | 631 | $_POST['oldpasswrd'] = un_htmlspecialchars($_POST['oldpasswrd']); |
@@ -610,33 +634,35 @@ discard block |
||
| 610 | 634 | $good_password = in_array(true, call_integration_hook('integrate_verify_password', array($cur_profile['member_name'], $_POST['oldpasswrd'], false)), true); |
| 611 | 635 | |
| 612 | 636 | // Bad password!!! |
| 613 | - if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) |
|
| 614 | - $post_errors[] = 'bad_password'; |
|
| 637 | + if (!$good_password && !hash_verify_password($user_profile[$memID]['member_name'], un_htmlspecialchars(stripslashes($_POST['oldpasswrd'])), $user_info['passwd'])) { |
|
| 638 | + $post_errors[] = 'bad_password'; |
|
| 639 | + } |
|
| 615 | 640 | |
| 616 | 641 | // Warn other elements not to jump the gun and do custom changes! |
| 617 | - if (in_array('bad_password', $post_errors)) |
|
| 618 | - $context['password_auth_failed'] = true; |
|
| 642 | + if (in_array('bad_password', $post_errors)) { |
|
| 643 | + $context['password_auth_failed'] = true; |
|
| 644 | + } |
|
| 619 | 645 | } |
| 620 | 646 | |
| 621 | 647 | // Change the IP address in the database. |
| 622 | - if ($context['user']['is_owner']) |
|
| 623 | - $profile_vars['member_ip'] = $user_info['ip']; |
|
| 648 | + if ($context['user']['is_owner']) { |
|
| 649 | + $profile_vars['member_ip'] = $user_info['ip']; |
|
| 650 | + } |
|
| 624 | 651 | |
| 625 | 652 | // Now call the sub-action function... |
| 626 | 653 | if ($current_area == 'activateaccount') |
| 627 | 654 | { |
| 628 | - if (empty($post_errors)) |
|
| 629 | - activateAccount($memID); |
|
| 630 | - } |
|
| 631 | - elseif ($current_area == 'deleteaccount') |
|
| 655 | + if (empty($post_errors)) { |
|
| 656 | + activateAccount($memID); |
|
| 657 | + } |
|
| 658 | + } elseif ($current_area == 'deleteaccount') |
|
| 632 | 659 | { |
| 633 | 660 | if (empty($post_errors)) |
| 634 | 661 | { |
| 635 | 662 | deleteAccount2($memID); |
| 636 | 663 | redirectexit(); |
| 637 | 664 | } |
| 638 | - } |
|
| 639 | - elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 665 | + } elseif ($current_area == 'groupmembership' && empty($post_errors)) |
|
| 640 | 666 | { |
| 641 | 667 | $msg = groupMembership2($profile_vars, $post_errors, $memID); |
| 642 | 668 | |
@@ -647,10 +673,9 @@ discard block |
||
| 647 | 673 | elseif ($current_area == 'authentication') |
| 648 | 674 | { |
| 649 | 675 | authentication($memID, true); |
| 650 | - } |
|
| 651 | - elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) |
|
| 652 | - saveProfileFields(); |
|
| 653 | - else |
|
| 676 | + } elseif (in_array($current_area, array('account', 'forumprofile', 'theme'))) { |
|
| 677 | + saveProfileFields(); |
|
| 678 | + } else |
|
| 654 | 679 | { |
| 655 | 680 | $force_redirect = true; |
| 656 | 681 | // Ensure we include this. |
@@ -666,34 +691,36 @@ discard block |
||
| 666 | 691 | // Load the language file so we can give a nice explanation of the errors. |
| 667 | 692 | loadLanguage('Errors'); |
| 668 | 693 | $context['post_errors'] = $post_errors; |
| 669 | - } |
|
| 670 | - elseif (!empty($profile_vars)) |
|
| 694 | + } elseif (!empty($profile_vars)) |
|
| 671 | 695 | { |
| 672 | 696 | // If we've changed the password, notify any integration that may be listening in. |
| 673 | - if (isset($profile_vars['passwd'])) |
|
| 674 | - call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 697 | + if (isset($profile_vars['passwd'])) { |
|
| 698 | + call_integration_hook('integrate_reset_pass', array($cur_profile['member_name'], $cur_profile['member_name'], $_POST['passwrd2'])); |
|
| 699 | + } |
|
| 675 | 700 | |
| 676 | 701 | updateMemberData($memID, $profile_vars); |
| 677 | 702 | |
| 678 | 703 | // What if this is the newest member? |
| 679 | - if ($modSettings['latestMember'] == $memID) |
|
| 680 | - updateStats('member'); |
|
| 681 | - elseif (isset($profile_vars['real_name'])) |
|
| 682 | - updateSettings(array('memberlist_updated' => time())); |
|
| 704 | + if ($modSettings['latestMember'] == $memID) { |
|
| 705 | + updateStats('member'); |
|
| 706 | + } elseif (isset($profile_vars['real_name'])) { |
|
| 707 | + updateSettings(array('memberlist_updated' => time())); |
|
| 708 | + } |
|
| 683 | 709 | |
| 684 | 710 | // If the member changed his/her birthdate, update calendar statistics. |
| 685 | - if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) |
|
| 686 | - updateSettings(array( |
|
| 711 | + if (isset($profile_vars['birthdate']) || isset($profile_vars['real_name'])) { |
|
| 712 | + updateSettings(array( |
|
| 687 | 713 | 'calendar_updated' => time(), |
| 688 | 714 | )); |
| 715 | + } |
|
| 689 | 716 | |
| 690 | 717 | // Anything worth logging? |
| 691 | 718 | if (!empty($context['log_changes']) && !empty($modSettings['modlog_enabled'])) |
| 692 | 719 | { |
| 693 | 720 | $log_changes = array(); |
| 694 | 721 | require_once($sourcedir . '/Logging.php'); |
| 695 | - foreach ($context['log_changes'] as $k => $v) |
|
| 696 | - $log_changes[] = array( |
|
| 722 | + foreach ($context['log_changes'] as $k => $v) { |
|
| 723 | + $log_changes[] = array( |
|
| 697 | 724 | 'action' => $k, |
| 698 | 725 | 'log_type' => 'user', |
| 699 | 726 | 'extra' => array_merge($v, array( |
@@ -701,14 +728,16 @@ discard block |
||
| 701 | 728 | 'member_affected' => $memID, |
| 702 | 729 | )), |
| 703 | 730 | ); |
| 731 | + } |
|
| 704 | 732 | |
| 705 | 733 | logActions($log_changes); |
| 706 | 734 | } |
| 707 | 735 | |
| 708 | 736 | // Have we got any post save functions to execute? |
| 709 | - if (!empty($context['profile_execute_on_save'])) |
|
| 710 | - foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 737 | + if (!empty($context['profile_execute_on_save'])) { |
|
| 738 | + foreach ($context['profile_execute_on_save'] as $saveFunc) |
|
| 711 | 739 | $saveFunc(); |
| 740 | + } |
|
| 712 | 741 | |
| 713 | 742 | // Let them know it worked! |
| 714 | 743 | $context['profile_updated'] = $context['user']['is_owner'] ? $txt['profile_updated_own'] : sprintf($txt['profile_updated_else'], $cur_profile['member_name']); |
@@ -722,27 +751,31 @@ discard block |
||
| 722 | 751 | if (!empty($post_errors)) |
| 723 | 752 | { |
| 724 | 753 | // Set all the errors so the template knows what went wrong. |
| 725 | - foreach ($post_errors as $error_type) |
|
| 726 | - $context['modify_error'][$error_type] = true; |
|
| 754 | + foreach ($post_errors as $error_type) { |
|
| 755 | + $context['modify_error'][$error_type] = true; |
|
| 756 | + } |
|
| 727 | 757 | } |
| 728 | 758 | // If it's you then we should redirect upon save. |
| 729 | - elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) |
|
| 730 | - redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 731 | - elseif (!empty($force_redirect)) |
|
| 732 | - redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 759 | + elseif (!empty($profile_vars) && $context['user']['is_owner'] && !$context['do_preview']) { |
|
| 760 | + redirectexit('action=profile;area=' . $current_area . (!empty($current_sa) ? ';sa=' . $current_sa : '') . ';updated'); |
|
| 761 | + } elseif (!empty($force_redirect)) { |
|
| 762 | + redirectexit('action=profile' . ($context['user']['is_owner'] ? '' : ';u=' . $memID) . ';area=' . $current_area); |
|
| 763 | + } |
|
| 733 | 764 | |
| 734 | 765 | |
| 735 | 766 | // Get the right callable. |
| 736 | 767 | $call = call_helper($profile_include_data['function'], true); |
| 737 | 768 | |
| 738 | 769 | // Is it valid? |
| 739 | - if (!empty($call)) |
|
| 740 | - call_user_func($call, $memID); |
|
| 770 | + if (!empty($call)) { |
|
| 771 | + call_user_func($call, $memID); |
|
| 772 | + } |
|
| 741 | 773 | |
| 742 | 774 | // Set the page title if it's not already set... |
| 743 | - if (!isset($context['page_title'])) |
|
| 744 | - $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 745 | -} |
|
| 775 | + if (!isset($context['page_title'])) { |
|
| 776 | + $context['page_title'] = $txt['profile'] . (isset($txt[$current_area]) ? ' - ' . $txt[$current_area] : ''); |
|
| 777 | + } |
|
| 778 | + } |
|
| 746 | 779 | |
| 747 | 780 | /** |
| 748 | 781 | * Set up the requirements for the profile popup - the area that is shown as the popup menu for the current user. |
@@ -865,16 +898,18 @@ discard block |
||
| 865 | 898 | if (!allowedTo('admin_forum') && $area != 'register') |
| 866 | 899 | { |
| 867 | 900 | // If it's the owner they can see two types of private fields, regardless. |
| 868 | - if ($memID == $user_info['id']) |
|
| 869 | - $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 870 | - else |
|
| 871 | - $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 901 | + if ($memID == $user_info['id']) { |
|
| 902 | + $where .= $area == 'summary' ? ' AND private < 3' : ' AND (private = 0 OR private = 2)'; |
|
| 903 | + } else { |
|
| 904 | + $where .= $area == 'summary' ? ' AND private < 2' : ' AND private = 0'; |
|
| 905 | + } |
|
| 872 | 906 | } |
| 873 | 907 | |
| 874 | - if ($area == 'register') |
|
| 875 | - $where .= ' AND show_reg != 0'; |
|
| 876 | - elseif ($area != 'summary') |
|
| 877 | - $where .= ' AND show_profile = {string:area}'; |
|
| 908 | + if ($area == 'register') { |
|
| 909 | + $where .= ' AND show_reg != 0'; |
|
| 910 | + } elseif ($area != 'summary') { |
|
| 911 | + $where .= ' AND show_profile = {string:area}'; |
|
| 912 | + } |
|
| 878 | 913 | |
| 879 | 914 | // Load all the relevant fields - and data. |
| 880 | 915 | $request = $smcFunc['db_query']('', ' |
@@ -900,13 +935,15 @@ discard block |
||
| 900 | 935 | if (isset($_POST['customfield']) && isset($_POST['customfield'][$row['col_name']])) |
| 901 | 936 | { |
| 902 | 937 | $value = $smcFunc['htmlspecialchars']($_POST['customfield'][$row['col_name']]); |
| 903 | - if (in_array($row['field_type'], array('select', 'radio'))) |
|
| 904 | - $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 938 | + if (in_array($row['field_type'], array('select', 'radio'))) { |
|
| 939 | + $value = ($options = explode(',', $row['field_options'])) && isset($options[$value]) ? $options[$value] : ''; |
|
| 940 | + } |
|
| 905 | 941 | } |
| 906 | 942 | |
| 907 | 943 | // Don't show the "disabled" option for the "gender" field if we are on the "summary" area. |
| 908 | - if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
| 909 | - continue; |
|
| 944 | + if ($area == 'summary' && $row['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
| 945 | + continue; |
|
| 946 | + } |
|
| 910 | 947 | |
| 911 | 948 | // HTML for the input form. |
| 912 | 949 | $output_html = $value; |
@@ -915,8 +952,7 @@ discard block |
||
| 915 | 952 | $true = (!$exists && $row['default_value']) || $value; |
| 916 | 953 | $input_html = '<input type="checkbox" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($true ? ' checked' : '') . ' class="input_check">'; |
| 917 | 954 | $output_html = $true ? $txt['yes'] : $txt['no']; |
| 918 | - } |
|
| 919 | - elseif ($row['field_type'] == 'select') |
|
| 955 | + } elseif ($row['field_type'] == 'select') |
|
| 920 | 956 | { |
| 921 | 957 | $input_html = '<select name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"><option value="-1"></option>'; |
| 922 | 958 | $options = explode(',', $row['field_options']); |
@@ -924,13 +960,13 @@ discard block |
||
| 924 | 960 | { |
| 925 | 961 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 926 | 962 | $input_html .= '<option value="' . $k . '"' . ($true ? ' selected' : '') . '>' . $v . '</option>'; |
| 927 | - if ($true) |
|
| 928 | - $output_html = $v; |
|
| 963 | + if ($true) { |
|
| 964 | + $output_html = $v; |
|
| 965 | + } |
|
| 929 | 966 | } |
| 930 | 967 | |
| 931 | 968 | $input_html .= '</select>'; |
| 932 | - } |
|
| 933 | - elseif ($row['field_type'] == 'radio') |
|
| 969 | + } elseif ($row['field_type'] == 'radio') |
|
| 934 | 970 | { |
| 935 | 971 | $input_html = '<fieldset>'; |
| 936 | 972 | $options = explode(',', $row['field_options']); |
@@ -938,36 +974,37 @@ discard block |
||
| 938 | 974 | { |
| 939 | 975 | $true = (!$exists && $row['default_value'] == $v) || $value == $v; |
| 940 | 976 | $input_html .= '<label for="customfield_' . $row['col_name'] . '_' . $k . '"><input type="radio" name="customfield[' . $row['col_name'] . ']" class="input_radio" id="customfield_' . $row['col_name'] . '_' . $k . '" value="' . $k . '"' . ($true ? ' checked' : '') . '>' . $v . '</label><br>'; |
| 941 | - if ($true) |
|
| 942 | - $output_html = $v; |
|
| 977 | + if ($true) { |
|
| 978 | + $output_html = $v; |
|
| 979 | + } |
|
| 943 | 980 | } |
| 944 | 981 | $input_html .= '</fieldset>'; |
| 945 | - } |
|
| 946 | - elseif ($row['field_type'] == 'text') |
|
| 982 | + } elseif ($row['field_type'] == 'text') |
|
| 947 | 983 | { |
| 948 | 984 | $input_html = '<input type="text" name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . ($row['field_length'] != 0 ? ' maxlength="' . $row['field_length'] . '"' : '') . ' size="' . ($row['field_length'] == 0 || $row['field_length'] >= 50 ? 50 : ($row['field_length'] > 30 ? 30 : ($row['field_length'] > 10 ? 20 : 10))) . '" value="' . un_htmlspecialchars($value) . '" class="input_text"' . ($row['show_reg'] == 2 ? ' required' : '') . '>'; |
| 949 | - } |
|
| 950 | - else |
|
| 985 | + } else |
|
| 951 | 986 | { |
| 952 | 987 | @list ($rows, $cols) = @explode(',', $row['default_value']); |
| 953 | 988 | $input_html = '<textarea name="customfield[' . $row['col_name'] . ']" id="customfield[' . $row['col_name'] . ']"' . (!empty($rows) ? ' rows="' . $rows . '"' : '') . (!empty($cols) ? ' cols="' . $cols . '"' : '') . ($row['show_reg'] == 2 ? ' required' : '') . '>' . un_htmlspecialchars($value) . '</textarea>'; |
| 954 | 989 | } |
| 955 | 990 | |
| 956 | 991 | // Parse BBCode |
| 957 | - if ($row['bbc']) |
|
| 958 | - $output_html = parse_bbc($output_html); |
|
| 959 | - elseif ($row['field_type'] == 'textarea') |
|
| 960 | - // Allow for newlines at least |
|
| 992 | + if ($row['bbc']) { |
|
| 993 | + $output_html = parse_bbc($output_html); |
|
| 994 | + } elseif ($row['field_type'] == 'textarea') { |
|
| 995 | + // Allow for newlines at least |
|
| 961 | 996 | $output_html = strtr($output_html, array("\n" => '<br>')); |
| 997 | + } |
|
| 962 | 998 | |
| 963 | 999 | // Enclosing the user input within some other text? |
| 964 | - if (!empty($row['enclose']) && !empty($output_html)) |
|
| 965 | - $output_html = strtr($row['enclose'], array( |
|
| 1000 | + if (!empty($row['enclose']) && !empty($output_html)) { |
|
| 1001 | + $output_html = strtr($row['enclose'], array( |
|
| 966 | 1002 | '{SCRIPTURL}' => $scripturl, |
| 967 | 1003 | '{IMAGES_URL}' => $settings['images_url'], |
| 968 | 1004 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 969 | 1005 | '{INPUT}' => un_htmlspecialchars($output_html), |
| 970 | 1006 | )); |
| 1007 | + } |
|
| 971 | 1008 | |
| 972 | 1009 | $context['custom_fields'][] = array( |
| 973 | 1010 | 'name' => $row['field_name'], |
@@ -14,8 +14,9 @@ discard block |
||
| 14 | 14 | * @version 2.1 Beta 3 |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | -if (!defined('SMF')) |
|
| 17 | +if (!defined('SMF')) { |
|
| 18 | 18 | die('No direct access...'); |
| 19 | +} |
|
| 19 | 20 | |
| 20 | 21 | /** |
| 21 | 22 | * Handles showing the post screen, loading the post to be modified, and loading any post quoted. |
@@ -35,12 +36,14 @@ discard block |
||
| 35 | 36 | global $sourcedir, $smcFunc, $language; |
| 36 | 37 | |
| 37 | 38 | loadLanguage('Post'); |
| 38 | - if (!empty($modSettings['drafts_post_enabled'])) |
|
| 39 | - loadLanguage('Drafts'); |
|
| 39 | + if (!empty($modSettings['drafts_post_enabled'])) { |
|
| 40 | + loadLanguage('Drafts'); |
|
| 41 | + } |
|
| 40 | 42 | |
| 41 | 43 | // You can't reply with a poll... hacker. |
| 42 | - if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) |
|
| 43 | - unset($_REQUEST['poll']); |
|
| 44 | + if (isset($_REQUEST['poll']) && !empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 45 | + unset($_REQUEST['poll']); |
|
| 46 | + } |
|
| 44 | 47 | |
| 45 | 48 | // Posting an event? |
| 46 | 49 | $context['make_event'] = isset($_REQUEST['calendar']); |
@@ -54,8 +57,9 @@ discard block |
||
| 54 | 57 | $context['auto_notify'] = !empty($context['notify_prefs']['msg_auto_notify']); |
| 55 | 58 | |
| 56 | 59 | // You must be posting to *some* board. |
| 57 | - if (empty($board) && !$context['make_event']) |
|
| 58 | - fatal_lang_error('no_board', false); |
|
| 60 | + if (empty($board) && !$context['make_event']) { |
|
| 61 | + fatal_lang_error('no_board', false); |
|
| 62 | + } |
|
| 59 | 63 | |
| 60 | 64 | require_once($sourcedir . '/Subs-Post.php'); |
| 61 | 65 | |
@@ -78,10 +82,11 @@ discard block |
||
| 78 | 82 | array( |
| 79 | 83 | 'msg' => (int) $_REQUEST['msg'], |
| 80 | 84 | )); |
| 81 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
| 82 | - unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 83 | - else |
|
| 84 | - list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 85 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
| 86 | + unset($_REQUEST['msg'], $_POST['msg'], $_GET['msg']); |
|
| 87 | + } else { |
|
| 88 | + list ($topic) = $smcFunc['db_fetch_row']($request); |
|
| 89 | + } |
|
| 85 | 90 | $smcFunc['db_free_result']($request); |
| 86 | 91 | } |
| 87 | 92 | |
@@ -108,33 +113,36 @@ discard block |
||
| 108 | 113 | $smcFunc['db_free_result']($request); |
| 109 | 114 | |
| 110 | 115 | // If this topic already has a poll, they sure can't add another. |
| 111 | - if (isset($_REQUEST['poll']) && $pollID > 0) |
|
| 112 | - unset($_REQUEST['poll']); |
|
| 116 | + if (isset($_REQUEST['poll']) && $pollID > 0) { |
|
| 117 | + unset($_REQUEST['poll']); |
|
| 118 | + } |
|
| 113 | 119 | |
| 114 | 120 | if (empty($_REQUEST['msg'])) |
| 115 | 121 | { |
| 116 | - if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) |
|
| 117 | - is_not_guest(); |
|
| 122 | + if ($user_info['is_guest'] && !allowedTo('post_reply_any') && (!$modSettings['postmod_active'] || !allowedTo('post_unapproved_replies_any'))) { |
|
| 123 | + is_not_guest(); |
|
| 124 | + } |
|
| 118 | 125 | |
| 119 | 126 | // By default the reply will be approved... |
| 120 | 127 | $context['becomes_approved'] = true; |
| 121 | 128 | if ($id_member_poster != $user_info['id'] || $user_info['is_guest']) |
| 122 | 129 | { |
| 123 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 124 | - $context['becomes_approved'] = false; |
|
| 125 | - else |
|
| 126 | - isAllowedTo('post_reply_any'); |
|
| 127 | - } |
|
| 128 | - elseif (!allowedTo('post_reply_any')) |
|
| 130 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 131 | + $context['becomes_approved'] = false; |
|
| 132 | + } else { |
|
| 133 | + isAllowedTo('post_reply_any'); |
|
| 134 | + } |
|
| 135 | + } elseif (!allowedTo('post_reply_any')) |
|
| 129 | 136 | { |
| 130 | - if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) |
|
| 131 | - $context['becomes_approved'] = false; |
|
| 132 | - else |
|
| 133 | - isAllowedTo('post_reply_own'); |
|
| 137 | + if ($modSettings['postmod_active'] && ((allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) || allowedTo('post_unapproved_replies_any'))) { |
|
| 138 | + $context['becomes_approved'] = false; |
|
| 139 | + } else { |
|
| 140 | + isAllowedTo('post_reply_own'); |
|
| 141 | + } |
|
| 134 | 142 | } |
| 143 | + } else { |
|
| 144 | + $context['becomes_approved'] = true; |
|
| 135 | 145 | } |
| 136 | - else |
|
| 137 | - $context['becomes_approved'] = true; |
|
| 138 | 146 | |
| 139 | 147 | $context['can_lock'] = allowedTo('lock_any') || ($user_info['id'] == $id_member_poster && allowedTo('lock_own')); |
| 140 | 148 | $context['can_sticky'] = allowedTo('make_sticky'); |
@@ -146,18 +154,19 @@ discard block |
||
| 146 | 154 | $context['sticky'] = isset($_REQUEST['sticky']) ? !empty($_REQUEST['sticky']) : $sticky; |
| 147 | 155 | |
| 148 | 156 | // Check whether this is a really old post being bumped... |
| 149 | - if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) |
|
| 150 | - $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 151 | - } |
|
| 152 | - else |
|
| 157 | + if (!empty($modSettings['oldTopicDays']) && $lastPostTime + $modSettings['oldTopicDays'] * 86400 < time() && empty($sticky) && !isset($_REQUEST['subject'])) { |
|
| 158 | + $post_errors[] = array('old_topic', array($modSettings['oldTopicDays'])); |
|
| 159 | + } |
|
| 160 | + } else |
|
| 153 | 161 | { |
| 154 | 162 | $context['becomes_approved'] = true; |
| 155 | 163 | if ((!$context['make_event'] || !empty($board))) |
| 156 | 164 | { |
| 157 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 158 | - $context['becomes_approved'] = false; |
|
| 159 | - else |
|
| 160 | - isAllowedTo('post_new'); |
|
| 165 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 166 | + $context['becomes_approved'] = false; |
|
| 167 | + } else { |
|
| 168 | + isAllowedTo('post_new'); |
|
| 169 | + } |
|
| 161 | 170 | } |
| 162 | 171 | |
| 163 | 172 | $locked = 0; |
@@ -193,20 +202,24 @@ discard block |
||
| 193 | 202 | } |
| 194 | 203 | |
| 195 | 204 | // Don't allow a post if it's locked and you aren't all powerful. |
| 196 | - if ($locked && !allowedTo('moderate_board')) |
|
| 197 | - fatal_lang_error('topic_locked', false); |
|
| 205 | + if ($locked && !allowedTo('moderate_board')) { |
|
| 206 | + fatal_lang_error('topic_locked', false); |
|
| 207 | + } |
|
| 198 | 208 | // Check the users permissions - is the user allowed to add or post a poll? |
| 199 | 209 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 200 | 210 | { |
| 201 | 211 | // New topic, new poll. |
| 202 | - if (empty($topic)) |
|
| 203 | - isAllowedTo('poll_post'); |
|
| 212 | + if (empty($topic)) { |
|
| 213 | + isAllowedTo('poll_post'); |
|
| 214 | + } |
|
| 204 | 215 | // This is an old topic - but it is yours! Can you add to it? |
| 205 | - elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) |
|
| 206 | - isAllowedTo('poll_add_own'); |
|
| 216 | + elseif ($user_info['id'] == $id_member_poster && !allowedTo('poll_add_any')) { |
|
| 217 | + isAllowedTo('poll_add_own'); |
|
| 218 | + } |
|
| 207 | 219 | // If you're not the owner, can you add to any poll? |
| 208 | - else |
|
| 209 | - isAllowedTo('poll_add_any'); |
|
| 220 | + else { |
|
| 221 | + isAllowedTo('poll_add_any'); |
|
| 222 | + } |
|
| 210 | 223 | |
| 211 | 224 | require_once($sourcedir . '/Subs-Members.php'); |
| 212 | 225 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
@@ -235,8 +248,9 @@ discard block |
||
| 235 | 248 | if ($context['make_event']) |
| 236 | 249 | { |
| 237 | 250 | // They might want to pick a board. |
| 238 | - if (!isset($context['current_board'])) |
|
| 239 | - $context['current_board'] = 0; |
|
| 251 | + if (!isset($context['current_board'])) { |
|
| 252 | + $context['current_board'] = 0; |
|
| 253 | + } |
|
| 240 | 254 | |
| 241 | 255 | // Start loading up the event info. |
| 242 | 256 | $context['event'] = array(); |
@@ -250,10 +264,11 @@ discard block |
||
| 250 | 264 | isAllowedTo('calendar_post'); |
| 251 | 265 | |
| 252 | 266 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
| 253 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 254 | - $time_string = '%k:%M'; |
|
| 255 | - else |
|
| 256 | - $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 267 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 268 | + $time_string = '%k:%M'; |
|
| 269 | + } else { |
|
| 270 | + $time_string = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 271 | + } |
|
| 257 | 272 | |
| 258 | 273 | $js_time_string = str_replace( |
| 259 | 274 | array('%H', '%k', '%I', '%l', '%M', '%p', '%P', '%r', '%R', '%S', '%T', '%X'), |
@@ -275,8 +290,7 @@ discard block |
||
| 275 | 290 | require_once($sourcedir . '/Subs-Calendar.php'); |
| 276 | 291 | $eventProperties = getEventProperties($context['event']['id']); |
| 277 | 292 | $context['event'] = array_merge($context['event'], $eventProperties); |
| 278 | - } |
|
| 279 | - else |
|
| 293 | + } else |
|
| 280 | 294 | { |
| 281 | 295 | // Get the current event information. |
| 282 | 296 | require_once($sourcedir . '/Subs-Calendar.php'); |
@@ -284,15 +298,18 @@ discard block |
||
| 284 | 298 | $context['event'] = array_merge($context['event'], $eventProperties); |
| 285 | 299 | |
| 286 | 300 | // Make sure the year and month are in the valid range. |
| 287 | - if ($context['event']['month'] < 1 || $context['event']['month'] > 12) |
|
| 288 | - fatal_lang_error('invalid_month', false); |
|
| 289 | - if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) |
|
| 290 | - fatal_lang_error('invalid_year', false); |
|
| 301 | + if ($context['event']['month'] < 1 || $context['event']['month'] > 12) { |
|
| 302 | + fatal_lang_error('invalid_month', false); |
|
| 303 | + } |
|
| 304 | + if ($context['event']['year'] < $modSettings['cal_minyear'] || $context['event']['year'] > $modSettings['cal_maxyear']) { |
|
| 305 | + fatal_lang_error('invalid_year', false); |
|
| 306 | + } |
|
| 291 | 307 | |
| 292 | 308 | // Get a list of boards they can post in. |
| 293 | 309 | $boards = boardsAllowedTo('post_new'); |
| 294 | - if (empty($boards)) |
|
| 295 | - fatal_lang_error('cannot_post_new', 'user'); |
|
| 310 | + if (empty($boards)) { |
|
| 311 | + fatal_lang_error('cannot_post_new', 'user'); |
|
| 312 | + } |
|
| 296 | 313 | |
| 297 | 314 | // Load a list of boards for this event in the context. |
| 298 | 315 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
@@ -411,10 +428,11 @@ discard block |
||
| 411 | 428 | |
| 412 | 429 | if (!empty($context['new_replies'])) |
| 413 | 430 | { |
| 414 | - if ($context['new_replies'] == 1) |
|
| 415 | - $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 416 | - else |
|
| 417 | - $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 431 | + if ($context['new_replies'] == 1) { |
|
| 432 | + $txt['error_new_replies'] = isset($_GET['last_msg']) ? $txt['error_new_reply_reading'] : $txt['error_new_reply']; |
|
| 433 | + } else { |
|
| 434 | + $txt['error_new_replies'] = sprintf(isset($_GET['last_msg']) ? $txt['error_new_replies_reading'] : $txt['error_new_replies'], $context['new_replies']); |
|
| 435 | + } |
|
| 418 | 436 | |
| 419 | 437 | $post_errors[] = 'new_replies'; |
| 420 | 438 | |
@@ -426,9 +444,9 @@ discard block |
||
| 426 | 444 | // Get a response prefix (like 'Re:') in the default forum language. |
| 427 | 445 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 428 | 446 | { |
| 429 | - if ($language === $user_info['language']) |
|
| 430 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 431 | - else |
|
| 447 | + if ($language === $user_info['language']) { |
|
| 448 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 449 | + } else |
|
| 432 | 450 | { |
| 433 | 451 | loadLanguage('index', $language, false); |
| 434 | 452 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -441,8 +459,9 @@ discard block |
||
| 441 | 459 | // Do we have a body, but an error happened. |
| 442 | 460 | if (isset($_REQUEST['message']) || isset($_REQUEST['quickReply']) || !empty($context['post_error'])) |
| 443 | 461 | { |
| 444 | - if (isset($_REQUEST['quickReply'])) |
|
| 445 | - $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 462 | + if (isset($_REQUEST['quickReply'])) { |
|
| 463 | + $_REQUEST['message'] = $_REQUEST['quickReply']; |
|
| 464 | + } |
|
| 446 | 465 | |
| 447 | 466 | // Validate inputs. |
| 448 | 467 | if (empty($context['post_error'])) |
@@ -450,15 +469,17 @@ discard block |
||
| 450 | 469 | // This means they didn't click Post and get an error. |
| 451 | 470 | $really_previewing = true; |
| 452 | 471 | |
| 453 | - } |
|
| 454 | - else |
|
| 472 | + } else |
|
| 455 | 473 | { |
| 456 | - if (!isset($_REQUEST['subject'])) |
|
| 457 | - $_REQUEST['subject'] = ''; |
|
| 458 | - if (!isset($_REQUEST['message'])) |
|
| 459 | - $_REQUEST['message'] = ''; |
|
| 460 | - if (!isset($_REQUEST['icon'])) |
|
| 461 | - $_REQUEST['icon'] = 'xx'; |
|
| 474 | + if (!isset($_REQUEST['subject'])) { |
|
| 475 | + $_REQUEST['subject'] = ''; |
|
| 476 | + } |
|
| 477 | + if (!isset($_REQUEST['message'])) { |
|
| 478 | + $_REQUEST['message'] = ''; |
|
| 479 | + } |
|
| 480 | + if (!isset($_REQUEST['icon'])) { |
|
| 481 | + $_REQUEST['icon'] = 'xx'; |
|
| 482 | + } |
|
| 462 | 483 | |
| 463 | 484 | // They are previewing if they asked to preview (i.e. came from quick reply). |
| 464 | 485 | $really_previewing = !empty($_POST['preview']); |
@@ -474,8 +495,9 @@ discard block |
||
| 474 | 495 | $form_message = $smcFunc['htmlspecialchars']($_REQUEST['message'], ENT_QUOTES); |
| 475 | 496 | |
| 476 | 497 | // Make sure the subject isn't too long - taking into account special characters. |
| 477 | - if ($smcFunc['strlen']($form_subject) > 100) |
|
| 478 | - $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 498 | + if ($smcFunc['strlen']($form_subject) > 100) { |
|
| 499 | + $form_subject = $smcFunc['substr']($form_subject, 0, 100); |
|
| 500 | + } |
|
| 479 | 501 | |
| 480 | 502 | if (isset($_REQUEST['poll'])) |
| 481 | 503 | { |
@@ -487,8 +509,9 @@ discard block |
||
| 487 | 509 | $_POST['options'] = empty($_POST['options']) ? array() : htmlspecialchars__recursive($_POST['options']); |
| 488 | 510 | foreach ($_POST['options'] as $option) |
| 489 | 511 | { |
| 490 | - if (trim($option) == '') |
|
| 491 | - continue; |
|
| 512 | + if (trim($option) == '') { |
|
| 513 | + continue; |
|
| 514 | + } |
|
| 492 | 515 | |
| 493 | 516 | $context['choices'][] = array( |
| 494 | 517 | 'id' => $choice_id++, |
@@ -550,13 +573,14 @@ discard block |
||
| 550 | 573 | $context['preview_subject'] = $form_subject; |
| 551 | 574 | |
| 552 | 575 | censorText($context['preview_subject']); |
| 576 | + } else { |
|
| 577 | + $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 553 | 578 | } |
| 554 | - else |
|
| 555 | - $context['preview_subject'] = '<em>' . $txt['no_subject'] . '</em>'; |
|
| 556 | 579 | |
| 557 | 580 | // Protect any CDATA blocks. |
| 558 | - if (isset($_REQUEST['xml'])) |
|
| 559 | - $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]><![CDATA[>')); |
|
| 581 | + if (isset($_REQUEST['xml'])) { |
|
| 582 | + $context['preview_message'] = strtr($context['preview_message'], array(']]>' => ']]]]>< == 0) |
|
| 599 | - fatal_lang_error('no_board', false); |
|
| 622 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 623 | + fatal_lang_error('no_board', false); |
|
| 624 | + } |
|
| 600 | 625 | $row = $smcFunc['db_fetch_assoc']($request); |
| 601 | 626 | |
| 602 | 627 | $attachment_stuff = array($row); |
| 603 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 604 | - $attachment_stuff[] = $row2; |
|
| 628 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 629 | + $attachment_stuff[] = $row2; |
|
| 630 | + } |
|
| 605 | 631 | $smcFunc['db_free_result']($request); |
| 606 | 632 | |
| 607 | 633 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 608 | 634 | { |
| 609 | 635 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 610 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 611 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 612 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 613 | - isAllowedTo('modify_replies'); |
|
| 614 | - else |
|
| 615 | - isAllowedTo('modify_own'); |
|
| 636 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 637 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 638 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 639 | + isAllowedTo('modify_replies'); |
|
| 640 | + } else { |
|
| 641 | + isAllowedTo('modify_own'); |
|
| 642 | + } |
|
| 643 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 644 | + isAllowedTo('modify_replies'); |
|
| 645 | + } else { |
|
| 646 | + isAllowedTo('modify_any'); |
|
| 616 | 647 | } |
| 617 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 618 | - isAllowedTo('modify_replies'); |
|
| 619 | - else |
|
| 620 | - isAllowedTo('modify_any'); |
|
| 621 | 648 | |
| 622 | 649 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 623 | 650 | { |
@@ -641,8 +668,9 @@ discard block |
||
| 641 | 668 | |
| 642 | 669 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 643 | 670 | { |
| 644 | - if ($row['filesize'] <= 0) |
|
| 645 | - continue; |
|
| 671 | + if ($row['filesize'] <= 0) { |
|
| 672 | + continue; |
|
| 673 | + } |
|
| 646 | 674 | $context['current_attachments'][$row['id_attach']] = array( |
| 647 | 675 | 'name' => $smcFunc['htmlspecialchars']($row['filename']), |
| 648 | 676 | 'size' => $row['filesize'], |
@@ -712,29 +740,32 @@ discard block |
||
| 712 | 740 | ) |
| 713 | 741 | ); |
| 714 | 742 | // The message they were trying to edit was most likely deleted. |
| 715 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 716 | - fatal_lang_error('no_message', false); |
|
| 743 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 744 | + fatal_lang_error('no_message', false); |
|
| 745 | + } |
|
| 717 | 746 | $row = $smcFunc['db_fetch_assoc']($request); |
| 718 | 747 | |
| 719 | 748 | $attachment_stuff = array($row); |
| 720 | - while ($row2 = $smcFunc['db_fetch_assoc']($request)) |
|
| 721 | - $attachment_stuff[] = $row2; |
|
| 749 | + while ($row2 = $smcFunc['db_fetch_assoc']($request)) { |
|
| 750 | + $attachment_stuff[] = $row2; |
|
| 751 | + } |
|
| 722 | 752 | $smcFunc['db_free_result']($request); |
| 723 | 753 | |
| 724 | 754 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 725 | 755 | { |
| 726 | 756 | // Give an extra five minutes over the disable time threshold, so they can type - assuming the post is public. |
| 727 | - if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 728 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 729 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 730 | - isAllowedTo('modify_replies'); |
|
| 731 | - else |
|
| 732 | - isAllowedTo('modify_own'); |
|
| 757 | + if ($row['approved'] && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 758 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 759 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 760 | + isAllowedTo('modify_replies'); |
|
| 761 | + } else { |
|
| 762 | + isAllowedTo('modify_own'); |
|
| 763 | + } |
|
| 764 | + } elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 765 | + isAllowedTo('modify_replies'); |
|
| 766 | + } else { |
|
| 767 | + isAllowedTo('modify_any'); |
|
| 733 | 768 | } |
| 734 | - elseif ($row['id_member_poster'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 735 | - isAllowedTo('modify_replies'); |
|
| 736 | - else |
|
| 737 | - isAllowedTo('modify_any'); |
|
| 738 | 769 | |
| 739 | 770 | if ($context['can_announce'] && !empty($row['id_action'])) |
| 740 | 771 | { |
@@ -761,15 +792,17 @@ discard block |
||
| 761 | 792 | $context['icon'] = $row['icon']; |
| 762 | 793 | |
| 763 | 794 | // Show an "approve" box if the user can approve it, and the message isn't approved. |
| 764 | - if (!$row['approved'] && !$context['show_approval']) |
|
| 765 | - $context['show_approval'] = allowedTo('approve_posts'); |
|
| 795 | + if (!$row['approved'] && !$context['show_approval']) { |
|
| 796 | + $context['show_approval'] = allowedTo('approve_posts'); |
|
| 797 | + } |
|
| 766 | 798 | |
| 767 | 799 | // Sort the attachments so they are in the order saved |
| 768 | 800 | $temp = array(); |
| 769 | 801 | foreach ($attachment_stuff as $attachment) |
| 770 | 802 | { |
| 771 | - if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) |
|
| 772 | - $temp[$attachment['id_attach']] = $attachment; |
|
| 803 | + if ($attachment['filesize'] >= 0 && !empty($modSettings['attachmentEnable'])) { |
|
| 804 | + $temp[$attachment['id_attach']] = $attachment; |
|
| 805 | + } |
|
| 773 | 806 | |
| 774 | 807 | } |
| 775 | 808 | ksort($temp); |
@@ -831,14 +864,16 @@ discard block |
||
| 831 | 864 | 'is_approved' => 1, |
| 832 | 865 | ) |
| 833 | 866 | ); |
| 834 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 835 | - fatal_lang_error('quoted_post_deleted', false); |
|
| 867 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 868 | + fatal_lang_error('quoted_post_deleted', false); |
|
| 869 | + } |
|
| 836 | 870 | list ($form_subject, $mname, $mdate, $form_message) = $smcFunc['db_fetch_row']($request); |
| 837 | 871 | $smcFunc['db_free_result']($request); |
| 838 | 872 | |
| 839 | 873 | // Add 'Re: ' to the front of the quoted subject. |
| 840 | - if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 841 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 874 | + if (trim($context['response_prefix']) != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 875 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 876 | + } |
|
| 842 | 877 | |
| 843 | 878 | // Censor the message and subject. |
| 844 | 879 | censorText($form_message); |
@@ -851,10 +886,11 @@ discard block |
||
| 851 | 886 | for ($i = 0, $n = count($parts); $i < $n; $i++) |
| 852 | 887 | { |
| 853 | 888 | // It goes 0 = outside, 1 = begin tag, 2 = inside, 3 = close tag, repeat. |
| 854 | - if ($i % 4 == 0) |
|
| 855 | - $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
| 889 | + if ($i % 4 == 0) { |
|
| 890 | + $parts[$i] = preg_replace_callback('~\[html\](.+?)\[/html\]~is', function($m) |
|
| 856 | 891 | { |
| 857 | 892 | return '[html]' . preg_replace('~<br\s?/?' . '>~i', '<br /><br>', "$m[1]") . '[/html]'; |
| 893 | + } |
|
| 858 | 894 | }, $parts[$i]); |
| 859 | 895 | } |
| 860 | 896 | $form_message = implode('', $parts); |
@@ -863,8 +899,9 @@ discard block |
||
| 863 | 899 | $form_message = preg_replace('~<br ?/?' . '>~i', "\n", $form_message); |
| 864 | 900 | |
| 865 | 901 | // Remove any nested quotes, if necessary. |
| 866 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 867 | - $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 902 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 903 | + $form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message); |
|
| 904 | + } |
|
| 868 | 905 | |
| 869 | 906 | // Add a quote string on the front and end. |
| 870 | 907 | $form_message = '[quote author=' . $mname . ' link=msg=' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]'; |
@@ -876,15 +913,15 @@ discard block |
||
| 876 | 913 | $form_subject = $first_subject; |
| 877 | 914 | |
| 878 | 915 | // Add 'Re: ' to the front of the subject. |
| 879 | - if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) |
|
| 880 | - $form_subject = $context['response_prefix'] . $form_subject; |
|
| 916 | + if (trim($context['response_prefix']) != '' && $form_subject != '' && $smcFunc['strpos']($form_subject, trim($context['response_prefix'])) !== 0) { |
|
| 917 | + $form_subject = $context['response_prefix'] . $form_subject; |
|
| 918 | + } |
|
| 881 | 919 | |
| 882 | 920 | // Censor the subject. |
| 883 | 921 | censorText($form_subject); |
| 884 | 922 | |
| 885 | 923 | $form_message = ''; |
| 886 | - } |
|
| 887 | - else |
|
| 924 | + } else |
|
| 888 | 925 | { |
| 889 | 926 | $form_subject = isset($_GET['subject']) ? $_GET['subject'] : ''; |
| 890 | 927 | $form_message = ''; |
@@ -902,13 +939,15 @@ discard block |
||
| 902 | 939 | if (isset($_REQUEST['msg'])) |
| 903 | 940 | { |
| 904 | 941 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 905 | - foreach ($context['current_attachments'] as $attachment) |
|
| 906 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 942 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 943 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 944 | + } |
|
| 907 | 945 | } |
| 908 | 946 | |
| 909 | 947 | // A bit of house keeping first. |
| 910 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 911 | - unset($_SESSION['temp_attachments']); |
|
| 948 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 949 | + unset($_SESSION['temp_attachments']); |
|
| 950 | + } |
|
| 912 | 951 | |
| 913 | 952 | if (!empty($_SESSION['temp_attachments'])) |
| 914 | 953 | { |
@@ -917,9 +956,10 @@ discard block |
||
| 917 | 956 | { |
| 918 | 957 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 919 | 958 | { |
| 920 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 921 | - if (file_exists($attachment['tmp_name'])) |
|
| 959 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) { |
|
| 960 | + if (file_exists($attachment['tmp_name'])) |
|
| 922 | 961 | unlink($attachment['tmp_name']); |
| 962 | + } |
|
| 923 | 963 | } |
| 924 | 964 | $post_errors[] = 'temp_attachments_gone'; |
| 925 | 965 | $_SESSION['temp_attachments'] = array(); |
@@ -933,8 +973,9 @@ discard block |
||
| 933 | 973 | // See if any files still exist before showing the warning message and the files attached. |
| 934 | 974 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 935 | 975 | { |
| 936 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 937 | - continue; |
|
| 976 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 977 | + continue; |
|
| 978 | + } |
|
| 938 | 979 | |
| 939 | 980 | if (file_exists($attachment['tmp_name'])) |
| 940 | 981 | { |
@@ -944,20 +985,21 @@ discard block |
||
| 944 | 985 | break; |
| 945 | 986 | } |
| 946 | 987 | } |
| 947 | - } |
|
| 948 | - else |
|
| 988 | + } else |
|
| 949 | 989 | { |
| 950 | 990 | // Since, they don't belong here. Let's inform the user that they exist.. |
| 951 | - if (!empty($topic)) |
|
| 952 | - $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 953 | - else |
|
| 954 | - $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 991 | + if (!empty($topic)) { |
|
| 992 | + $delete_url = $scripturl . '?action=post' . (!empty($_REQUEST['msg']) ? (';msg=' . $_REQUEST['msg']) : '') . (!empty($_REQUEST['last_msg']) ? (';last_msg=' . $_REQUEST['last_msg']) : '') . ';topic=' . $topic . ';delete_temp'; |
|
| 993 | + } else { |
|
| 994 | + $delete_url = $scripturl . '?action=post;board=' . $board . ';delete_temp'; |
|
| 995 | + } |
|
| 955 | 996 | |
| 956 | 997 | // Compile a list of the files to show the user. |
| 957 | 998 | $file_list = array(); |
| 958 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 959 | - if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 999 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) { |
|
| 1000 | + if (strpos($attachID, 'post_tmp_' . $user_info['id']) !== false) |
|
| 960 | 1001 | $file_list[] = $attachment['name']; |
| 1002 | + } |
|
| 961 | 1003 | |
| 962 | 1004 | $_SESSION['temp_attachments']['post']['files'] = $file_list; |
| 963 | 1005 | $file_list = '<div class="attachments">' . implode('<br>', $file_list) . '</div>'; |
@@ -969,8 +1011,7 @@ discard block |
||
| 969 | 1011 | |
| 970 | 1012 | $post_errors[] = array('temp_attachments_found', array($delete_url, $goback_url, $file_list)); |
| 971 | 1013 | $context['ignore_temp_attachments'] = true; |
| 972 | - } |
|
| 973 | - else |
|
| 1014 | + } else |
|
| 974 | 1015 | { |
| 975 | 1016 | $post_errors[] = array('temp_attachments_lost', array($delete_url, $file_list)); |
| 976 | 1017 | $context['ignore_temp_attachments'] = true; |
@@ -978,16 +1019,19 @@ discard block |
||
| 978 | 1019 | } |
| 979 | 1020 | } |
| 980 | 1021 | |
| 981 | - if (!empty($context['we_are_history'])) |
|
| 982 | - $post_errors[] = $context['we_are_history']; |
|
| 1022 | + if (!empty($context['we_are_history'])) { |
|
| 1023 | + $post_errors[] = $context['we_are_history']; |
|
| 1024 | + } |
|
| 983 | 1025 | |
| 984 | 1026 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 985 | 1027 | { |
| 986 | - if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) |
|
| 987 | - break; |
|
| 1028 | + if (isset($context['ignore_temp_attachments']) || isset($_SESSION['temp_attachments']['post']['files'])) { |
|
| 1029 | + break; |
|
| 1030 | + } |
|
| 988 | 1031 | |
| 989 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 990 | - continue; |
|
| 1032 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 1033 | + continue; |
|
| 1034 | + } |
|
| 991 | 1035 | |
| 992 | 1036 | if ($attachID == 'initial_error') |
| 993 | 1037 | { |
@@ -1002,15 +1046,17 @@ discard block |
||
| 1002 | 1046 | { |
| 1003 | 1047 | $txt['error_attach_errors'] = empty($txt['error_attach_errors']) ? '<br>' : ''; |
| 1004 | 1048 | $txt['error_attach_errors'] .= vsprintf($txt['attach_warning'], $attachment['name']) . '<div style="padding: 0 1em;">'; |
| 1005 | - foreach ($attachment['errors'] as $error) |
|
| 1006 | - $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 1049 | + foreach ($attachment['errors'] as $error) { |
|
| 1050 | + $txt['error_attach_errors'] .= (is_array($error) ? vsprintf($txt[$error[0]], $error[1]) : $txt[$error]) . '<br >'; |
|
| 1051 | + } |
|
| 1007 | 1052 | $txt['error_attach_errors'] .= '</div>'; |
| 1008 | 1053 | $post_errors[] = 'attach_errors'; |
| 1009 | 1054 | |
| 1010 | 1055 | // Take out the trash. |
| 1011 | 1056 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1012 | - if (file_exists($attachment['tmp_name'])) |
|
| 1013 | - unlink($attachment['tmp_name']); |
|
| 1057 | + if (file_exists($attachment['tmp_name'])) { |
|
| 1058 | + unlink($attachment['tmp_name']); |
|
| 1059 | + } |
|
| 1014 | 1060 | continue; |
| 1015 | 1061 | } |
| 1016 | 1062 | |
@@ -1023,8 +1069,9 @@ discard block |
||
| 1023 | 1069 | |
| 1024 | 1070 | $context['attachments']['quantity']++; |
| 1025 | 1071 | $context['attachments']['total_size'] += $attachment['size']; |
| 1026 | - if (!isset($context['files_in_session_warning'])) |
|
| 1027 | - $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1072 | + if (!isset($context['files_in_session_warning'])) { |
|
| 1073 | + $context['files_in_session_warning'] = $txt['attached_files_in_session']; |
|
| 1074 | + } |
|
| 1028 | 1075 | |
| 1029 | 1076 | $context['current_attachments'][$attachID] = array( |
| 1030 | 1077 | 'name' => '<u>' . $smcFunc['htmlspecialchars']($attachment['name']) . '</u>', |
@@ -1052,8 +1099,9 @@ discard block |
||
| 1052 | 1099 | } |
| 1053 | 1100 | |
| 1054 | 1101 | // If they came from quick reply, and have to enter verification details, give them some notice. |
| 1055 | - if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) |
|
| 1056 | - $post_errors[] = 'need_qr_verification'; |
|
| 1102 | + if (!empty($_REQUEST['from_qr']) && !empty($context['require_verification'])) { |
|
| 1103 | + $post_errors[] = 'need_qr_verification'; |
|
| 1104 | + } |
|
| 1057 | 1105 | |
| 1058 | 1106 | /* |
| 1059 | 1107 | * There are two error types: serious and minor. Serious errors |
@@ -1070,52 +1118,56 @@ discard block |
||
| 1070 | 1118 | { |
| 1071 | 1119 | loadLanguage('Errors'); |
| 1072 | 1120 | $context['error_type'] = 'minor'; |
| 1073 | - foreach ($post_errors as $post_error) |
|
| 1074 | - if (is_array($post_error)) |
|
| 1121 | + foreach ($post_errors as $post_error) { |
|
| 1122 | + if (is_array($post_error)) |
|
| 1075 | 1123 | { |
| 1076 | 1124 | $post_error_id = $post_error[0]; |
| 1125 | + } |
|
| 1077 | 1126 | $context['post_error'][$post_error_id] = vsprintf($txt['error_' . $post_error_id], $post_error[1]); |
| 1078 | 1127 | |
| 1079 | 1128 | // If it's not a minor error flag it as such. |
| 1080 | - if (!in_array($post_error_id, $minor_errors)) |
|
| 1081 | - $context['error_type'] = 'serious'; |
|
| 1082 | - } |
|
| 1083 | - else |
|
| 1129 | + if (!in_array($post_error_id, $minor_errors)) { |
|
| 1130 | + $context['error_type'] = 'serious'; |
|
| 1131 | + } |
|
| 1132 | + } else |
|
| 1084 | 1133 | { |
| 1085 | 1134 | $context['post_error'][$post_error] = $txt['error_' . $post_error]; |
| 1086 | 1135 | |
| 1087 | 1136 | // If it's not a minor error flag it as such. |
| 1088 | - if (!in_array($post_error, $minor_errors)) |
|
| 1089 | - $context['error_type'] = 'serious'; |
|
| 1137 | + if (!in_array($post_error, $minor_errors)) { |
|
| 1138 | + $context['error_type'] = 'serious'; |
|
| 1139 | + } |
|
| 1090 | 1140 | } |
| 1091 | 1141 | } |
| 1092 | 1142 | |
| 1093 | 1143 | // What are you doing? Posting a poll, modifying, previewing, new post, or reply... |
| 1094 | - if (isset($_REQUEST['poll'])) |
|
| 1095 | - $context['page_title'] = $txt['new_poll']; |
|
| 1096 | - elseif ($context['make_event']) |
|
| 1097 | - $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1098 | - elseif (isset($_REQUEST['msg'])) |
|
| 1099 | - $context['page_title'] = $txt['modify_msg']; |
|
| 1100 | - elseif (isset($_REQUEST['subject'], $context['preview_subject'])) |
|
| 1101 | - $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1102 | - elseif (empty($topic)) |
|
| 1103 | - $context['page_title'] = $txt['start_new_topic']; |
|
| 1104 | - else |
|
| 1105 | - $context['page_title'] = $txt['post_reply']; |
|
| 1144 | + if (isset($_REQUEST['poll'])) { |
|
| 1145 | + $context['page_title'] = $txt['new_poll']; |
|
| 1146 | + } elseif ($context['make_event']) { |
|
| 1147 | + $context['page_title'] = $context['event']['id'] == -1 ? $txt['calendar_post_event'] : $txt['calendar_edit']; |
|
| 1148 | + } elseif (isset($_REQUEST['msg'])) { |
|
| 1149 | + $context['page_title'] = $txt['modify_msg']; |
|
| 1150 | + } elseif (isset($_REQUEST['subject'], $context['preview_subject'])) { |
|
| 1151 | + $context['page_title'] = $txt['preview'] . ' - ' . strip_tags($context['preview_subject']); |
|
| 1152 | + } elseif (empty($topic)) { |
|
| 1153 | + $context['page_title'] = $txt['start_new_topic']; |
|
| 1154 | + } else { |
|
| 1155 | + $context['page_title'] = $txt['post_reply']; |
|
| 1156 | + } |
|
| 1106 | 1157 | |
| 1107 | 1158 | // Build the link tree. |
| 1108 | - if (empty($topic)) |
|
| 1109 | - $context['linktree'][] = array( |
|
| 1159 | + if (empty($topic)) { |
|
| 1160 | + $context['linktree'][] = array( |
|
| 1110 | 1161 | 'name' => '<em>' . $txt['start_new_topic'] . '</em>' |
| 1111 | 1162 | ); |
| 1112 | - else |
|
| 1113 | - $context['linktree'][] = array( |
|
| 1163 | + } else { |
|
| 1164 | + $context['linktree'][] = array( |
|
| 1114 | 1165 | 'url' => $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start'], |
| 1115 | 1166 | 'name' => $form_subject, |
| 1116 | 1167 | 'extra_before' => '<span><strong class="nav">' . $context['page_title'] . ' (</strong></span>', |
| 1117 | 1168 | 'extra_after' => '<span><strong class="nav">)</strong></span>' |
| 1118 | 1169 | ); |
| 1170 | + } |
|
| 1119 | 1171 | |
| 1120 | 1172 | $context['subject'] = addcslashes($form_subject, '"'); |
| 1121 | 1173 | $context['message'] = str_replace(array('"', '<', '>', ' '), array('"', '<', '>', ' '), $form_message); |
@@ -1159,8 +1211,9 @@ discard block |
||
| 1159 | 1211 | // Message icons - customized icons are off? |
| 1160 | 1212 | $context['icons'] = getMessageIcons($board); |
| 1161 | 1213 | |
| 1162 | - if (!empty($context['icons'])) |
|
| 1163 | - $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1214 | + if (!empty($context['icons'])) { |
|
| 1215 | + $context['icons'][count($context['icons']) - 1]['is_last'] = true; |
|
| 1216 | + } |
|
| 1164 | 1217 | |
| 1165 | 1218 | // Are we starting a poll? if set the poll icon as selected if its available |
| 1166 | 1219 | if (isset($_REQUEST['poll'])) |
@@ -1180,8 +1233,9 @@ discard block |
||
| 1180 | 1233 | for ($i = 0, $n = count($context['icons']); $i < $n; $i++) |
| 1181 | 1234 | { |
| 1182 | 1235 | $context['icons'][$i]['selected'] = $context['icon'] == $context['icons'][$i]['value']; |
| 1183 | - if ($context['icons'][$i]['selected']) |
|
| 1184 | - $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1236 | + if ($context['icons'][$i]['selected']) { |
|
| 1237 | + $context['icon_url'] = $context['icons'][$i]['url']; |
|
| 1238 | + } |
|
| 1185 | 1239 | } |
| 1186 | 1240 | if (empty($context['icon_url'])) |
| 1187 | 1241 | { |
@@ -1195,8 +1249,9 @@ discard block |
||
| 1195 | 1249 | )); |
| 1196 | 1250 | } |
| 1197 | 1251 | |
| 1198 | - if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) |
|
| 1199 | - getTopic(); |
|
| 1252 | + if (!empty($topic) && !empty($modSettings['topicSummaryPosts'])) { |
|
| 1253 | + getTopic(); |
|
| 1254 | + } |
|
| 1200 | 1255 | |
| 1201 | 1256 | // If the user can post attachments prepare the warning labels. |
| 1202 | 1257 | if ($context['can_post_attachment']) |
@@ -1207,12 +1262,13 @@ discard block |
||
| 1207 | 1262 | $context['attachment_restrictions'] = array(); |
| 1208 | 1263 | $context['allowed_extensions'] = strtr(strtolower($modSettings['attachmentExtensions']), array(',' => ', ')); |
| 1209 | 1264 | $attachmentRestrictionTypes = array('attachmentNumPerPostLimit', 'attachmentPostLimit', 'attachmentSizeLimit'); |
| 1210 | - foreach ($attachmentRestrictionTypes as $type) |
|
| 1211 | - if (!empty($modSettings[$type])) |
|
| 1265 | + foreach ($attachmentRestrictionTypes as $type) { |
|
| 1266 | + if (!empty($modSettings[$type])) |
|
| 1212 | 1267 | { |
| 1213 | 1268 | // Show the max number of attachments if not 0. |
| 1214 | 1269 | if ($type == 'attachmentNumPerPostLimit') |
| 1215 | 1270 | $context['attachment_restrictions'][] = sprintf($txt['attach_remaining'], $modSettings['attachmentNumPerPostLimit'] - $context['attachments']['quantity']); |
| 1271 | + } |
|
| 1216 | 1272 | } |
| 1217 | 1273 | } |
| 1218 | 1274 | |
@@ -1246,8 +1302,8 @@ discard block |
||
| 1246 | 1302 | |
| 1247 | 1303 | if (!empty($context['current_attachments'])) |
| 1248 | 1304 | { |
| 1249 | - foreach ($context['current_attachments'] as $key => $mock) |
|
| 1250 | - addInlineJavaScript(' |
|
| 1305 | + foreach ($context['current_attachments'] as $key => $mock) { |
|
| 1306 | + addInlineJavaScript(' |
|
| 1251 | 1307 | current_attachments.push({ |
| 1252 | 1308 | name: '. JavaScriptEscape($mock['name']) . ', |
| 1253 | 1309 | size: '. $mock['size'] . ', |
@@ -1256,6 +1312,7 @@ discard block |
||
| 1256 | 1312 | type: '. JavaScriptEscape(!empty($mock['mime_type']) ? $mock['mime_type'] : '') . ', |
| 1257 | 1313 | thumbID: '. (!empty($mock['thumb']) ? $mock['thumb'] : 0) . ' |
| 1258 | 1314 | });', true); |
| 1315 | + } |
|
| 1259 | 1316 | } |
| 1260 | 1317 | |
| 1261 | 1318 | // File Upload. |
@@ -1341,8 +1398,9 @@ discard block |
||
| 1341 | 1398 | |
| 1342 | 1399 | |
| 1343 | 1400 | // Finally, load the template. |
| 1344 | - if (!isset($_REQUEST['xml'])) |
|
| 1345 | - loadTemplate('Post'); |
|
| 1401 | + if (!isset($_REQUEST['xml'])) { |
|
| 1402 | + loadTemplate('Post'); |
|
| 1403 | + } |
|
| 1346 | 1404 | |
| 1347 | 1405 | call_integration_hook('integrate_post_end'); |
| 1348 | 1406 | } |
@@ -1363,13 +1421,14 @@ discard block |
||
| 1363 | 1421 | // Sneaking off, are we? |
| 1364 | 1422 | if (empty($_POST) && empty($topic)) |
| 1365 | 1423 | { |
| 1366 | - if (empty($_SERVER['CONTENT_LENGTH'])) |
|
| 1367 | - redirectexit('action=post;board=' . $board . '.0'); |
|
| 1368 | - else |
|
| 1369 | - fatal_lang_error('post_upload_error', false); |
|
| 1424 | + if (empty($_SERVER['CONTENT_LENGTH'])) { |
|
| 1425 | + redirectexit('action=post;board=' . $board . '.0'); |
|
| 1426 | + } else { |
|
| 1427 | + fatal_lang_error('post_upload_error', false); |
|
| 1428 | + } |
|
| 1429 | + } elseif (empty($_POST) && !empty($topic)) { |
|
| 1430 | + redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1370 | 1431 | } |
| 1371 | - elseif (empty($_POST) && !empty($topic)) |
|
| 1372 | - redirectexit('action=post;topic=' . $topic . '.0'); |
|
| 1373 | 1432 | |
| 1374 | 1433 | // No need! |
| 1375 | 1434 | $context['robot_no_index'] = true; |
@@ -1381,8 +1440,9 @@ discard block |
||
| 1381 | 1440 | $post_errors = array(); |
| 1382 | 1441 | |
| 1383 | 1442 | // If the session has timed out, let the user re-submit their form. |
| 1384 | - if (checkSession('post', '', false) != '') |
|
| 1385 | - $post_errors[] = 'session_timeout'; |
|
| 1443 | + if (checkSession('post', '', false) != '') { |
|
| 1444 | + $post_errors[] = 'session_timeout'; |
|
| 1445 | + } |
|
| 1386 | 1446 | |
| 1387 | 1447 | // Wrong verification code? |
| 1388 | 1448 | if (!$user_info['is_admin'] && !$user_info['is_mod'] && !empty($modSettings['posts_require_captcha']) && ($user_info['posts'] < $modSettings['posts_require_captcha'] || ($user_info['is_guest'] && $modSettings['posts_require_captcha'] == -1))) |
@@ -1392,33 +1452,38 @@ discard block |
||
| 1392 | 1452 | 'id' => 'post', |
| 1393 | 1453 | ); |
| 1394 | 1454 | $context['require_verification'] = create_control_verification($verificationOptions, true); |
| 1395 | - if (is_array($context['require_verification'])) |
|
| 1396 | - $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1455 | + if (is_array($context['require_verification'])) { |
|
| 1456 | + $post_errors = array_merge($post_errors, $context['require_verification']); |
|
| 1457 | + } |
|
| 1397 | 1458 | } |
| 1398 | 1459 | |
| 1399 | 1460 | require_once($sourcedir . '/Subs-Post.php'); |
| 1400 | 1461 | loadLanguage('Post'); |
| 1401 | 1462 | |
| 1402 | 1463 | // Drafts enabled and needed? |
| 1403 | - if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) |
|
| 1404 | - require_once($sourcedir . '/Drafts.php'); |
|
| 1464 | + if (!empty($modSettings['drafts_post_enabled']) && (isset($_POST['save_draft']) || isset($_POST['id_draft']))) { |
|
| 1465 | + require_once($sourcedir . '/Drafts.php'); |
|
| 1466 | + } |
|
| 1405 | 1467 | |
| 1406 | 1468 | // First check to see if they are trying to delete any current attachments. |
| 1407 | 1469 | if (isset($_POST['attach_del'])) |
| 1408 | 1470 | { |
| 1409 | 1471 | $keep_temp = array(); |
| 1410 | 1472 | $keep_ids = array(); |
| 1411 | - foreach ($_POST['attach_del'] as $dummy) |
|
| 1412 | - if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1473 | + foreach ($_POST['attach_del'] as $dummy) { |
|
| 1474 | + if (strpos($dummy, 'post_tmp_' . $user_info['id']) !== false) |
|
| 1413 | 1475 | $keep_temp[] = $dummy; |
| 1414 | - else |
|
| 1415 | - $keep_ids[] = (int) $dummy; |
|
| 1476 | + } |
|
| 1477 | + else { |
|
| 1478 | + $keep_ids[] = (int) $dummy; |
|
| 1479 | + } |
|
| 1416 | 1480 | |
| 1417 | - if (isset($_SESSION['temp_attachments'])) |
|
| 1418 | - foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1481 | + if (isset($_SESSION['temp_attachments'])) { |
|
| 1482 | + foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
|
| 1419 | 1483 | { |
| 1420 | 1484 | if ((isset($_SESSION['temp_attachments']['post']['files'], $attachment['name']) && in_array($attachment['name'], $_SESSION['temp_attachments']['post']['files'])) || in_array($attachID, $keep_temp) || strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
| 1421 | 1485 | continue; |
| 1486 | + } |
|
| 1422 | 1487 | |
| 1423 | 1488 | unset($_SESSION['temp_attachments'][$attachID]); |
| 1424 | 1489 | unlink($attachment['tmp_name']); |
@@ -1460,24 +1525,28 @@ discard block |
||
| 1460 | 1525 | $smcFunc['db_free_result']($request); |
| 1461 | 1526 | |
| 1462 | 1527 | // Though the topic should be there, it might have vanished. |
| 1463 | - if (!is_array($topic_info)) |
|
| 1464 | - fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1528 | + if (!is_array($topic_info)) { |
|
| 1529 | + fatal_lang_error('topic_doesnt_exist', 404); |
|
| 1530 | + } |
|
| 1465 | 1531 | |
| 1466 | 1532 | // Did this topic suddenly move? Just checking... |
| 1467 | - if ($topic_info['id_board'] != $board) |
|
| 1468 | - fatal_lang_error('not_a_topic'); |
|
| 1533 | + if ($topic_info['id_board'] != $board) { |
|
| 1534 | + fatal_lang_error('not_a_topic'); |
|
| 1535 | + } |
|
| 1469 | 1536 | } |
| 1470 | 1537 | |
| 1471 | 1538 | // Replying to a topic? |
| 1472 | 1539 | if (!empty($topic) && !isset($_REQUEST['msg'])) |
| 1473 | 1540 | { |
| 1474 | 1541 | // Don't allow a post if it's locked. |
| 1475 | - if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) |
|
| 1476 | - fatal_lang_error('topic_locked', false); |
|
| 1542 | + if ($topic_info['locked'] != 0 && !allowedTo('moderate_board')) { |
|
| 1543 | + fatal_lang_error('topic_locked', false); |
|
| 1544 | + } |
|
| 1477 | 1545 | |
| 1478 | 1546 | // Sorry, multiple polls aren't allowed... yet. You should stop giving me ideas :P. |
| 1479 | - if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) |
|
| 1480 | - unset($_REQUEST['poll']); |
|
| 1547 | + if (isset($_REQUEST['poll']) && $topic_info['id_poll'] > 0) { |
|
| 1548 | + unset($_REQUEST['poll']); |
|
| 1549 | + } |
|
| 1481 | 1550 | |
| 1482 | 1551 | // Do the permissions and approval stuff... |
| 1483 | 1552 | $becomesApproved = true; |
@@ -1493,44 +1562,43 @@ discard block |
||
| 1493 | 1562 | |
| 1494 | 1563 | // Set a nice session var... |
| 1495 | 1564 | $_SESSION['becomesUnapproved'] = true; |
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1565 | + } elseif ($topic_info['id_member_started'] != $user_info['id']) |
|
| 1499 | 1566 | { |
| 1500 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) |
|
| 1501 | - $becomesApproved = false; |
|
| 1502 | - |
|
| 1503 | - else |
|
| 1504 | - isAllowedTo('post_reply_any'); |
|
| 1505 | - } |
|
| 1506 | - elseif (!allowedTo('post_reply_any')) |
|
| 1567 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_any') && !allowedTo('post_reply_any')) { |
|
| 1568 | + $becomesApproved = false; |
|
| 1569 | + } else { |
|
| 1570 | + isAllowedTo('post_reply_any'); |
|
| 1571 | + } |
|
| 1572 | + } elseif (!allowedTo('post_reply_any')) |
|
| 1507 | 1573 | { |
| 1508 | - if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) |
|
| 1509 | - $becomesApproved = false; |
|
| 1510 | - |
|
| 1511 | - else |
|
| 1512 | - isAllowedTo('post_reply_own'); |
|
| 1574 | + if ($modSettings['postmod_active'] && allowedTo('post_unapproved_replies_own') && !allowedTo('post_reply_own')) { |
|
| 1575 | + $becomesApproved = false; |
|
| 1576 | + } else { |
|
| 1577 | + isAllowedTo('post_reply_own'); |
|
| 1578 | + } |
|
| 1513 | 1579 | } |
| 1514 | 1580 | |
| 1515 | 1581 | if (isset($_POST['lock'])) |
| 1516 | 1582 | { |
| 1517 | 1583 | // Nothing is changed to the lock. |
| 1518 | - if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1519 | - unset($_POST['lock']); |
|
| 1584 | + if ((empty($topic_info['locked']) && empty($_POST['lock'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1585 | + unset($_POST['lock']); |
|
| 1586 | + } |
|
| 1520 | 1587 | |
| 1521 | 1588 | // You're have no permission to lock this topic. |
| 1522 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1523 | - unset($_POST['lock']); |
|
| 1589 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1590 | + unset($_POST['lock']); |
|
| 1591 | + } |
|
| 1524 | 1592 | |
| 1525 | 1593 | // You are allowed to (un)lock your own topic only. |
| 1526 | 1594 | elseif (!allowedTo('lock_any')) |
| 1527 | 1595 | { |
| 1528 | 1596 | // You cannot override a moderator lock. |
| 1529 | - if ($topic_info['locked'] == 1) |
|
| 1530 | - unset($_POST['lock']); |
|
| 1531 | - |
|
| 1532 | - else |
|
| 1533 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1597 | + if ($topic_info['locked'] == 1) { |
|
| 1598 | + unset($_POST['lock']); |
|
| 1599 | + } else { |
|
| 1600 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1601 | + } |
|
| 1534 | 1602 | } |
| 1535 | 1603 | // Hail mighty moderator, (un)lock this topic immediately. |
| 1536 | 1604 | else |
@@ -1538,19 +1606,21 @@ discard block |
||
| 1538 | 1606 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1539 | 1607 | |
| 1540 | 1608 | // Did someone (un)lock this while you were posting? |
| 1541 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1542 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1609 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1610 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1611 | + } |
|
| 1543 | 1612 | } |
| 1544 | 1613 | } |
| 1545 | 1614 | |
| 1546 | 1615 | // So you wanna (un)sticky this...let's see. |
| 1547 | - if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) |
|
| 1548 | - unset($_POST['sticky']); |
|
| 1549 | - elseif (isset($_POST['sticky'])) |
|
| 1616 | + if (isset($_POST['sticky']) && ($_POST['sticky'] == $topic_info['is_sticky'] || !allowedTo('make_sticky'))) { |
|
| 1617 | + unset($_POST['sticky']); |
|
| 1618 | + } elseif (isset($_POST['sticky'])) |
|
| 1550 | 1619 | { |
| 1551 | 1620 | // Did someone (un)sticky this while you were posting? |
| 1552 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1553 | - $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1621 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1622 | + $post_errors[] = 'topic_' . (empty($topic_info['is_sticky']) ? 'un' : '') . 'sticky'; |
|
| 1623 | + } |
|
| 1554 | 1624 | } |
| 1555 | 1625 | |
| 1556 | 1626 | // If drafts are enabled, then pass this off |
@@ -1577,26 +1647,31 @@ discard block |
||
| 1577 | 1647 | |
| 1578 | 1648 | // Do like, the permissions, for safety and stuff... |
| 1579 | 1649 | $becomesApproved = true; |
| 1580 | - if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) |
|
| 1581 | - $becomesApproved = false; |
|
| 1582 | - else |
|
| 1583 | - isAllowedTo('post_new'); |
|
| 1650 | + if ($modSettings['postmod_active'] && !allowedTo('post_new') && allowedTo('post_unapproved_topics')) { |
|
| 1651 | + $becomesApproved = false; |
|
| 1652 | + } else { |
|
| 1653 | + isAllowedTo('post_new'); |
|
| 1654 | + } |
|
| 1584 | 1655 | |
| 1585 | 1656 | if (isset($_POST['lock'])) |
| 1586 | 1657 | { |
| 1587 | 1658 | // New topics are by default not locked. |
| 1588 | - if (empty($_POST['lock'])) |
|
| 1589 | - unset($_POST['lock']); |
|
| 1659 | + if (empty($_POST['lock'])) { |
|
| 1660 | + unset($_POST['lock']); |
|
| 1661 | + } |
|
| 1590 | 1662 | // Besides, you need permission. |
| 1591 | - elseif (!allowedTo(array('lock_any', 'lock_own'))) |
|
| 1592 | - unset($_POST['lock']); |
|
| 1663 | + elseif (!allowedTo(array('lock_any', 'lock_own'))) { |
|
| 1664 | + unset($_POST['lock']); |
|
| 1665 | + } |
|
| 1593 | 1666 | // A moderator-lock (1) can override a user-lock (2). |
| 1594 | - else |
|
| 1595 | - $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1667 | + else { |
|
| 1668 | + $_POST['lock'] = allowedTo('lock_any') ? 1 : 2; |
|
| 1669 | + } |
|
| 1596 | 1670 | } |
| 1597 | 1671 | |
| 1598 | - if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) |
|
| 1599 | - unset($_POST['sticky']); |
|
| 1672 | + if (isset($_POST['sticky']) && (empty($_POST['sticky']) || !allowedTo('make_sticky'))) { |
|
| 1673 | + unset($_POST['sticky']); |
|
| 1674 | + } |
|
| 1600 | 1675 | |
| 1601 | 1676 | // Saving your new topic as a draft first? |
| 1602 | 1677 | if (!empty($modSettings['drafts_post_enabled']) && isset($_POST['save_draft'])) |
@@ -1621,31 +1696,37 @@ discard block |
||
| 1621 | 1696 | 'id_msg' => $_REQUEST['msg'], |
| 1622 | 1697 | ) |
| 1623 | 1698 | ); |
| 1624 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1625 | - fatal_lang_error('cant_find_messages', false); |
|
| 1699 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1700 | + fatal_lang_error('cant_find_messages', false); |
|
| 1701 | + } |
|
| 1626 | 1702 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1627 | 1703 | $smcFunc['db_free_result']($request); |
| 1628 | 1704 | |
| 1629 | - if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) |
|
| 1630 | - fatal_lang_error('topic_locked', false); |
|
| 1705 | + if (!empty($topic_info['locked']) && !allowedTo('moderate_board')) { |
|
| 1706 | + fatal_lang_error('topic_locked', false); |
|
| 1707 | + } |
|
| 1631 | 1708 | |
| 1632 | 1709 | if (isset($_POST['lock'])) |
| 1633 | 1710 | { |
| 1634 | 1711 | // Nothing changes to the lock status. |
| 1635 | - if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) |
|
| 1636 | - unset($_POST['lock']); |
|
| 1712 | + if ((empty($_POST['lock']) && empty($topic_info['locked'])) || (!empty($_POST['lock']) && !empty($topic_info['locked']))) { |
|
| 1713 | + unset($_POST['lock']); |
|
| 1714 | + } |
|
| 1637 | 1715 | // You're simply not allowed to (un)lock this. |
| 1638 | - elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) |
|
| 1639 | - unset($_POST['lock']); |
|
| 1716 | + elseif (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $topic_info['id_member_started'])) { |
|
| 1717 | + unset($_POST['lock']); |
|
| 1718 | + } |
|
| 1640 | 1719 | // You're only allowed to lock your own topics. |
| 1641 | 1720 | elseif (!allowedTo('lock_any')) |
| 1642 | 1721 | { |
| 1643 | 1722 | // You're not allowed to break a moderator's lock. |
| 1644 | - if ($topic_info['locked'] == 1) |
|
| 1645 | - unset($_POST['lock']); |
|
| 1723 | + if ($topic_info['locked'] == 1) { |
|
| 1724 | + unset($_POST['lock']); |
|
| 1725 | + } |
|
| 1646 | 1726 | // Lock it with a soft lock or unlock it. |
| 1647 | - else |
|
| 1648 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1727 | + else { |
|
| 1728 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 1729 | + } |
|
| 1649 | 1730 | } |
| 1650 | 1731 | // You must be the moderator. |
| 1651 | 1732 | else |
@@ -1653,44 +1734,46 @@ discard block |
||
| 1653 | 1734 | $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
| 1654 | 1735 | |
| 1655 | 1736 | // Did someone (un)lock this while you were posting? |
| 1656 | - if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) |
|
| 1657 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1737 | + if (isset($_POST['already_locked']) && $_POST['already_locked'] != $topic_info['locked']) { |
|
| 1738 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'locked'; |
|
| 1739 | + } |
|
| 1658 | 1740 | } |
| 1659 | 1741 | } |
| 1660 | 1742 | |
| 1661 | 1743 | // Change the sticky status of this topic? |
| 1662 | - if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) |
|
| 1663 | - unset($_POST['sticky']); |
|
| 1664 | - elseif (isset($_POST['sticky'])) |
|
| 1744 | + if (isset($_POST['sticky']) && (!allowedTo('make_sticky') || $_POST['sticky'] == $topic_info['is_sticky'])) { |
|
| 1745 | + unset($_POST['sticky']); |
|
| 1746 | + } elseif (isset($_POST['sticky'])) |
|
| 1665 | 1747 | { |
| 1666 | 1748 | // Did someone (un)sticky this while you were posting? |
| 1667 | - if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) |
|
| 1668 | - $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1749 | + if (isset($_POST['already_sticky']) && $_POST['already_sticky'] != $topic_info['is_sticky']) { |
|
| 1750 | + $post_errors[] = 'topic_' . (empty($topic_info['locked']) ? 'un' : '') . 'stickied'; |
|
| 1751 | + } |
|
| 1669 | 1752 | } |
| 1670 | 1753 | |
| 1671 | 1754 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 1672 | 1755 | { |
| 1673 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 1674 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 1675 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 1676 | - isAllowedTo('modify_replies'); |
|
| 1677 | - else |
|
| 1678 | - isAllowedTo('modify_own'); |
|
| 1679 | - } |
|
| 1680 | - elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1756 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 1757 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 1758 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 1759 | + isAllowedTo('modify_replies'); |
|
| 1760 | + } else { |
|
| 1761 | + isAllowedTo('modify_own'); |
|
| 1762 | + } |
|
| 1763 | + } elseif ($topic_info['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 1681 | 1764 | { |
| 1682 | 1765 | isAllowedTo('modify_replies'); |
| 1683 | 1766 | |
| 1684 | 1767 | // If you're modifying a reply, I say it better be logged... |
| 1685 | 1768 | $moderationAction = true; |
| 1686 | - } |
|
| 1687 | - else |
|
| 1769 | + } else |
|
| 1688 | 1770 | { |
| 1689 | 1771 | isAllowedTo('modify_any'); |
| 1690 | 1772 | |
| 1691 | 1773 | // Log it, assuming you're not modifying your own post. |
| 1692 | - if ($row['id_member'] != $user_info['id']) |
|
| 1693 | - $moderationAction = true; |
|
| 1774 | + if ($row['id_member'] != $user_info['id']) { |
|
| 1775 | + $moderationAction = true; |
|
| 1776 | + } |
|
| 1694 | 1777 | } |
| 1695 | 1778 | |
| 1696 | 1779 | // If drafts are enabled, then lets send this off to save |
@@ -1727,20 +1810,24 @@ discard block |
||
| 1727 | 1810 | $_POST['guestname'] = !isset($_POST['guestname']) ? '' : trim($_POST['guestname']); |
| 1728 | 1811 | $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']); |
| 1729 | 1812 | |
| 1730 | - if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') |
|
| 1731 | - $post_errors[] = 'no_name'; |
|
| 1732 | - if ($smcFunc['strlen']($_POST['guestname']) > 25) |
|
| 1733 | - $post_errors[] = 'long_name'; |
|
| 1813 | + if ($_POST['guestname'] == '' || $_POST['guestname'] == '_') { |
|
| 1814 | + $post_errors[] = 'no_name'; |
|
| 1815 | + } |
|
| 1816 | + if ($smcFunc['strlen']($_POST['guestname']) > 25) { |
|
| 1817 | + $post_errors[] = 'long_name'; |
|
| 1818 | + } |
|
| 1734 | 1819 | |
| 1735 | 1820 | if (empty($modSettings['guest_post_no_email'])) |
| 1736 | 1821 | { |
| 1737 | 1822 | // Only check if they changed it! |
| 1738 | 1823 | if (!isset($row) || $row['poster_email'] != $_POST['email']) |
| 1739 | 1824 | { |
| 1740 | - if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) |
|
| 1741 | - $post_errors[] = 'no_email'; |
|
| 1742 | - if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) |
|
| 1743 | - $post_errors[] = 'bad_email'; |
|
| 1825 | + if (!allowedTo('moderate_forum') && (!isset($_POST['email']) || $_POST['email'] == '')) { |
|
| 1826 | + $post_errors[] = 'no_email'; |
|
| 1827 | + } |
|
| 1828 | + if (!allowedTo('moderate_forum') && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 1829 | + $post_errors[] = 'bad_email'; |
|
| 1830 | + } |
|
| 1744 | 1831 | } |
| 1745 | 1832 | |
| 1746 | 1833 | // Now make sure this email address is not banned from posting. |
@@ -1756,75 +1843,89 @@ discard block |
||
| 1756 | 1843 | } |
| 1757 | 1844 | |
| 1758 | 1845 | // Coming from the quickReply? |
| 1759 | - if (isset($_POST['quickReply'])) |
|
| 1760 | - $_POST['message'] = $_POST['quickReply']; |
|
| 1846 | + if (isset($_POST['quickReply'])) { |
|
| 1847 | + $_POST['message'] = $_POST['quickReply']; |
|
| 1848 | + } |
|
| 1761 | 1849 | |
| 1762 | 1850 | // Check the subject and message. |
| 1763 | - if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') |
|
| 1764 | - $post_errors[] = 'no_subject'; |
|
| 1765 | - if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') |
|
| 1766 | - $post_errors[] = 'no_message'; |
|
| 1767 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 1768 | - $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1769 | - else |
|
| 1851 | + if (!isset($_POST['subject']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['subject'])) === '') { |
|
| 1852 | + $post_errors[] = 'no_subject'; |
|
| 1853 | + } |
|
| 1854 | + if (!isset($_POST['message']) || $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['message']), ENT_QUOTES) === '') { |
|
| 1855 | + $post_errors[] = 'no_message'; |
|
| 1856 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) { |
|
| 1857 | + $post_errors[] = array('long_message', array($modSettings['max_messageLength'])); |
|
| 1858 | + } else |
|
| 1770 | 1859 | { |
| 1771 | 1860 | // Prepare the message a bit for some additional testing. |
| 1772 | 1861 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 1773 | 1862 | |
| 1774 | 1863 | // Preparse code. (Zef) |
| 1775 | - if ($user_info['is_guest']) |
|
| 1776 | - $user_info['name'] = $_POST['guestname']; |
|
| 1864 | + if ($user_info['is_guest']) { |
|
| 1865 | + $user_info['name'] = $_POST['guestname']; |
|
| 1866 | + } |
|
| 1777 | 1867 | preparsecode($_POST['message']); |
| 1778 | 1868 | |
| 1779 | 1869 | // Let's see if there's still some content left without the tags. |
| 1780 | - if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) |
|
| 1781 | - $post_errors[] = 'no_message'; |
|
| 1870 | + if ($smcFunc['htmltrim'](strip_tags(parse_bbc($_POST['message'], false), implode('', $context['allowed_html_tags']))) === '' && (!allowedTo('admin_forum') || strpos($_POST['message'], '[html]') === false)) { |
|
| 1871 | + $post_errors[] = 'no_message'; |
|
| 1872 | + } |
|
| 1873 | + } |
|
| 1874 | + if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 1875 | + $post_errors[] = 'no_event'; |
|
| 1782 | 1876 | } |
| 1783 | - if (isset($_POST['calendar']) && !isset($_REQUEST['deleteevent']) && $smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 1784 | - $post_errors[] = 'no_event'; |
|
| 1785 | 1877 | // You are not! |
| 1786 | - if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) |
|
| 1787 | - fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1878 | + if (isset($_POST['message']) && strtolower($_POST['message']) == 'i am the administrator.' && !$user_info['is_admin']) { |
|
| 1879 | + fatal_error('Knave! Masquerader! Charlatan!', false); |
|
| 1880 | + } |
|
| 1788 | 1881 | |
| 1789 | 1882 | // Validate the poll... |
| 1790 | 1883 | if (isset($_REQUEST['poll']) && $modSettings['pollMode'] == '1') |
| 1791 | 1884 | { |
| 1792 | - if (!empty($topic) && !isset($_REQUEST['msg'])) |
|
| 1793 | - fatal_lang_error('no_access', false); |
|
| 1885 | + if (!empty($topic) && !isset($_REQUEST['msg'])) { |
|
| 1886 | + fatal_lang_error('no_access', false); |
|
| 1887 | + } |
|
| 1794 | 1888 | |
| 1795 | 1889 | // This is a new topic... so it's a new poll. |
| 1796 | - if (empty($topic)) |
|
| 1797 | - isAllowedTo('poll_post'); |
|
| 1890 | + if (empty($topic)) { |
|
| 1891 | + isAllowedTo('poll_post'); |
|
| 1892 | + } |
|
| 1798 | 1893 | // Can you add to your own topics? |
| 1799 | - elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) |
|
| 1800 | - isAllowedTo('poll_add_own'); |
|
| 1894 | + elseif ($user_info['id'] == $topic_info['id_member_started'] && !allowedTo('poll_add_any')) { |
|
| 1895 | + isAllowedTo('poll_add_own'); |
|
| 1896 | + } |
|
| 1801 | 1897 | // Can you add polls to any topic, then? |
| 1802 | - else |
|
| 1803 | - isAllowedTo('poll_add_any'); |
|
| 1898 | + else { |
|
| 1899 | + isAllowedTo('poll_add_any'); |
|
| 1900 | + } |
|
| 1804 | 1901 | |
| 1805 | - if (!isset($_POST['question']) || trim($_POST['question']) == '') |
|
| 1806 | - $post_errors[] = 'no_question'; |
|
| 1902 | + if (!isset($_POST['question']) || trim($_POST['question']) == '') { |
|
| 1903 | + $post_errors[] = 'no_question'; |
|
| 1904 | + } |
|
| 1807 | 1905 | |
| 1808 | 1906 | $_POST['options'] = empty($_POST['options']) ? array() : htmltrim__recursive($_POST['options']); |
| 1809 | 1907 | |
| 1810 | 1908 | // Get rid of empty ones. |
| 1811 | - foreach ($_POST['options'] as $k => $option) |
|
| 1812 | - if ($option == '') |
|
| 1909 | + foreach ($_POST['options'] as $k => $option) { |
|
| 1910 | + if ($option == '') |
|
| 1813 | 1911 | unset($_POST['options'][$k], $_POST['options'][$k]); |
| 1912 | + } |
|
| 1814 | 1913 | |
| 1815 | 1914 | // What are you going to vote between with one choice?!? |
| 1816 | - if (count($_POST['options']) < 2) |
|
| 1817 | - $post_errors[] = 'poll_few'; |
|
| 1818 | - elseif (count($_POST['options']) > 256) |
|
| 1819 | - $post_errors[] = 'poll_many'; |
|
| 1915 | + if (count($_POST['options']) < 2) { |
|
| 1916 | + $post_errors[] = 'poll_few'; |
|
| 1917 | + } elseif (count($_POST['options']) > 256) { |
|
| 1918 | + $post_errors[] = 'poll_many'; |
|
| 1919 | + } |
|
| 1820 | 1920 | } |
| 1821 | 1921 | |
| 1822 | 1922 | if ($posterIsGuest) |
| 1823 | 1923 | { |
| 1824 | 1924 | // If user is a guest, make sure the chosen name isn't taken. |
| 1825 | 1925 | require_once($sourcedir . '/Subs-Members.php'); |
| 1826 | - if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) |
|
| 1827 | - $post_errors[] = 'bad_name'; |
|
| 1926 | + if (isReservedName($_POST['guestname'], 0, true, false) && (!isset($row['poster_name']) || $_POST['guestname'] != $row['poster_name'])) { |
|
| 1927 | + $post_errors[] = 'bad_name'; |
|
| 1928 | + } |
|
| 1828 | 1929 | } |
| 1829 | 1930 | // If the user isn't a guest, get his or her name and email. |
| 1830 | 1931 | elseif (!isset($_REQUEST['msg'])) |
@@ -1855,8 +1956,9 @@ discard block |
||
| 1855 | 1956 | } |
| 1856 | 1957 | |
| 1857 | 1958 | // Make sure the user isn't spamming the board. |
| 1858 | - if (!isset($_REQUEST['msg'])) |
|
| 1859 | - spamProtection('post'); |
|
| 1959 | + if (!isset($_REQUEST['msg'])) { |
|
| 1960 | + spamProtection('post'); |
|
| 1961 | + } |
|
| 1860 | 1962 | |
| 1861 | 1963 | // At about this point, we're posting and that's that. |
| 1862 | 1964 | ignore_user_abort(true); |
@@ -1869,32 +1971,36 @@ discard block |
||
| 1869 | 1971 | $_POST['modify_reason'] = empty($_POST['modify_reason']) ? '' : strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 1870 | 1972 | |
| 1871 | 1973 | // At this point, we want to make sure the subject isn't too long. |
| 1872 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 1873 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1974 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 1975 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 1976 | + } |
|
| 1874 | 1977 | |
| 1875 | 1978 | // Same with the "why did you edit this" text. |
| 1876 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 1877 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1979 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 1980 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 1981 | + } |
|
| 1878 | 1982 | |
| 1879 | 1983 | // Make the poll... |
| 1880 | 1984 | if (isset($_REQUEST['poll'])) |
| 1881 | 1985 | { |
| 1882 | 1986 | // Make sure that the user has not entered a ridiculous number of options.. |
| 1883 | - if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) |
|
| 1884 | - $_POST['poll_max_votes'] = 1; |
|
| 1885 | - elseif ($_POST['poll_max_votes'] > count($_POST['options'])) |
|
| 1886 | - $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1887 | - else |
|
| 1888 | - $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1987 | + if (empty($_POST['poll_max_votes']) || $_POST['poll_max_votes'] <= 0) { |
|
| 1988 | + $_POST['poll_max_votes'] = 1; |
|
| 1989 | + } elseif ($_POST['poll_max_votes'] > count($_POST['options'])) { |
|
| 1990 | + $_POST['poll_max_votes'] = count($_POST['options']); |
|
| 1991 | + } else { |
|
| 1992 | + $_POST['poll_max_votes'] = (int) $_POST['poll_max_votes']; |
|
| 1993 | + } |
|
| 1889 | 1994 | |
| 1890 | 1995 | $_POST['poll_expire'] = (int) $_POST['poll_expire']; |
| 1891 | 1996 | $_POST['poll_expire'] = $_POST['poll_expire'] > 9999 ? 9999 : ($_POST['poll_expire'] < 0 ? 0 : $_POST['poll_expire']); |
| 1892 | 1997 | |
| 1893 | 1998 | // Just set it to zero if it's not there.. |
| 1894 | - if (!isset($_POST['poll_hide'])) |
|
| 1895 | - $_POST['poll_hide'] = 0; |
|
| 1896 | - else |
|
| 1897 | - $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 1999 | + if (!isset($_POST['poll_hide'])) { |
|
| 2000 | + $_POST['poll_hide'] = 0; |
|
| 2001 | + } else { |
|
| 2002 | + $_POST['poll_hide'] = (int) $_POST['poll_hide']; |
|
| 2003 | + } |
|
| 1898 | 2004 | $_POST['poll_change_vote'] = isset($_POST['poll_change_vote']) ? 1 : 0; |
| 1899 | 2005 | |
| 1900 | 2006 | $_POST['poll_guest_vote'] = isset($_POST['poll_guest_vote']) ? 1 : 0; |
@@ -1903,16 +2009,19 @@ discard block |
||
| 1903 | 2009 | { |
| 1904 | 2010 | require_once($sourcedir . '/Subs-Members.php'); |
| 1905 | 2011 | $allowedVoteGroups = groupsAllowedTo('poll_vote', $board); |
| 1906 | - if (!in_array(-1, $allowedVoteGroups['allowed'])) |
|
| 1907 | - $_POST['poll_guest_vote'] = 0; |
|
| 2012 | + if (!in_array(-1, $allowedVoteGroups['allowed'])) { |
|
| 2013 | + $_POST['poll_guest_vote'] = 0; |
|
| 2014 | + } |
|
| 1908 | 2015 | } |
| 1909 | 2016 | |
| 1910 | 2017 | // If the user tries to set the poll too far in advance, don't let them. |
| 1911 | - if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) |
|
| 1912 | - fatal_lang_error('poll_range_error', false); |
|
| 2018 | + if (!empty($_POST['poll_expire']) && $_POST['poll_expire'] < 1) { |
|
| 2019 | + fatal_lang_error('poll_range_error', false); |
|
| 2020 | + } |
|
| 1913 | 2021 | // Don't allow them to select option 2 for hidden results if it's not time limited. |
| 1914 | - elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) |
|
| 1915 | - $_POST['poll_hide'] = 1; |
|
| 2022 | + elseif (empty($_POST['poll_expire']) && $_POST['poll_hide'] == 2) { |
|
| 2023 | + $_POST['poll_hide'] = 1; |
|
| 2024 | + } |
|
| 1916 | 2025 | |
| 1917 | 2026 | // Clean up the question and answers. |
| 1918 | 2027 | $_POST['question'] = $smcFunc['htmlspecialchars']($_POST['question']); |
@@ -1926,13 +2035,15 @@ discard block |
||
| 1926 | 2035 | { |
| 1927 | 2036 | $attachIDs = array(); |
| 1928 | 2037 | $attach_errors = array(); |
| 1929 | - if (!empty($context['we_are_history'])) |
|
| 1930 | - $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 2038 | + if (!empty($context['we_are_history'])) { |
|
| 2039 | + $attach_errors[] = '<dd>' . $txt['error_temp_attachments_flushed'] . '<br><br></dd>'; |
|
| 2040 | + } |
|
| 1931 | 2041 | |
| 1932 | 2042 | foreach ($_SESSION['temp_attachments'] as $attachID => $attachment) |
| 1933 | 2043 | { |
| 1934 | - if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) |
|
| 1935 | - continue; |
|
| 2044 | + if ($attachID != 'initial_error' && strpos($attachID, 'post_tmp_' . $user_info['id']) === false) { |
|
| 2045 | + continue; |
|
| 2046 | + } |
|
| 1936 | 2047 | |
| 1937 | 2048 | // If there was an initial error just show that message. |
| 1938 | 2049 | if ($attachID == 'initial_error') |
@@ -1961,12 +2072,13 @@ discard block |
||
| 1961 | 2072 | if (createAttachment($attachmentOptions)) |
| 1962 | 2073 | { |
| 1963 | 2074 | $attachIDs[] = $attachmentOptions['id']; |
| 1964 | - if (!empty($attachmentOptions['thumb'])) |
|
| 1965 | - $attachIDs[] = $attachmentOptions['thumb']; |
|
| 2075 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 2076 | + $attachIDs[] = $attachmentOptions['thumb']; |
|
| 2077 | + } |
|
| 1966 | 2078 | } |
| 2079 | + } else { |
|
| 2080 | + $attach_errors[] = '<dt> </dt>'; |
|
| 1967 | 2081 | } |
| 1968 | - else |
|
| 1969 | - $attach_errors[] = '<dt> </dt>'; |
|
| 1970 | 2082 | |
| 1971 | 2083 | if (!empty($attachmentOptions['errors'])) |
| 1972 | 2084 | { |
@@ -1978,14 +2090,16 @@ discard block |
||
| 1978 | 2090 | if (!is_array($error)) |
| 1979 | 2091 | { |
| 1980 | 2092 | $attach_errors[] = '<dd>' . $txt[$error] . '</dd>'; |
| 1981 | - if (in_array($error, $log_these)) |
|
| 1982 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2093 | + if (in_array($error, $log_these)) { |
|
| 2094 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 2095 | + } |
|
| 2096 | + } else { |
|
| 2097 | + $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1983 | 2098 | } |
| 1984 | - else |
|
| 1985 | - $attach_errors[] = '<dd>' . vsprintf($txt[$error[0]], $error[1]) . '</dd>'; |
|
| 1986 | 2099 | } |
| 1987 | - if (file_exists($attachment['tmp_name'])) |
|
| 1988 | - unlink($attachment['tmp_name']); |
|
| 2100 | + if (file_exists($attachment['tmp_name'])) { |
|
| 2101 | + unlink($attachment['tmp_name']); |
|
| 2102 | + } |
|
| 1989 | 2103 | } |
| 1990 | 2104 | } |
| 1991 | 2105 | unset($_SESSION['temp_attachments']); |
@@ -2026,24 +2140,24 @@ discard block |
||
| 2026 | 2140 | ); |
| 2027 | 2141 | |
| 2028 | 2142 | call_integration_hook('integrate_poll_add_edit', array($id_poll, false)); |
| 2143 | + } else { |
|
| 2144 | + $id_poll = 0; |
|
| 2029 | 2145 | } |
| 2030 | - else |
|
| 2031 | - $id_poll = 0; |
|
| 2032 | 2146 | |
| 2033 | 2147 | // Creating a new topic? |
| 2034 | 2148 | $newTopic = empty($_REQUEST['msg']) && empty($topic); |
| 2035 | 2149 | |
| 2036 | 2150 | // Check the icon. |
| 2037 | - if (!isset($_POST['icon'])) |
|
| 2038 | - $_POST['icon'] = 'xx'; |
|
| 2039 | - |
|
| 2040 | - else |
|
| 2151 | + if (!isset($_POST['icon'])) { |
|
| 2152 | + $_POST['icon'] = 'xx'; |
|
| 2153 | + } else |
|
| 2041 | 2154 | { |
| 2042 | 2155 | $_POST['icon'] = $smcFunc['htmlspecialchars']($_POST['icon']); |
| 2043 | 2156 | |
| 2044 | 2157 | // Need to figure it out if this is a valid icon name. |
| 2045 | - if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) |
|
| 2046 | - $_POST['icon'] = 'xx'; |
|
| 2158 | + if ((!file_exists($settings['theme_dir'] . '/images/post/' . $_POST['icon'] . '.png')) && (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon'] . '.png'))) { |
|
| 2159 | + $_POST['icon'] = 'xx'; |
|
| 2160 | + } |
|
| 2047 | 2161 | } |
| 2048 | 2162 | |
| 2049 | 2163 | // Collect all parameters for the creation or modification of a post. |
@@ -2084,8 +2198,9 @@ discard block |
||
| 2084 | 2198 | } |
| 2085 | 2199 | |
| 2086 | 2200 | // This will save some time... |
| 2087 | - if (empty($approve_has_changed)) |
|
| 2088 | - unset($msgOptions['approved']); |
|
| 2201 | + if (empty($approve_has_changed)) { |
|
| 2202 | + unset($msgOptions['approved']); |
|
| 2203 | + } |
|
| 2089 | 2204 | |
| 2090 | 2205 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2091 | 2206 | } |
@@ -2094,8 +2209,9 @@ discard block |
||
| 2094 | 2209 | { |
| 2095 | 2210 | createPost($msgOptions, $topicOptions, $posterOptions); |
| 2096 | 2211 | |
| 2097 | - if (isset($topicOptions['id'])) |
|
| 2098 | - $topic = $topicOptions['id']; |
|
| 2212 | + if (isset($topicOptions['id'])) { |
|
| 2213 | + $topic = $topicOptions['id']; |
|
| 2214 | + } |
|
| 2099 | 2215 | } |
| 2100 | 2216 | |
| 2101 | 2217 | // Assign the previously uploaded attachments to the brand new message. |
@@ -2107,8 +2223,9 @@ discard block |
||
| 2107 | 2223 | } |
| 2108 | 2224 | |
| 2109 | 2225 | // If we had a draft for this, its time to remove it since it was just posted |
| 2110 | - if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) |
|
| 2111 | - DeleteDraft($_POST['id_draft']); |
|
| 2226 | + if (!empty($modSettings['drafts_post_enabled']) && !empty($_POST['id_draft'])) { |
|
| 2227 | + DeleteDraft($_POST['id_draft']); |
|
| 2228 | + } |
|
| 2112 | 2229 | |
| 2113 | 2230 | // Editing or posting an event? |
| 2114 | 2231 | if (isset($_POST['calendar']) && (!isset($_REQUEST['eventid']) || $_REQUEST['eventid'] == -1)) |
@@ -2127,8 +2244,7 @@ discard block |
||
| 2127 | 2244 | 'member' => $user_info['id'], |
| 2128 | 2245 | ); |
| 2129 | 2246 | insertEvent($eventOptions); |
| 2130 | - } |
|
| 2131 | - elseif (isset($_POST['calendar'])) |
|
| 2247 | + } elseif (isset($_POST['calendar'])) |
|
| 2132 | 2248 | { |
| 2133 | 2249 | $_REQUEST['eventid'] = (int) $_REQUEST['eventid']; |
| 2134 | 2250 | |
@@ -2156,14 +2272,15 @@ discard block |
||
| 2156 | 2272 | } |
| 2157 | 2273 | |
| 2158 | 2274 | // Delete it? |
| 2159 | - if (isset($_REQUEST['deleteevent'])) |
|
| 2160 | - $smcFunc['db_query']('', ' |
|
| 2275 | + if (isset($_REQUEST['deleteevent'])) { |
|
| 2276 | + $smcFunc['db_query']('', ' |
|
| 2161 | 2277 | DELETE FROM {db_prefix}calendar |
| 2162 | 2278 | WHERE id_event = {int:id_event}', |
| 2163 | 2279 | array( |
| 2164 | 2280 | 'id_event' => $_REQUEST['eventid'], |
| 2165 | 2281 | ) |
| 2166 | 2282 | ); |
| 2283 | + } |
|
| 2167 | 2284 | // ... or just update it? |
| 2168 | 2285 | else |
| 2169 | 2286 | { |
@@ -2205,9 +2322,8 @@ discard block |
||
| 2205 | 2322 | array($user_info['id'], $topic, 0), |
| 2206 | 2323 | array('id_member', 'id_topic', 'id_board') |
| 2207 | 2324 | ); |
| 2208 | - } |
|
| 2209 | - elseif (!$newTopic) |
|
| 2210 | - $smcFunc['db_query']('', ' |
|
| 2325 | + } elseif (!$newTopic) { |
|
| 2326 | + $smcFunc['db_query']('', ' |
|
| 2211 | 2327 | DELETE FROM {db_prefix}log_notify |
| 2212 | 2328 | WHERE id_member = {int:current_member} |
| 2213 | 2329 | AND id_topic = {int:current_topic}', |
@@ -2216,16 +2332,20 @@ discard block |
||
| 2216 | 2332 | 'current_topic' => $topic, |
| 2217 | 2333 | ) |
| 2218 | 2334 | ); |
| 2335 | + } |
|
| 2219 | 2336 | |
| 2220 | 2337 | // Log an act of moderation - modifying. |
| 2221 | - if (!empty($moderationAction)) |
|
| 2222 | - logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2338 | + if (!empty($moderationAction)) { |
|
| 2339 | + logAction('modify', array('topic' => $topic, 'message' => (int) $_REQUEST['msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 2340 | + } |
|
| 2223 | 2341 | |
| 2224 | - if (isset($_POST['lock']) && $_POST['lock'] != 2) |
|
| 2225 | - logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2342 | + if (isset($_POST['lock']) && $_POST['lock'] != 2) { |
|
| 2343 | + logAction(empty($_POST['lock']) ? 'unlock' : 'lock', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2344 | + } |
|
| 2226 | 2345 | |
| 2227 | - if (isset($_POST['sticky'])) |
|
| 2228 | - logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2346 | + if (isset($_POST['sticky'])) { |
|
| 2347 | + logAction(empty($_POST['sticky']) ? 'unsticky' : 'sticky', array('topic' => $topicOptions['id'], 'board' => $topicOptions['board'])); |
|
| 2348 | + } |
|
| 2229 | 2349 | |
| 2230 | 2350 | // Returning to the topic? |
| 2231 | 2351 | if (!empty($_REQUEST['goback'])) |
@@ -2244,26 +2364,31 @@ discard block |
||
| 2244 | 2364 | ); |
| 2245 | 2365 | } |
| 2246 | 2366 | |
| 2247 | - if ($board_info['num_topics'] == 0) |
|
| 2248 | - cache_put_data('board-' . $board, null, 120); |
|
| 2367 | + if ($board_info['num_topics'] == 0) { |
|
| 2368 | + cache_put_data('board-' . $board, null, 120); |
|
| 2369 | + } |
|
| 2249 | 2370 | |
| 2250 | 2371 | call_integration_hook('integrate_post2_end'); |
| 2251 | 2372 | |
| 2252 | - if (!empty($_POST['announce_topic'])) |
|
| 2253 | - redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2373 | + if (!empty($_POST['announce_topic'])) { |
|
| 2374 | + redirectexit('action=announce;sa=selectgroup;topic=' . $topic . (!empty($_POST['move']) && allowedTo('move_any') ? ';move' : '') . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2375 | + } |
|
| 2254 | 2376 | |
| 2255 | - if (!empty($_POST['move']) && allowedTo('move_any')) |
|
| 2256 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2377 | + if (!empty($_POST['move']) && allowedTo('move_any')) { |
|
| 2378 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2379 | + } |
|
| 2257 | 2380 | |
| 2258 | 2381 | // Return to post if the mod is on. |
| 2259 | - if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) |
|
| 2260 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2261 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2262 | - redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2382 | + if (isset($_REQUEST['msg']) && !empty($_REQUEST['goback'])) { |
|
| 2383 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'], isBrowser('ie')); |
|
| 2384 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2385 | + redirectexit('topic=' . $topic . '.new#new', isBrowser('ie')); |
|
| 2386 | + } |
|
| 2263 | 2387 | // Dut-dut-duh-duh-DUH-duh-dut-duh-duh! *dances to the Final Fantasy Fanfare...* |
| 2264 | - else |
|
| 2265 | - redirectexit('board=' . $board . '.0'); |
|
| 2266 | -} |
|
| 2388 | + else { |
|
| 2389 | + redirectexit('board=' . $board . '.0'); |
|
| 2390 | + } |
|
| 2391 | + } |
|
| 2267 | 2392 | |
| 2268 | 2393 | /** |
| 2269 | 2394 | * Handle the announce topic function (action=announce). |
@@ -2281,8 +2406,9 @@ discard block |
||
| 2281 | 2406 | |
| 2282 | 2407 | validateSession(); |
| 2283 | 2408 | |
| 2284 | - if (empty($topic)) |
|
| 2285 | - fatal_lang_error('topic_gone', false); |
|
| 2409 | + if (empty($topic)) { |
|
| 2410 | + fatal_lang_error('topic_gone', false); |
|
| 2411 | + } |
|
| 2286 | 2412 | |
| 2287 | 2413 | loadLanguage('Post'); |
| 2288 | 2414 | loadTemplate('Post'); |
@@ -2309,8 +2435,9 @@ discard block |
||
| 2309 | 2435 | global $txt, $context, $topic, $board_info, $smcFunc; |
| 2310 | 2436 | |
| 2311 | 2437 | $groups = array_merge($board_info['groups'], array(1)); |
| 2312 | - foreach ($groups as $id => $group) |
|
| 2313 | - $groups[$id] = (int) $group; |
|
| 2438 | + foreach ($groups as $id => $group) { |
|
| 2439 | + $groups[$id] = (int) $group; |
|
| 2440 | + } |
|
| 2314 | 2441 | |
| 2315 | 2442 | $context['groups'] = array(); |
| 2316 | 2443 | if (in_array(0, $groups)) |
@@ -2353,8 +2480,9 @@ discard block |
||
| 2353 | 2480 | 'group_list' => $groups, |
| 2354 | 2481 | ) |
| 2355 | 2482 | ); |
| 2356 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2357 | - $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2483 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2484 | + $context['groups'][$row['id_group']]['name'] = $row['group_name']; |
|
| 2485 | + } |
|
| 2358 | 2486 | $smcFunc['db_free_result']($request); |
| 2359 | 2487 | |
| 2360 | 2488 | // Get the subject of the topic we're about to announce. |
@@ -2396,16 +2524,19 @@ discard block |
||
| 2396 | 2524 | $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start']; |
| 2397 | 2525 | $groups = array_merge($board_info['groups'], array(1)); |
| 2398 | 2526 | |
| 2399 | - if (isset($_POST['membergroups'])) |
|
| 2400 | - $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2527 | + if (isset($_POST['membergroups'])) { |
|
| 2528 | + $_POST['who'] = explode(',', $_POST['membergroups']); |
|
| 2529 | + } |
|
| 2401 | 2530 | |
| 2402 | 2531 | // Check whether at least one membergroup was selected. |
| 2403 | - if (empty($_POST['who'])) |
|
| 2404 | - fatal_lang_error('no_membergroup_selected'); |
|
| 2532 | + if (empty($_POST['who'])) { |
|
| 2533 | + fatal_lang_error('no_membergroup_selected'); |
|
| 2534 | + } |
|
| 2405 | 2535 | |
| 2406 | 2536 | // Make sure all membergroups are integers and can access the board of the announcement. |
| 2407 | - foreach ($_POST['who'] as $id => $mg) |
|
| 2408 | - $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2537 | + foreach ($_POST['who'] as $id => $mg) { |
|
| 2538 | + $_POST['who'][$id] = in_array((int) $mg, $groups) ? (int) $mg : 0; |
|
| 2539 | + } |
|
| 2409 | 2540 | |
| 2410 | 2541 | // Get the topic subject and censor it. |
| 2411 | 2542 | $request = $smcFunc['db_query']('', ' |
@@ -2451,12 +2582,13 @@ discard block |
||
| 2451 | 2582 | if ($smcFunc['db_num_rows']($request) == 0) |
| 2452 | 2583 | { |
| 2453 | 2584 | logAction('announce_topic', array('topic' => $topic), 'user'); |
| 2454 | - if (!empty($_REQUEST['move']) && allowedTo('move_any')) |
|
| 2455 | - redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2456 | - elseif (!empty($_REQUEST['goback'])) |
|
| 2457 | - redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2458 | - else |
|
| 2459 | - redirectexit('board=' . $board . '.0'); |
|
| 2585 | + if (!empty($_REQUEST['move']) && allowedTo('move_any')) { |
|
| 2586 | + redirectexit('action=movetopic;topic=' . $topic . '.0' . (empty($_REQUEST['goback']) ? '' : ';goback')); |
|
| 2587 | + } elseif (!empty($_REQUEST['goback'])) { |
|
| 2588 | + redirectexit('topic=' . $topic . '.new;boardseen#new', isBrowser('ie')); |
|
| 2589 | + } else { |
|
| 2590 | + redirectexit('board=' . $board . '.0'); |
|
| 2591 | + } |
|
| 2460 | 2592 | } |
| 2461 | 2593 | |
| 2462 | 2594 | $announcements = array(); |
@@ -2475,8 +2607,9 @@ discard block |
||
| 2475 | 2607 | foreach ($rows as $row) |
| 2476 | 2608 | { |
| 2477 | 2609 | // Force them to have it? |
| 2478 | - if (empty($prefs[$row['id_member']]['announcements'])) |
|
| 2479 | - continue; |
|
| 2610 | + if (empty($prefs[$row['id_member']]['announcements'])) { |
|
| 2611 | + continue; |
|
| 2612 | + } |
|
| 2480 | 2613 | |
| 2481 | 2614 | $cur_language = empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']; |
| 2482 | 2615 | |
@@ -2504,8 +2637,9 @@ discard block |
||
| 2504 | 2637 | } |
| 2505 | 2638 | |
| 2506 | 2639 | // For each language send a different mail - low priority... |
| 2507 | - foreach ($announcements as $lang => $mail) |
|
| 2508 | - sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2640 | + foreach ($announcements as $lang => $mail) { |
|
| 2641 | + sendmail($mail['recipients'], $mail['subject'], $mail['body'], null, 'ann-' . $lang, $mail['is_html'], 5); |
|
| 2642 | + } |
|
| 2509 | 2643 | |
| 2510 | 2644 | $context['percentage_done'] = round(100 * $context['start'] / $modSettings['latestMember'], 1); |
| 2511 | 2645 | |
@@ -2515,9 +2649,10 @@ discard block |
||
| 2515 | 2649 | $context['sub_template'] = 'announcement_send'; |
| 2516 | 2650 | |
| 2517 | 2651 | // Go back to the correct language for the user ;). |
| 2518 | - if (!empty($modSettings['userLanguage'])) |
|
| 2519 | - loadLanguage('Post'); |
|
| 2520 | -} |
|
| 2652 | + if (!empty($modSettings['userLanguage'])) { |
|
| 2653 | + loadLanguage('Post'); |
|
| 2654 | + } |
|
| 2655 | + } |
|
| 2521 | 2656 | |
| 2522 | 2657 | /** |
| 2523 | 2658 | * Get the topic for display purposes. |
@@ -2530,12 +2665,13 @@ discard block |
||
| 2530 | 2665 | { |
| 2531 | 2666 | global $topic, $modSettings, $context, $smcFunc, $counter, $options; |
| 2532 | 2667 | |
| 2533 | - if (isset($_REQUEST['xml'])) |
|
| 2534 | - $limit = ' |
|
| 2668 | + if (isset($_REQUEST['xml'])) { |
|
| 2669 | + $limit = ' |
|
| 2535 | 2670 | LIMIT ' . (empty($context['new_replies']) ? '0' : $context['new_replies']); |
| 2536 | - else |
|
| 2537 | - $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2671 | + } else { |
|
| 2672 | + $limit = empty($modSettings['topicSummaryPosts']) ? '' : ' |
|
| 2538 | 2673 | LIMIT ' . (int) $modSettings['topicSummaryPosts']; |
| 2674 | + } |
|
| 2539 | 2675 | |
| 2540 | 2676 | // If you're modifying, get only those posts before the current one. (otherwise get all.) |
| 2541 | 2677 | $request = $smcFunc['db_query']('', ' |
@@ -2573,8 +2709,9 @@ discard block |
||
| 2573 | 2709 | 'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($row['id_member'], $context['user']['ignoreusers']), |
| 2574 | 2710 | ); |
| 2575 | 2711 | |
| 2576 | - if (!empty($context['new_replies'])) |
|
| 2577 | - $context['new_replies']--; |
|
| 2712 | + if (!empty($context['new_replies'])) { |
|
| 2713 | + $context['new_replies']--; |
|
| 2714 | + } |
|
| 2578 | 2715 | } |
| 2579 | 2716 | $smcFunc['db_free_result']($request); |
| 2580 | 2717 | } |
@@ -2591,8 +2728,9 @@ discard block |
||
| 2591 | 2728 | global $sourcedir, $smcFunc; |
| 2592 | 2729 | |
| 2593 | 2730 | loadLanguage('Post'); |
| 2594 | - if (!isset($_REQUEST['xml'])) |
|
| 2595 | - loadTemplate('Post'); |
|
| 2731 | + if (!isset($_REQUEST['xml'])) { |
|
| 2732 | + loadTemplate('Post'); |
|
| 2733 | + } |
|
| 2596 | 2734 | |
| 2597 | 2735 | include_once($sourcedir . '/Subs-Post.php'); |
| 2598 | 2736 | |
@@ -2623,8 +2761,9 @@ discard block |
||
| 2623 | 2761 | $smcFunc['db_free_result']($request); |
| 2624 | 2762 | |
| 2625 | 2763 | $context['sub_template'] = 'quotefast'; |
| 2626 | - if (!empty($row)) |
|
| 2627 | - $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2764 | + if (!empty($row)) { |
|
| 2765 | + $can_view_post = $row['approved'] || ($row['id_member'] != 0 && $row['id_member'] == $user_info['id']) || allowedTo('approve_posts', $row['id_board']); |
|
| 2766 | + } |
|
| 2628 | 2767 | |
| 2629 | 2768 | if (!empty($can_view_post)) |
| 2630 | 2769 | { |
@@ -2657,8 +2796,9 @@ discard block |
||
| 2657 | 2796 | } |
| 2658 | 2797 | |
| 2659 | 2798 | // Remove any nested quotes. |
| 2660 | - if (!empty($modSettings['removeNestedQuotes'])) |
|
| 2661 | - $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2799 | + if (!empty($modSettings['removeNestedQuotes'])) { |
|
| 2800 | + $row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']); |
|
| 2801 | + } |
|
| 2662 | 2802 | |
| 2663 | 2803 | $lb = "\n"; |
| 2664 | 2804 | |
@@ -2684,14 +2824,14 @@ discard block |
||
| 2684 | 2824 | 'time' => '', |
| 2685 | 2825 | ), |
| 2686 | 2826 | ); |
| 2687 | - } |
|
| 2688 | - else |
|
| 2689 | - $context['quote'] = array( |
|
| 2827 | + } else { |
|
| 2828 | + $context['quote'] = array( |
|
| 2690 | 2829 | 'xml' => '', |
| 2691 | 2830 | 'mozilla' => '', |
| 2692 | 2831 | 'text' => '', |
| 2693 | 2832 | ); |
| 2694 | -} |
|
| 2833 | + } |
|
| 2834 | + } |
|
| 2695 | 2835 | |
| 2696 | 2836 | /** |
| 2697 | 2837 | * Used to edit the body or subject of a message inline |
@@ -2703,8 +2843,9 @@ discard block |
||
| 2703 | 2843 | global $user_info, $context, $smcFunc, $language, $board_info; |
| 2704 | 2844 | |
| 2705 | 2845 | // We have to have a topic! |
| 2706 | - if (empty($topic)) |
|
| 2707 | - obExit(false); |
|
| 2846 | + if (empty($topic)) { |
|
| 2847 | + obExit(false); |
|
| 2848 | + } |
|
| 2708 | 2849 | |
| 2709 | 2850 | checkSession('get'); |
| 2710 | 2851 | require_once($sourcedir . '/Subs-Post.php'); |
@@ -2730,31 +2871,35 @@ discard block |
||
| 2730 | 2871 | 'guest_id' => 0, |
| 2731 | 2872 | ) |
| 2732 | 2873 | ); |
| 2733 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 2734 | - fatal_lang_error('no_board', false); |
|
| 2874 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 2875 | + fatal_lang_error('no_board', false); |
|
| 2876 | + } |
|
| 2735 | 2877 | $row = $smcFunc['db_fetch_assoc']($request); |
| 2736 | 2878 | $smcFunc['db_free_result']($request); |
| 2737 | 2879 | |
| 2738 | 2880 | // Change either body or subject requires permissions to modify messages. |
| 2739 | 2881 | if (isset($_POST['message']) || isset($_POST['subject']) || isset($_REQUEST['icon'])) |
| 2740 | 2882 | { |
| 2741 | - if (!empty($row['locked'])) |
|
| 2742 | - isAllowedTo('moderate_board'); |
|
| 2883 | + if (!empty($row['locked'])) { |
|
| 2884 | + isAllowedTo('moderate_board'); |
|
| 2885 | + } |
|
| 2743 | 2886 | |
| 2744 | 2887 | if ($row['id_member'] == $user_info['id'] && !allowedTo('modify_any')) |
| 2745 | 2888 | { |
| 2746 | - if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) |
|
| 2747 | - fatal_lang_error('modify_post_time_passed', false); |
|
| 2748 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) |
|
| 2749 | - isAllowedTo('modify_replies'); |
|
| 2750 | - else |
|
| 2751 | - isAllowedTo('modify_own'); |
|
| 2889 | + if ((!$modSettings['postmod_active'] || $row['approved']) && !empty($modSettings['edit_disable_time']) && $row['poster_time'] + ($modSettings['edit_disable_time'] + 5) * 60 < time()) { |
|
| 2890 | + fatal_lang_error('modify_post_time_passed', false); |
|
| 2891 | + } elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_own')) { |
|
| 2892 | + isAllowedTo('modify_replies'); |
|
| 2893 | + } else { |
|
| 2894 | + isAllowedTo('modify_own'); |
|
| 2895 | + } |
|
| 2752 | 2896 | } |
| 2753 | 2897 | // Otherwise, they're locked out; someone who can modify the replies is needed. |
| 2754 | - elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) |
|
| 2755 | - isAllowedTo('modify_replies'); |
|
| 2756 | - else |
|
| 2757 | - isAllowedTo('modify_any'); |
|
| 2898 | + elseif ($row['id_member_started'] == $user_info['id'] && !allowedTo('modify_any')) { |
|
| 2899 | + isAllowedTo('modify_replies'); |
|
| 2900 | + } else { |
|
| 2901 | + isAllowedTo('modify_any'); |
|
| 2902 | + } |
|
| 2758 | 2903 | |
| 2759 | 2904 | // Only log this action if it wasn't your message. |
| 2760 | 2905 | $moderationAction = $row['id_member'] != $user_info['id']; |
@@ -2766,10 +2911,10 @@ discard block |
||
| 2766 | 2911 | $_POST['subject'] = strtr($smcFunc['htmlspecialchars']($_POST['subject']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2767 | 2912 | |
| 2768 | 2913 | // Maximum number of characters. |
| 2769 | - if ($smcFunc['strlen']($_POST['subject']) > 100) |
|
| 2770 | - $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2771 | - } |
|
| 2772 | - elseif (isset($_POST['subject'])) |
|
| 2914 | + if ($smcFunc['strlen']($_POST['subject']) > 100) { |
|
| 2915 | + $_POST['subject'] = $smcFunc['substr']($_POST['subject'], 0, 100); |
|
| 2916 | + } |
|
| 2917 | + } elseif (isset($_POST['subject'])) |
|
| 2773 | 2918 | { |
| 2774 | 2919 | $post_errors[] = 'no_subject'; |
| 2775 | 2920 | unset($_POST['subject']); |
@@ -2781,13 +2926,11 @@ discard block |
||
| 2781 | 2926 | { |
| 2782 | 2927 | $post_errors[] = 'no_message'; |
| 2783 | 2928 | unset($_POST['message']); |
| 2784 | - } |
|
| 2785 | - elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2929 | + } elseif (!empty($modSettings['max_messageLength']) && $smcFunc['strlen']($_POST['message']) > $modSettings['max_messageLength']) |
|
| 2786 | 2930 | { |
| 2787 | 2931 | $post_errors[] = 'long_message'; |
| 2788 | 2932 | unset($_POST['message']); |
| 2789 | - } |
|
| 2790 | - else |
|
| 2933 | + } else |
|
| 2791 | 2934 | { |
| 2792 | 2935 | $_POST['message'] = $smcFunc['htmlspecialchars']($_POST['message'], ENT_QUOTES); |
| 2793 | 2936 | |
@@ -2803,31 +2946,34 @@ discard block |
||
| 2803 | 2946 | |
| 2804 | 2947 | if (isset($_POST['lock'])) |
| 2805 | 2948 | { |
| 2806 | - if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) |
|
| 2807 | - unset($_POST['lock']); |
|
| 2808 | - elseif (!allowedTo('lock_any')) |
|
| 2949 | + if (!allowedTo(array('lock_any', 'lock_own')) || (!allowedTo('lock_any') && $user_info['id'] != $row['id_member'])) { |
|
| 2950 | + unset($_POST['lock']); |
|
| 2951 | + } elseif (!allowedTo('lock_any')) |
|
| 2809 | 2952 | { |
| 2810 | - if ($row['locked'] == 1) |
|
| 2811 | - unset($_POST['lock']); |
|
| 2812 | - else |
|
| 2813 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2953 | + if ($row['locked'] == 1) { |
|
| 2954 | + unset($_POST['lock']); |
|
| 2955 | + } else { |
|
| 2956 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 2; |
|
| 2957 | + } |
|
| 2958 | + } elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) { |
|
| 2959 | + unset($_POST['lock']); |
|
| 2960 | + } else { |
|
| 2961 | + $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2814 | 2962 | } |
| 2815 | - elseif (!empty($row['locked']) && !empty($_POST['lock']) || $_POST['lock'] == $row['locked']) |
|
| 2816 | - unset($_POST['lock']); |
|
| 2817 | - else |
|
| 2818 | - $_POST['lock'] = empty($_POST['lock']) ? 0 : 1; |
|
| 2819 | 2963 | } |
| 2820 | 2964 | |
| 2821 | - if (isset($_POST['sticky']) && !allowedTo('make_sticky')) |
|
| 2822 | - unset($_POST['sticky']); |
|
| 2965 | + if (isset($_POST['sticky']) && !allowedTo('make_sticky')) { |
|
| 2966 | + unset($_POST['sticky']); |
|
| 2967 | + } |
|
| 2823 | 2968 | |
| 2824 | 2969 | if (isset($_POST['modify_reason'])) |
| 2825 | 2970 | { |
| 2826 | 2971 | $_POST['modify_reason'] = strtr($smcFunc['htmlspecialchars']($_POST['modify_reason']), array("\r" => '', "\n" => '', "\t" => '')); |
| 2827 | 2972 | |
| 2828 | 2973 | // Maximum number of characters. |
| 2829 | - if ($smcFunc['strlen']($_POST['modify_reason']) > 100) |
|
| 2830 | - $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2974 | + if ($smcFunc['strlen']($_POST['modify_reason']) > 100) { |
|
| 2975 | + $_POST['modify_reason'] = $smcFunc['substr']($_POST['modify_reason'], 0, 100); |
|
| 2976 | + } |
|
| 2831 | 2977 | } |
| 2832 | 2978 | |
| 2833 | 2979 | if (empty($post_errors)) |
@@ -2864,8 +3010,9 @@ discard block |
||
| 2864 | 3010 | } |
| 2865 | 3011 | } |
| 2866 | 3012 | // If nothing was changed there's no need to add an entry to the moderation log. |
| 2867 | - else |
|
| 2868 | - $moderationAction = false; |
|
| 3013 | + else { |
|
| 3014 | + $moderationAction = false; |
|
| 3015 | + } |
|
| 2869 | 3016 | |
| 2870 | 3017 | modifyPost($msgOptions, $topicOptions, $posterOptions); |
| 2871 | 3018 | |
@@ -2883,9 +3030,9 @@ discard block |
||
| 2883 | 3030 | // Get the proper (default language) response prefix first. |
| 2884 | 3031 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
| 2885 | 3032 | { |
| 2886 | - if ($language === $user_info['language']) |
|
| 2887 | - $context['response_prefix'] = $txt['response_prefix']; |
|
| 2888 | - else |
|
| 3033 | + if ($language === $user_info['language']) { |
|
| 3034 | + $context['response_prefix'] = $txt['response_prefix']; |
|
| 3035 | + } else |
|
| 2889 | 3036 | { |
| 2890 | 3037 | loadLanguage('index', $language, false); |
| 2891 | 3038 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -2907,8 +3054,9 @@ discard block |
||
| 2907 | 3054 | ); |
| 2908 | 3055 | } |
| 2909 | 3056 | |
| 2910 | - if (!empty($moderationAction)) |
|
| 2911 | - logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 3057 | + if (!empty($moderationAction)) { |
|
| 3058 | + logAction('modify', array('topic' => $topic, 'message' => $row['id_msg'], 'member' => $row['id_member'], 'board' => $board)); |
|
| 3059 | + } |
|
| 2912 | 3060 | } |
| 2913 | 3061 | |
| 2914 | 3062 | if (isset($_REQUEST['xml'])) |
@@ -2949,8 +3097,7 @@ discard block |
||
| 2949 | 3097 | ); |
| 2950 | 3098 | |
| 2951 | 3099 | censorText($context['message']['subject']); |
| 2952 | - } |
|
| 2953 | - else |
|
| 3100 | + } else |
|
| 2954 | 3101 | { |
| 2955 | 3102 | $context['message'] = array( |
| 2956 | 3103 | 'id' => $row['id_msg'], |
@@ -2962,15 +3109,16 @@ discard block |
||
| 2962 | 3109 | loadLanguage('Errors'); |
| 2963 | 3110 | foreach ($post_errors as $post_error) |
| 2964 | 3111 | { |
| 2965 | - if ($post_error == 'long_message') |
|
| 2966 | - $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 2967 | - else |
|
| 2968 | - $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3112 | + if ($post_error == 'long_message') { |
|
| 3113 | + $context['message']['errors'][] = sprintf($txt['error_' . $post_error], $modSettings['max_messageLength']); |
|
| 3114 | + } else { |
|
| 3115 | + $context['message']['errors'][] = $txt['error_' . $post_error]; |
|
| 3116 | + } |
|
| 2969 | 3117 | } |
| 2970 | 3118 | } |
| 3119 | + } else { |
|
| 3120 | + obExit(false); |
|
| 3121 | + } |
|
| 2971 | 3122 | } |
| 2972 | - else |
|
| 2973 | - obExit(false); |
|
| 2974 | -} |
|
| 2975 | 3123 | |
| 2976 | 3124 | ?> |
| 2977 | 3125 | \ No newline at end of file |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -27,8 +28,9 @@ discard block |
||
| 27 | 28 | { |
| 28 | 29 | $supported = function_exists('apc_fetch') && function_exists('apc_store'); |
| 29 | 30 | |
| 30 | - if ($test) |
|
| 31 | - return $supported; |
|
| 31 | + if ($test) { |
|
| 32 | + return $supported; |
|
| 33 | + } |
|
| 32 | 34 | return parent::isSupported() && $supported; |
| 33 | 35 | } |
| 34 | 36 | |
@@ -50,10 +52,11 @@ discard block |
||
| 50 | 52 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 51 | 53 | |
| 52 | 54 | // An extended key is needed to counteract a bug in APC. |
| 53 | - if ($value === null) |
|
| 54 | - return apc_delete($key . 'smf'); |
|
| 55 | - else |
|
| 56 | - return apc_store($key . 'smf', $value, $ttl); |
|
| 55 | + if ($value === null) { |
|
| 56 | + return apc_delete($key . 'smf'); |
|
| 57 | + } else { |
|
| 58 | + return apc_store($key . 'smf', $value, $ttl); |
|
| 59 | + } |
|
| 57 | 60 | } |
| 58 | 61 | |
| 59 | 62 | /** |
@@ -67,9 +70,9 @@ discard block |
||
| 67 | 70 | // Always returns true. |
| 68 | 71 | apc_clear_cache('user'); |
| 69 | 72 | apc_clear_cache('system'); |
| 73 | + } elseif ($type === 'user') { |
|
| 74 | + apc_clear_cache('user'); |
|
| 70 | 75 | } |
| 71 | - elseif ($type === 'user') |
|
| 72 | - apc_clear_cache('user'); |
|
| 73 | 76 | |
| 74 | 77 | $this->invalidateCache(); |
| 75 | 78 | return true; |
@@ -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,30 +4550,35 @@ 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 | $functions = explode(',', $modSettings[$hook]); |
| 4325 | 4568 | // Loop through each function. |
| 4326 | 4569 | foreach ($functions as $function) |
| 4327 | 4570 | { |
| 4328 | 4571 | // Hook has been marked as "disabled". Skip it! |
| 4329 | - if (strpos($function, '!') !== false) |
|
| 4330 | - continue; |
|
| 4572 | + if (strpos($function, '!') !== false) { |
|
| 4573 | + continue; |
|
| 4574 | + } |
|
| 4331 | 4575 | |
| 4332 | 4576 | $call = call_helper($function, true); |
| 4333 | 4577 | |
| 4334 | 4578 | // Is it valid? |
| 4335 | - if (!empty($call)) |
|
| 4336 | - $results[$function] = call_user_func_array($call, $parameters); |
|
| 4579 | + if (!empty($call)) { |
|
| 4580 | + $results[$function] = call_user_func_array($call, $parameters); |
|
| 4581 | + } |
|
| 4337 | 4582 | |
| 4338 | 4583 | // Whatever it was suppose to call, it failed :( |
| 4339 | 4584 | elseif (!empty($function)) |
@@ -4349,8 +4594,9 @@ discard block |
||
| 4349 | 4594 | } |
| 4350 | 4595 | |
| 4351 | 4596 | // "Assume" the file resides on $boarddir somewhere... |
| 4352 | - else |
|
| 4353 | - log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4597 | + else { |
|
| 4598 | + log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general'); |
|
| 4599 | + } |
|
| 4354 | 4600 | } |
| 4355 | 4601 | } |
| 4356 | 4602 | |
@@ -4372,12 +4618,14 @@ discard block |
||
| 4372 | 4618 | global $smcFunc, $modSettings; |
| 4373 | 4619 | |
| 4374 | 4620 | // Any objects? |
| 4375 | - if ($object) |
|
| 4376 | - $function = $function . '#'; |
|
| 4621 | + if ($object) { |
|
| 4622 | + $function = $function . '#'; |
|
| 4623 | + } |
|
| 4377 | 4624 | |
| 4378 | 4625 | // Any files to load? |
| 4379 | - if (!empty($file) && is_string($file)) |
|
| 4380 | - $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4626 | + if (!empty($file) && is_string($file)) { |
|
| 4627 | + $function = $file . (!empty($function) ? '|' . $function : ''); |
|
| 4628 | + } |
|
| 4381 | 4629 | |
| 4382 | 4630 | // Get the correct string. |
| 4383 | 4631 | $integration_call = $function; |
@@ -4399,13 +4647,14 @@ discard block |
||
| 4399 | 4647 | if (!empty($current_functions)) |
| 4400 | 4648 | { |
| 4401 | 4649 | $current_functions = explode(',', $current_functions); |
| 4402 | - if (in_array($integration_call, $current_functions)) |
|
| 4403 | - return; |
|
| 4650 | + if (in_array($integration_call, $current_functions)) { |
|
| 4651 | + return; |
|
| 4652 | + } |
|
| 4404 | 4653 | |
| 4405 | 4654 | $permanent_functions = array_merge($current_functions, array($integration_call)); |
| 4655 | + } else { |
|
| 4656 | + $permanent_functions = array($integration_call); |
|
| 4406 | 4657 | } |
| 4407 | - else |
|
| 4408 | - $permanent_functions = array($integration_call); |
|
| 4409 | 4658 | |
| 4410 | 4659 | updateSettings(array($hook => implode(',', $permanent_functions))); |
| 4411 | 4660 | } |
@@ -4414,8 +4663,9 @@ discard block |
||
| 4414 | 4663 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4415 | 4664 | |
| 4416 | 4665 | // Do nothing, if it's already there. |
| 4417 | - if (in_array($integration_call, $functions)) |
|
| 4418 | - return; |
|
| 4666 | + if (in_array($integration_call, $functions)) { |
|
| 4667 | + return; |
|
| 4668 | + } |
|
| 4419 | 4669 | |
| 4420 | 4670 | $functions[] = $integration_call; |
| 4421 | 4671 | $modSettings[$hook] = implode(',', $functions); |
@@ -4438,12 +4688,14 @@ discard block |
||
| 4438 | 4688 | global $smcFunc, $modSettings; |
| 4439 | 4689 | |
| 4440 | 4690 | // Any objects? |
| 4441 | - if ($object) |
|
| 4442 | - $function = $function . '#'; |
|
| 4691 | + if ($object) { |
|
| 4692 | + $function = $function . '#'; |
|
| 4693 | + } |
|
| 4443 | 4694 | |
| 4444 | 4695 | // Any files to load? |
| 4445 | - if (!empty($file) && is_string($file)) |
|
| 4446 | - $function = $file . '|' . $function; |
|
| 4696 | + if (!empty($file) && is_string($file)) { |
|
| 4697 | + $function = $file . '|' . $function; |
|
| 4698 | + } |
|
| 4447 | 4699 | |
| 4448 | 4700 | // Get the correct string. |
| 4449 | 4701 | $integration_call = $function; |
@@ -4464,16 +4716,18 @@ discard block |
||
| 4464 | 4716 | { |
| 4465 | 4717 | $current_functions = explode(',', $current_functions); |
| 4466 | 4718 | |
| 4467 | - if (in_array($integration_call, $current_functions)) |
|
| 4468 | - updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4719 | + if (in_array($integration_call, $current_functions)) { |
|
| 4720 | + updateSettings(array($hook => implode(',', array_diff($current_functions, array($integration_call))))); |
|
| 4721 | + } |
|
| 4469 | 4722 | } |
| 4470 | 4723 | |
| 4471 | 4724 | // Turn the function list into something usable. |
| 4472 | 4725 | $functions = empty($modSettings[$hook]) ? array() : explode(',', $modSettings[$hook]); |
| 4473 | 4726 | |
| 4474 | 4727 | // You can only remove it if it's available. |
| 4475 | - if (!in_array($integration_call, $functions)) |
|
| 4476 | - return; |
|
| 4728 | + if (!in_array($integration_call, $functions)) { |
|
| 4729 | + return; |
|
| 4730 | + } |
|
| 4477 | 4731 | |
| 4478 | 4732 | $functions = array_diff($functions, array($integration_call)); |
| 4479 | 4733 | $modSettings[$hook] = implode(',', $functions); |
@@ -4494,17 +4748,20 @@ discard block |
||
| 4494 | 4748 | global $context, $smcFunc, $txt, $db_show_debug; |
| 4495 | 4749 | |
| 4496 | 4750 | // Really? |
| 4497 | - if (empty($string)) |
|
| 4498 | - return false; |
|
| 4751 | + if (empty($string)) { |
|
| 4752 | + return false; |
|
| 4753 | + } |
|
| 4499 | 4754 | |
| 4500 | 4755 | // An array? should be a "callable" array IE array(object/class, valid_callable). |
| 4501 | 4756 | // A closure? should be a callable one. |
| 4502 | - if (is_array($string) || $string instanceof Closure) |
|
| 4503 | - return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4757 | + if (is_array($string) || $string instanceof Closure) { |
|
| 4758 | + return $return ? $string : (is_callable($string) ? call_user_func($string) : false); |
|
| 4759 | + } |
|
| 4504 | 4760 | |
| 4505 | 4761 | // No full objects, sorry! pass a method or a property instead! |
| 4506 | - if (is_object($string)) |
|
| 4507 | - return false; |
|
| 4762 | + if (is_object($string)) { |
|
| 4763 | + return false; |
|
| 4764 | + } |
|
| 4508 | 4765 | |
| 4509 | 4766 | // Stay vitaminized my friends... |
| 4510 | 4767 | $string = $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($string)); |
@@ -4513,8 +4770,9 @@ discard block |
||
| 4513 | 4770 | $string = load_file($string); |
| 4514 | 4771 | |
| 4515 | 4772 | // Loaded file failed |
| 4516 | - if (empty($string)) |
|
| 4517 | - return false; |
|
| 4773 | + if (empty($string)) { |
|
| 4774 | + return false; |
|
| 4775 | + } |
|
| 4518 | 4776 | |
| 4519 | 4777 | // Found a method. |
| 4520 | 4778 | if (strpos($string, '::') !== false) |
@@ -4535,8 +4793,9 @@ discard block |
||
| 4535 | 4793 | // Add another one to the list. |
| 4536 | 4794 | if ($db_show_debug === true) |
| 4537 | 4795 | { |
| 4538 | - if (!isset($context['debug']['instances'])) |
|
| 4539 | - $context['debug']['instances'] = array(); |
|
| 4796 | + if (!isset($context['debug']['instances'])) { |
|
| 4797 | + $context['debug']['instances'] = array(); |
|
| 4798 | + } |
|
| 4540 | 4799 | |
| 4541 | 4800 | $context['debug']['instances'][$class] = $class; |
| 4542 | 4801 | } |
@@ -4546,13 +4805,15 @@ discard block |
||
| 4546 | 4805 | } |
| 4547 | 4806 | |
| 4548 | 4807 | // Right then. This is a call to a static method. |
| 4549 | - else |
|
| 4550 | - $func = array($class, $method); |
|
| 4808 | + else { |
|
| 4809 | + $func = array($class, $method); |
|
| 4810 | + } |
|
| 4551 | 4811 | } |
| 4552 | 4812 | |
| 4553 | 4813 | // Nope! just a plain regular function. |
| 4554 | - else |
|
| 4555 | - $func = $string; |
|
| 4814 | + else { |
|
| 4815 | + $func = $string; |
|
| 4816 | + } |
|
| 4556 | 4817 | |
| 4557 | 4818 | // Right, we got what we need, time to do some checks. |
| 4558 | 4819 | if (!is_callable($func, false, $callable_name)) |
@@ -4568,17 +4829,18 @@ discard block |
||
| 4568 | 4829 | else |
| 4569 | 4830 | { |
| 4570 | 4831 | // What are we gonna do about it? |
| 4571 | - if ($return) |
|
| 4572 | - return $func; |
|
| 4832 | + if ($return) { |
|
| 4833 | + return $func; |
|
| 4834 | + } |
|
| 4573 | 4835 | |
| 4574 | 4836 | // If this is a plain function, avoid the heat of calling call_user_func(). |
| 4575 | 4837 | else |
| 4576 | 4838 | { |
| 4577 | - if (is_array($func)) |
|
| 4578 | - call_user_func($func); |
|
| 4579 | - |
|
| 4580 | - else |
|
| 4581 | - $func(); |
|
| 4839 | + if (is_array($func)) { |
|
| 4840 | + call_user_func($func); |
|
| 4841 | + } else { |
|
| 4842 | + $func(); |
|
| 4843 | + } |
|
| 4582 | 4844 | } |
| 4583 | 4845 | } |
| 4584 | 4846 | } |
@@ -4595,31 +4857,34 @@ discard block |
||
| 4595 | 4857 | { |
| 4596 | 4858 | global $sourcedir, $txt, $boarddir, $settings; |
| 4597 | 4859 | |
| 4598 | - if (empty($string)) |
|
| 4599 | - return false; |
|
| 4860 | + if (empty($string)) { |
|
| 4861 | + return false; |
|
| 4862 | + } |
|
| 4600 | 4863 | |
| 4601 | 4864 | if (strpos($string, '|') !== false) |
| 4602 | 4865 | { |
| 4603 | 4866 | list ($file, $string) = explode('|', $string); |
| 4604 | 4867 | |
| 4605 | 4868 | // Match the wildcards to their regular vars. |
| 4606 | - if (empty($settings['theme_dir'])) |
|
| 4607 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4608 | - |
|
| 4609 | - else |
|
| 4610 | - $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4869 | + if (empty($settings['theme_dir'])) { |
|
| 4870 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
|
| 4871 | + } else { |
|
| 4872 | + $absPath = strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
|
| 4873 | + } |
|
| 4611 | 4874 | |
| 4612 | 4875 | // Load the file if it can be loaded. |
| 4613 | - if (file_exists($absPath)) |
|
| 4614 | - require_once($absPath); |
|
| 4876 | + if (file_exists($absPath)) { |
|
| 4877 | + require_once($absPath); |
|
| 4878 | + } |
|
| 4615 | 4879 | |
| 4616 | 4880 | // No? try a fallback to $sourcedir |
| 4617 | 4881 | else |
| 4618 | 4882 | { |
| 4619 | 4883 | $absPath = $sourcedir .'/'. $file; |
| 4620 | 4884 | |
| 4621 | - if (file_exists($absPath)) |
|
| 4622 | - require_once($absPath); |
|
| 4885 | + if (file_exists($absPath)) { |
|
| 4886 | + require_once($absPath); |
|
| 4887 | + } |
|
| 4623 | 4888 | |
| 4624 | 4889 | // Sorry, can't do much for you at this point. |
| 4625 | 4890 | else |
@@ -4646,8 +4911,9 @@ discard block |
||
| 4646 | 4911 | global $user_info, $smcFunc; |
| 4647 | 4912 | |
| 4648 | 4913 | // Make sure we have something to work with. |
| 4649 | - if (empty($topic)) |
|
| 4650 | - return array(); |
|
| 4914 | + if (empty($topic)) { |
|
| 4915 | + return array(); |
|
| 4916 | + } |
|
| 4651 | 4917 | |
| 4652 | 4918 | |
| 4653 | 4919 | // We already know the number of likes per message, we just want to know whether the current user liked it or not. |
@@ -4670,8 +4936,9 @@ discard block |
||
| 4670 | 4936 | 'topic' => $topic, |
| 4671 | 4937 | ) |
| 4672 | 4938 | ); |
| 4673 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 4674 | - $temp[] = (int) $row['content_id']; |
|
| 4939 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 4940 | + $temp[] = (int) $row['content_id']; |
|
| 4941 | + } |
|
| 4675 | 4942 | |
| 4676 | 4943 | cache_put_data($cache_key, $temp, $ttl); |
| 4677 | 4944 | } |
@@ -4692,8 +4959,9 @@ discard block |
||
| 4692 | 4959 | { |
| 4693 | 4960 | global $context; |
| 4694 | 4961 | |
| 4695 | - if (empty($string)) |
|
| 4696 | - return $string; |
|
| 4962 | + if (empty($string)) { |
|
| 4963 | + return $string; |
|
| 4964 | + } |
|
| 4697 | 4965 | |
| 4698 | 4966 | // UTF-8 occurences of MS special characters |
| 4699 | 4967 | $findchars_utf8 = array( |
@@ -4734,10 +5002,11 @@ discard block |
||
| 4734 | 5002 | '--', // — |
| 4735 | 5003 | ); |
| 4736 | 5004 | |
| 4737 | - if ($context['utf8']) |
|
| 4738 | - $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 4739 | - else |
|
| 4740 | - $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5005 | + if ($context['utf8']) { |
|
| 5006 | + $string = str_replace($findchars_utf8, $replacechars, $string); |
|
| 5007 | + } else { |
|
| 5008 | + $string = str_replace($findchars_iso, $replacechars, $string); |
|
| 5009 | + } |
|
| 4741 | 5010 | |
| 4742 | 5011 | return $string; |
| 4743 | 5012 | } |
@@ -4756,49 +5025,59 @@ discard block |
||
| 4756 | 5025 | { |
| 4757 | 5026 | global $context; |
| 4758 | 5027 | |
| 4759 | - if (!isset($matches[2])) |
|
| 4760 | - return ''; |
|
| 5028 | + if (!isset($matches[2])) { |
|
| 5029 | + return ''; |
|
| 5030 | + } |
|
| 4761 | 5031 | |
| 4762 | 5032 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4763 | 5033 | |
| 4764 | 5034 | // remove left to right / right to left overrides |
| 4765 | - if ($num === 0x202D || $num === 0x202E) |
|
| 4766 | - return ''; |
|
| 5035 | + if ($num === 0x202D || $num === 0x202E) { |
|
| 5036 | + return ''; |
|
| 5037 | + } |
|
| 4767 | 5038 | |
| 4768 | 5039 | // Quote, Ampersand, Apostrophe, Less/Greater Than get html replaced |
| 4769 | - if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) |
|
| 4770 | - return '&#' . $num . ';'; |
|
| 5040 | + if (in_array($num, array(0x22, 0x26, 0x27, 0x3C, 0x3E))) { |
|
| 5041 | + return '&#' . $num . ';'; |
|
| 5042 | + } |
|
| 4771 | 5043 | |
| 4772 | 5044 | if (empty($context['utf8'])) |
| 4773 | 5045 | { |
| 4774 | 5046 | // no control characters |
| 4775 | - if ($num < 0x20) |
|
| 4776 | - return ''; |
|
| 5047 | + if ($num < 0x20) { |
|
| 5048 | + return ''; |
|
| 5049 | + } |
|
| 4777 | 5050 | // text is text |
| 4778 | - elseif ($num < 0x80) |
|
| 4779 | - return chr($num); |
|
| 5051 | + elseif ($num < 0x80) { |
|
| 5052 | + return chr($num); |
|
| 5053 | + } |
|
| 4780 | 5054 | // all others get html-ised |
| 4781 | - else |
|
| 4782 | - return '&#' . $matches[2] . ';'; |
|
| 4783 | - } |
|
| 4784 | - else |
|
| 5055 | + else { |
|
| 5056 | + return '&#' . $matches[2] . ';'; |
|
| 5057 | + } |
|
| 5058 | + } else |
|
| 4785 | 5059 | { |
| 4786 | 5060 | // <0x20 are control characters, 0x20 is a space, > 0x10FFFF is past the end of the utf8 character set |
| 4787 | 5061 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text) |
| 4788 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) |
|
| 4789 | - return ''; |
|
| 5062 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF)) { |
|
| 5063 | + return ''; |
|
| 5064 | + } |
|
| 4790 | 5065 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4791 | - elseif ($num < 0x80) |
|
| 4792 | - return chr($num); |
|
| 5066 | + elseif ($num < 0x80) { |
|
| 5067 | + return chr($num); |
|
| 5068 | + } |
|
| 4793 | 5069 | // <0x800 (2048) |
| 4794 | - elseif ($num < 0x800) |
|
| 4795 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5070 | + elseif ($num < 0x800) { |
|
| 5071 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5072 | + } |
|
| 4796 | 5073 | // < 0x10000 (65536) |
| 4797 | - elseif ($num < 0x10000) |
|
| 4798 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5074 | + elseif ($num < 0x10000) { |
|
| 5075 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5076 | + } |
|
| 4799 | 5077 | // <= 0x10FFFF (1114111) |
| 4800 | - else |
|
| 4801 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5078 | + else { |
|
| 5079 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5080 | + } |
|
| 4802 | 5081 | } |
| 4803 | 5082 | } |
| 4804 | 5083 | |
@@ -4814,28 +5093,34 @@ discard block |
||
| 4814 | 5093 | */ |
| 4815 | 5094 | function fixchar__callback($matches) |
| 4816 | 5095 | { |
| 4817 | - if (!isset($matches[1])) |
|
| 4818 | - return ''; |
|
| 5096 | + if (!isset($matches[1])) { |
|
| 5097 | + return ''; |
|
| 5098 | + } |
|
| 4819 | 5099 | |
| 4820 | 5100 | $num = $matches[1][0] === 'x' ? hexdec(substr($matches[1], 1)) : (int) $matches[1]; |
| 4821 | 5101 | |
| 4822 | 5102 | // <0x20 are control characters, > 0x10FFFF is past the end of the utf8 character set |
| 4823 | 5103 | // 0xD800 >= $num <= 0xDFFF are surrogate markers (not valid for utf8 text), 0x202D-E are left to right overrides |
| 4824 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) |
|
| 4825 | - return ''; |
|
| 5104 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num === 0x202D || $num === 0x202E) { |
|
| 5105 | + return ''; |
|
| 5106 | + } |
|
| 4826 | 5107 | // <0x80 (or less than 128) are standard ascii characters a-z A-Z 0-9 and punctuation |
| 4827 | - elseif ($num < 0x80) |
|
| 4828 | - return chr($num); |
|
| 5108 | + elseif ($num < 0x80) { |
|
| 5109 | + return chr($num); |
|
| 5110 | + } |
|
| 4829 | 5111 | // <0x800 (2048) |
| 4830 | - elseif ($num < 0x800) |
|
| 4831 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5112 | + elseif ($num < 0x800) { |
|
| 5113 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 5114 | + } |
|
| 4832 | 5115 | // < 0x10000 (65536) |
| 4833 | - elseif ($num < 0x10000) |
|
| 4834 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5116 | + elseif ($num < 0x10000) { |
|
| 5117 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5118 | + } |
|
| 4835 | 5119 | // <= 0x10FFFF (1114111) |
| 4836 | - else |
|
| 4837 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 4838 | -} |
|
| 5120 | + else { |
|
| 5121 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 5122 | + } |
|
| 5123 | + } |
|
| 4839 | 5124 | |
| 4840 | 5125 | /** |
| 4841 | 5126 | * Strips out invalid html entities, replaces others with html style { codes |
@@ -4848,17 +5133,19 @@ discard block |
||
| 4848 | 5133 | */ |
| 4849 | 5134 | function entity_fix__callback($matches) |
| 4850 | 5135 | { |
| 4851 | - if (!isset($matches[2])) |
|
| 4852 | - return ''; |
|
| 5136 | + if (!isset($matches[2])) { |
|
| 5137 | + return ''; |
|
| 5138 | + } |
|
| 4853 | 5139 | |
| 4854 | 5140 | $num = $matches[2][0] === 'x' ? hexdec(substr($matches[2], 1)) : (int) $matches[2]; |
| 4855 | 5141 | |
| 4856 | 5142 | // we don't allow control characters, characters out of range, byte markers, etc |
| 4857 | - if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) |
|
| 4858 | - return ''; |
|
| 4859 | - else |
|
| 4860 | - return '&#' . $num . ';'; |
|
| 4861 | -} |
|
| 5143 | + if ($num < 0x20 || $num > 0x10FFFF || ($num >= 0xD800 && $num <= 0xDFFF) || $num == 0x202D || $num == 0x202E) { |
|
| 5144 | + return ''; |
|
| 5145 | + } else { |
|
| 5146 | + return '&#' . $num . ';'; |
|
| 5147 | + } |
|
| 5148 | + } |
|
| 4862 | 5149 | |
| 4863 | 5150 | /** |
| 4864 | 5151 | * Return a Gravatar URL based on |
@@ -4882,18 +5169,23 @@ discard block |
||
| 4882 | 5169 | $ratings = array('G', 'PG', 'R', 'X'); |
| 4883 | 5170 | $defaults = array('mm', 'identicon', 'monsterid', 'wavatar', 'retro', 'blank'); |
| 4884 | 5171 | $url_params = array(); |
| 4885 | - if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) |
|
| 4886 | - $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 4887 | - if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) |
|
| 4888 | - $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 4889 | - if (!empty($modSettings['avatar_max_width_external'])) |
|
| 4890 | - $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 4891 | - if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) |
|
| 4892 | - if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 5172 | + if (!empty($modSettings['gravatarMaxRating']) && in_array($modSettings['gravatarMaxRating'], $ratings)) { |
|
| 5173 | + $url_params[] = 'rating=' . $modSettings['gravatarMaxRating']; |
|
| 5174 | + } |
|
| 5175 | + if (!empty($modSettings['gravatarDefault']) && in_array($modSettings['gravatarDefault'], $defaults)) { |
|
| 5176 | + $url_params[] = 'default=' . $modSettings['gravatarDefault']; |
|
| 5177 | + } |
|
| 5178 | + if (!empty($modSettings['avatar_max_width_external'])) { |
|
| 5179 | + $size_string = (int) $modSettings['avatar_max_width_external']; |
|
| 5180 | + } |
|
| 5181 | + if (!empty($modSettings['avatar_max_height_external']) && !empty($size_string)) { |
|
| 5182 | + if ((int) $modSettings['avatar_max_height_external'] < $size_string) |
|
| 4893 | 5183 | $size_string = $modSettings['avatar_max_height_external']; |
| 5184 | + } |
|
| 4894 | 5185 | |
| 4895 | - if (!empty($size_string)) |
|
| 4896 | - $url_params[] = 's=' . $size_string; |
|
| 5186 | + if (!empty($size_string)) { |
|
| 5187 | + $url_params[] = 's=' . $size_string; |
|
| 5188 | + } |
|
| 4897 | 5189 | } |
| 4898 | 5190 | $http_method = !empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 ? 'https://secure' : 'http://www'; |
| 4899 | 5191 | |
@@ -4912,22 +5204,26 @@ discard block |
||
| 4912 | 5204 | static $timezones = null, $lastwhen = null; |
| 4913 | 5205 | |
| 4914 | 5206 | // No point doing this over if we already did it once |
| 4915 | - if (!empty($timezones) && $when == $lastwhen) |
|
| 4916 | - return $timezones; |
|
| 4917 | - else |
|
| 4918 | - $lastwhen = $when; |
|
| 5207 | + if (!empty($timezones) && $when == $lastwhen) { |
|
| 5208 | + return $timezones; |
|
| 5209 | + } else { |
|
| 5210 | + $lastwhen = $when; |
|
| 5211 | + } |
|
| 4919 | 5212 | |
| 4920 | 5213 | // Parseable datetime string? |
| 4921 | - if (is_int($timestamp = strtotime($when))) |
|
| 4922 | - $when = $timestamp; |
|
| 5214 | + if (is_int($timestamp = strtotime($when))) { |
|
| 5215 | + $when = $timestamp; |
|
| 5216 | + } |
|
| 4923 | 5217 | |
| 4924 | 5218 | // A Unix timestamp? |
| 4925 | - elseif (is_numeric($when)) |
|
| 4926 | - $when = intval($when); |
|
| 5219 | + elseif (is_numeric($when)) { |
|
| 5220 | + $when = intval($when); |
|
| 5221 | + } |
|
| 4927 | 5222 | |
| 4928 | 5223 | // Invalid value? Just get current Unix timestamp. |
| 4929 | - else |
|
| 4930 | - $when = time(); |
|
| 5224 | + else { |
|
| 5225 | + $when = time(); |
|
| 5226 | + } |
|
| 4931 | 5227 | |
| 4932 | 5228 | // We'll need these too |
| 4933 | 5229 | $date_when = date_create('@' . $when); |
@@ -4991,8 +5287,9 @@ discard block |
||
| 4991 | 5287 | foreach ($priority_countries as $country) |
| 4992 | 5288 | { |
| 4993 | 5289 | $country_tzids = @timezone_identifiers_list(DateTimeZone::PER_COUNTRY, strtoupper(trim($country))); |
| 4994 | - if (!empty($country_tzids)) |
|
| 4995 | - $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5290 | + if (!empty($country_tzids)) { |
|
| 5291 | + $priority_tzids = array_merge($priority_tzids, $country_tzids); |
|
| 5292 | + } |
|
| 4996 | 5293 | } |
| 4997 | 5294 | |
| 4998 | 5295 | // Process the preferred timezones first, then the rest. |
@@ -5002,8 +5299,9 @@ discard block |
||
| 5002 | 5299 | foreach ($tzids as $tzid) |
| 5003 | 5300 | { |
| 5004 | 5301 | // We don't want UTC right now |
| 5005 | - if ($tzid == 'UTC') |
|
| 5006 | - continue; |
|
| 5302 | + if ($tzid == 'UTC') { |
|
| 5303 | + continue; |
|
| 5304 | + } |
|
| 5007 | 5305 | |
| 5008 | 5306 | $tz = timezone_open($tzid); |
| 5009 | 5307 | |
@@ -5018,12 +5316,14 @@ discard block |
||
| 5018 | 5316 | $tzgeo = timezone_location_get($tz); |
| 5019 | 5317 | |
| 5020 | 5318 | // Don't overwrite our preferred tzids |
| 5021 | - if (empty($zones[$tzkey]['tzid'])) |
|
| 5022 | - $zones[$tzkey]['tzid'] = $tzid; |
|
| 5319 | + if (empty($zones[$tzkey]['tzid'])) { |
|
| 5320 | + $zones[$tzkey]['tzid'] = $tzid; |
|
| 5321 | + } |
|
| 5023 | 5322 | |
| 5024 | 5323 | // A time zone from a prioritized country? |
| 5025 | - if (in_array($tzid, $priority_tzids)) |
|
| 5026 | - $priority_zones[$tzkey] = true; |
|
| 5324 | + if (in_array($tzid, $priority_tzids)) { |
|
| 5325 | + $priority_zones[$tzkey] = true; |
|
| 5326 | + } |
|
| 5027 | 5327 | |
| 5028 | 5328 | // Keep track of the location and offset for this tzid |
| 5029 | 5329 | $tzid_parts = explode('/', $tzid); |
@@ -5044,15 +5344,17 @@ discard block |
||
| 5044 | 5344 | |
| 5045 | 5345 | date_timezone_set($date_when, timezone_open($tzvalue['tzid'])); |
| 5046 | 5346 | |
| 5047 | - if (!empty($timezone_descriptions[$tzvalue['tzid']])) |
|
| 5048 | - $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5049 | - else |
|
| 5050 | - $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5347 | + if (!empty($timezone_descriptions[$tzvalue['tzid']])) { |
|
| 5348 | + $desc = $timezone_descriptions[$tzvalue['tzid']]; |
|
| 5349 | + } else { |
|
| 5350 | + $desc = implode(', ', array_unique($tzvalue['locations'])); |
|
| 5351 | + } |
|
| 5051 | 5352 | |
| 5052 | - if (isset($priority_zones[$tzkey])) |
|
| 5053 | - $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5054 | - else |
|
| 5055 | - $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5353 | + if (isset($priority_zones[$tzkey])) { |
|
| 5354 | + $priority_timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5355 | + } else { |
|
| 5356 | + $timezones[$tzvalue['tzid']] = $tzinfo[0]['abbr'] . ' - ' . $desc . ' [UTC' . date_format($date_when, 'P') . ']'; |
|
| 5357 | + } |
|
| 5056 | 5358 | } |
| 5057 | 5359 | |
| 5058 | 5360 | $timezones = array_merge( |
@@ -5106,9 +5408,9 @@ discard block |
||
| 5106 | 5408 | 'Indian/Kerguelen' => 'TFT', |
| 5107 | 5409 | ); |
| 5108 | 5410 | |
| 5109 | - if (!empty($missing_tz_abbrs[$tzid])) |
|
| 5110 | - $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5111 | - else |
|
| 5411 | + if (!empty($missing_tz_abbrs[$tzid])) { |
|
| 5412 | + $tz_abbrev = $missing_tz_abbrs[$tzid]; |
|
| 5413 | + } else |
|
| 5112 | 5414 | { |
| 5113 | 5415 | // Russia likes to experiment with time zones often, and names them as offsets from Moscow |
| 5114 | 5416 | $tz_location = timezone_location_get(timezone_open($tzid)); |
@@ -5136,8 +5438,9 @@ discard block |
||
| 5136 | 5438 | */ |
| 5137 | 5439 | function inet_ptod($ip_address) |
| 5138 | 5440 | { |
| 5139 | - if (!isValidIP($ip_address)) |
|
| 5140 | - return $ip_address; |
|
| 5441 | + if (!isValidIP($ip_address)) { |
|
| 5442 | + return $ip_address; |
|
| 5443 | + } |
|
| 5141 | 5444 | |
| 5142 | 5445 | $bin = inet_pton($ip_address); |
| 5143 | 5446 | return $bin; |
@@ -5149,13 +5452,15 @@ discard block |
||
| 5149 | 5452 | */ |
| 5150 | 5453 | function inet_dtop($bin) |
| 5151 | 5454 | { |
| 5152 | - if(empty($bin)) |
|
| 5153 | - return ''; |
|
| 5455 | + if(empty($bin)) { |
|
| 5456 | + return ''; |
|
| 5457 | + } |
|
| 5154 | 5458 | |
| 5155 | 5459 | global $db_type; |
| 5156 | 5460 | |
| 5157 | - if ($db_type == 'postgresql') |
|
| 5158 | - return $bin; |
|
| 5461 | + if ($db_type == 'postgresql') { |
|
| 5462 | + return $bin; |
|
| 5463 | + } |
|
| 5159 | 5464 | |
| 5160 | 5465 | $ip_address = inet_ntop($bin); |
| 5161 | 5466 | |
@@ -5180,26 +5485,32 @@ discard block |
||
| 5180 | 5485 | */ |
| 5181 | 5486 | function _safe_serialize($value) |
| 5182 | 5487 | { |
| 5183 | - if(is_null($value)) |
|
| 5184 | - return 'N;'; |
|
| 5488 | + if(is_null($value)) { |
|
| 5489 | + return 'N;'; |
|
| 5490 | + } |
|
| 5185 | 5491 | |
| 5186 | - if(is_bool($value)) |
|
| 5187 | - return 'b:'. (int) $value .';'; |
|
| 5492 | + if(is_bool($value)) { |
|
| 5493 | + return 'b:'. (int) $value .';'; |
|
| 5494 | + } |
|
| 5188 | 5495 | |
| 5189 | - if(is_int($value)) |
|
| 5190 | - return 'i:'. $value .';'; |
|
| 5496 | + if(is_int($value)) { |
|
| 5497 | + return 'i:'. $value .';'; |
|
| 5498 | + } |
|
| 5191 | 5499 | |
| 5192 | - if(is_float($value)) |
|
| 5193 | - return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5500 | + if(is_float($value)) { |
|
| 5501 | + return 'd:'. str_replace(',', '.', $value) .';'; |
|
| 5502 | + } |
|
| 5194 | 5503 | |
| 5195 | - if(is_string($value)) |
|
| 5196 | - return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5504 | + if(is_string($value)) { |
|
| 5505 | + return 's:'. strlen($value) .':"'. $value .'";'; |
|
| 5506 | + } |
|
| 5197 | 5507 | |
| 5198 | 5508 | if(is_array($value)) |
| 5199 | 5509 | { |
| 5200 | 5510 | $out = ''; |
| 5201 | - foreach($value as $k => $v) |
|
| 5202 | - $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5511 | + foreach($value as $k => $v) { |
|
| 5512 | + $out .= _safe_serialize($k) . _safe_serialize($v); |
|
| 5513 | + } |
|
| 5203 | 5514 | |
| 5204 | 5515 | return 'a:'. count($value) .':{'. $out .'}'; |
| 5205 | 5516 | } |
@@ -5225,8 +5536,9 @@ discard block |
||
| 5225 | 5536 | |
| 5226 | 5537 | $out = _safe_serialize($value); |
| 5227 | 5538 | |
| 5228 | - if (isset($mbIntEnc)) |
|
| 5229 | - mb_internal_encoding($mbIntEnc); |
|
| 5539 | + if (isset($mbIntEnc)) { |
|
| 5540 | + mb_internal_encoding($mbIntEnc); |
|
| 5541 | + } |
|
| 5230 | 5542 | |
| 5231 | 5543 | return $out; |
| 5232 | 5544 | } |
@@ -5243,8 +5555,9 @@ discard block |
||
| 5243 | 5555 | function _safe_unserialize($str) |
| 5244 | 5556 | { |
| 5245 | 5557 | // Input is not a string. |
| 5246 | - if(empty($str) || !is_string($str)) |
|
| 5247 | - return false; |
|
| 5558 | + if(empty($str) || !is_string($str)) { |
|
| 5559 | + return false; |
|
| 5560 | + } |
|
| 5248 | 5561 | |
| 5249 | 5562 | $stack = array(); |
| 5250 | 5563 | $expected = array(); |
@@ -5260,43 +5573,38 @@ discard block |
||
| 5260 | 5573 | while($state != 1) |
| 5261 | 5574 | { |
| 5262 | 5575 | $type = isset($str[0]) ? $str[0] : ''; |
| 5263 | - if($type == '}') |
|
| 5264 | - $str = substr($str, 1); |
|
| 5265 | - |
|
| 5266 | - else if($type == 'N' && $str[1] == ';') |
|
| 5576 | + if($type == '}') { |
|
| 5577 | + $str = substr($str, 1); |
|
| 5578 | + } else if($type == 'N' && $str[1] == ';') |
|
| 5267 | 5579 | { |
| 5268 | 5580 | $value = null; |
| 5269 | 5581 | $str = substr($str, 2); |
| 5270 | - } |
|
| 5271 | - else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5582 | + } else if($type == 'b' && preg_match('/^b:([01]);/', $str, $matches)) |
|
| 5272 | 5583 | { |
| 5273 | 5584 | $value = $matches[1] == '1' ? true : false; |
| 5274 | 5585 | $str = substr($str, 4); |
| 5275 | - } |
|
| 5276 | - else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5586 | + } else if($type == 'i' && preg_match('/^i:(-?[0-9]+);(.*)/s', $str, $matches)) |
|
| 5277 | 5587 | { |
| 5278 | 5588 | $value = (int)$matches[1]; |
| 5279 | 5589 | $str = $matches[2]; |
| 5280 | - } |
|
| 5281 | - else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5590 | + } else if($type == 'd' && preg_match('/^d:(-?[0-9]+\.?[0-9]*(E[+-][0-9]+)?);(.*)/s', $str, $matches)) |
|
| 5282 | 5591 | { |
| 5283 | 5592 | $value = (float)$matches[1]; |
| 5284 | 5593 | $str = $matches[3]; |
| 5285 | - } |
|
| 5286 | - else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5594 | + } else if($type == 's' && preg_match('/^s:([0-9]+):"(.*)/s', $str, $matches) && substr($matches[2], (int)$matches[1], 2) == '";') |
|
| 5287 | 5595 | { |
| 5288 | 5596 | $value = substr($matches[2], 0, (int)$matches[1]); |
| 5289 | 5597 | $str = substr($matches[2], (int)$matches[1] + 2); |
| 5290 | - } |
|
| 5291 | - else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5598 | + } else if($type == 'a' && preg_match('/^a:([0-9]+):{(.*)/s', $str, $matches)) |
|
| 5292 | 5599 | { |
| 5293 | 5600 | $expectedLength = (int)$matches[1]; |
| 5294 | 5601 | $str = $matches[2]; |
| 5295 | 5602 | } |
| 5296 | 5603 | |
| 5297 | 5604 | // Object or unknown/malformed type. |
| 5298 | - else |
|
| 5299 | - return false; |
|
| 5605 | + else { |
|
| 5606 | + return false; |
|
| 5607 | + } |
|
| 5300 | 5608 | |
| 5301 | 5609 | switch($state) |
| 5302 | 5610 | { |
@@ -5324,8 +5632,9 @@ discard block |
||
| 5324 | 5632 | if($type == '}') |
| 5325 | 5633 | { |
| 5326 | 5634 | // Array size is less than expected. |
| 5327 | - if(count($list) < end($expected)) |
|
| 5328 | - return false; |
|
| 5635 | + if(count($list) < end($expected)) { |
|
| 5636 | + return false; |
|
| 5637 | + } |
|
| 5329 | 5638 | |
| 5330 | 5639 | unset($list); |
| 5331 | 5640 | $list = &$stack[count($stack)-1]; |
@@ -5334,8 +5643,9 @@ discard block |
||
| 5334 | 5643 | // Go to terminal state if we're at the end of the root array. |
| 5335 | 5644 | array_pop($expected); |
| 5336 | 5645 | |
| 5337 | - if(count($expected) == 0) |
|
| 5338 | - $state = 1; |
|
| 5646 | + if(count($expected) == 0) { |
|
| 5647 | + $state = 1; |
|
| 5648 | + } |
|
| 5339 | 5649 | |
| 5340 | 5650 | break; |
| 5341 | 5651 | } |
@@ -5343,8 +5653,9 @@ discard block |
||
| 5343 | 5653 | if($type == 'i' || $type == 's') |
| 5344 | 5654 | { |
| 5345 | 5655 | // Array size exceeds expected length. |
| 5346 | - if(count($list) >= end($expected)) |
|
| 5347 | - return false; |
|
| 5656 | + if(count($list) >= end($expected)) { |
|
| 5657 | + return false; |
|
| 5658 | + } |
|
| 5348 | 5659 | |
| 5349 | 5660 | $key = $value; |
| 5350 | 5661 | $state = 3; |
@@ -5378,8 +5689,9 @@ discard block |
||
| 5378 | 5689 | } |
| 5379 | 5690 | |
| 5380 | 5691 | // Trailing data in input. |
| 5381 | - if(!empty($str)) |
|
| 5382 | - return false; |
|
| 5692 | + if(!empty($str)) { |
|
| 5693 | + return false; |
|
| 5694 | + } |
|
| 5383 | 5695 | |
| 5384 | 5696 | return $data; |
| 5385 | 5697 | } |
@@ -5402,8 +5714,9 @@ discard block |
||
| 5402 | 5714 | |
| 5403 | 5715 | $out = _safe_unserialize($str); |
| 5404 | 5716 | |
| 5405 | - if (isset($mbIntEnc)) |
|
| 5406 | - mb_internal_encoding($mbIntEnc); |
|
| 5717 | + if (isset($mbIntEnc)) { |
|
| 5718 | + mb_internal_encoding($mbIntEnc); |
|
| 5719 | + } |
|
| 5407 | 5720 | |
| 5408 | 5721 | return $out; |
| 5409 | 5722 | } |
@@ -5418,12 +5731,14 @@ discard block |
||
| 5418 | 5731 | function smf_chmod($file, $value = 0) |
| 5419 | 5732 | { |
| 5420 | 5733 | // No file? no checks! |
| 5421 | - if (empty($file)) |
|
| 5422 | - return false; |
|
| 5734 | + if (empty($file)) { |
|
| 5735 | + return false; |
|
| 5736 | + } |
|
| 5423 | 5737 | |
| 5424 | 5738 | // Already writable? |
| 5425 | - if (is_writable($file)) |
|
| 5426 | - return true; |
|
| 5739 | + if (is_writable($file)) { |
|
| 5740 | + return true; |
|
| 5741 | + } |
|
| 5427 | 5742 | |
| 5428 | 5743 | // Do we have a file or a dir? |
| 5429 | 5744 | $isDir = is_dir($file); |
@@ -5439,10 +5754,9 @@ discard block |
||
| 5439 | 5754 | { |
| 5440 | 5755 | $isWritable = true; |
| 5441 | 5756 | break; |
| 5757 | + } else { |
|
| 5758 | + @chmod($file, $val); |
|
| 5442 | 5759 | } |
| 5443 | - |
|
| 5444 | - else |
|
| 5445 | - @chmod($file, $val); |
|
| 5446 | 5760 | } |
| 5447 | 5761 | |
| 5448 | 5762 | return $isWritable; |
@@ -5461,8 +5775,9 @@ discard block |
||
| 5461 | 5775 | global $txt; |
| 5462 | 5776 | |
| 5463 | 5777 | // Come on... |
| 5464 | - if (empty($json) || !is_string($json)) |
|
| 5465 | - return array(); |
|
| 5778 | + if (empty($json) || !is_string($json)) { |
|
| 5779 | + return array(); |
|
| 5780 | + } |
|
| 5466 | 5781 | |
| 5467 | 5782 | $returnArray = @json_decode($json, $returnAsArray); |
| 5468 | 5783 | |
@@ -5500,11 +5815,11 @@ discard block |
||
| 5500 | 5815 | $jsonDebug = $jsonDebug[0]; |
| 5501 | 5816 | loadLanguage('Errors'); |
| 5502 | 5817 | |
| 5503 | - if (!empty($jsonDebug)) |
|
| 5504 | - log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5505 | - |
|
| 5506 | - else |
|
| 5507 | - log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5818 | + if (!empty($jsonDebug)) { |
|
| 5819 | + log_error($txt['json_'. $jsonError], 'critical', $jsonDebug['file'], $jsonDebug['line']); |
|
| 5820 | + } else { |
|
| 5821 | + log_error($txt['json_'. $jsonError], 'critical'); |
|
| 5822 | + } |
|
| 5508 | 5823 | |
| 5509 | 5824 | // Everyone expects an array. |
| 5510 | 5825 | return array(); |
@@ -5534,8 +5849,9 @@ discard block |
||
| 5534 | 5849 | global $db_show_debug, $modSettings; |
| 5535 | 5850 | |
| 5536 | 5851 | // Defensive programming anyone? |
| 5537 | - if (empty($data)) |
|
| 5538 | - return false; |
|
| 5852 | + if (empty($data)) { |
|
| 5853 | + return false; |
|
| 5854 | + } |
|
| 5539 | 5855 | |
| 5540 | 5856 | // Don't need extra stuff... |
| 5541 | 5857 | $db_show_debug = false; |
@@ -5543,11 +5859,11 @@ discard block |
||
| 5543 | 5859 | // Kill anything else. |
| 5544 | 5860 | ob_end_clean(); |
| 5545 | 5861 | |
| 5546 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 5547 | - @ob_start('ob_gzhandler'); |
|
| 5548 | - |
|
| 5549 | - else |
|
| 5550 | - ob_start(); |
|
| 5862 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 5863 | + @ob_start('ob_gzhandler'); |
|
| 5864 | + } else { |
|
| 5865 | + ob_start(); |
|
| 5866 | + } |
|
| 5551 | 5867 | |
| 5552 | 5868 | // Set the header. |
| 5553 | 5869 | header($type); |
@@ -5579,8 +5895,9 @@ discard block |
||
| 5579 | 5895 | static $done = false; |
| 5580 | 5896 | |
| 5581 | 5897 | // If we don't need to do anything, don't |
| 5582 | - if (!$update && $done) |
|
| 5583 | - return; |
|
| 5898 | + if (!$update && $done) { |
|
| 5899 | + return; |
|
| 5900 | + } |
|
| 5584 | 5901 | |
| 5585 | 5902 | // Should we get a new copy of the official list of TLDs? |
| 5586 | 5903 | if ($update) |
@@ -5601,10 +5918,11 @@ discard block |
||
| 5601 | 5918 | // Clean $tlds and convert it to an array |
| 5602 | 5919 | $tlds = array_filter(explode("\n", strtolower($tlds)), function($line) { |
| 5603 | 5920 | $line = trim($line); |
| 5604 | - if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) |
|
| 5605 | - return false; |
|
| 5606 | - else |
|
| 5607 | - return true; |
|
| 5921 | + if (empty($line) || strpos($line, '#') !== false || strpos($line, ' ') !== false) { |
|
| 5922 | + return false; |
|
| 5923 | + } else { |
|
| 5924 | + return true; |
|
| 5925 | + } |
|
| 5608 | 5926 | }); |
| 5609 | 5927 | |
| 5610 | 5928 | // Convert Punycode to Unicode |
@@ -5658,8 +5976,9 @@ discard block |
||
| 5658 | 5976 | $idx += $digit * $w; |
| 5659 | 5977 | $t = ($k <= $bias) ? $tmin : (($k >= $bias + $tmax) ? $tmax : ($k - $bias)); |
| 5660 | 5978 | |
| 5661 | - if ($digit < $t) |
|
| 5662 | - break; |
|
| 5979 | + if ($digit < $t) { |
|
| 5980 | + break; |
|
| 5981 | + } |
|
| 5663 | 5982 | |
| 5664 | 5983 | $w = (int) ($w * ($base - $t)); |
| 5665 | 5984 | } |
@@ -5668,8 +5987,9 @@ discard block |
||
| 5668 | 5987 | $delta = intval($is_first ? ($delta / $damp) : ($delta / 2)); |
| 5669 | 5988 | $delta += intval($delta / ($deco_len + 1)); |
| 5670 | 5989 | |
| 5671 | - for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) |
|
| 5672 | - $delta = intval($delta / ($base - $tmin)); |
|
| 5990 | + for ($k = 0; $delta > (($base - $tmin) * $tmax) / 2; $k += $base) { |
|
| 5991 | + $delta = intval($delta / ($base - $tmin)); |
|
| 5992 | + } |
|
| 5673 | 5993 | |
| 5674 | 5994 | $bias = intval($k + ($base - $tmin + 1) * $delta / ($delta + $skew)); |
| 5675 | 5995 | $is_first = false; |
@@ -5678,8 +5998,9 @@ discard block |
||
| 5678 | 5998 | |
| 5679 | 5999 | if ($deco_len > 0) |
| 5680 | 6000 | { |
| 5681 | - for ($i = $deco_len; $i > $idx; $i--) |
|
| 5682 | - $decoded[$i] = $decoded[($i - 1)]; |
|
| 6001 | + for ($i = $deco_len; $i > $idx; $i--) { |
|
| 6002 | + $decoded[$i] = $decoded[($i - 1)]; |
|
| 6003 | + } |
|
| 5683 | 6004 | } |
| 5684 | 6005 | $decoded[$idx++] = $char; |
| 5685 | 6006 | } |
@@ -5687,24 +6008,29 @@ discard block |
||
| 5687 | 6008 | foreach ($decoded as $k => $v) |
| 5688 | 6009 | { |
| 5689 | 6010 | // 7bit are transferred literally |
| 5690 | - if ($v < 128) |
|
| 5691 | - $output .= chr($v); |
|
| 6011 | + if ($v < 128) { |
|
| 6012 | + $output .= chr($v); |
|
| 6013 | + } |
|
| 5692 | 6014 | |
| 5693 | 6015 | // 2 bytes |
| 5694 | - elseif ($v < (1 << 11)) |
|
| 5695 | - $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6016 | + elseif ($v < (1 << 11)) { |
|
| 6017 | + $output .= chr(192+($v >> 6)) . chr(128+($v & 63)); |
|
| 6018 | + } |
|
| 5696 | 6019 | |
| 5697 | 6020 | // 3 bytes |
| 5698 | - elseif ($v < (1 << 16)) |
|
| 5699 | - $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6021 | + elseif ($v < (1 << 16)) { |
|
| 6022 | + $output .= chr(224+($v >> 12)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6023 | + } |
|
| 5700 | 6024 | |
| 5701 | 6025 | // 4 bytes |
| 5702 | - elseif ($v < (1 << 21)) |
|
| 5703 | - $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6026 | + elseif ($v < (1 << 21)) { |
|
| 6027 | + $output .= chr(240+($v >> 18)) . chr(128+(($v >> 12) & 63)) . chr(128+(($v >> 6) & 63)) . chr(128+($v & 63)); |
|
| 6028 | + } |
|
| 5704 | 6029 | |
| 5705 | 6030 | // 'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k |
| 5706 | - else |
|
| 5707 | - $output .= $safe_char; |
|
| 6031 | + else { |
|
| 6032 | + $output .= $safe_char; |
|
| 6033 | + } |
|
| 5708 | 6034 | } |
| 5709 | 6035 | |
| 5710 | 6036 | $output_parts[] = $output; |
@@ -5799,8 +6125,7 @@ discard block |
||
| 5799 | 6125 | |
| 5800 | 6126 | $strlen = 'mb_strlen'; |
| 5801 | 6127 | $substr = 'mb_substr'; |
| 5802 | - } |
|
| 5803 | - else |
|
| 6128 | + } else |
|
| 5804 | 6129 | { |
| 5805 | 6130 | $strlen = $smcFunc['strlen']; |
| 5806 | 6131 | $substr = $smcFunc['substr']; |
@@ -5814,20 +6139,21 @@ discard block |
||
| 5814 | 6139 | |
| 5815 | 6140 | $first = $substr($string, 0, 1); |
| 5816 | 6141 | |
| 5817 | - if (empty($index[$first])) |
|
| 5818 | - $index[$first] = array(); |
|
| 6142 | + if (empty($index[$first])) { |
|
| 6143 | + $index[$first] = array(); |
|
| 6144 | + } |
|
| 5819 | 6145 | |
| 5820 | 6146 | if ($strlen($string) > 1) |
| 5821 | 6147 | { |
| 5822 | 6148 | // Sanity check on recursion |
| 5823 | - if ($depth > 99) |
|
| 5824 | - $index[$first][$substr($string, 1)] = ''; |
|
| 5825 | - |
|
| 5826 | - else |
|
| 5827 | - $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6149 | + if ($depth > 99) { |
|
| 6150 | + $index[$first][$substr($string, 1)] = ''; |
|
| 6151 | + } else { |
|
| 6152 | + $index[$first] = $add_string_to_index($substr($string, 1), $index[$first]); |
|
| 6153 | + } |
|
| 6154 | + } else { |
|
| 6155 | + $index[$first][''] = ''; |
|
| 5828 | 6156 | } |
| 5829 | - else |
|
| 5830 | - $index[$first][''] = ''; |
|
| 5831 | 6157 | |
| 5832 | 6158 | $depth--; |
| 5833 | 6159 | return $index; |
@@ -5850,9 +6176,9 @@ discard block |
||
| 5850 | 6176 | $key_regex = preg_quote($key, $delim); |
| 5851 | 6177 | $new_key = $key; |
| 5852 | 6178 | |
| 5853 | - if (empty($value)) |
|
| 5854 | - $sub_regex = ''; |
|
| 5855 | - else |
|
| 6179 | + if (empty($value)) { |
|
| 6180 | + $sub_regex = ''; |
|
| 6181 | + } else |
|
| 5856 | 6182 | { |
| 5857 | 6183 | $sub_regex = $index_to_regex($value, $delim); |
| 5858 | 6184 | |
@@ -5860,22 +6186,22 @@ discard block |
||
| 5860 | 6186 | { |
| 5861 | 6187 | $new_key_array = explode('(?'.'>', $sub_regex); |
| 5862 | 6188 | $new_key .= $new_key_array[0]; |
| 6189 | + } else { |
|
| 6190 | + $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5863 | 6191 | } |
| 5864 | - else |
|
| 5865 | - $sub_regex = '(?'.'>' . $sub_regex . ')'; |
|
| 5866 | 6192 | } |
| 5867 | 6193 | |
| 5868 | - if ($depth > 1) |
|
| 5869 | - $regex[$new_key] = $key_regex . $sub_regex; |
|
| 5870 | - else |
|
| 6194 | + if ($depth > 1) { |
|
| 6195 | + $regex[$new_key] = $key_regex . $sub_regex; |
|
| 6196 | + } else |
|
| 5871 | 6197 | { |
| 5872 | 6198 | if (($length += strlen($key_regex) + 1) < $max_length || empty($regex)) |
| 5873 | 6199 | { |
| 5874 | 6200 | $regex[$new_key] = $key_regex . $sub_regex; |
| 5875 | 6201 | unset($index[$key]); |
| 6202 | + } else { |
|
| 6203 | + break; |
|
| 5876 | 6204 | } |
| 5877 | - else |
|
| 5878 | - break; |
|
| 5879 | 6205 | } |
| 5880 | 6206 | } |
| 5881 | 6207 | |
@@ -5884,10 +6210,11 @@ discard block |
||
| 5884 | 6210 | $l1 = $strlen($k1); |
| 5885 | 6211 | $l2 = $strlen($k2); |
| 5886 | 6212 | |
| 5887 | - if ($l1 == $l2) |
|
| 5888 | - return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 5889 | - else |
|
| 5890 | - return $l1 > $l2 ? -1 : 1; |
|
| 6213 | + if ($l1 == $l2) { |
|
| 6214 | + return strcmp($k1, $k2) > 0 ? 1 : -1; |
|
| 6215 | + } else { |
|
| 6216 | + return $l1 > $l2 ? -1 : 1; |
|
| 6217 | + } |
|
| 5891 | 6218 | }); |
| 5892 | 6219 | |
| 5893 | 6220 | $depth--; |
@@ -5898,15 +6225,18 @@ discard block |
||
| 5898 | 6225 | $index = array(); |
| 5899 | 6226 | $regexes = array(); |
| 5900 | 6227 | |
| 5901 | - foreach ($strings as $string) |
|
| 5902 | - $index = $add_string_to_index($string, $index); |
|
| 6228 | + foreach ($strings as $string) { |
|
| 6229 | + $index = $add_string_to_index($string, $index); |
|
| 6230 | + } |
|
| 5903 | 6231 | |
| 5904 | - while (!empty($index)) |
|
| 5905 | - $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6232 | + while (!empty($index)) { |
|
| 6233 | + $regexes[] = '(?'.'>' . $index_to_regex($index, $delim) . ')'; |
|
| 6234 | + } |
|
| 5906 | 6235 | |
| 5907 | 6236 | // Restore PHP's internal character encoding to whatever it was originally |
| 5908 | - if (!empty($current_encoding)) |
|
| 5909 | - mb_internal_encoding($current_encoding); |
|
| 6237 | + if (!empty($current_encoding)) { |
|
| 6238 | + mb_internal_encoding($current_encoding); |
|
| 6239 | + } |
|
| 5910 | 6240 | |
| 5911 | 6241 | return $regexes; |
| 5912 | 6242 | } |
@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | * @version 2.1 Beta 3 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -if (!defined('SMF')) |
|
| 14 | +if (!defined('SMF')) { |
|
| 15 | 15 | die('Hacking attempt...'); |
| 16 | +} |
|
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | 19 | * Our Cache API class |
@@ -44,8 +45,9 @@ discard block |
||
| 44 | 45 | { |
| 45 | 46 | $supported = function_exists('xcache_get') && function_exists('xcache_set') && ini_get('xcache.var_size') > 0; |
| 46 | 47 | |
| 47 | - if ($test) |
|
| 48 | - return $supported; |
|
| 48 | + if ($test) { |
|
| 49 | + return $supported; |
|
| 50 | + } |
|
| 49 | 51 | return parent::isSupported() && $supported; |
| 50 | 52 | } |
| 51 | 53 | |
@@ -66,10 +68,11 @@ discard block |
||
| 66 | 68 | { |
| 67 | 69 | $key = $this->prefix . strtr($key, ':/', '-_'); |
| 68 | 70 | |
| 69 | - if ($value === null) |
|
| 70 | - return xcache_unset($key); |
|
| 71 | - else |
|
| 72 | - return xcache_set($key, $value, $ttl); |
|
| 71 | + if ($value === null) { |
|
| 72 | + return xcache_unset($key); |
|
| 73 | + } else { |
|
| 74 | + return xcache_set($key, $value, $ttl); |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | /** |
@@ -88,10 +91,12 @@ discard block |
||
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | // if passed a type, clear that type out |
| 91 | - if ($type === '' || $type === 'user') |
|
| 92 | - xcache_clear_cache(XC_TYPE_VAR, 0); |
|
| 93 | - if ($type === '' || $type === 'data') |
|
| 94 | - xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 94 | + if ($type === '' || $type === 'user') { |
|
| 95 | + xcache_clear_cache(XC_TYPE_VAR, 0); |
|
| 96 | + } |
|
| 97 | + if ($type === '' || $type === 'data') { |
|
| 98 | + xcache_clear_cache(XC_TYPE_PHP, 0); |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $this->invalidateCache(); |
| 97 | 102 | return true; |
@@ -110,8 +115,9 @@ discard block |
||
| 110 | 115 | // While we could md5 this when saving, this could be tricky to be sure it doesn't get corrupted on additional saves. |
| 111 | 116 | $config_vars[] = array('xcache_adminpass', $txt['cache_xcache_adminpass'], 'db', 'text', 0); |
| 112 | 117 | |
| 113 | - if (!isset($context['settings_post_javascript'])) |
|
| 114 | - $context['settings_post_javascript'] = ''; |
|
| 118 | + if (!isset($context['settings_post_javascript'])) { |
|
| 119 | + $context['settings_post_javascript'] = ''; |
|
| 120 | + } |
|
| 115 | 121 | |
| 116 | 122 | $context['settings_post_javascript'] .= ' |
| 117 | 123 | $("#cache_accelerator").change(function (e) { |
@@ -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 | * Get all birthdays within the given time range. |
@@ -60,8 +61,7 @@ discard block |
||
| 60 | 61 | 'max_year' => $year_high, |
| 61 | 62 | ) |
| 62 | 63 | ); |
| 63 | - } |
|
| 64 | - else |
|
| 64 | + } else |
|
| 65 | 65 | { |
| 66 | 66 | $result = $smcFunc['db_query']('birthday_array', ' |
| 67 | 67 | SELECT id_member, real_name, YEAR(birthdate) AS birth_year, birthdate |
@@ -91,10 +91,11 @@ discard block |
||
| 91 | 91 | $bday = array(); |
| 92 | 92 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 93 | 93 | { |
| 94 | - if ($year_low != $year_high) |
|
| 95 | - $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
| 96 | - else |
|
| 97 | - $age_year = $year_low; |
|
| 94 | + if ($year_low != $year_high) { |
|
| 95 | + $age_year = substr($row['birthdate'], 5) < substr($high_date, 5) ? $year_high : $year_low; |
|
| 96 | + } else { |
|
| 97 | + $age_year = $year_low; |
|
| 98 | + } |
|
| 98 | 99 | |
| 99 | 100 | $bday[$age_year . substr($row['birthdate'], 4)][] = array( |
| 100 | 101 | 'id' => $row['id_member'], |
@@ -108,8 +109,9 @@ discard block |
||
| 108 | 109 | ksort($bday); |
| 109 | 110 | |
| 110 | 111 | // Set is_last, so the themes know when to stop placing separators. |
| 111 | - foreach ($bday as $mday => $array) |
|
| 112 | - $bday[$mday][count($array) - 1]['is_last'] = true; |
|
| 112 | + foreach ($bday as $mday => $array) { |
|
| 113 | + $bday[$mday][count($array) - 1]['is_last'] = true; |
|
| 114 | + } |
|
| 113 | 115 | |
| 114 | 116 | return $bday; |
| 115 | 117 | } |
@@ -157,8 +159,9 @@ discard block |
||
| 157 | 159 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 158 | 160 | { |
| 159 | 161 | // If the attached topic is not approved then for the moment pretend it doesn't exist |
| 160 | - if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) |
|
| 161 | - continue; |
|
| 162 | + if (!empty($row['id_first_msg']) && $modSettings['postmod_active'] && !$row['approved']) { |
|
| 163 | + continue; |
|
| 164 | + } |
|
| 162 | 165 | |
| 163 | 166 | // Force a censor of the title - as often these are used by others. |
| 164 | 167 | censorText($row['title'], $use_permissions ? false : true); |
@@ -167,8 +170,9 @@ discard block |
||
| 167 | 170 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
| 168 | 171 | |
| 169 | 172 | // Sanity check |
| 170 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
| 171 | - continue; |
|
| 173 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
| 174 | + continue; |
|
| 175 | + } |
|
| 172 | 176 | |
| 173 | 177 | // Get set up for the loop |
| 174 | 178 | $start_object = date_create($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : ''), timezone_open($tz)); |
@@ -232,8 +236,8 @@ discard block |
||
| 232 | 236 | ); |
| 233 | 237 | |
| 234 | 238 | // If we're using permissions (calendar pages?) then just ouput normal contextual style information. |
| 235 | - if ($use_permissions) |
|
| 236 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 239 | + if ($use_permissions) { |
|
| 240 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 237 | 241 | 'href' => $row['id_board'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
| 238 | 242 | 'link' => $row['id_board'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
| 239 | 243 | 'can_edit' => allowedTo('calendar_edit_any') || ($row['id_member'] == $user_info['id'] && allowedTo('calendar_edit_own')), |
@@ -241,9 +245,10 @@ discard block |
||
| 241 | 245 | 'can_export' => !empty($modSettings['cal_export']) ? true : false, |
| 242 | 246 | 'export_href' => $scripturl . '?action=calendar;sa=ical;eventid=' . $row['id_event'] . ';' . $context['session_var'] . '=' . $context['session_id'], |
| 243 | 247 | )); |
| 248 | + } |
|
| 244 | 249 | // Otherwise, this is going to be cached and the VIEWER'S permissions should apply... just put together some info. |
| 245 | - else |
|
| 246 | - $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 250 | + else { |
|
| 251 | + $events[date_format($cal_date, 'Y-m-d')][] = array_merge($eventProperties, array( |
|
| 247 | 252 | 'href' => $row['id_topic'] == 0 ? '' : $scripturl . '?topic=' . $row['id_topic'] . '.0', |
| 248 | 253 | 'link' => $row['id_topic'] == 0 ? $row['title'] : '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.0">' . $row['title'] . '</a>', |
| 249 | 254 | 'can_edit' => false, |
@@ -253,6 +258,7 @@ discard block |
||
| 253 | 258 | 'poster' => $row['id_member'], |
| 254 | 259 | 'allowed_groups' => explode(',', $row['member_groups']), |
| 255 | 260 | )); |
| 261 | + } |
|
| 256 | 262 | |
| 257 | 263 | date_add($cal_date, date_interval_create_from_date_string('1 day')); |
| 258 | 264 | } |
@@ -262,8 +268,9 @@ discard block |
||
| 262 | 268 | // If we're doing normal contextual data, go through and make things clear to the templates ;). |
| 263 | 269 | if ($use_permissions) |
| 264 | 270 | { |
| 265 | - foreach ($events as $mday => $array) |
|
| 266 | - $events[$mday][count($array) - 1]['is_last'] = true; |
|
| 271 | + foreach ($events as $mday => $array) { |
|
| 272 | + $events[$mday][count($array) - 1]['is_last'] = true; |
|
| 273 | + } |
|
| 267 | 274 | } |
| 268 | 275 | |
| 269 | 276 | ksort($events); |
@@ -283,11 +290,12 @@ discard block |
||
| 283 | 290 | global $smcFunc; |
| 284 | 291 | |
| 285 | 292 | // Get the lowest and highest dates for "all years". |
| 286 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
| 287 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
| 293 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
| 294 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_dec} |
|
| 288 | 295 | OR event_date BETWEEN {date:all_year_jan} AND {date:all_year_high}'; |
| 289 | - else |
|
| 290 | - $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
| 296 | + } else { |
|
| 297 | + $allyear_part = 'event_date BETWEEN {date:all_year_low} AND {date:all_year_high}'; |
|
| 298 | + } |
|
| 291 | 299 | |
| 292 | 300 | // Find some holidays... ;). |
| 293 | 301 | $result = $smcFunc['db_query']('', ' |
@@ -307,10 +315,11 @@ discard block |
||
| 307 | 315 | $holidays = array(); |
| 308 | 316 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 309 | 317 | { |
| 310 | - if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) |
|
| 311 | - $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
| 312 | - else |
|
| 313 | - $event_year = substr($low_date, 0, 4); |
|
| 318 | + if (substr($low_date, 0, 4) != substr($high_date, 0, 4)) { |
|
| 319 | + $event_year = substr($row['event_date'], 5) < substr($high_date, 5) ? substr($high_date, 0, 4) : substr($low_date, 0, 4); |
|
| 320 | + } else { |
|
| 321 | + $event_year = substr($low_date, 0, 4); |
|
| 322 | + } |
|
| 314 | 323 | |
| 315 | 324 | $holidays[$event_year . substr($row['event_date'], 4)][] = $row['title']; |
| 316 | 325 | } |
@@ -336,10 +345,12 @@ discard block |
||
| 336 | 345 | isAllowedTo('calendar_post'); |
| 337 | 346 | |
| 338 | 347 | // No board? No topic?!? |
| 339 | - if (empty($board)) |
|
| 340 | - fatal_lang_error('missing_board_id', false); |
|
| 341 | - if (empty($topic)) |
|
| 342 | - fatal_lang_error('missing_topic_id', false); |
|
| 348 | + if (empty($board)) { |
|
| 349 | + fatal_lang_error('missing_board_id', false); |
|
| 350 | + } |
|
| 351 | + if (empty($topic)) { |
|
| 352 | + fatal_lang_error('missing_topic_id', false); |
|
| 353 | + } |
|
| 343 | 354 | |
| 344 | 355 | // Administrator, Moderator, or owner. Period. |
| 345 | 356 | if (!allowedTo('admin_forum') && !allowedTo('moderate_board')) |
@@ -357,12 +368,14 @@ discard block |
||
| 357 | 368 | if ($row = $smcFunc['db_fetch_assoc']($result)) |
| 358 | 369 | { |
| 359 | 370 | // Not the owner of the topic. |
| 360 | - if ($row['id_member_started'] != $user_info['id']) |
|
| 361 | - fatal_lang_error('not_your_topic', 'user'); |
|
| 371 | + if ($row['id_member_started'] != $user_info['id']) { |
|
| 372 | + fatal_lang_error('not_your_topic', 'user'); |
|
| 373 | + } |
|
| 362 | 374 | } |
| 363 | 375 | // Topic/Board doesn't exist..... |
| 364 | - else |
|
| 365 | - fatal_lang_error('calendar_no_topic', 'general'); |
|
| 376 | + else { |
|
| 377 | + fatal_lang_error('calendar_no_topic', 'general'); |
|
| 378 | + } |
|
| 366 | 379 | $smcFunc['db_free_result']($result); |
| 367 | 380 | } |
| 368 | 381 | } |
@@ -450,14 +463,16 @@ discard block |
||
| 450 | 463 | if (!empty($calendarOptions['start_day'])) |
| 451 | 464 | { |
| 452 | 465 | $nShift -= $calendarOptions['start_day']; |
| 453 | - if ($nShift < 0) |
|
| 454 | - $nShift = 7 + $nShift; |
|
| 466 | + if ($nShift < 0) { |
|
| 467 | + $nShift = 7 + $nShift; |
|
| 468 | + } |
|
| 455 | 469 | } |
| 456 | 470 | |
| 457 | 471 | // Number of rows required to fit the month. |
| 458 | 472 | $nRows = floor(($month_info['last_day']['day_of_month'] + $nShift) / 7); |
| 459 | - if (($month_info['last_day']['day_of_month'] + $nShift) % 7) |
|
| 460 | - $nRows++; |
|
| 473 | + if (($month_info['last_day']['day_of_month'] + $nShift) % 7) { |
|
| 474 | + $nRows++; |
|
| 475 | + } |
|
| 461 | 476 | |
| 462 | 477 | // Fetch the arrays for birthdays, posted events, and holidays. |
| 463 | 478 | $bday = $calendarOptions['show_birthdays'] ? getBirthdayRange($month_info['first_day']['date'], $month_info['last_day']['date']) : array(); |
@@ -470,8 +485,9 @@ discard block |
||
| 470 | 485 | { |
| 471 | 486 | $calendarGrid['week_days'][] = $count; |
| 472 | 487 | $count++; |
| 473 | - if ($count == 7) |
|
| 474 | - $count = 0; |
|
| 488 | + if ($count == 7) { |
|
| 489 | + $count = 0; |
|
| 490 | + } |
|
| 475 | 491 | } |
| 476 | 492 | |
| 477 | 493 | // Iterate through each week. |
@@ -488,8 +504,9 @@ discard block |
||
| 488 | 504 | { |
| 489 | 505 | $nDay = ($nRow * 7) + $nCol - $nShift + 1; |
| 490 | 506 | |
| 491 | - if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) |
|
| 492 | - $nDay = 0; |
|
| 507 | + if ($nDay < 1 || $nDay > $month_info['last_day']['day_of_month']) { |
|
| 508 | + $nDay = 0; |
|
| 509 | + } |
|
| 493 | 510 | |
| 494 | 511 | $date = sprintf('%04d-%02d-%02d', $year, $month, $nDay); |
| 495 | 512 | |
@@ -507,8 +524,9 @@ discard block |
||
| 507 | 524 | } |
| 508 | 525 | |
| 509 | 526 | // What is the last day of the month? |
| 510 | - if ($is_previous === true) |
|
| 511 | - $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
| 527 | + if ($is_previous === true) { |
|
| 528 | + $calendarGrid['last_of_month'] = $month_info['last_day']['day_of_month']; |
|
| 529 | + } |
|
| 512 | 530 | |
| 513 | 531 | // We'll use the shift in the template. |
| 514 | 532 | $calendarGrid['shift'] = $nShift; |
@@ -542,8 +560,9 @@ discard block |
||
| 542 | 560 | { |
| 543 | 561 | // Here we offset accordingly to get things to the real start of a week. |
| 544 | 562 | $date_diff = $day_of_week - $calendarOptions['start_day']; |
| 545 | - if ($date_diff < 0) |
|
| 546 | - $date_diff += 7; |
|
| 563 | + if ($date_diff < 0) { |
|
| 564 | + $date_diff += 7; |
|
| 565 | + } |
|
| 547 | 566 | $new_timestamp = mktime(0, 0, 0, $month, $day, $year) - $date_diff * 86400; |
| 548 | 567 | $day = (int) strftime('%d', $new_timestamp); |
| 549 | 568 | $month = (int) strftime('%m', $new_timestamp); |
@@ -673,18 +692,20 @@ discard block |
||
| 673 | 692 | { |
| 674 | 693 | foreach ($date_events as $event_key => $event_val) |
| 675 | 694 | { |
| 676 | - if (in_array($event_val['id'], $temp)) |
|
| 677 | - unset($calendarGrid['events'][$date][$event_key]); |
|
| 678 | - else |
|
| 679 | - $temp[] = $event_val['id']; |
|
| 695 | + if (in_array($event_val['id'], $temp)) { |
|
| 696 | + unset($calendarGrid['events'][$date][$event_key]); |
|
| 697 | + } else { |
|
| 698 | + $temp[] = $event_val['id']; |
|
| 699 | + } |
|
| 680 | 700 | } |
| 681 | 701 | } |
| 682 | 702 | |
| 683 | 703 | // Give birthdays and holidays a friendly format, without the year |
| 684 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 685 | - $date_format = '%b %d'; |
|
| 686 | - else |
|
| 687 | - $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
| 704 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 705 | + $date_format = '%b %d'; |
|
| 706 | + } else { |
|
| 707 | + $date_format = str_replace(array('%Y', '%y', '%G', '%g', '%C', '%c', '%D'), array('', '', '', '', '', '%b %d', '%m/%d'), $matches[0]); |
|
| 708 | + } |
|
| 688 | 709 | |
| 689 | 710 | foreach (array('birthdays', 'holidays') as $type) |
| 690 | 711 | { |
@@ -779,8 +800,9 @@ discard block |
||
| 779 | 800 | // Holidays between now and now + days. |
| 780 | 801 | for ($i = $now; $i < $now + $days_for_index; $i += 86400) |
| 781 | 802 | { |
| 782 | - if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) |
|
| 783 | - $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
| 803 | + if (isset($cached_data['holidays'][strftime('%Y-%m-%d', $i)])) { |
|
| 804 | + $return_data['calendar_holidays'] = array_merge($return_data['calendar_holidays'], $cached_data['holidays'][strftime('%Y-%m-%d', $i)]); |
|
| 805 | + } |
|
| 784 | 806 | } |
| 785 | 807 | |
| 786 | 808 | // Happy Birthday, guys and gals! |
@@ -789,8 +811,9 @@ discard block |
||
| 789 | 811 | $loop_date = strftime('%Y-%m-%d', $i); |
| 790 | 812 | if (isset($cached_data['birthdays'][$loop_date])) |
| 791 | 813 | { |
| 792 | - foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) |
|
| 793 | - $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
| 814 | + foreach ($cached_data['birthdays'][$loop_date] as $index => $dummy) { |
|
| 815 | + $cached_data['birthdays'][strftime('%Y-%m-%d', $i)][$index]['is_today'] = $loop_date === $today['date']; |
|
| 816 | + } |
|
| 794 | 817 | $return_data['calendar_birthdays'] = array_merge($return_data['calendar_birthdays'], $cached_data['birthdays'][$loop_date]); |
| 795 | 818 | } |
| 796 | 819 | } |
@@ -802,8 +825,9 @@ discard block |
||
| 802 | 825 | $loop_date = strftime('%Y-%m-%d', $i); |
| 803 | 826 | |
| 804 | 827 | // No events today? Check the next day. |
| 805 | - if (empty($cached_data['events'][$loop_date])) |
|
| 806 | - continue; |
|
| 828 | + if (empty($cached_data['events'][$loop_date])) { |
|
| 829 | + continue; |
|
| 830 | + } |
|
| 807 | 831 | |
| 808 | 832 | // Loop through all events to add a few last-minute values. |
| 809 | 833 | foreach ($cached_data['events'][$loop_date] as $ev => $event) |
@@ -816,9 +840,9 @@ discard block |
||
| 816 | 840 | { |
| 817 | 841 | unset($cached_data['events'][$loop_date][$ev]); |
| 818 | 842 | continue; |
| 843 | + } else { |
|
| 844 | + $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
| 819 | 845 | } |
| 820 | - else |
|
| 821 | - $duplicates[$this_event['topic'] . $this_event['title']] = true; |
|
| 822 | 846 | |
| 823 | 847 | // Might be set to true afterwards, depending on the permissions. |
| 824 | 848 | $this_event['can_edit'] = false; |
@@ -826,15 +850,18 @@ discard block |
||
| 826 | 850 | $this_event['date'] = $loop_date; |
| 827 | 851 | } |
| 828 | 852 | |
| 829 | - if (!empty($cached_data['events'][$loop_date])) |
|
| 830 | - $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
| 853 | + if (!empty($cached_data['events'][$loop_date])) { |
|
| 854 | + $return_data['calendar_events'] = array_merge($return_data['calendar_events'], $cached_data['events'][$loop_date]); |
|
| 855 | + } |
|
| 831 | 856 | } |
| 832 | 857 | |
| 833 | 858 | // Mark the last item so that a list separator can be used in the template. |
| 834 | - for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) |
|
| 835 | - $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
| 836 | - for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) |
|
| 837 | - $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
| 859 | + for ($i = 0, $n = count($return_data['calendar_birthdays']); $i < $n; $i++) { |
|
| 860 | + $return_data['calendar_birthdays'][$i]['is_last'] = !isset($return_data['calendar_birthdays'][$i + 1]); |
|
| 861 | + } |
|
| 862 | + for ($i = 0, $n = count($return_data['calendar_events']); $i < $n; $i++) { |
|
| 863 | + $return_data['calendar_events'][$i]['is_last'] = !isset($return_data['calendar_events'][$i + 1]); |
|
| 864 | + } |
|
| 838 | 865 | |
| 839 | 866 | return array( |
| 840 | 867 | 'data' => $return_data, |
@@ -882,37 +909,46 @@ discard block |
||
| 882 | 909 | if (isset($_POST['start_date'])) |
| 883 | 910 | { |
| 884 | 911 | $d = date_parse($_POST['start_date']); |
| 885 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
| 886 | - fatal_lang_error('invalid_date', false); |
|
| 887 | - if (empty($d['year'])) |
|
| 888 | - fatal_lang_error('event_year_missing', false); |
|
| 889 | - if (empty($d['month'])) |
|
| 890 | - fatal_lang_error('event_month_missing', false); |
|
| 891 | - } |
|
| 892 | - elseif (isset($_POST['start_datetime'])) |
|
| 912 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
| 913 | + fatal_lang_error('invalid_date', false); |
|
| 914 | + } |
|
| 915 | + if (empty($d['year'])) { |
|
| 916 | + fatal_lang_error('event_year_missing', false); |
|
| 917 | + } |
|
| 918 | + if (empty($d['month'])) { |
|
| 919 | + fatal_lang_error('event_month_missing', false); |
|
| 920 | + } |
|
| 921 | + } elseif (isset($_POST['start_datetime'])) |
|
| 893 | 922 | { |
| 894 | 923 | $d = date_parse($_POST['start_datetime']); |
| 895 | - if (!empty($d['error_count']) || !empty($d['warning_count'])) |
|
| 896 | - fatal_lang_error('invalid_date', false); |
|
| 897 | - if (empty($d['year'])) |
|
| 898 | - fatal_lang_error('event_year_missing', false); |
|
| 899 | - if (empty($d['month'])) |
|
| 900 | - fatal_lang_error('event_month_missing', false); |
|
| 924 | + if (!empty($d['error_count']) || !empty($d['warning_count'])) { |
|
| 925 | + fatal_lang_error('invalid_date', false); |
|
| 926 | + } |
|
| 927 | + if (empty($d['year'])) { |
|
| 928 | + fatal_lang_error('event_year_missing', false); |
|
| 929 | + } |
|
| 930 | + if (empty($d['month'])) { |
|
| 931 | + fatal_lang_error('event_month_missing', false); |
|
| 932 | + } |
|
| 901 | 933 | } |
| 902 | 934 | // The 2.0 way |
| 903 | 935 | else |
| 904 | 936 | { |
| 905 | 937 | // No month? No year? |
| 906 | - if (!isset($_POST['month'])) |
|
| 907 | - fatal_lang_error('event_month_missing', false); |
|
| 908 | - if (!isset($_POST['year'])) |
|
| 909 | - fatal_lang_error('event_year_missing', false); |
|
| 938 | + if (!isset($_POST['month'])) { |
|
| 939 | + fatal_lang_error('event_month_missing', false); |
|
| 940 | + } |
|
| 941 | + if (!isset($_POST['year'])) { |
|
| 942 | + fatal_lang_error('event_year_missing', false); |
|
| 943 | + } |
|
| 910 | 944 | |
| 911 | 945 | // Check the month and year... |
| 912 | - if ($_POST['month'] < 1 || $_POST['month'] > 12) |
|
| 913 | - fatal_lang_error('invalid_month', false); |
|
| 914 | - if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) |
|
| 915 | - fatal_lang_error('invalid_year', false); |
|
| 946 | + if ($_POST['month'] < 1 || $_POST['month'] > 12) { |
|
| 947 | + fatal_lang_error('invalid_month', false); |
|
| 948 | + } |
|
| 949 | + if ($_POST['year'] < $modSettings['cal_minyear'] || $_POST['year'] > $modSettings['cal_maxyear']) { |
|
| 950 | + fatal_lang_error('invalid_year', false); |
|
| 951 | + } |
|
| 916 | 952 | } |
| 917 | 953 | } |
| 918 | 954 | |
@@ -922,8 +958,9 @@ discard block |
||
| 922 | 958 | // If they want to us to calculate an end date, make sure it will fit in an acceptable range. |
| 923 | 959 | if (isset($_POST['span'])) |
| 924 | 960 | { |
| 925 | - if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) |
|
| 926 | - fatal_lang_error('invalid_days_numb', false); |
|
| 961 | + if (($_POST['span'] < 1) || (!empty($modSettings['cal_maxspan']) && $_POST['span'] > $modSettings['cal_maxspan'])) { |
|
| 962 | + fatal_lang_error('invalid_days_numb', false); |
|
| 963 | + } |
|
| 927 | 964 | } |
| 928 | 965 | |
| 929 | 966 | // There is no need to validate the following values if we are just deleting the event. |
@@ -933,24 +970,29 @@ discard block |
||
| 933 | 970 | if (empty($_POST['start_date']) && empty($_POST['start_datetime'])) |
| 934 | 971 | { |
| 935 | 972 | // No day? |
| 936 | - if (!isset($_POST['day'])) |
|
| 937 | - fatal_lang_error('event_day_missing', false); |
|
| 973 | + if (!isset($_POST['day'])) { |
|
| 974 | + fatal_lang_error('event_day_missing', false); |
|
| 975 | + } |
|
| 938 | 976 | |
| 939 | 977 | // Bad day? |
| 940 | - if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) |
|
| 941 | - fatal_lang_error('invalid_date', false); |
|
| 978 | + if (!checkdate($_POST['month'], $_POST['day'], $_POST['year'])) { |
|
| 979 | + fatal_lang_error('invalid_date', false); |
|
| 980 | + } |
|
| 942 | 981 | } |
| 943 | 982 | |
| 944 | - if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) |
|
| 945 | - fatal_lang_error('event_title_missing', false); |
|
| 946 | - elseif (!isset($_POST['evtitle'])) |
|
| 947 | - $_POST['evtitle'] = $_POST['subject']; |
|
| 983 | + if (!isset($_POST['evtitle']) && !isset($_POST['subject'])) { |
|
| 984 | + fatal_lang_error('event_title_missing', false); |
|
| 985 | + } elseif (!isset($_POST['evtitle'])) { |
|
| 986 | + $_POST['evtitle'] = $_POST['subject']; |
|
| 987 | + } |
|
| 948 | 988 | |
| 949 | 989 | // No title? |
| 950 | - if ($smcFunc['htmltrim']($_POST['evtitle']) === '') |
|
| 951 | - fatal_lang_error('no_event_title', false); |
|
| 952 | - if ($smcFunc['strlen']($_POST['evtitle']) > 100) |
|
| 953 | - $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
| 990 | + if ($smcFunc['htmltrim']($_POST['evtitle']) === '') { |
|
| 991 | + fatal_lang_error('no_event_title', false); |
|
| 992 | + } |
|
| 993 | + if ($smcFunc['strlen']($_POST['evtitle']) > 100) { |
|
| 994 | + $_POST['evtitle'] = $smcFunc['substr']($_POST['evtitle'], 0, 100); |
|
| 995 | + } |
|
| 954 | 996 | $_POST['evtitle'] = str_replace(';', '', $_POST['evtitle']); |
| 955 | 997 | } |
| 956 | 998 | } |
@@ -977,8 +1019,9 @@ discard block |
||
| 977 | 1019 | ); |
| 978 | 1020 | |
| 979 | 1021 | // No results, return false. |
| 980 | - if ($smcFunc['db_num_rows'] === 0) |
|
| 981 | - return false; |
|
| 1022 | + if ($smcFunc['db_num_rows'] === 0) { |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 982 | 1025 | |
| 983 | 1026 | // Grab the results and return. |
| 984 | 1027 | list ($poster) = $smcFunc['db_fetch_row']($request); |
@@ -1112,8 +1155,9 @@ discard block |
||
| 1112 | 1155 | call_integration_hook('integrate_modify_event', array($event_id, &$eventOptions, &$event_columns, &$event_parameters)); |
| 1113 | 1156 | |
| 1114 | 1157 | $column_clauses = array(); |
| 1115 | - foreach ($event_columns as $col => $crit) |
|
| 1116 | - $column_clauses[] = $col . ' = ' . $crit; |
|
| 1158 | + foreach ($event_columns as $col => $crit) { |
|
| 1159 | + $column_clauses[] = $col . ' = ' . $crit; |
|
| 1160 | + } |
|
| 1117 | 1161 | |
| 1118 | 1162 | $smcFunc['db_query']('', ' |
| 1119 | 1163 | UPDATE {db_prefix}calendar |
@@ -1198,8 +1242,9 @@ discard block |
||
| 1198 | 1242 | ); |
| 1199 | 1243 | |
| 1200 | 1244 | // If nothing returned, we are in poo, poo. |
| 1201 | - if ($smcFunc['db_num_rows']($request) === 0) |
|
| 1202 | - return false; |
|
| 1245 | + if ($smcFunc['db_num_rows']($request) === 0) { |
|
| 1246 | + return false; |
|
| 1247 | + } |
|
| 1203 | 1248 | |
| 1204 | 1249 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1205 | 1250 | $smcFunc['db_free_result']($request); |
@@ -1207,8 +1252,9 @@ discard block |
||
| 1207 | 1252 | list($start, $end, $allday, $span, $tz, $tz_abbrev) = buildEventDatetimes($row); |
| 1208 | 1253 | |
| 1209 | 1254 | // Sanity check |
| 1210 | - if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) |
|
| 1211 | - return false; |
|
| 1255 | + if (!empty($start['error_count']) || !empty($start['warning_count']) || !empty($end['error_count']) || !empty($end['warning_count'])) { |
|
| 1256 | + return false; |
|
| 1257 | + } |
|
| 1212 | 1258 | |
| 1213 | 1259 | $return_value = array( |
| 1214 | 1260 | 'boards' => array(), |
@@ -1345,24 +1391,27 @@ discard block |
||
| 1345 | 1391 | |
| 1346 | 1392 | // Set $span, in case we need it |
| 1347 | 1393 | $span = isset($eventOptions['span']) ? $eventOptions['span'] : (isset($_POST['span']) ? $_POST['span'] : 0); |
| 1348 | - if ($span > 0) |
|
| 1349 | - $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
| 1394 | + if ($span > 0) { |
|
| 1395 | + $span = !empty($modSettings['cal_maxspan']) ? min($modSettings['cal_maxspan'], $span - 1) : $span - 1; |
|
| 1396 | + } |
|
| 1350 | 1397 | |
| 1351 | 1398 | // Define the timezone for this event, falling back to the default if not provided |
| 1352 | - if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1353 | - $tz = $eventOptions['tz']; |
|
| 1354 | - elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1355 | - $tz = $_POST['tz']; |
|
| 1356 | - else |
|
| 1357 | - $tz = getUserTimezone(); |
|
| 1399 | + if (!empty($eventOptions['tz']) && in_array($eventOptions['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1400 | + $tz = $eventOptions['tz']; |
|
| 1401 | + } elseif (!empty($_POST['tz']) && in_array($_POST['tz'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1402 | + $tz = $_POST['tz']; |
|
| 1403 | + } else { |
|
| 1404 | + $tz = getUserTimezone(); |
|
| 1405 | + } |
|
| 1358 | 1406 | |
| 1359 | 1407 | // Is this supposed to be an all day event, or should it have specific start and end times? |
| 1360 | - if (isset($eventOptions['allday'])) |
|
| 1361 | - $allday = $eventOptions['allday']; |
|
| 1362 | - elseif (empty($_POST['allday'])) |
|
| 1363 | - $allday = false; |
|
| 1364 | - else |
|
| 1365 | - $allday = true; |
|
| 1408 | + if (isset($eventOptions['allday'])) { |
|
| 1409 | + $allday = $eventOptions['allday']; |
|
| 1410 | + } elseif (empty($_POST['allday'])) { |
|
| 1411 | + $allday = false; |
|
| 1412 | + } else { |
|
| 1413 | + $allday = true; |
|
| 1414 | + } |
|
| 1366 | 1415 | |
| 1367 | 1416 | // Input might come as individual parameters... |
| 1368 | 1417 | $start_year = isset($eventOptions['year']) ? $eventOptions['year'] : (isset($_POST['year']) ? $_POST['year'] : null); |
@@ -1389,10 +1438,12 @@ discard block |
||
| 1389 | 1438 | $end_time_string = isset($eventOptions['end_time']) ? $eventOptions['end_time'] : (isset($_POST['end_time']) ? $_POST['end_time'] : null); |
| 1390 | 1439 | |
| 1391 | 1440 | // If the date and time were given in separate strings, combine them |
| 1392 | - if (empty($start_string) && isset($start_date_string)) |
|
| 1393 | - $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
| 1394 | - if (empty($end_string) && isset($end_date_string)) |
|
| 1395 | - $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
| 1441 | + if (empty($start_string) && isset($start_date_string)) { |
|
| 1442 | + $start_string = $start_date_string . (isset($start_time_string) ? ' ' . $start_time_string : ''); |
|
| 1443 | + } |
|
| 1444 | + if (empty($end_string) && isset($end_date_string)) { |
|
| 1445 | + $end_string = $end_date_string . (isset($end_time_string) ? ' ' . $end_time_string : ''); |
|
| 1446 | + } |
|
| 1396 | 1447 | |
| 1397 | 1448 | // If some form of string input was given, override individually defined options with it |
| 1398 | 1449 | if (isset($start_string)) |
@@ -1483,10 +1534,11 @@ discard block |
||
| 1483 | 1534 | if ($start_object >= $end_object) |
| 1484 | 1535 | { |
| 1485 | 1536 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
| 1486 | - if ($span > 0) |
|
| 1487 | - date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
| 1488 | - else |
|
| 1489 | - date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
| 1537 | + if ($span > 0) { |
|
| 1538 | + date_add($end_object, date_interval_create_from_date_string($span . ' days')); |
|
| 1539 | + } else { |
|
| 1540 | + date_add($end_object, date_interval_create_from_date_string('1 hour')); |
|
| 1541 | + } |
|
| 1490 | 1542 | } |
| 1491 | 1543 | |
| 1492 | 1544 | // Is $end_object too late? |
@@ -1499,9 +1551,9 @@ discard block |
||
| 1499 | 1551 | { |
| 1500 | 1552 | $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, $start_hour, $start_minute, $start_second) . ' ' . $tz); |
| 1501 | 1553 | date_add($end_object, date_interval_create_from_date_string($modSettings['cal_maxspan'] . ' days')); |
| 1554 | + } else { |
|
| 1555 | + $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
| 1502 | 1556 | } |
| 1503 | - else |
|
| 1504 | - $end_object = date_create(sprintf('%04d-%02d-%02d %02d:%02d:%02d', $start_year, $start_month, $start_day, '11', '59', '59') . ' ' . $tz); |
|
| 1505 | 1557 | } |
| 1506 | 1558 | } |
| 1507 | 1559 | |
@@ -1514,8 +1566,7 @@ discard block |
||
| 1514 | 1566 | $start_time = null; |
| 1515 | 1567 | $end_time = null; |
| 1516 | 1568 | $tz = null; |
| 1517 | - } |
|
| 1518 | - else |
|
| 1569 | + } else |
|
| 1519 | 1570 | { |
| 1520 | 1571 | $start_time = date_format($start_object, 'H:i:s'); |
| 1521 | 1572 | $end_time = date_format($end_object, 'H:i:s'); |
@@ -1536,16 +1587,18 @@ discard block |
||
| 1536 | 1587 | require_once($sourcedir . '/Subs.php'); |
| 1537 | 1588 | |
| 1538 | 1589 | // First, try to create a better date format, ignoring the "time" elements. |
| 1539 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 1540 | - $date_format = '%F'; |
|
| 1541 | - else |
|
| 1542 | - $date_format = $matches[0]; |
|
| 1590 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 1591 | + $date_format = '%F'; |
|
| 1592 | + } else { |
|
| 1593 | + $date_format = $matches[0]; |
|
| 1594 | + } |
|
| 1543 | 1595 | |
| 1544 | 1596 | // We want a fairly compact version of the time, but as close as possible to the user's settings. |
| 1545 | - if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 1546 | - $time_format = '%k:%M'; |
|
| 1547 | - else |
|
| 1548 | - $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 1597 | + if (preg_match('~%[HkIlMpPrRSTX](?:[^%]*%[HkIlMpPrRSTX])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 1598 | + $time_format = '%k:%M'; |
|
| 1599 | + } else { |
|
| 1600 | + $time_format = str_replace(array('%I', '%H', '%S', '%r', '%R', '%T'), array('%l', '%k', '', '%l:%M %p', '%k:%M', '%l:%M'), $matches[0]); |
|
| 1601 | + } |
|
| 1549 | 1602 | |
| 1550 | 1603 | // Should this be an all day event? |
| 1551 | 1604 | $allday = (empty($row['start_time']) || empty($row['end_time']) || empty($row['timezone']) || !in_array($row['timezone'], timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) ? true : false; |
@@ -1554,8 +1607,9 @@ discard block |
||
| 1554 | 1607 | $span = 1 + date_interval_format(date_diff(date_create($row['start_date']), date_create($row['end_date'])), '%d'); |
| 1555 | 1608 | |
| 1556 | 1609 | // We need to have a defined timezone in the steps below |
| 1557 | - if (empty($row['timezone'])) |
|
| 1558 | - $row['timezone'] = getUserTimezone(); |
|
| 1610 | + if (empty($row['timezone'])) { |
|
| 1611 | + $row['timezone'] = getUserTimezone(); |
|
| 1612 | + } |
|
| 1559 | 1613 | |
| 1560 | 1614 | // Get most of the standard date information for the start and end datetimes |
| 1561 | 1615 | $start = date_parse($row['start_date'] . (!$allday ? ' ' . $row['start_time'] : '')); |
@@ -1607,8 +1661,9 @@ discard block |
||
| 1607 | 1661 | global $smcFunc, $context, $user_info, $modSettings; |
| 1608 | 1662 | static $member_cache = array(); |
| 1609 | 1663 | |
| 1610 | - if (is_null($id_member) && $user_info['is_guest'] == false) |
|
| 1611 | - $id_member = $context['user']['id']; |
|
| 1664 | + if (is_null($id_member) && $user_info['is_guest'] == false) { |
|
| 1665 | + $id_member = $context['user']['id']; |
|
| 1666 | + } |
|
| 1612 | 1667 | |
| 1613 | 1668 | //check if the cache got the data |
| 1614 | 1669 | if (isset($id_member) && isset($member_cache[$id_member])) |
@@ -1630,11 +1685,13 @@ discard block |
||
| 1630 | 1685 | $smcFunc['db_free_result']($request); |
| 1631 | 1686 | } |
| 1632 | 1687 | |
| 1633 | - if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) |
|
| 1634 | - $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
| 1688 | + if (empty($timezone) || !in_array($timezone, timezone_identifiers_list(DateTimeZone::ALL_WITH_BC))) { |
|
| 1689 | + $timezone = isset($modSettings['default_timezone']) ? $modSettings['default_timezone'] : date_default_timezone_get(); |
|
| 1690 | + } |
|
| 1635 | 1691 | |
| 1636 | - if (isset($id_member)) |
|
| 1637 | - $member_cache[$id_member] = $timezone; |
|
| 1692 | + if (isset($id_member)) { |
|
| 1693 | + $member_cache[$id_member] = $timezone; |
|
| 1694 | + } |
|
| 1638 | 1695 | |
| 1639 | 1696 | return $timezone; |
| 1640 | 1697 | } |
@@ -1663,8 +1720,9 @@ discard block |
||
| 1663 | 1720 | ) |
| 1664 | 1721 | ); |
| 1665 | 1722 | $holidays = array(); |
| 1666 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1667 | - $holidays[] = $row; |
|
| 1723 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1724 | + $holidays[] = $row; |
|
| 1725 | + } |
|
| 1668 | 1726 | $smcFunc['db_free_result']($request); |
| 1669 | 1727 | |
| 1670 | 1728 | return $holidays; |
@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | * @version 2.1 Beta 3 |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | -if (!defined('SMF')) |
|
| 19 | +if (!defined('SMF')) { |
|
| 20 | 20 | die('No direct access...'); |
| 21 | +} |
|
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Reads a .tar.gz file, filename, in and extracts file(s) from it. |
@@ -67,47 +68,53 @@ discard block |
||
| 67 | 68 | loadLanguage('Packages'); |
| 68 | 69 | |
| 69 | 70 | // This function sorta needs gzinflate! |
| 70 | - if (!function_exists('gzinflate')) |
|
| 71 | - fatal_lang_error('package_no_zlib', 'critical'); |
|
| 71 | + if (!function_exists('gzinflate')) { |
|
| 72 | + fatal_lang_error('package_no_zlib', 'critical'); |
|
| 73 | + } |
|
| 72 | 74 | |
| 73 | 75 | if (substr($gzfilename, 0, 7) == 'http://' || substr($gzfilename, 0, 8) == 'https://') |
| 74 | 76 | { |
| 75 | 77 | $data = fetch_web_data($gzfilename); |
| 76 | 78 | |
| 77 | - if ($data === false) |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - else |
|
| 79 | + if ($data === false) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 82 | + } else |
|
| 81 | 83 | { |
| 82 | 84 | $data = @file_get_contents($gzfilename); |
| 83 | 85 | |
| 84 | - if ($data === false) |
|
| 85 | - return false; |
|
| 86 | + if ($data === false) { |
|
| 87 | + return false; |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | umask(0); |
| 89 | - if (!$single_file && $destination !== null && !file_exists($destination)) |
|
| 90 | - mktree($destination, 0777); |
|
| 92 | + if (!$single_file && $destination !== null && !file_exists($destination)) { |
|
| 93 | + mktree($destination, 0777); |
|
| 94 | + } |
|
| 91 | 95 | |
| 92 | 96 | // No signature? |
| 93 | - if (strlen($data) < 2) |
|
| 94 | - return false; |
|
| 97 | + if (strlen($data) < 2) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 95 | 100 | |
| 96 | 101 | $id = unpack('H2a/H2b', substr($data, 0, 2)); |
| 97 | 102 | if (strtolower($id['a'] . $id['b']) != '1f8b') |
| 98 | 103 | { |
| 99 | 104 | // Okay, this ain't no tar.gz, but maybe it's a zip file. |
| 100 | - if (substr($data, 0, 2) == 'PK') |
|
| 101 | - return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 102 | - else |
|
| 103 | - return false; |
|
| 105 | + if (substr($data, 0, 2) == 'PK') { |
|
| 106 | + return read_zip_file($gzfilename, $destination, $single_file, $overwrite, $files_to_extract); |
|
| 107 | + } else { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 104 | 110 | } |
| 105 | 111 | |
| 106 | 112 | $flags = unpack('Ct/Cf', substr($data, 2, 2)); |
| 107 | 113 | |
| 108 | 114 | // Not deflate! |
| 109 | - if ($flags['t'] != 8) |
|
| 110 | - return false; |
|
| 115 | + if ($flags['t'] != 8) { |
|
| 116 | + return false; |
|
| 117 | + } |
|
| 111 | 118 | $flags = $flags['f']; |
| 112 | 119 | |
| 113 | 120 | $offset = 10; |
@@ -117,18 +124,21 @@ discard block |
||
| 117 | 124 | // @todo Might be mussed. |
| 118 | 125 | if ($flags & 12) |
| 119 | 126 | { |
| 120 | - while ($flags & 8 && $data{$offset++} != "\0") |
|
| 121 | - continue; |
|
| 122 | - while ($flags & 4 && $data{$offset++} != "\0") |
|
| 123 | - continue; |
|
| 127 | + while ($flags & 8 && $data{$offset++} != "\0") { |
|
| 128 | + continue; |
|
| 129 | + } |
|
| 130 | + while ($flags & 4 && $data{$offset++} != "\0") { |
|
| 131 | + continue; |
|
| 132 | + } |
|
| 124 | 133 | } |
| 125 | 134 | |
| 126 | 135 | $crc = unpack('Vcrc32/Visize', substr($data, strlen($data) - 8, 8)); |
| 127 | 136 | $data = @gzinflate(substr($data, $offset, strlen($data) - 8 - $offset)); |
| 128 | 137 | |
| 129 | 138 | // smf_crc32 and crc32 may not return the same results, so we accept either. |
| 130 | - if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) |
|
| 131 | - return false; |
|
| 139 | + if ($crc['crc32'] != smf_crc32($data) && $crc['crc32'] != crc32($data)) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 132 | 142 | |
| 133 | 143 | $blocks = strlen($data) / 512 - 1; |
| 134 | 144 | $offset = 0; |
@@ -149,83 +159,98 @@ discard block |
||
| 149 | 159 | |
| 150 | 160 | foreach ($current as $k => $v) |
| 151 | 161 | { |
| 152 | - if (in_array($k, $octdec)) |
|
| 153 | - $current[$k] = octdec(trim($v)); |
|
| 154 | - else |
|
| 155 | - $current[$k] = trim($v); |
|
| 162 | + if (in_array($k, $octdec)) { |
|
| 163 | + $current[$k] = octdec(trim($v)); |
|
| 164 | + } else { |
|
| 165 | + $current[$k] = trim($v); |
|
| 166 | + } |
|
| 156 | 167 | } |
| 157 | 168 | |
| 158 | - if ($current['type'] == 5 && substr($current['filename'], -1) != '/') |
|
| 159 | - $current['filename'] .= '/'; |
|
| 169 | + if ($current['type'] == 5 && substr($current['filename'], -1) != '/') { |
|
| 170 | + $current['filename'] .= '/'; |
|
| 171 | + } |
|
| 160 | 172 | |
| 161 | 173 | $checksum = 256; |
| 162 | - for ($i = 0; $i < 148; $i++) |
|
| 163 | - $checksum += ord($header{$i}); |
|
| 164 | - for ($i = 156; $i < 512; $i++) |
|
| 165 | - $checksum += ord($header{$i}); |
|
| 174 | + for ($i = 0; $i < 148; $i++) { |
|
| 175 | + $checksum += ord($header{$i}); |
|
| 176 | + } |
|
| 177 | + for ($i = 156; $i < 512; $i++) { |
|
| 178 | + $checksum += ord($header{$i}); |
|
| 179 | + } |
|
| 166 | 180 | |
| 167 | - if ($current['checksum'] != $checksum) |
|
| 168 | - break; |
|
| 181 | + if ($current['checksum'] != $checksum) { |
|
| 182 | + break; |
|
| 183 | + } |
|
| 169 | 184 | |
| 170 | 185 | $size = ceil($current['size'] / 512); |
| 171 | 186 | $current['data'] = substr($data, ++$offset << 9, $current['size']); |
| 172 | 187 | $offset += $size; |
| 173 | 188 | |
| 174 | 189 | // Not a directory and doesn't exist already... |
| 175 | - if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) |
|
| 176 | - $write_this = true; |
|
| 190 | + if (substr($current['filename'], -1, 1) != '/' && !file_exists($destination . '/' . $current['filename'])) { |
|
| 191 | + $write_this = true; |
|
| 192 | + } |
|
| 177 | 193 | // File exists... check if it is newer. |
| 178 | - elseif (substr($current['filename'], -1, 1) != '/') |
|
| 179 | - $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 194 | + elseif (substr($current['filename'], -1, 1) != '/') { |
|
| 195 | + $write_this = $overwrite || filemtime($destination . '/' . $current['filename']) < $current['mtime']; |
|
| 196 | + } |
|
| 180 | 197 | // Folder... create. |
| 181 | 198 | elseif ($destination !== null && !$single_file) |
| 182 | 199 | { |
| 183 | 200 | // Protect from accidental parent directory writing... |
| 184 | 201 | $current['filename'] = strtr($current['filename'], array('../' => '', '/..' => '')); |
| 185 | 202 | |
| 186 | - if (!file_exists($destination . '/' . $current['filename'])) |
|
| 187 | - mktree($destination . '/' . $current['filename'], 0777); |
|
| 203 | + if (!file_exists($destination . '/' . $current['filename'])) { |
|
| 204 | + mktree($destination . '/' . $current['filename'], 0777); |
|
| 205 | + } |
|
| 188 | 206 | $write_this = false; |
| 207 | + } else { |
|
| 208 | + $write_this = false; |
|
| 189 | 209 | } |
| 190 | - else |
|
| 191 | - $write_this = false; |
|
| 192 | 210 | |
| 193 | 211 | if ($write_this && $destination !== null) |
| 194 | 212 | { |
| 195 | - if (strpos($current['filename'], '/') !== false && !$single_file) |
|
| 196 | - mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 213 | + if (strpos($current['filename'], '/') !== false && !$single_file) { |
|
| 214 | + mktree($destination . '/' . dirname($current['filename']), 0777); |
|
| 215 | + } |
|
| 197 | 216 | |
| 198 | 217 | // Is this the file we're looking for? |
| 199 | - if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) |
|
| 200 | - return $current['data']; |
|
| 218 | + if ($single_file && ($destination == $current['filename'] || $destination == '*/' . basename($current['filename']))) { |
|
| 219 | + return $current['data']; |
|
| 220 | + } |
|
| 201 | 221 | // If we're looking for another file, keep going. |
| 202 | - elseif ($single_file) |
|
| 203 | - continue; |
|
| 222 | + elseif ($single_file) { |
|
| 223 | + continue; |
|
| 224 | + } |
|
| 204 | 225 | // Looking for restricted files? |
| 205 | - elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) |
|
| 206 | - continue; |
|
| 226 | + elseif ($files_to_extract !== null && !in_array($current['filename'], $files_to_extract)) { |
|
| 227 | + continue; |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | package_put_contents($destination . '/' . $current['filename'], $current['data']); |
| 209 | 231 | } |
| 210 | 232 | |
| 211 | - if (substr($current['filename'], -1, 1) != '/') |
|
| 212 | - $return[] = array( |
|
| 233 | + if (substr($current['filename'], -1, 1) != '/') { |
|
| 234 | + $return[] = array( |
|
| 213 | 235 | 'filename' => $current['filename'], |
| 214 | 236 | 'md5' => md5($current['data']), |
| 215 | 237 | 'preview' => substr($current['data'], 0, 100), |
| 216 | 238 | 'size' => $current['size'], |
| 217 | 239 | 'skipped' => false |
| 218 | 240 | ); |
| 241 | + } |
|
| 219 | 242 | } |
| 220 | 243 | |
| 221 | - if ($destination !== null && !$single_file) |
|
| 222 | - package_flush_cache(); |
|
| 244 | + if ($destination !== null && !$single_file) { |
|
| 245 | + package_flush_cache(); |
|
| 246 | + } |
|
| 223 | 247 | |
| 224 | - if ($single_file) |
|
| 225 | - return false; |
|
| 226 | - else |
|
| 227 | - return $return; |
|
| 228 | -} |
|
| 248 | + if ($single_file) { |
|
| 249 | + return false; |
|
| 250 | + } else { |
|
| 251 | + return $return; |
|
| 252 | + } |
|
| 253 | + } |
|
| 229 | 254 | |
| 230 | 255 | /** |
| 231 | 256 | * Extract zip data. A functional copy of {@list read_zip_data()}. |
@@ -254,65 +279,74 @@ discard block |
||
| 254 | 279 | { |
| 255 | 280 | $i = $iterator->getSubPathname(); |
| 256 | 281 | // If this is a file, and it doesn't exist.... happy days! |
| 257 | - if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) |
|
| 258 | - $write_this = true; |
|
| 282 | + if (substr($i, -1) != '/' && !file_exists($destination . '/' . $i)) { |
|
| 283 | + $write_this = true; |
|
| 284 | + } |
|
| 259 | 285 | // If the file exists, we may not want to overwrite it. |
| 260 | - elseif (substr($i, -1) != '/') |
|
| 261 | - $write_this = $overwrite; |
|
| 262 | - else |
|
| 263 | - $write_this = false; |
|
| 286 | + elseif (substr($i, -1) != '/') { |
|
| 287 | + $write_this = $overwrite; |
|
| 288 | + } else { |
|
| 289 | + $write_this = false; |
|
| 290 | + } |
|
| 264 | 291 | |
| 265 | 292 | // Get the actual compressed data. |
| 266 | - if (!$file_info->isDir()) |
|
| 267 | - $file_data = file_get_contents($file_info); |
|
| 268 | - elseif ($destination !== null && !$single_file) |
|
| 293 | + if (!$file_info->isDir()) { |
|
| 294 | + $file_data = file_get_contents($file_info); |
|
| 295 | + } elseif ($destination !== null && !$single_file) |
|
| 269 | 296 | { |
| 270 | 297 | // Folder... create. |
| 271 | - if (!file_exists($destination . '/' . $i)) |
|
| 272 | - mktree($destination . '/' . $i, 0777); |
|
| 298 | + if (!file_exists($destination . '/' . $i)) { |
|
| 299 | + mktree($destination . '/' . $i, 0777); |
|
| 300 | + } |
|
| 273 | 301 | $file_data = null; |
| 302 | + } else { |
|
| 303 | + $file_data = null; |
|
| 274 | 304 | } |
| 275 | - else |
|
| 276 | - $file_data = null; |
|
| 277 | 305 | |
| 278 | 306 | // Okay! We can write this file, looks good from here... |
| 279 | 307 | if ($write_this && $destination !== null) |
| 280 | 308 | { |
| 281 | - if (!$single_file && !is_dir($destination . '/' . dirname($i))) |
|
| 282 | - mktree($destination . '/' . dirname($i), 0777); |
|
| 309 | + if (!$single_file && !is_dir($destination . '/' . dirname($i))) { |
|
| 310 | + mktree($destination . '/' . dirname($i), 0777); |
|
| 311 | + } |
|
| 283 | 312 | |
| 284 | 313 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 285 | - if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) |
|
| 286 | - return $file_data; |
|
| 314 | + if ($single_file && ($destination == $i || $destination == '*/' . basename($i))) { |
|
| 315 | + return $file_data; |
|
| 316 | + } |
|
| 287 | 317 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 288 | - elseif ($single_file) |
|
| 289 | - continue; |
|
| 318 | + elseif ($single_file) { |
|
| 319 | + continue; |
|
| 320 | + } |
|
| 290 | 321 | // Don't really want this? |
| 291 | - elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) |
|
| 292 | - continue; |
|
| 322 | + elseif ($files_to_extract !== null && !in_array($i, $files_to_extract)) { |
|
| 323 | + continue; |
|
| 324 | + } |
|
| 293 | 325 | |
| 294 | 326 | package_put_contents($destination . '/' . $i, $file_data); |
| 295 | 327 | } |
| 296 | 328 | |
| 297 | - if (substr($i, -1, 1) != '/') |
|
| 298 | - $return[] = array( |
|
| 329 | + if (substr($i, -1, 1) != '/') { |
|
| 330 | + $return[] = array( |
|
| 299 | 331 | 'filename' => $i, |
| 300 | 332 | 'md5' => md5($file_data), |
| 301 | 333 | 'preview' => substr($file_data, 0, 100), |
| 302 | 334 | 'size' => strlen($file_data), |
| 303 | 335 | 'skipped' => false |
| 304 | 336 | ); |
| 337 | + } |
|
| 305 | 338 | } |
| 306 | 339 | |
| 307 | - if ($destination !== null && !$single_file) |
|
| 308 | - package_flush_cache(); |
|
| 340 | + if ($destination !== null && !$single_file) { |
|
| 341 | + package_flush_cache(); |
|
| 342 | + } |
|
| 309 | 343 | |
| 310 | - if ($single_file) |
|
| 311 | - return false; |
|
| 312 | - else |
|
| 313 | - return $return; |
|
| 314 | - } |
|
| 315 | - catch (Exception $e) |
|
| 344 | + if ($single_file) { |
|
| 345 | + return false; |
|
| 346 | + } else { |
|
| 347 | + return $return; |
|
| 348 | + } |
|
| 349 | + } catch (Exception $e) |
|
| 316 | 350 | { |
| 317 | 351 | return false; |
| 318 | 352 | } |
@@ -334,13 +368,15 @@ discard block |
||
| 334 | 368 | function read_zip_data($data, $destination, $single_file = false, $overwrite = false, $files_to_extract = null) |
| 335 | 369 | { |
| 336 | 370 | umask(0); |
| 337 | - if ($destination !== null && !file_exists($destination) && !$single_file) |
|
| 338 | - mktree($destination, 0777); |
|
| 371 | + if ($destination !== null && !file_exists($destination) && !$single_file) { |
|
| 372 | + mktree($destination, 0777); |
|
| 373 | + } |
|
| 339 | 374 | |
| 340 | 375 | // Look for the end of directory signature 0x06054b50 |
| 341 | 376 | $data_ecr = explode("\x50\x4b\x05\x06", $data); |
| 342 | - if (!isset($data_ecr[1])) |
|
| 343 | - return false; |
|
| 377 | + if (!isset($data_ecr[1])) { |
|
| 378 | + return false; |
|
| 379 | + } |
|
| 344 | 380 | |
| 345 | 381 | $return = array(); |
| 346 | 382 | |
@@ -355,8 +391,9 @@ discard block |
||
| 355 | 391 | array_shift($file_sections); |
| 356 | 392 | |
| 357 | 393 | // sections and count from the signature must match or the zip file is bad |
| 358 | - if (count($file_sections) != $zip_info['files']) |
|
| 359 | - return false; |
|
| 394 | + if (count($file_sections) != $zip_info['files']) { |
|
| 395 | + return false; |
|
| 396 | + } |
|
| 360 | 397 | |
| 361 | 398 | // go though each file in the archive |
| 362 | 399 | foreach ($file_sections as $data) |
@@ -378,68 +415,79 @@ discard block |
||
| 378 | 415 | } |
| 379 | 416 | |
| 380 | 417 | // If this is a file, and it doesn't exist.... happy days! |
| 381 | - if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) |
|
| 382 | - $write_this = true; |
|
| 418 | + if (substr($file_info['filename'], -1) != '/' && !file_exists($destination . '/' . $file_info['filename'])) { |
|
| 419 | + $write_this = true; |
|
| 420 | + } |
|
| 383 | 421 | // If the file exists, we may not want to overwrite it. |
| 384 | - elseif (substr($file_info['filename'], -1) != '/') |
|
| 385 | - $write_this = $overwrite; |
|
| 422 | + elseif (substr($file_info['filename'], -1) != '/') { |
|
| 423 | + $write_this = $overwrite; |
|
| 424 | + } |
|
| 386 | 425 | // This is a directory, so we're gonna want to create it. (probably...) |
| 387 | 426 | elseif ($destination !== null && !$single_file) |
| 388 | 427 | { |
| 389 | 428 | // Just a little accident prevention, don't mind me. |
| 390 | 429 | $file_info['filename'] = strtr($file_info['filename'], array('../' => '', '/..' => '')); |
| 391 | 430 | |
| 392 | - if (!file_exists($destination . '/' . $file_info['filename'])) |
|
| 393 | - mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 431 | + if (!file_exists($destination . '/' . $file_info['filename'])) { |
|
| 432 | + mktree($destination . '/' . $file_info['filename'], 0777); |
|
| 433 | + } |
|
| 394 | 434 | $write_this = false; |
| 435 | + } else { |
|
| 436 | + $write_this = false; |
|
| 395 | 437 | } |
| 396 | - else |
|
| 397 | - $write_this = false; |
|
| 398 | 438 | |
| 399 | 439 | // Get the actual compressed data. |
| 400 | 440 | $file_info['data'] = substr($data, 26 + $file_info['filename_length'] + $file_info['extrafield_length']); |
| 401 | 441 | |
| 402 | 442 | // Only inflate it if we need to ;) |
| 403 | - if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) |
|
| 404 | - $file_info['data'] = gzinflate($file_info['data']); |
|
| 443 | + if (!empty($file_info['compress_method']) || ($file_info['compressed_size'] != $file_info['size'])) { |
|
| 444 | + $file_info['data'] = gzinflate($file_info['data']); |
|
| 445 | + } |
|
| 405 | 446 | |
| 406 | 447 | // Okay! We can write this file, looks good from here... |
| 407 | 448 | if ($write_this && $destination !== null) |
| 408 | 449 | { |
| 409 | - if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) |
|
| 410 | - mktree($file_info['dir'], 0777); |
|
| 450 | + if ((strpos($file_info['filename'], '/') !== false && !$single_file) || (!$single_file && !is_dir($file_info['dir']))) { |
|
| 451 | + mktree($file_info['dir'], 0777); |
|
| 452 | + } |
|
| 411 | 453 | |
| 412 | 454 | // If we're looking for a specific file, and this is it... ka-bam, baby. |
| 413 | - if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) |
|
| 414 | - return $file_info['data']; |
|
| 455 | + if ($single_file && ($destination == $file_info['filename'] || $destination == '*/' . basename($file_info['filename']))) { |
|
| 456 | + return $file_info['data']; |
|
| 457 | + } |
|
| 415 | 458 | // Oh? Another file. Fine. You don't like this file, do you? I know how it is. Yeah... just go away. No, don't apologize. I know this file's just not *good enough* for you. |
| 416 | - elseif ($single_file) |
|
| 417 | - continue; |
|
| 459 | + elseif ($single_file) { |
|
| 460 | + continue; |
|
| 461 | + } |
|
| 418 | 462 | // Don't really want this? |
| 419 | - elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) |
|
| 420 | - continue; |
|
| 463 | + elseif ($files_to_extract !== null && !in_array($file_info['filename'], $files_to_extract)) { |
|
| 464 | + continue; |
|
| 465 | + } |
|
| 421 | 466 | |
| 422 | 467 | package_put_contents($destination . '/' . $file_info['filename'], $file_info['data']); |
| 423 | 468 | } |
| 424 | 469 | |
| 425 | - if (substr($file_info['filename'], -1, 1) != '/') |
|
| 426 | - $return[] = array( |
|
| 470 | + if (substr($file_info['filename'], -1, 1) != '/') { |
|
| 471 | + $return[] = array( |
|
| 427 | 472 | 'filename' => $file_info['filename'], |
| 428 | 473 | 'md5' => md5($file_info['data']), |
| 429 | 474 | 'preview' => substr($file_info['data'], 0, 100), |
| 430 | 475 | 'size' => $file_info['size'], |
| 431 | 476 | 'skipped' => false |
| 432 | 477 | ); |
| 478 | + } |
|
| 433 | 479 | } |
| 434 | 480 | |
| 435 | - if ($destination !== null && !$single_file) |
|
| 436 | - package_flush_cache(); |
|
| 481 | + if ($destination !== null && !$single_file) { |
|
| 482 | + package_flush_cache(); |
|
| 483 | + } |
|
| 437 | 484 | |
| 438 | - if ($single_file) |
|
| 439 | - return false; |
|
| 440 | - else |
|
| 441 | - return $return; |
|
| 442 | -} |
|
| 485 | + if ($single_file) { |
|
| 486 | + return false; |
|
| 487 | + } else { |
|
| 488 | + return $return; |
|
| 489 | + } |
|
| 490 | + } |
|
| 443 | 491 | |
| 444 | 492 | /** |
| 445 | 493 | * Checks the existence of a remote file since file_exists() does not do remote. |
@@ -451,14 +499,16 @@ discard block |
||
| 451 | 499 | { |
| 452 | 500 | $a_url = parse_url($url); |
| 453 | 501 | |
| 454 | - if (!isset($a_url['scheme'])) |
|
| 455 | - return false; |
|
| 502 | + if (!isset($a_url['scheme'])) { |
|
| 503 | + return false; |
|
| 504 | + } |
|
| 456 | 505 | |
| 457 | 506 | // Attempt to connect... |
| 458 | 507 | $temp = ''; |
| 459 | 508 | $fid = fsockopen($a_url['host'], !isset($a_url['port']) ? 80 : $a_url['port'], $temp, $temp, 8); |
| 460 | - if (!$fid) |
|
| 461 | - return false; |
|
| 509 | + if (!$fid) { |
|
| 510 | + return false; |
|
| 511 | + } |
|
| 462 | 512 | |
| 463 | 513 | fputs($fid, 'HEAD ' . $a_url['path'] . ' HTTP/1.0' . "\r\n" . 'Host: ' . $a_url['host'] . "\r\n\r\n"); |
| 464 | 514 | $head = fread($fid, 1024); |
@@ -493,8 +543,9 @@ discard block |
||
| 493 | 543 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 494 | 544 | { |
| 495 | 545 | // Already found this? If so don't add it twice! |
| 496 | - if (in_array($row['package_id'], $found)) |
|
| 497 | - continue; |
|
| 546 | + if (in_array($row['package_id'], $found)) { |
|
| 547 | + continue; |
|
| 548 | + } |
|
| 498 | 549 | |
| 499 | 550 | $found[] = $row['package_id']; |
| 500 | 551 | |
@@ -529,19 +580,21 @@ discard block |
||
| 529 | 580 | global $sourcedir, $packagesdir; |
| 530 | 581 | |
| 531 | 582 | // Extract package-info.xml from downloaded file. (*/ is used because it could be in any directory.) |
| 532 | - if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) |
|
| 533 | - $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 534 | - else |
|
| 583 | + if (strpos($gzfilename, 'http://') !== false || strpos($gzfilename, 'https://') !== false) { |
|
| 584 | + $packageInfo = read_tgz_data($gzfilename, 'package-info.xml', true); |
|
| 585 | + } else |
|
| 535 | 586 | { |
| 536 | - if (!file_exists($packagesdir . '/' . $gzfilename)) |
|
| 537 | - return 'package_get_error_not_found'; |
|
| 587 | + if (!file_exists($packagesdir . '/' . $gzfilename)) { |
|
| 588 | + return 'package_get_error_not_found'; |
|
| 589 | + } |
|
| 538 | 590 | |
| 539 | - if (is_file($packagesdir . '/' . $gzfilename)) |
|
| 540 | - $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 541 | - elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) |
|
| 542 | - $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 543 | - else |
|
| 544 | - return 'package_get_error_missing_xml'; |
|
| 591 | + if (is_file($packagesdir . '/' . $gzfilename)) { |
|
| 592 | + $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/package-info.xml', true); |
|
| 593 | + } elseif (file_exists($packagesdir . '/' . $gzfilename . '/package-info.xml')) { |
|
| 594 | + $packageInfo = file_get_contents($packagesdir . '/' . $gzfilename . '/package-info.xml'); |
|
| 595 | + } else { |
|
| 596 | + return 'package_get_error_missing_xml'; |
|
| 597 | + } |
|
| 545 | 598 | } |
| 546 | 599 | |
| 547 | 600 | // Nothing? |
@@ -549,10 +602,11 @@ discard block |
||
| 549 | 602 | { |
| 550 | 603 | // Perhaps they are trying to install a theme, lets tell them nicely this is the wrong function |
| 551 | 604 | $packageInfo = read_tgz_file($packagesdir . '/' . $gzfilename, '*/theme_info.xml', true); |
| 552 | - if (!empty($packageInfo)) |
|
| 553 | - return 'package_get_error_is_theme'; |
|
| 554 | - else |
|
| 555 | - return 'package_get_error_is_zero'; |
|
| 605 | + if (!empty($packageInfo)) { |
|
| 606 | + return 'package_get_error_is_theme'; |
|
| 607 | + } else { |
|
| 608 | + return 'package_get_error_is_zero'; |
|
| 609 | + } |
|
| 556 | 610 | } |
| 557 | 611 | |
| 558 | 612 | // Parse package-info.xml into an xmlArray. |
@@ -560,8 +614,9 @@ discard block |
||
| 560 | 614 | $packageInfo = new xmlArray($packageInfo); |
| 561 | 615 | |
| 562 | 616 | // @todo Error message of some sort? |
| 563 | - if (!$packageInfo->exists('package-info[0]')) |
|
| 564 | - return 'package_get_error_packageinfo_corrupt'; |
|
| 617 | + if (!$packageInfo->exists('package-info[0]')) { |
|
| 618 | + return 'package_get_error_packageinfo_corrupt'; |
|
| 619 | + } |
|
| 565 | 620 | |
| 566 | 621 | $packageInfo = $packageInfo->path('package-info[0]'); |
| 567 | 622 | |
@@ -580,8 +635,9 @@ discard block |
||
| 580 | 635 | } |
| 581 | 636 | } |
| 582 | 637 | |
| 583 | - if (!isset($package['type'])) |
|
| 584 | - $package['type'] = 'modification'; |
|
| 638 | + if (!isset($package['type'])) { |
|
| 639 | + $package['type'] = 'modification'; |
|
| 640 | + } |
|
| 585 | 641 | |
| 586 | 642 | return $package; |
| 587 | 643 | } |
@@ -634,15 +690,14 @@ discard block |
||
| 634 | 690 | { |
| 635 | 691 | $ftp_file = strtr($file, array($_SESSION['pack_ftp']['root'] => '')); |
| 636 | 692 | $package_ftp->chmod($ftp_file, $perms); |
| 693 | + } else { |
|
| 694 | + smf_chmod($file, $perms); |
|
| 637 | 695 | } |
| 638 | - else |
|
| 639 | - smf_chmod($file, $perms); |
|
| 640 | 696 | |
| 641 | 697 | $new_permissions = @fileperms($file); |
| 642 | 698 | $result = $new_permissions == $perms ? 'success' : 'failure'; |
| 643 | 699 | unset($_SESSION['pack_ftp']['original_perms'][$file]); |
| 644 | - } |
|
| 645 | - elseif ($do_change) |
|
| 700 | + } elseif ($do_change) |
|
| 646 | 701 | { |
| 647 | 702 | $new_permissions = ''; |
| 648 | 703 | $result = 'skipped'; |
@@ -758,8 +813,7 @@ discard block |
||
| 758 | 813 | |
| 759 | 814 | $context['sub_template'] = 'show_list'; |
| 760 | 815 | $context['default_list'] = 'restore_file_permissions'; |
| 761 | - } |
|
| 762 | - else |
|
| 816 | + } else |
|
| 763 | 817 | { |
| 764 | 818 | unset($listOptions['columns']['result']); |
| 765 | 819 | } |
@@ -769,12 +823,14 @@ discard block |
||
| 769 | 823 | createList($listOptions); |
| 770 | 824 | |
| 771 | 825 | // If we just restored permissions then whereever we are, we are now done and dusted. |
| 772 | - if (!empty($_POST['restore_perms'])) |
|
| 773 | - obExit(); |
|
| 826 | + if (!empty($_POST['restore_perms'])) { |
|
| 827 | + obExit(); |
|
| 828 | + } |
|
| 774 | 829 | } |
| 775 | 830 | // Otherwise, it's entirely irrelevant? |
| 776 | - elseif ($restore_write_status) |
|
| 777 | - return true; |
|
| 831 | + elseif ($restore_write_status) { |
|
| 832 | + return true; |
|
| 833 | + } |
|
| 778 | 834 | |
| 779 | 835 | // This is where we report what we got up to. |
| 780 | 836 | $return_data = array( |
@@ -812,11 +868,12 @@ discard block |
||
| 812 | 868 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 813 | 869 | { |
| 814 | 870 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 815 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) |
|
| 816 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 871 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || substr($_POST['ftp_path'], 0, 1) == '/')) { |
|
| 872 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 873 | + } |
|
| 874 | + } else { |
|
| 875 | + $ftp_root = $boarddir; |
|
| 817 | 876 | } |
| 818 | - else |
|
| 819 | - $ftp_root = $boarddir; |
|
| 820 | 877 | |
| 821 | 878 | $_SESSION['pack_ftp'] = array( |
| 822 | 879 | 'server' => $_POST['ftp_server'], |
@@ -828,8 +885,9 @@ discard block |
||
| 828 | 885 | 'connected' => true, |
| 829 | 886 | ); |
| 830 | 887 | |
| 831 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 832 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 888 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 889 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 890 | + } |
|
| 833 | 891 | |
| 834 | 892 | // This is now the primary connection. |
| 835 | 893 | $package_ftp = $ftp; |
@@ -842,12 +900,13 @@ discard block |
||
| 842 | 900 | foreach ($chmodFiles as $k => $file) |
| 843 | 901 | { |
| 844 | 902 | // Sometimes this can somehow happen maybe? |
| 845 | - if (empty($file)) |
|
| 846 | - unset($chmodFiles[$k]); |
|
| 903 | + if (empty($file)) { |
|
| 904 | + unset($chmodFiles[$k]); |
|
| 905 | + } |
|
| 847 | 906 | // Already writable? |
| 848 | - elseif (@is_writable($file)) |
|
| 849 | - $return_data['files']['writable'][] = $file; |
|
| 850 | - else |
|
| 907 | + elseif (@is_writable($file)) { |
|
| 908 | + $return_data['files']['writable'][] = $file; |
|
| 909 | + } else |
|
| 851 | 910 | { |
| 852 | 911 | // Now try to change that. |
| 853 | 912 | $return_data['files'][package_chmod($file, 'writable', true) ? 'writable' : 'notwritable'][] = $file; |
@@ -864,19 +923,21 @@ discard block |
||
| 864 | 923 | { |
| 865 | 924 | require_once($sourcedir . '/Class-Package.php'); |
| 866 | 925 | $ftp = new ftp_connection(null); |
| 926 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 927 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 867 | 928 | } |
| 868 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 869 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 870 | 929 | |
| 871 | 930 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 872 | 931 | |
| 873 | - if ($found_path) |
|
| 874 | - $_POST['ftp_path'] = $detect_path; |
|
| 875 | - elseif (!isset($_POST['ftp_path'])) |
|
| 876 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 932 | + if ($found_path) { |
|
| 933 | + $_POST['ftp_path'] = $detect_path; |
|
| 934 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 935 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 936 | + } |
|
| 877 | 937 | |
| 878 | - if (!isset($_POST['ftp_username'])) |
|
| 879 | - $_POST['ftp_username'] = $username; |
|
| 938 | + if (!isset($_POST['ftp_username'])) { |
|
| 939 | + $_POST['ftp_username'] = $username; |
|
| 940 | + } |
|
| 880 | 941 | } |
| 881 | 942 | |
| 882 | 943 | $context['package_ftp'] = array( |
@@ -889,8 +950,9 @@ discard block |
||
| 889 | 950 | ); |
| 890 | 951 | |
| 891 | 952 | // Which files failed? |
| 892 | - if (!isset($context['notwritable_files'])) |
|
| 893 | - $context['notwritable_files'] = array(); |
|
| 953 | + if (!isset($context['notwritable_files'])) { |
|
| 954 | + $context['notwritable_files'] = array(); |
|
| 955 | + } |
|
| 894 | 956 | $context['notwritable_files'] = array_merge($context['notwritable_files'], $return_data['files']['notwritable']); |
| 895 | 957 | |
| 896 | 958 | // Sent here to die? |
@@ -923,40 +985,48 @@ discard block |
||
| 923 | 985 | foreach ($files as $k => $file) |
| 924 | 986 | { |
| 925 | 987 | // If this file doesn't exist, then we actually want to look at the directory, no? |
| 926 | - if (!file_exists($file)) |
|
| 927 | - $file = dirname($file); |
|
| 988 | + if (!file_exists($file)) { |
|
| 989 | + $file = dirname($file); |
|
| 990 | + } |
|
| 928 | 991 | |
| 929 | 992 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 930 | - if (!@is_writable($file)) |
|
| 931 | - smf_chmod($file, 0755); |
|
| 932 | - if (!@is_writable($file)) |
|
| 933 | - smf_chmod($file, 0777); |
|
| 934 | - if (!@is_writable(dirname($file))) |
|
| 935 | - smf_chmod($file, 0755); |
|
| 936 | - if (!@is_writable(dirname($file))) |
|
| 937 | - smf_chmod($file, 0777); |
|
| 993 | + if (!@is_writable($file)) { |
|
| 994 | + smf_chmod($file, 0755); |
|
| 995 | + } |
|
| 996 | + if (!@is_writable($file)) { |
|
| 997 | + smf_chmod($file, 0777); |
|
| 998 | + } |
|
| 999 | + if (!@is_writable(dirname($file))) { |
|
| 1000 | + smf_chmod($file, 0755); |
|
| 1001 | + } |
|
| 1002 | + if (!@is_writable(dirname($file))) { |
|
| 1003 | + smf_chmod($file, 0777); |
|
| 1004 | + } |
|
| 938 | 1005 | |
| 939 | 1006 | $fp = is_dir($file) ? @opendir($file) : @fopen($file, 'rb'); |
| 940 | 1007 | if (@is_writable($file) && $fp) |
| 941 | 1008 | { |
| 942 | 1009 | unset($files[$k]); |
| 943 | - if (!is_dir($file)) |
|
| 944 | - fclose($fp); |
|
| 945 | - else |
|
| 946 | - closedir($fp); |
|
| 1010 | + if (!is_dir($file)) { |
|
| 1011 | + fclose($fp); |
|
| 1012 | + } else { |
|
| 1013 | + closedir($fp); |
|
| 1014 | + } |
|
| 947 | 1015 | } |
| 948 | 1016 | } |
| 949 | 1017 | |
| 950 | 1018 | // No FTP required! |
| 951 | - if (empty($files)) |
|
| 952 | - return array(); |
|
| 1019 | + if (empty($files)) { |
|
| 1020 | + return array(); |
|
| 1021 | + } |
|
| 953 | 1022 | } |
| 954 | 1023 | |
| 955 | 1024 | // They've opted to not use FTP, and try anyway. |
| 956 | 1025 | if (isset($_SESSION['pack_ftp']) && $_SESSION['pack_ftp'] == false) |
| 957 | 1026 | { |
| 958 | - if ($files === null) |
|
| 959 | - return array(); |
|
| 1027 | + if ($files === null) { |
|
| 1028 | + return array(); |
|
| 1029 | + } |
|
| 960 | 1030 | |
| 961 | 1031 | foreach ($files as $k => $file) |
| 962 | 1032 | { |
@@ -968,26 +1038,29 @@ discard block |
||
| 968 | 1038 | smf_chmod($file, 0755); |
| 969 | 1039 | } |
| 970 | 1040 | |
| 971 | - if (!@is_writable($file)) |
|
| 972 | - smf_chmod($file, 0777); |
|
| 973 | - if (!@is_writable(dirname($file))) |
|
| 974 | - smf_chmod(dirname($file), 0777); |
|
| 1041 | + if (!@is_writable($file)) { |
|
| 1042 | + smf_chmod($file, 0777); |
|
| 1043 | + } |
|
| 1044 | + if (!@is_writable(dirname($file))) { |
|
| 1045 | + smf_chmod(dirname($file), 0777); |
|
| 1046 | + } |
|
| 975 | 1047 | |
| 976 | - if (@is_writable($file)) |
|
| 977 | - unset($files[$k]); |
|
| 1048 | + if (@is_writable($file)) { |
|
| 1049 | + unset($files[$k]); |
|
| 1050 | + } |
|
| 978 | 1051 | } |
| 979 | 1052 | |
| 980 | 1053 | return $files; |
| 981 | - } |
|
| 982 | - elseif (isset($_SESSION['pack_ftp'])) |
|
| 1054 | + } elseif (isset($_SESSION['pack_ftp'])) |
|
| 983 | 1055 | { |
| 984 | 1056 | // Load the file containing the ftp_connection class. |
| 985 | 1057 | require_once($sourcedir . '/Class-Package.php'); |
| 986 | 1058 | |
| 987 | 1059 | $package_ftp = new ftp_connection($_SESSION['pack_ftp']['server'], $_SESSION['pack_ftp']['port'], $_SESSION['pack_ftp']['username'], package_crypt($_SESSION['pack_ftp']['password'])); |
| 988 | 1060 | |
| 989 | - if ($files === null) |
|
| 990 | - return array(); |
|
| 1061 | + if ($files === null) { |
|
| 1062 | + return array(); |
|
| 1063 | + } |
|
| 991 | 1064 | |
| 992 | 1065 | foreach ($files as $k => $file) |
| 993 | 1066 | { |
@@ -1001,13 +1074,16 @@ discard block |
||
| 1001 | 1074 | $package_ftp->chmod($ftp_file, 0755); |
| 1002 | 1075 | } |
| 1003 | 1076 | |
| 1004 | - if (!@is_writable($file)) |
|
| 1005 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1006 | - if (!@is_writable(dirname($file))) |
|
| 1007 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1077 | + if (!@is_writable($file)) { |
|
| 1078 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1079 | + } |
|
| 1080 | + if (!@is_writable(dirname($file))) { |
|
| 1081 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 1082 | + } |
|
| 1008 | 1083 | |
| 1009 | - if (@is_writable($file)) |
|
| 1010 | - unset($files[$k]); |
|
| 1084 | + if (@is_writable($file)) { |
|
| 1085 | + unset($files[$k]); |
|
| 1086 | + } |
|
| 1011 | 1087 | } |
| 1012 | 1088 | |
| 1013 | 1089 | return $files; |
@@ -1019,8 +1095,7 @@ discard block |
||
| 1019 | 1095 | |
| 1020 | 1096 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1021 | 1097 | return $files; |
| 1022 | - } |
|
| 1023 | - elseif (isset($_POST['ftp_username'])) |
|
| 1098 | + } elseif (isset($_POST['ftp_username'])) |
|
| 1024 | 1099 | { |
| 1025 | 1100 | require_once($sourcedir . '/Class-Package.php'); |
| 1026 | 1101 | $ftp = new ftp_connection($_POST['ftp_server'], $_POST['ftp_port'], $_POST['ftp_username'], $_POST['ftp_password']); |
@@ -1042,19 +1117,21 @@ discard block |
||
| 1042 | 1117 | { |
| 1043 | 1118 | require_once($sourcedir . '/Class-Package.php'); |
| 1044 | 1119 | $ftp = new ftp_connection(null); |
| 1120 | + } elseif ($ftp->error !== false && !isset($ftp_error)) { |
|
| 1121 | + $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1045 | 1122 | } |
| 1046 | - elseif ($ftp->error !== false && !isset($ftp_error)) |
|
| 1047 | - $ftp_error = $ftp->last_message === null ? '' : $ftp->last_message; |
|
| 1048 | 1123 | |
| 1049 | 1124 | list ($username, $detect_path, $found_path) = $ftp->detect_path($boarddir); |
| 1050 | 1125 | |
| 1051 | - if ($found_path) |
|
| 1052 | - $_POST['ftp_path'] = $detect_path; |
|
| 1053 | - elseif (!isset($_POST['ftp_path'])) |
|
| 1054 | - $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1126 | + if ($found_path) { |
|
| 1127 | + $_POST['ftp_path'] = $detect_path; |
|
| 1128 | + } elseif (!isset($_POST['ftp_path'])) { |
|
| 1129 | + $_POST['ftp_path'] = isset($modSettings['package_path']) ? $modSettings['package_path'] : $detect_path; |
|
| 1130 | + } |
|
| 1055 | 1131 | |
| 1056 | - if (!isset($_POST['ftp_username'])) |
|
| 1057 | - $_POST['ftp_username'] = $username; |
|
| 1132 | + if (!isset($_POST['ftp_username'])) { |
|
| 1133 | + $_POST['ftp_username'] = $username; |
|
| 1134 | + } |
|
| 1058 | 1135 | |
| 1059 | 1136 | $context['package_ftp'] = array( |
| 1060 | 1137 | 'server' => isset($_POST['ftp_server']) ? $_POST['ftp_server'] : (isset($modSettings['package_server']) ? $modSettings['package_server'] : 'localhost'), |
@@ -1066,23 +1143,24 @@ discard block |
||
| 1066 | 1143 | ); |
| 1067 | 1144 | |
| 1068 | 1145 | // If we're returning dump out here. |
| 1069 | - if ($return) |
|
| 1070 | - return $files; |
|
| 1146 | + if ($return) { |
|
| 1147 | + return $files; |
|
| 1148 | + } |
|
| 1071 | 1149 | |
| 1072 | 1150 | $context['page_title'] = $txt['package_ftp_necessary']; |
| 1073 | 1151 | $context['sub_template'] = 'ftp_required'; |
| 1074 | 1152 | obExit(); |
| 1075 | - } |
|
| 1076 | - else |
|
| 1153 | + } else |
|
| 1077 | 1154 | { |
| 1078 | 1155 | if (!in_array($_POST['ftp_path'], array('', '/'))) |
| 1079 | 1156 | { |
| 1080 | 1157 | $ftp_root = strtr($boarddir, array($_POST['ftp_path'] => '')); |
| 1081 | - if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) |
|
| 1082 | - $ftp_root = substr($ftp_root, 0, -1); |
|
| 1158 | + if (substr($ftp_root, -1) == '/' && ($_POST['ftp_path'] == '' || $_POST['ftp_path'][0] == '/')) { |
|
| 1159 | + $ftp_root = substr($ftp_root, 0, -1); |
|
| 1160 | + } |
|
| 1161 | + } else { |
|
| 1162 | + $ftp_root = $boarddir; |
|
| 1083 | 1163 | } |
| 1084 | - else |
|
| 1085 | - $ftp_root = $boarddir; |
|
| 1086 | 1164 | |
| 1087 | 1165 | $_SESSION['pack_ftp'] = array( |
| 1088 | 1166 | 'server' => $_POST['ftp_server'], |
@@ -1093,8 +1171,9 @@ discard block |
||
| 1093 | 1171 | 'root' => $ftp_root, |
| 1094 | 1172 | ); |
| 1095 | 1173 | |
| 1096 | - if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) |
|
| 1097 | - updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1174 | + if (!isset($modSettings['package_path']) || $modSettings['package_path'] != $_POST['ftp_path']) { |
|
| 1175 | + updateSettings(array('package_path' => $_POST['ftp_path'])); |
|
| 1176 | + } |
|
| 1098 | 1177 | |
| 1099 | 1178 | $files = packageRequireFTP($destination_url, $files, $return); |
| 1100 | 1179 | } |
@@ -1122,16 +1201,18 @@ discard block |
||
| 1122 | 1201 | global $packagesdir, $forum_version, $context, $temp_path, $language, $smcFunc; |
| 1123 | 1202 | |
| 1124 | 1203 | // Mayday! That action doesn't exist!! |
| 1125 | - if (empty($packageXML) || !$packageXML->exists($method)) |
|
| 1126 | - return array(); |
|
| 1204 | + if (empty($packageXML) || !$packageXML->exists($method)) { |
|
| 1205 | + return array(); |
|
| 1206 | + } |
|
| 1127 | 1207 | |
| 1128 | 1208 | // We haven't found the package script yet... |
| 1129 | 1209 | $script = false; |
| 1130 | 1210 | $the_version = strtr($forum_version, array('SMF ' => '')); |
| 1131 | 1211 | |
| 1132 | 1212 | // Emulation support... |
| 1133 | - if (!empty($_SESSION['version_emulate'])) |
|
| 1134 | - $the_version = $_SESSION['version_emulate']; |
|
| 1213 | + if (!empty($_SESSION['version_emulate'])) { |
|
| 1214 | + $the_version = $_SESSION['version_emulate']; |
|
| 1215 | + } |
|
| 1135 | 1216 | |
| 1136 | 1217 | // Single package emulation |
| 1137 | 1218 | if (!empty($_REQUEST['ve']) && !empty($_REQUEST['package'])) |
@@ -1139,8 +1220,9 @@ discard block |
||
| 1139 | 1220 | $the_version = $_REQUEST['ve']; |
| 1140 | 1221 | $_SESSION['single_version_emulate'][$_REQUEST['package']] = $the_version; |
| 1141 | 1222 | } |
| 1142 | - if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) |
|
| 1143 | - $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1223 | + if (!empty($_REQUEST['package']) && (!empty($_SESSION['single_version_emulate'][$_REQUEST['package']]))) { |
|
| 1224 | + $the_version = $_SESSION['single_version_emulate'][$_REQUEST['package']]; |
|
| 1225 | + } |
|
| 1144 | 1226 | |
| 1145 | 1227 | // Get all the versions of this method and find the right one. |
| 1146 | 1228 | $these_methods = $packageXML->set($method); |
@@ -1150,16 +1232,18 @@ discard block |
||
| 1150 | 1232 | if ($this_method->exists('@for')) |
| 1151 | 1233 | { |
| 1152 | 1234 | // Don't keep going if this won't work for this version of SMF. |
| 1153 | - if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) |
|
| 1154 | - continue; |
|
| 1235 | + if (!matchPackageVersion($the_version, $this_method->fetch('@for'))) { |
|
| 1236 | + continue; |
|
| 1237 | + } |
|
| 1155 | 1238 | } |
| 1156 | 1239 | |
| 1157 | 1240 | // Upgrades may go from a certain old version of the mod. |
| 1158 | 1241 | if ($method == 'upgrade' && $this_method->exists('@from')) |
| 1159 | 1242 | { |
| 1160 | 1243 | // Well, this is for the wrong old version... |
| 1161 | - if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) |
|
| 1162 | - continue; |
|
| 1244 | + if (!matchPackageVersion($previous_version, $this_method->fetch('@from'))) { |
|
| 1245 | + continue; |
|
| 1246 | + } |
|
| 1163 | 1247 | } |
| 1164 | 1248 | |
| 1165 | 1249 | // We've found it! |
@@ -1168,8 +1252,9 @@ discard block |
||
| 1168 | 1252 | } |
| 1169 | 1253 | |
| 1170 | 1254 | // Bad news, a matching script wasn't found! |
| 1171 | - if (!($script instanceof xmlArray)) |
|
| 1172 | - return array(); |
|
| 1255 | + if (!($script instanceof xmlArray)) { |
|
| 1256 | + return array(); |
|
| 1257 | + } |
|
| 1173 | 1258 | |
| 1174 | 1259 | // Find all the actions in this method - in theory, these should only be allowed actions. (* means all.) |
| 1175 | 1260 | $actions = $script->set('*'); |
@@ -1198,12 +1283,12 @@ discard block |
||
| 1198 | 1283 | if ((isset($_REQUEST['readme']) && $action->fetch('@lang') == $_REQUEST['readme']) || (isset($_REQUEST['license']) && $action->fetch('@lang') == $_REQUEST['license']) || (!isset($_REQUEST['readme']) && $action->fetch('@lang') == $language) || (!isset($_REQUEST['license']) && $action->fetch('@lang') == $language)) |
| 1199 | 1284 | { |
| 1200 | 1285 | // In case the user put the blocks in the wrong order. |
| 1201 | - if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') |
|
| 1202 | - $context[$type][] = 'default'; |
|
| 1286 | + if (isset($context[$type]['selected']) && $context[$type]['selected'] == 'default') { |
|
| 1287 | + $context[$type][] = 'default'; |
|
| 1288 | + } |
|
| 1203 | 1289 | |
| 1204 | 1290 | $context[$type]['selected'] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
| 1205 | - } |
|
| 1206 | - else |
|
| 1291 | + } else |
|
| 1207 | 1292 | { |
| 1208 | 1293 | // We don't want this now, but we'll allow the user to select to read it. |
| 1209 | 1294 | $context[$type][] = $smcFunc['htmlspecialchars']($action->fetch('@lang')); |
@@ -1218,9 +1303,9 @@ discard block |
||
| 1218 | 1303 | { |
| 1219 | 1304 | $context[$type][] = 'default'; |
| 1220 | 1305 | continue; |
| 1306 | + } else { |
|
| 1307 | + $context[$type]['selected'] = 'default'; |
|
| 1221 | 1308 | } |
| 1222 | - else |
|
| 1223 | - $context[$type]['selected'] = 'default'; |
|
| 1224 | 1309 | } |
| 1225 | 1310 | } |
| 1226 | 1311 | |
@@ -1230,9 +1315,9 @@ discard block |
||
| 1230 | 1315 | $filename = $temp_path . '$auto_' . $temp_auto++ . (in_array($actionType, array('readme', 'redirect', 'license')) ? '.txt' : ($actionType == 'code' || $actionType == 'database' ? '.php' : '.mod')); |
| 1231 | 1316 | package_put_contents($filename, $action->fetch('.')); |
| 1232 | 1317 | $filename = strtr($filename, array($temp_path => '')); |
| 1318 | + } else { |
|
| 1319 | + $filename = $action->fetch('.'); |
|
| 1233 | 1320 | } |
| 1234 | - else |
|
| 1235 | - $filename = $action->fetch('.'); |
|
| 1236 | 1321 | |
| 1237 | 1322 | $return[] = array( |
| 1238 | 1323 | 'type' => $actionType, |
@@ -1247,8 +1332,7 @@ discard block |
||
| 1247 | 1332 | ); |
| 1248 | 1333 | |
| 1249 | 1334 | continue; |
| 1250 | - } |
|
| 1251 | - elseif ($actionType == 'hook') |
|
| 1335 | + } elseif ($actionType == 'hook') |
|
| 1252 | 1336 | { |
| 1253 | 1337 | $return[] = array( |
| 1254 | 1338 | 'type' => $actionType, |
@@ -1260,16 +1344,16 @@ discard block |
||
| 1260 | 1344 | 'description' => '', |
| 1261 | 1345 | ); |
| 1262 | 1346 | continue; |
| 1263 | - } |
|
| 1264 | - elseif ($actionType == 'credits') |
|
| 1347 | + } elseif ($actionType == 'credits') |
|
| 1265 | 1348 | { |
| 1266 | 1349 | // quick check of any supplied url |
| 1267 | 1350 | $url = $action->exists('@url') ? $action->fetch('@url') : ''; |
| 1268 | 1351 | if (strlen(trim($url)) > 0 && substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://') |
| 1269 | 1352 | { |
| 1270 | 1353 | $url = 'http://' . $url; |
| 1271 | - if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) |
|
| 1272 | - $url = ''; |
|
| 1354 | + if (strlen($url) < 8 || (substr($url, 0, 7) !== 'http://' && substr($url, 0, 8) !== 'https://')) { |
|
| 1355 | + $url = ''; |
|
| 1356 | + } |
|
| 1273 | 1357 | } |
| 1274 | 1358 | |
| 1275 | 1359 | $return[] = array( |
@@ -1281,8 +1365,7 @@ discard block |
||
| 1281 | 1365 | 'title' => $action->fetch('.'), |
| 1282 | 1366 | ); |
| 1283 | 1367 | continue; |
| 1284 | - } |
|
| 1285 | - elseif ($actionType == 'requires') |
|
| 1368 | + } elseif ($actionType == 'requires') |
|
| 1286 | 1369 | { |
| 1287 | 1370 | $return[] = array( |
| 1288 | 1371 | 'type' => $actionType, |
@@ -1291,14 +1374,12 @@ discard block |
||
| 1291 | 1374 | 'description' => '', |
| 1292 | 1375 | ); |
| 1293 | 1376 | continue; |
| 1294 | - } |
|
| 1295 | - elseif ($actionType == 'error') |
|
| 1377 | + } elseif ($actionType == 'error') |
|
| 1296 | 1378 | { |
| 1297 | 1379 | $return[] = array( |
| 1298 | 1380 | 'type' => 'error', |
| 1299 | 1381 | ); |
| 1300 | - } |
|
| 1301 | - elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1382 | + } elseif (in_array($actionType, array('require-file', 'remove-file', 'require-dir', 'remove-dir', 'move-file', 'move-dir', 'create-file', 'create-dir'))) |
|
| 1302 | 1383 | { |
| 1303 | 1384 | $this_action = &$return[]; |
| 1304 | 1385 | $this_action = array( |
@@ -1312,8 +1393,7 @@ discard block |
||
| 1312 | 1393 | { |
| 1313 | 1394 | $this_action['unparsed_destination'] = $action->fetch('@destination'); |
| 1314 | 1395 | $this_action['destination'] = parse_path($action->fetch('@destination')) . '/' . basename($this_action['filename']); |
| 1315 | - } |
|
| 1316 | - else |
|
| 1396 | + } else |
|
| 1317 | 1397 | { |
| 1318 | 1398 | $this_action['unparsed_filename'] = $this_action['filename']; |
| 1319 | 1399 | $this_action['filename'] = parse_path($this_action['filename']); |
@@ -1322,10 +1402,11 @@ discard block |
||
| 1322 | 1402 | // If we're moving or requiring (copying) a file. |
| 1323 | 1403 | if (substr($actionType, 0, 4) == 'move' || substr($actionType, 0, 7) == 'require') |
| 1324 | 1404 | { |
| 1325 | - if ($action->exists('@from')) |
|
| 1326 | - $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1327 | - else |
|
| 1328 | - $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1405 | + if ($action->exists('@from')) { |
|
| 1406 | + $this_action['source'] = parse_path($action->fetch('@from')); |
|
| 1407 | + } else { |
|
| 1408 | + $this_action['source'] = $temp_path . $this_action['filename']; |
|
| 1409 | + } |
|
| 1329 | 1410 | } |
| 1330 | 1411 | |
| 1331 | 1412 | // Check if these things can be done. (chmod's etc.) |
@@ -1334,22 +1415,23 @@ discard block |
||
| 1334 | 1415 | if (!mktree($this_action['destination'], false)) |
| 1335 | 1416 | { |
| 1336 | 1417 | $temp = $this_action['destination']; |
| 1337 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1338 | - $temp = dirname($temp); |
|
| 1418 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1419 | + $temp = dirname($temp); |
|
| 1420 | + } |
|
| 1339 | 1421 | |
| 1340 | 1422 | $return[] = array( |
| 1341 | 1423 | 'type' => 'chmod', |
| 1342 | 1424 | 'filename' => $temp |
| 1343 | 1425 | ); |
| 1344 | 1426 | } |
| 1345 | - } |
|
| 1346 | - elseif ($actionType == 'create-file') |
|
| 1427 | + } elseif ($actionType == 'create-file') |
|
| 1347 | 1428 | { |
| 1348 | 1429 | if (!mktree(dirname($this_action['destination']), false)) |
| 1349 | 1430 | { |
| 1350 | 1431 | $temp = dirname($this_action['destination']); |
| 1351 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1352 | - $temp = dirname($temp); |
|
| 1432 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1433 | + $temp = dirname($temp); |
|
| 1434 | + } |
|
| 1353 | 1435 | |
| 1354 | 1436 | $return[] = array( |
| 1355 | 1437 | 'type' => 'chmod', |
@@ -1357,36 +1439,38 @@ discard block |
||
| 1357 | 1439 | ); |
| 1358 | 1440 | } |
| 1359 | 1441 | |
| 1360 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1361 | - $return[] = array( |
|
| 1442 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1443 | + $return[] = array( |
|
| 1362 | 1444 | 'type' => 'chmod', |
| 1363 | 1445 | 'filename' => $this_action['destination'] |
| 1364 | 1446 | ); |
| 1365 | - } |
|
| 1366 | - elseif ($actionType == 'require-dir') |
|
| 1447 | + } |
|
| 1448 | + } elseif ($actionType == 'require-dir') |
|
| 1367 | 1449 | { |
| 1368 | 1450 | if (!mktree($this_action['destination'], false)) |
| 1369 | 1451 | { |
| 1370 | 1452 | $temp = $this_action['destination']; |
| 1371 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1372 | - $temp = dirname($temp); |
|
| 1453 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1454 | + $temp = dirname($temp); |
|
| 1455 | + } |
|
| 1373 | 1456 | |
| 1374 | 1457 | $return[] = array( |
| 1375 | 1458 | 'type' => 'chmod', |
| 1376 | 1459 | 'filename' => $temp |
| 1377 | 1460 | ); |
| 1378 | 1461 | } |
| 1379 | - } |
|
| 1380 | - elseif ($actionType == 'require-file') |
|
| 1462 | + } elseif ($actionType == 'require-file') |
|
| 1381 | 1463 | { |
| 1382 | - if ($action->exists('@theme')) |
|
| 1383 | - $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1464 | + if ($action->exists('@theme')) { |
|
| 1465 | + $this_action['theme_action'] = $action->fetch('@theme'); |
|
| 1466 | + } |
|
| 1384 | 1467 | |
| 1385 | 1468 | if (!mktree(dirname($this_action['destination']), false)) |
| 1386 | 1469 | { |
| 1387 | 1470 | $temp = dirname($this_action['destination']); |
| 1388 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1389 | - $temp = dirname($temp); |
|
| 1471 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1472 | + $temp = dirname($temp); |
|
| 1473 | + } |
|
| 1390 | 1474 | |
| 1391 | 1475 | $return[] = array( |
| 1392 | 1476 | 'type' => 'chmod', |
@@ -1394,19 +1478,20 @@ discard block |
||
| 1394 | 1478 | ); |
| 1395 | 1479 | } |
| 1396 | 1480 | |
| 1397 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1398 | - $return[] = array( |
|
| 1481 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1482 | + $return[] = array( |
|
| 1399 | 1483 | 'type' => 'chmod', |
| 1400 | 1484 | 'filename' => $this_action['destination'] |
| 1401 | 1485 | ); |
| 1402 | - } |
|
| 1403 | - elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1486 | + } |
|
| 1487 | + } elseif ($actionType == 'move-dir' || $actionType == 'move-file') |
|
| 1404 | 1488 | { |
| 1405 | 1489 | if (!mktree(dirname($this_action['destination']), false)) |
| 1406 | 1490 | { |
| 1407 | 1491 | $temp = dirname($this_action['destination']); |
| 1408 | - while (!file_exists($temp) && strlen($temp) > 1) |
|
| 1409 | - $temp = dirname($temp); |
|
| 1492 | + while (!file_exists($temp) && strlen($temp) > 1) { |
|
| 1493 | + $temp = dirname($temp); |
|
| 1494 | + } |
|
| 1410 | 1495 | |
| 1411 | 1496 | $return[] = array( |
| 1412 | 1497 | 'type' => 'chmod', |
@@ -1414,30 +1499,30 @@ discard block |
||
| 1414 | 1499 | ); |
| 1415 | 1500 | } |
| 1416 | 1501 | |
| 1417 | - if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) |
|
| 1418 | - $return[] = array( |
|
| 1502 | + if (!is_writable($this_action['destination']) && (file_exists($this_action['destination']) || !is_writable(dirname($this_action['destination'])))) { |
|
| 1503 | + $return[] = array( |
|
| 1419 | 1504 | 'type' => 'chmod', |
| 1420 | 1505 | 'filename' => $this_action['destination'] |
| 1421 | 1506 | ); |
| 1422 | - } |
|
| 1423 | - elseif ($actionType == 'remove-dir') |
|
| 1507 | + } |
|
| 1508 | + } elseif ($actionType == 'remove-dir') |
|
| 1424 | 1509 | { |
| 1425 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1426 | - $return[] = array( |
|
| 1510 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1511 | + $return[] = array( |
|
| 1427 | 1512 | 'type' => 'chmod', |
| 1428 | 1513 | 'filename' => $this_action['filename'] |
| 1429 | 1514 | ); |
| 1430 | - } |
|
| 1431 | - elseif ($actionType == 'remove-file') |
|
| 1515 | + } |
|
| 1516 | + } elseif ($actionType == 'remove-file') |
|
| 1432 | 1517 | { |
| 1433 | - if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) |
|
| 1434 | - $return[] = array( |
|
| 1518 | + if (!is_writable($this_action['filename']) && file_exists($this_action['filename'])) { |
|
| 1519 | + $return[] = array( |
|
| 1435 | 1520 | 'type' => 'chmod', |
| 1436 | 1521 | 'filename' => $this_action['filename'] |
| 1437 | 1522 | ); |
| 1523 | + } |
|
| 1438 | 1524 | } |
| 1439 | - } |
|
| 1440 | - else |
|
| 1525 | + } else |
|
| 1441 | 1526 | { |
| 1442 | 1527 | $return[] = array( |
| 1443 | 1528 | 'type' => 'error', |
@@ -1448,8 +1533,9 @@ discard block |
||
| 1448 | 1533 | } |
| 1449 | 1534 | |
| 1450 | 1535 | // Only testing - just return a list of things to be done. |
| 1451 | - if ($testing_only) |
|
| 1452 | - return $return; |
|
| 1536 | + if ($testing_only) { |
|
| 1537 | + return $return; |
|
| 1538 | + } |
|
| 1453 | 1539 | |
| 1454 | 1540 | umask(0); |
| 1455 | 1541 | |
@@ -1457,78 +1543,81 @@ discard block |
||
| 1457 | 1543 | $not_done = array(array('type' => '!')); |
| 1458 | 1544 | foreach ($return as $action) |
| 1459 | 1545 | { |
| 1460 | - if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) |
|
| 1461 | - $not_done[] = $action; |
|
| 1546 | + if (in_array($action['type'], array('modification', 'code', 'database', 'redirect', 'hook', 'credits'))) { |
|
| 1547 | + $not_done[] = $action; |
|
| 1548 | + } |
|
| 1462 | 1549 | |
| 1463 | 1550 | if ($action['type'] == 'create-dir') |
| 1464 | 1551 | { |
| 1465 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1466 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1467 | - } |
|
| 1468 | - elseif ($action['type'] == 'create-file') |
|
| 1552 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1553 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1554 | + } |
|
| 1555 | + } elseif ($action['type'] == 'create-file') |
|
| 1469 | 1556 | { |
| 1470 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1471 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1557 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1558 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1559 | + } |
|
| 1472 | 1560 | |
| 1473 | 1561 | // Create an empty file. |
| 1474 | 1562 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1475 | 1563 | |
| 1476 | - if (!file_exists($action['destination'])) |
|
| 1477 | - $failure = true; |
|
| 1478 | - } |
|
| 1479 | - elseif ($action['type'] == 'require-dir') |
|
| 1564 | + if (!file_exists($action['destination'])) { |
|
| 1565 | + $failure = true; |
|
| 1566 | + } |
|
| 1567 | + } elseif ($action['type'] == 'require-dir') |
|
| 1480 | 1568 | { |
| 1481 | 1569 | copytree($action['source'], $action['destination']); |
| 1482 | 1570 | // Any other theme folders? |
| 1483 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1484 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1571 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1572 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1485 | 1573 | copytree($action['source'], $theme_destination); |
| 1486 | - } |
|
| 1487 | - elseif ($action['type'] == 'require-file') |
|
| 1574 | + } |
|
| 1575 | + } elseif ($action['type'] == 'require-file') |
|
| 1488 | 1576 | { |
| 1489 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1490 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1577 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1578 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1579 | + } |
|
| 1491 | 1580 | |
| 1492 | 1581 | package_put_contents($action['destination'], package_get_contents($action['source']), $testing_only); |
| 1493 | 1582 | |
| 1494 | 1583 | $failure |= !copy($action['source'], $action['destination']); |
| 1495 | 1584 | |
| 1496 | 1585 | // Any other theme files? |
| 1497 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) |
|
| 1498 | - foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1586 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['destination']])) { |
|
| 1587 | + foreach ($context['theme_copies'][$action['type']][$action['destination']] as $theme_destination) |
|
| 1499 | 1588 | { |
| 1500 | 1589 | if (!mktree(dirname($theme_destination), 0755) || !is_writable(dirname($theme_destination))) |
| 1501 | 1590 | $failure |= !mktree(dirname($theme_destination), 0777); |
| 1591 | + } |
|
| 1502 | 1592 | |
| 1503 | 1593 | package_put_contents($theme_destination, package_get_contents($action['source']), $testing_only); |
| 1504 | 1594 | |
| 1505 | 1595 | $failure |= !copy($action['source'], $theme_destination); |
| 1506 | 1596 | } |
| 1507 | - } |
|
| 1508 | - elseif ($action['type'] == 'move-file') |
|
| 1597 | + } elseif ($action['type'] == 'move-file') |
|
| 1509 | 1598 | { |
| 1510 | - if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) |
|
| 1511 | - $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1599 | + if (!mktree(dirname($action['destination']), 0755) || !is_writable(dirname($action['destination']))) { |
|
| 1600 | + $failure |= !mktree(dirname($action['destination']), 0777); |
|
| 1601 | + } |
|
| 1512 | 1602 | |
| 1513 | 1603 | $failure |= !rename($action['source'], $action['destination']); |
| 1514 | - } |
|
| 1515 | - elseif ($action['type'] == 'move-dir') |
|
| 1604 | + } elseif ($action['type'] == 'move-dir') |
|
| 1516 | 1605 | { |
| 1517 | - if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) |
|
| 1518 | - $failure |= !mktree($action['destination'], 0777); |
|
| 1606 | + if (!mktree($action['destination'], 0755) || !is_writable($action['destination'])) { |
|
| 1607 | + $failure |= !mktree($action['destination'], 0777); |
|
| 1608 | + } |
|
| 1519 | 1609 | |
| 1520 | 1610 | $failure |= !rename($action['source'], $action['destination']); |
| 1521 | - } |
|
| 1522 | - elseif ($action['type'] == 'remove-dir') |
|
| 1611 | + } elseif ($action['type'] == 'remove-dir') |
|
| 1523 | 1612 | { |
| 1524 | 1613 | deltree($action['filename']); |
| 1525 | 1614 | |
| 1526 | 1615 | // Any other theme folders? |
| 1527 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1528 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1616 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1617 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1529 | 1618 | deltree($theme_destination); |
| 1530 | - } |
|
| 1531 | - elseif ($action['type'] == 'remove-file') |
|
| 1619 | + } |
|
| 1620 | + } elseif ($action['type'] == 'remove-file') |
|
| 1532 | 1621 | { |
| 1533 | 1622 | // Make sure the file exists before deleting it. |
| 1534 | 1623 | if (file_exists($action['filename'])) |
@@ -1537,16 +1626,18 @@ discard block |
||
| 1537 | 1626 | $failure |= !unlink($action['filename']); |
| 1538 | 1627 | } |
| 1539 | 1628 | // The file that was supposed to be deleted couldn't be found. |
| 1540 | - else |
|
| 1541 | - $failure = true; |
|
| 1629 | + else { |
|
| 1630 | + $failure = true; |
|
| 1631 | + } |
|
| 1542 | 1632 | |
| 1543 | 1633 | // Any other theme folders? |
| 1544 | - if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) |
|
| 1545 | - foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1634 | + if (!empty($context['theme_copies']) && !empty($context['theme_copies'][$action['type']][$action['filename']])) { |
|
| 1635 | + foreach ($context['theme_copies'][$action['type']][$action['filename']] as $theme_destination) |
|
| 1546 | 1636 | if (file_exists($theme_destination)) |
| 1547 | 1637 | $failure |= !unlink($theme_destination); |
| 1548 | - else |
|
| 1549 | - $failure = true; |
|
| 1638 | + } else { |
|
| 1639 | + $failure = true; |
|
| 1640 | + } |
|
| 1550 | 1641 | } |
| 1551 | 1642 | } |
| 1552 | 1643 | |
@@ -1568,8 +1659,9 @@ discard block |
||
| 1568 | 1659 | { |
| 1569 | 1660 | static $near_version = 0; |
| 1570 | 1661 | |
| 1571 | - if ($reset) |
|
| 1572 | - $near_version = 0; |
|
| 1662 | + if ($reset) { |
|
| 1663 | + $near_version = 0; |
|
| 1664 | + } |
|
| 1573 | 1665 | |
| 1574 | 1666 | // Normalize the $versions while we remove our previous Doh! |
| 1575 | 1667 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
@@ -1578,16 +1670,19 @@ discard block |
||
| 1578 | 1670 | foreach ($versions as $for) |
| 1579 | 1671 | { |
| 1580 | 1672 | // Adjust for those wild cards |
| 1581 | - if (strpos($for, '*') !== false) |
|
| 1582 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1673 | + if (strpos($for, '*') !== false) { |
|
| 1674 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1675 | + } |
|
| 1583 | 1676 | |
| 1584 | 1677 | // If we have a range, grab the lower value, done this way so it looks normal-er to the user e.g. 2.0 vs 2.0.99 |
| 1585 | - if (strpos($for, '-') !== false) |
|
| 1586 | - list ($for, $higher) = explode('-', $for); |
|
| 1678 | + if (strpos($for, '-') !== false) { |
|
| 1679 | + list ($for, $higher) = explode('-', $for); |
|
| 1680 | + } |
|
| 1587 | 1681 | |
| 1588 | 1682 | // Do the compare, if the for is greater, than what we have but not greater than what we are running ..... |
| 1589 | - if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) |
|
| 1590 | - $near_version = $for; |
|
| 1683 | + if (compareVersions($near_version, $for) === -1 && compareVersions($for, $the_version) !== 1) { |
|
| 1684 | + $near_version = $for; |
|
| 1685 | + } |
|
| 1591 | 1686 | } |
| 1592 | 1687 | |
| 1593 | 1688 | return !empty($near_version) ? $near_version : false; |
@@ -1610,15 +1705,17 @@ discard block |
||
| 1610 | 1705 | $versions = explode(',', str_replace(array(' ', '2.0rc1-1'), array('', '2.0rc1.1'), strtolower($versions))); |
| 1611 | 1706 | |
| 1612 | 1707 | // Perhaps we do accept anything? |
| 1613 | - if (in_array('all', $versions)) |
|
| 1614 | - return true; |
|
| 1708 | + if (in_array('all', $versions)) { |
|
| 1709 | + return true; |
|
| 1710 | + } |
|
| 1615 | 1711 | |
| 1616 | 1712 | // Loop through each version. |
| 1617 | 1713 | foreach ($versions as $for) |
| 1618 | 1714 | { |
| 1619 | 1715 | // Wild card spotted? |
| 1620 | - if (strpos($for, '*') !== false) |
|
| 1621 | - $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1716 | + if (strpos($for, '*') !== false) { |
|
| 1717 | + $for = str_replace('*', '0dev0', $for) . '-' . str_replace('*', '999', $for); |
|
| 1718 | + } |
|
| 1622 | 1719 | |
| 1623 | 1720 | // Do we have a range? |
| 1624 | 1721 | if (strpos($for, '-') !== false) |
@@ -1626,12 +1723,14 @@ discard block |
||
| 1626 | 1723 | list ($lower, $upper) = explode('-', $for); |
| 1627 | 1724 | |
| 1628 | 1725 | // Compare the version against lower and upper bounds. |
| 1629 | - if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) |
|
| 1630 | - return true; |
|
| 1726 | + if (compareVersions($version, $lower) > -1 && compareVersions($version, $upper) < 1) { |
|
| 1727 | + return true; |
|
| 1728 | + } |
|
| 1631 | 1729 | } |
| 1632 | 1730 | // Otherwise check if they are equal... |
| 1633 | - elseif (compareVersions($version, $for) === 0) |
|
| 1634 | - return true; |
|
| 1731 | + elseif (compareVersions($version, $for) === 0) { |
|
| 1732 | + return true; |
|
| 1733 | + } |
|
| 1635 | 1734 | } |
| 1636 | 1735 | |
| 1637 | 1736 | return false; |
@@ -1671,12 +1770,14 @@ discard block |
||
| 1671 | 1770 | } |
| 1672 | 1771 | |
| 1673 | 1772 | // Are they the same, perhaps? |
| 1674 | - if ($versions[1] === $versions[2]) |
|
| 1675 | - return 0; |
|
| 1773 | + if ($versions[1] === $versions[2]) { |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1676 | 1776 | |
| 1677 | 1777 | // Get version numbering categories... |
| 1678 | - if (!isset($categories)) |
|
| 1679 | - $categories = array_keys($versions[1]); |
|
| 1778 | + if (!isset($categories)) { |
|
| 1779 | + $categories = array_keys($versions[1]); |
|
| 1780 | + } |
|
| 1680 | 1781 | |
| 1681 | 1782 | // Loop through each category. |
| 1682 | 1783 | foreach ($categories as $category) |
@@ -1686,13 +1787,15 @@ discard block |
||
| 1686 | 1787 | { |
| 1687 | 1788 | // Dev builds are a problematic exception. |
| 1688 | 1789 | // (stable) dev < (stable) but (unstable) dev = (unstable) |
| 1689 | - if ($category == 'type') |
|
| 1690 | - return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1691 | - elseif ($category == 'dev') |
|
| 1692 | - return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1790 | + if ($category == 'type') { |
|
| 1791 | + return $versions[1][$category] > $versions[2][$category] ? ($versions[1]['dev'] ? -1 : 1) : ($versions[2]['dev'] ? 1 : -1); |
|
| 1792 | + } elseif ($category == 'dev') { |
|
| 1793 | + return $versions[1]['dev'] ? ($versions[2]['type'] == 'stable' ? -1 : 0) : ($versions[1]['type'] == 'stable' ? 1 : 0); |
|
| 1794 | + } |
|
| 1693 | 1795 | // Otherwise a simple comparison. |
| 1694 | - else |
|
| 1695 | - return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1796 | + else { |
|
| 1797 | + return $versions[1][$category] > $versions[2][$category] ? 1 : -1; |
|
| 1798 | + } |
|
| 1696 | 1799 | } |
| 1697 | 1800 | } |
| 1698 | 1801 | |
@@ -1726,11 +1829,13 @@ discard block |
||
| 1726 | 1829 | ); |
| 1727 | 1830 | |
| 1728 | 1831 | // do we parse in a package directory? |
| 1729 | - if (!empty($temp_path)) |
|
| 1730 | - $dirs['$package'] = $temp_path; |
|
| 1832 | + if (!empty($temp_path)) { |
|
| 1833 | + $dirs['$package'] = $temp_path; |
|
| 1834 | + } |
|
| 1731 | 1835 | |
| 1732 | - if (strlen($path) == 0) |
|
| 1733 | - trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1836 | + if (strlen($path) == 0) { |
|
| 1837 | + trigger_error('parse_path(): There should never be an empty filename', E_USER_ERROR); |
|
| 1838 | + } |
|
| 1734 | 1839 | |
| 1735 | 1840 | return strtr($path, $dirs); |
| 1736 | 1841 | } |
@@ -1747,8 +1852,9 @@ discard block |
||
| 1747 | 1852 | /** @var ftp_connection $package_ftp */ |
| 1748 | 1853 | global $package_ftp; |
| 1749 | 1854 | |
| 1750 | - if (!file_exists($dir)) |
|
| 1751 | - return; |
|
| 1855 | + if (!file_exists($dir)) { |
|
| 1856 | + return; |
|
| 1857 | + } |
|
| 1752 | 1858 | |
| 1753 | 1859 | $current_dir = @opendir($dir); |
| 1754 | 1860 | if ($current_dir == false) |
@@ -1756,8 +1862,9 @@ discard block |
||
| 1756 | 1862 | if ($delete_dir && isset($package_ftp)) |
| 1757 | 1863 | { |
| 1758 | 1864 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1759 | - if (!is_dir($dir)) |
|
| 1760 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1865 | + if (!is_dir($dir)) { |
|
| 1866 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1867 | + } |
|
| 1761 | 1868 | $package_ftp->unlink($ftp_file); |
| 1762 | 1869 | } |
| 1763 | 1870 | |
@@ -1766,26 +1873,28 @@ discard block |
||
| 1766 | 1873 | |
| 1767 | 1874 | while ($entryname = readdir($current_dir)) |
| 1768 | 1875 | { |
| 1769 | - if (in_array($entryname, array('.', '..'))) |
|
| 1770 | - continue; |
|
| 1876 | + if (in_array($entryname, array('.', '..'))) { |
|
| 1877 | + continue; |
|
| 1878 | + } |
|
| 1771 | 1879 | |
| 1772 | - if (is_dir($dir . '/' . $entryname)) |
|
| 1773 | - deltree($dir . '/' . $entryname); |
|
| 1774 | - else |
|
| 1880 | + if (is_dir($dir . '/' . $entryname)) { |
|
| 1881 | + deltree($dir . '/' . $entryname); |
|
| 1882 | + } else |
|
| 1775 | 1883 | { |
| 1776 | 1884 | // Here, 755 doesn't really matter since we're deleting it anyway. |
| 1777 | 1885 | if (isset($package_ftp)) |
| 1778 | 1886 | { |
| 1779 | 1887 | $ftp_file = strtr($dir . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
| 1780 | 1888 | |
| 1781 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1782 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1889 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1890 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1891 | + } |
|
| 1783 | 1892 | $package_ftp->unlink($ftp_file); |
| 1784 | - } |
|
| 1785 | - else |
|
| 1893 | + } else |
|
| 1786 | 1894 | { |
| 1787 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1788 | - smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1895 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1896 | + smf_chmod($dir . '/' . $entryname, 0777); |
|
| 1897 | + } |
|
| 1789 | 1898 | unlink($dir . '/' . $entryname); |
| 1790 | 1899 | } |
| 1791 | 1900 | } |
@@ -1798,14 +1907,15 @@ discard block |
||
| 1798 | 1907 | if (isset($package_ftp)) |
| 1799 | 1908 | { |
| 1800 | 1909 | $ftp_file = strtr($dir, array($_SESSION['pack_ftp']['root'] => '')); |
| 1801 | - if (!is_writable($dir . '/' . $entryname)) |
|
| 1802 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 1910 | + if (!is_writable($dir . '/' . $entryname)) { |
|
| 1911 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 1912 | + } |
|
| 1803 | 1913 | $package_ftp->unlink($ftp_file); |
| 1804 | - } |
|
| 1805 | - else |
|
| 1914 | + } else |
|
| 1806 | 1915 | { |
| 1807 | - if (!is_writable($dir)) |
|
| 1808 | - smf_chmod($dir, 0777); |
|
| 1916 | + if (!is_writable($dir)) { |
|
| 1917 | + smf_chmod($dir, 0777); |
|
| 1918 | + } |
|
| 1809 | 1919 | @rmdir($dir); |
| 1810 | 1920 | } |
| 1811 | 1921 | } |
@@ -1828,10 +1938,11 @@ discard block |
||
| 1828 | 1938 | { |
| 1829 | 1939 | if (!is_writable($strPath) && $mode !== false) |
| 1830 | 1940 | { |
| 1831 | - if (isset($package_ftp)) |
|
| 1832 | - $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1833 | - else |
|
| 1834 | - smf_chmod($strPath, $mode); |
|
| 1941 | + if (isset($package_ftp)) { |
|
| 1942 | + $package_ftp->chmod(strtr($strPath, array($_SESSION['pack_ftp']['root'] => '')), $mode); |
|
| 1943 | + } else { |
|
| 1944 | + smf_chmod($strPath, $mode); |
|
| 1945 | + } |
|
| 1835 | 1946 | } |
| 1836 | 1947 | |
| 1837 | 1948 | $test = @opendir($strPath); |
@@ -1839,36 +1950,37 @@ discard block |
||
| 1839 | 1950 | { |
| 1840 | 1951 | closedir($test); |
| 1841 | 1952 | return is_writable($strPath); |
| 1953 | + } else { |
|
| 1954 | + return false; |
|
| 1842 | 1955 | } |
| 1843 | - else |
|
| 1844 | - return false; |
|
| 1845 | 1956 | } |
| 1846 | 1957 | // Is this an invalid path and/or we can't make the directory? |
| 1847 | - if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) |
|
| 1848 | - return false; |
|
| 1958 | + if ($strPath == dirname($strPath) || !mktree(dirname($strPath), $mode)) { |
|
| 1959 | + return false; |
|
| 1960 | + } |
|
| 1849 | 1961 | |
| 1850 | 1962 | if (!is_writable(dirname($strPath)) && $mode !== false) |
| 1851 | 1963 | { |
| 1852 | - if (isset($package_ftp)) |
|
| 1853 | - $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1854 | - else |
|
| 1855 | - smf_chmod(dirname($strPath), $mode); |
|
| 1964 | + if (isset($package_ftp)) { |
|
| 1965 | + $package_ftp->chmod(dirname(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))), $mode); |
|
| 1966 | + } else { |
|
| 1967 | + smf_chmod(dirname($strPath), $mode); |
|
| 1968 | + } |
|
| 1856 | 1969 | } |
| 1857 | 1970 | |
| 1858 | - if ($mode !== false && isset($package_ftp)) |
|
| 1859 | - return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1860 | - elseif ($mode === false) |
|
| 1971 | + if ($mode !== false && isset($package_ftp)) { |
|
| 1972 | + return $package_ftp->create_dir(strtr($strPath, array($_SESSION['pack_ftp']['root'] => ''))); |
|
| 1973 | + } elseif ($mode === false) |
|
| 1861 | 1974 | { |
| 1862 | 1975 | $test = @opendir(dirname($strPath)); |
| 1863 | 1976 | if ($test) |
| 1864 | 1977 | { |
| 1865 | 1978 | closedir($test); |
| 1866 | 1979 | return true; |
| 1980 | + } else { |
|
| 1981 | + return false; |
|
| 1867 | 1982 | } |
| 1868 | - else |
|
| 1869 | - return false; |
|
| 1870 | - } |
|
| 1871 | - else |
|
| 1983 | + } else |
|
| 1872 | 1984 | { |
| 1873 | 1985 | @mkdir($strPath, $mode); |
| 1874 | 1986 | $test = @opendir($strPath); |
@@ -1876,9 +1988,9 @@ discard block |
||
| 1876 | 1988 | { |
| 1877 | 1989 | closedir($test); |
| 1878 | 1990 | return true; |
| 1991 | + } else { |
|
| 1992 | + return false; |
|
| 1879 | 1993 | } |
| 1880 | - else |
|
| 1881 | - return false; |
|
| 1882 | 1994 | } |
| 1883 | 1995 | } |
| 1884 | 1996 | |
@@ -1894,39 +2006,46 @@ discard block |
||
| 1894 | 2006 | /** @var ftp_connection $package_ftp */ |
| 1895 | 2007 | global $package_ftp; |
| 1896 | 2008 | |
| 1897 | - if (!file_exists($destination) || !is_writable($destination)) |
|
| 1898 | - mktree($destination, 0755); |
|
| 1899 | - if (!is_writable($destination)) |
|
| 1900 | - mktree($destination, 0777); |
|
| 2009 | + if (!file_exists($destination) || !is_writable($destination)) { |
|
| 2010 | + mktree($destination, 0755); |
|
| 2011 | + } |
|
| 2012 | + if (!is_writable($destination)) { |
|
| 2013 | + mktree($destination, 0777); |
|
| 2014 | + } |
|
| 1901 | 2015 | |
| 1902 | 2016 | $current_dir = opendir($source); |
| 1903 | - if ($current_dir == false) |
|
| 1904 | - return; |
|
| 2017 | + if ($current_dir == false) { |
|
| 2018 | + return; |
|
| 2019 | + } |
|
| 1905 | 2020 | |
| 1906 | 2021 | while ($entryname = readdir($current_dir)) |
| 1907 | 2022 | { |
| 1908 | - if (in_array($entryname, array('.', '..'))) |
|
| 1909 | - continue; |
|
| 2023 | + if (in_array($entryname, array('.', '..'))) { |
|
| 2024 | + continue; |
|
| 2025 | + } |
|
| 1910 | 2026 | |
| 1911 | - if (isset($package_ftp)) |
|
| 1912 | - $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2027 | + if (isset($package_ftp)) { |
|
| 2028 | + $ftp_file = strtr($destination . '/' . $entryname, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2029 | + } |
|
| 1913 | 2030 | |
| 1914 | 2031 | if (is_file($source . '/' . $entryname)) |
| 1915 | 2032 | { |
| 1916 | - if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) |
|
| 1917 | - $package_ftp->create_file($ftp_file); |
|
| 1918 | - elseif (!file_exists($destination . '/' . $entryname)) |
|
| 1919 | - @touch($destination . '/' . $entryname); |
|
| 2033 | + if (isset($package_ftp) && !file_exists($destination . '/' . $entryname)) { |
|
| 2034 | + $package_ftp->create_file($ftp_file); |
|
| 2035 | + } elseif (!file_exists($destination . '/' . $entryname)) { |
|
| 2036 | + @touch($destination . '/' . $entryname); |
|
| 2037 | + } |
|
| 1920 | 2038 | } |
| 1921 | 2039 | |
| 1922 | 2040 | package_chmod($destination . '/' . $entryname); |
| 1923 | 2041 | |
| 1924 | - if (is_dir($source . '/' . $entryname)) |
|
| 1925 | - copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 1926 | - elseif (file_exists($destination . '/' . $entryname)) |
|
| 1927 | - package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 1928 | - else |
|
| 1929 | - copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2042 | + if (is_dir($source . '/' . $entryname)) { |
|
| 2043 | + copytree($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2044 | + } elseif (file_exists($destination . '/' . $entryname)) { |
|
| 2045 | + package_put_contents($destination . '/' . $entryname, package_get_contents($source . '/' . $entryname)); |
|
| 2046 | + } else { |
|
| 2047 | + copy($source . '/' . $entryname, $destination . '/' . $entryname); |
|
| 2048 | + } |
|
| 1930 | 2049 | } |
| 1931 | 2050 | |
| 1932 | 2051 | closedir($current_dir); |
@@ -1944,21 +2063,24 @@ discard block |
||
| 1944 | 2063 | $data = array(); |
| 1945 | 2064 | |
| 1946 | 2065 | $dir = @dir($path . $sub_path); |
| 1947 | - if (!$dir) |
|
| 1948 | - return array(); |
|
| 2066 | + if (!$dir) { |
|
| 2067 | + return array(); |
|
| 2068 | + } |
|
| 1949 | 2069 | while ($entry = $dir->read()) |
| 1950 | 2070 | { |
| 1951 | - if ($entry == '.' || $entry == '..') |
|
| 1952 | - continue; |
|
| 2071 | + if ($entry == '.' || $entry == '..') { |
|
| 2072 | + continue; |
|
| 2073 | + } |
|
| 1953 | 2074 | |
| 1954 | - if (is_dir($path . $sub_path . '/' . $entry)) |
|
| 1955 | - $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 1956 | - else |
|
| 1957 | - $data[] = array( |
|
| 2075 | + if (is_dir($path . $sub_path . '/' . $entry)) { |
|
| 2076 | + $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); |
|
| 2077 | + } else { |
|
| 2078 | + $data[] = array( |
|
| 1958 | 2079 | 'filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, |
| 1959 | 2080 | 'size' => filesize($path . $sub_path . '/' . $entry), |
| 1960 | 2081 | 'skipped' => false, |
| 1961 | 2082 | ); |
| 2083 | + } |
|
| 1962 | 2084 | } |
| 1963 | 2085 | $dir->close(); |
| 1964 | 2086 | |
@@ -2013,8 +2135,9 @@ discard block |
||
| 2013 | 2135 | { |
| 2014 | 2136 | // If this filename is relative, if so take a guess at what it should be. |
| 2015 | 2137 | $real_filename = $filename; |
| 2016 | - if (strpos($filename, 'Themes') === 0) |
|
| 2017 | - $real_filename = $boarddir . '/' . $filename; |
|
| 2138 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2139 | + $real_filename = $boarddir . '/' . $filename; |
|
| 2140 | + } |
|
| 2018 | 2141 | |
| 2019 | 2142 | if (strpos($real_filename, $theme['theme_dir']) === 0) |
| 2020 | 2143 | { |
@@ -2033,8 +2156,9 @@ discard block |
||
| 2033 | 2156 | foreach ($theme_paths as $id => $theme) |
| 2034 | 2157 | { |
| 2035 | 2158 | // Default is getting done anyway, so no need for involvement here. |
| 2036 | - if ($id == 1) |
|
| 2037 | - continue; |
|
| 2159 | + if ($id == 1) { |
|
| 2160 | + continue; |
|
| 2161 | + } |
|
| 2038 | 2162 | |
| 2039 | 2163 | // For every template, do we want it? Yea, no, maybe? |
| 2040 | 2164 | foreach ($template_changes[1] as $index => $template_file) |
@@ -2057,8 +2181,9 @@ discard block |
||
| 2057 | 2181 | ); |
| 2058 | 2182 | |
| 2059 | 2183 | // Sometimes though, we have some additional files for other themes, if we have add them to the mix. |
| 2060 | - if (isset($custom_themes_add[$files_to_change[1]])) |
|
| 2061 | - $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2184 | + if (isset($custom_themes_add[$files_to_change[1]])) { |
|
| 2185 | + $files_to_change += $custom_themes_add[$files_to_change[1]]; |
|
| 2186 | + } |
|
| 2062 | 2187 | |
| 2063 | 2188 | // Now, loop through all the files we're changing, and, well, change them ;) |
| 2064 | 2189 | foreach ($files_to_change as $theme => $working_file) |
@@ -2092,11 +2217,13 @@ discard block |
||
| 2092 | 2217 | continue; |
| 2093 | 2218 | } |
| 2094 | 2219 | // Okay, we're creating this file then...? |
| 2095 | - elseif (!file_exists($working_file)) |
|
| 2096 | - $working_data = ''; |
|
| 2220 | + elseif (!file_exists($working_file)) { |
|
| 2221 | + $working_data = ''; |
|
| 2222 | + } |
|
| 2097 | 2223 | // Phew, it exists! Load 'er up! |
| 2098 | - else |
|
| 2099 | - $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2224 | + else { |
|
| 2225 | + $working_data = str_replace("\r", '', package_get_contents($working_file)); |
|
| 2226 | + } |
|
| 2100 | 2227 | |
| 2101 | 2228 | $actions[] = array( |
| 2102 | 2229 | 'type' => 'opened', |
@@ -2117,8 +2244,8 @@ discard block |
||
| 2117 | 2244 | |
| 2118 | 2245 | // Grab all search items of this operation (in most cases just 1). |
| 2119 | 2246 | $searches = $operation->set('search'); |
| 2120 | - foreach ($searches as $i => $search) |
|
| 2121 | - $actual_operation['searches'][] = array( |
|
| 2247 | + foreach ($searches as $i => $search) { |
|
| 2248 | + $actual_operation['searches'][] = array( |
|
| 2122 | 2249 | 'position' => $search->exists('@position') && in_array(trim($search->fetch('@position')), array('before', 'after', 'replace', 'end')) ? trim($search->fetch('@position')) : 'replace', |
| 2123 | 2250 | 'is_reg_exp' => $search->exists('@regexp') && trim($search->fetch('@regexp')) === 'true', |
| 2124 | 2251 | 'loose_whitespace' => $search->exists('@whitespace') && trim($search->fetch('@whitespace')) === 'loose', |
@@ -2127,6 +2254,7 @@ discard block |
||
| 2127 | 2254 | 'preg_search' => '', |
| 2128 | 2255 | 'preg_replace' => '', |
| 2129 | 2256 | ); |
| 2257 | + } |
|
| 2130 | 2258 | |
| 2131 | 2259 | // At least one search should be defined. |
| 2132 | 2260 | if (empty($actual_operation['searches'])) |
@@ -2151,30 +2279,32 @@ discard block |
||
| 2151 | 2279 | // Reverse modification of regular expressions are not allowed. |
| 2152 | 2280 | if ($search['is_reg_exp']) |
| 2153 | 2281 | { |
| 2154 | - if ($actual_operation['error'] === 'fatal') |
|
| 2155 | - $actions[] = array( |
|
| 2282 | + if ($actual_operation['error'] === 'fatal') { |
|
| 2283 | + $actions[] = array( |
|
| 2156 | 2284 | 'type' => 'failure', |
| 2157 | 2285 | 'filename' => $working_file, |
| 2158 | 2286 | 'search' => $search['search'], |
| 2159 | 2287 | 'is_custom' => $theme > 1 ? $theme : 0, |
| 2160 | 2288 | ); |
| 2289 | + } |
|
| 2161 | 2290 | |
| 2162 | 2291 | // Continue to the next operation. |
| 2163 | 2292 | continue 2; |
| 2164 | 2293 | } |
| 2165 | 2294 | |
| 2166 | 2295 | // The replacement is now the search subject... |
| 2167 | - if ($search['position'] === 'replace' || $search['position'] === 'end') |
|
| 2168 | - $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2169 | - else |
|
| 2296 | + if ($search['position'] === 'replace' || $search['position'] === 'end') { |
|
| 2297 | + $actual_operation['searches'][$i]['search'] = $search['add']; |
|
| 2298 | + } else |
|
| 2170 | 2299 | { |
| 2171 | 2300 | // Reversing a before/after modification becomes a replacement. |
| 2172 | 2301 | $actual_operation['searches'][$i]['position'] = 'replace'; |
| 2173 | 2302 | |
| 2174 | - if ($search['position'] === 'before') |
|
| 2175 | - $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2176 | - elseif ($search['position'] === 'after') |
|
| 2177 | - $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2303 | + if ($search['position'] === 'before') { |
|
| 2304 | + $actual_operation['searches'][$i]['search'] .= $search['add']; |
|
| 2305 | + } elseif ($search['position'] === 'after') { |
|
| 2306 | + $actual_operation['searches'][$i]['search'] = $search['add'] . $search['search']; |
|
| 2307 | + } |
|
| 2178 | 2308 | } |
| 2179 | 2309 | |
| 2180 | 2310 | // ...and the search subject is now the replacement. |
@@ -2202,16 +2332,17 @@ discard block |
||
| 2202 | 2332 | foreach ($actual_operation['searches'] as $i => $search) |
| 2203 | 2333 | { |
| 2204 | 2334 | // Not much needed if the search subject is already a regexp. |
| 2205 | - if ($search['is_reg_exp']) |
|
| 2206 | - $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2207 | - else |
|
| 2335 | + if ($search['is_reg_exp']) { |
|
| 2336 | + $actual_operation['searches'][$i]['preg_search'] = $search['search']; |
|
| 2337 | + } else |
|
| 2208 | 2338 | { |
| 2209 | 2339 | // Make the search subject fit into a regular expression. |
| 2210 | 2340 | $actual_operation['searches'][$i]['preg_search'] = preg_quote($search['search'], '~'); |
| 2211 | 2341 | |
| 2212 | 2342 | // Using 'loose', a random amount of tabs and spaces may be used. |
| 2213 | - if ($search['loose_whitespace']) |
|
| 2214 | - $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2343 | + if ($search['loose_whitespace']) { |
|
| 2344 | + $actual_operation['searches'][$i]['preg_search'] = preg_replace('~[ \t]+~', '[ \t]+', $actual_operation['searches'][$i]['preg_search']); |
|
| 2345 | + } |
|
| 2215 | 2346 | } |
| 2216 | 2347 | |
| 2217 | 2348 | // Shuzzup. This is done so we can safely use a regular expression. ($0 is bad!!) |
@@ -2237,8 +2368,7 @@ discard block |
||
| 2237 | 2368 | if ($undo) |
| 2238 | 2369 | { |
| 2239 | 2370 | $actual_operation['searches'][$i]['preg_replace'] = ''; |
| 2240 | - } |
|
| 2241 | - else |
|
| 2371 | + } else |
|
| 2242 | 2372 | { |
| 2243 | 2373 | $actual_operation['searches'][$i]['preg_search'] = '(\\n\\?\\>)?$'; |
| 2244 | 2374 | $actual_operation['searches'][$i]['preg_replace'] .= '$1'; |
@@ -2285,8 +2415,9 @@ discard block |
||
| 2285 | 2415 | } |
| 2286 | 2416 | |
| 2287 | 2417 | // Replace it into nothing? That's not an option...unless it's an undoing end. |
| 2288 | - if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) |
|
| 2289 | - continue; |
|
| 2418 | + if ($search['add'] === '' && ($search['position'] !== 'end' || !$undo)) { |
|
| 2419 | + continue; |
|
| 2420 | + } |
|
| 2290 | 2421 | |
| 2291 | 2422 | // Finally, we're doing some replacements. |
| 2292 | 2423 | $working_data = preg_replace('~' . $actual_operation['searches'][$i]['preg_search'] . '~s', $actual_operation['searches'][$i]['preg_replace'], $working_data, 1); |
@@ -2311,22 +2442,25 @@ discard block |
||
| 2311 | 2442 | |
| 2312 | 2443 | package_chmod($working_file); |
| 2313 | 2444 | |
| 2314 | - if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) |
|
| 2315 | - $actions[] = array( |
|
| 2445 | + if ((file_exists($working_file) && !is_writable($working_file)) || (!file_exists($working_file) && !is_writable(dirname($working_file)))) { |
|
| 2446 | + $actions[] = array( |
|
| 2316 | 2447 | 'type' => 'chmod', |
| 2317 | 2448 | 'filename' => $working_file |
| 2318 | 2449 | ); |
| 2450 | + } |
|
| 2319 | 2451 | |
| 2320 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2321 | - continue; |
|
| 2452 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2453 | + continue; |
|
| 2454 | + } |
|
| 2322 | 2455 | |
| 2323 | 2456 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2324 | 2457 | { |
| 2325 | 2458 | // No, no, not Settings.php! |
| 2326 | - if (basename($working_file) == 'Settings.php') |
|
| 2327 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2328 | - else |
|
| 2329 | - @copy($working_file, $working_file . '~'); |
|
| 2459 | + if (basename($working_file) == 'Settings.php') { |
|
| 2460 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2461 | + } else { |
|
| 2462 | + @copy($working_file, $working_file . '~'); |
|
| 2463 | + } |
|
| 2330 | 2464 | } |
| 2331 | 2465 | |
| 2332 | 2466 | // Always call this, even if in testing, because it won't really be written in testing mode. |
@@ -2393,8 +2527,9 @@ discard block |
||
| 2393 | 2527 | if ($code_match[1] != 'edit file' && $code_match[1] != 'file') |
| 2394 | 2528 | { |
| 2395 | 2529 | // It's a step, let's add that to the current steps. |
| 2396 | - if (isset($temp_changes[$step_counter])) |
|
| 2397 | - $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2530 | + if (isset($temp_changes[$step_counter])) { |
|
| 2531 | + $temp_changes[$step_counter]['changes'][] = $code_match[0]; |
|
| 2532 | + } |
|
| 2398 | 2533 | continue; |
| 2399 | 2534 | } |
| 2400 | 2535 | |
@@ -2411,11 +2546,13 @@ discard block |
||
| 2411 | 2546 | foreach ($theme_paths as $id => $theme) |
| 2412 | 2547 | { |
| 2413 | 2548 | // If this filename is relative, if so take a guess at what it should be. |
| 2414 | - if (strpos($filename, 'Themes') === 0) |
|
| 2415 | - $filename = $boarddir . '/' . $filename; |
|
| 2549 | + if (strpos($filename, 'Themes') === 0) { |
|
| 2550 | + $filename = $boarddir . '/' . $filename; |
|
| 2551 | + } |
|
| 2416 | 2552 | |
| 2417 | - if (strpos($filename, $theme['theme_dir']) === 0) |
|
| 2418 | - $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2553 | + if (strpos($filename, $theme['theme_dir']) === 0) { |
|
| 2554 | + $template_changes[$id][$counter] = substr($filename, strlen($theme['theme_dir']) + 1); |
|
| 2555 | + } |
|
| 2419 | 2556 | } |
| 2420 | 2557 | } |
| 2421 | 2558 | |
@@ -2428,8 +2565,9 @@ discard block |
||
| 2428 | 2565 | foreach ($theme_paths as $id => $theme) |
| 2429 | 2566 | { |
| 2430 | 2567 | // Don't do default, it means nothing to me. |
| 2431 | - if ($id == 1) |
|
| 2432 | - continue; |
|
| 2568 | + if ($id == 1) { |
|
| 2569 | + continue; |
|
| 2570 | + } |
|
| 2433 | 2571 | |
| 2434 | 2572 | // Now, for each file do we need to edit it? |
| 2435 | 2573 | foreach ($template_changes[1] as $pos => $template_file) |
@@ -2465,32 +2603,36 @@ discard block |
||
| 2465 | 2603 | package_chmod($working_file); |
| 2466 | 2604 | |
| 2467 | 2605 | // Don't even dare. |
| 2468 | - if (basename($working_file) == 'Settings_bak.php') |
|
| 2469 | - continue; |
|
| 2606 | + if (basename($working_file) == 'Settings_bak.php') { |
|
| 2607 | + continue; |
|
| 2608 | + } |
|
| 2470 | 2609 | |
| 2471 | - if (!is_writable($working_file)) |
|
| 2472 | - $actions[] = array( |
|
| 2610 | + if (!is_writable($working_file)) { |
|
| 2611 | + $actions[] = array( |
|
| 2473 | 2612 | 'type' => 'chmod', |
| 2474 | 2613 | 'filename' => $working_file |
| 2475 | 2614 | ); |
| 2615 | + } |
|
| 2476 | 2616 | |
| 2477 | 2617 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2478 | 2618 | { |
| 2479 | - if (basename($working_file) == 'Settings.php') |
|
| 2480 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2481 | - else |
|
| 2482 | - @copy($working_file, $working_file . '~'); |
|
| 2619 | + if (basename($working_file) == 'Settings.php') { |
|
| 2620 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2621 | + } else { |
|
| 2622 | + @copy($working_file, $working_file . '~'); |
|
| 2623 | + } |
|
| 2483 | 2624 | } |
| 2484 | 2625 | |
| 2485 | 2626 | package_put_contents($working_file, $working_data, $testing); |
| 2486 | 2627 | } |
| 2487 | 2628 | |
| 2488 | - if ($working_file !== null) |
|
| 2489 | - $actions[] = array( |
|
| 2629 | + if ($working_file !== null) { |
|
| 2630 | + $actions[] = array( |
|
| 2490 | 2631 | 'type' => 'saved', |
| 2491 | 2632 | 'filename' => $working_file, |
| 2492 | 2633 | 'is_custom' => $is_custom, |
| 2493 | 2634 | ); |
| 2635 | + } |
|
| 2494 | 2636 | |
| 2495 | 2637 | // Is this "now working on" file a theme specific one? |
| 2496 | 2638 | $is_custom = isset($theme_id_ref[$counter - 1]) ? $theme_id_ref[$counter - 1] : 0; |
@@ -2509,10 +2651,11 @@ discard block |
||
| 2509 | 2651 | { |
| 2510 | 2652 | $places_to_check = array($boarddir, $sourcedir, $settings['default_theme_dir'], $settings['default_theme_dir'] . '/languages'); |
| 2511 | 2653 | |
| 2512 | - foreach ($places_to_check as $place) |
|
| 2513 | - if (file_exists($place . '/' . $working_file)) |
|
| 2654 | + foreach ($places_to_check as $place) { |
|
| 2655 | + if (file_exists($place . '/' . $working_file)) |
|
| 2514 | 2656 | { |
| 2515 | 2657 | $working_file = $place . '/' . $working_file; |
| 2658 | + } |
|
| 2516 | 2659 | break; |
| 2517 | 2660 | } |
| 2518 | 2661 | } |
@@ -2526,8 +2669,7 @@ discard block |
||
| 2526 | 2669 | 'type' => 'opened', |
| 2527 | 2670 | 'filename' => $working_file |
| 2528 | 2671 | ); |
| 2529 | - } |
|
| 2530 | - else |
|
| 2672 | + } else |
|
| 2531 | 2673 | { |
| 2532 | 2674 | $actions[] = array( |
| 2533 | 2675 | 'type' => 'missing', |
@@ -2563,11 +2705,13 @@ discard block |
||
| 2563 | 2705 | $replace_with = $code_match[2]; |
| 2564 | 2706 | |
| 2565 | 2707 | // Add this afterward... |
| 2566 | - if ($code_match[1] == 'add' || $code_match[1] == 'add after') |
|
| 2567 | - $replace_with = $working_search . "\n" . $replace_with; |
|
| 2708 | + if ($code_match[1] == 'add' || $code_match[1] == 'add after') { |
|
| 2709 | + $replace_with = $working_search . "\n" . $replace_with; |
|
| 2710 | + } |
|
| 2568 | 2711 | // Add this beforehand. |
| 2569 | - elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') |
|
| 2570 | - $replace_with .= "\n" . $working_search; |
|
| 2712 | + elseif ($code_match[1] == 'before' || $code_match[1] == 'add before' || $code_match[1] == 'above' || $code_match[1] == 'add above') { |
|
| 2713 | + $replace_with .= "\n" . $working_search; |
|
| 2714 | + } |
|
| 2571 | 2715 | // Otherwise.. replace with $replace_with ;). |
| 2572 | 2716 | } |
| 2573 | 2717 | |
@@ -2630,29 +2774,32 @@ discard block |
||
| 2630 | 2774 | { |
| 2631 | 2775 | package_chmod($working_file); |
| 2632 | 2776 | |
| 2633 | - if (!is_writable($working_file)) |
|
| 2634 | - $actions[] = array( |
|
| 2777 | + if (!is_writable($working_file)) { |
|
| 2778 | + $actions[] = array( |
|
| 2635 | 2779 | 'type' => 'chmod', |
| 2636 | 2780 | 'filename' => $working_file |
| 2637 | 2781 | ); |
| 2782 | + } |
|
| 2638 | 2783 | |
| 2639 | 2784 | if (!$testing && !empty($modSettings['package_make_backups']) && file_exists($working_file)) |
| 2640 | 2785 | { |
| 2641 | - if (basename($working_file) == 'Settings.php') |
|
| 2642 | - @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2643 | - else |
|
| 2644 | - @copy($working_file, $working_file . '~'); |
|
| 2786 | + if (basename($working_file) == 'Settings.php') { |
|
| 2787 | + @copy($working_file, dirname($working_file) . '/Settings_bak.php'); |
|
| 2788 | + } else { |
|
| 2789 | + @copy($working_file, $working_file . '~'); |
|
| 2790 | + } |
|
| 2645 | 2791 | } |
| 2646 | 2792 | |
| 2647 | 2793 | package_put_contents($working_file, $working_data, $testing); |
| 2648 | 2794 | } |
| 2649 | 2795 | |
| 2650 | - if ($working_file !== null) |
|
| 2651 | - $actions[] = array( |
|
| 2796 | + if ($working_file !== null) { |
|
| 2797 | + $actions[] = array( |
|
| 2652 | 2798 | 'type' => 'saved', |
| 2653 | 2799 | 'filename' => $working_file, |
| 2654 | 2800 | 'is_custom' => $is_custom, |
| 2655 | 2801 | ); |
| 2802 | + } |
|
| 2656 | 2803 | |
| 2657 | 2804 | $actions[] = array( |
| 2658 | 2805 | 'type' => 'result', |
@@ -2678,17 +2825,19 @@ discard block |
||
| 2678 | 2825 | $mem_check = setMemoryLimit('128M'); |
| 2679 | 2826 | |
| 2680 | 2827 | // Windows doesn't seem to care about the memory_limit. |
| 2681 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2682 | - $package_cache = array(); |
|
| 2683 | - else |
|
| 2684 | - $package_cache = false; |
|
| 2828 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2829 | + $package_cache = array(); |
|
| 2830 | + } else { |
|
| 2831 | + $package_cache = false; |
|
| 2832 | + } |
|
| 2685 | 2833 | } |
| 2686 | 2834 | |
| 2687 | - if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) |
|
| 2688 | - return file_get_contents($filename); |
|
| 2689 | - else |
|
| 2690 | - return $package_cache[$filename]; |
|
| 2691 | -} |
|
| 2835 | + if (strpos($filename, 'Packages/') !== false || $package_cache === false || !isset($package_cache[$filename])) { |
|
| 2836 | + return file_get_contents($filename); |
|
| 2837 | + } else { |
|
| 2838 | + return $package_cache[$filename]; |
|
| 2839 | + } |
|
| 2840 | + } |
|
| 2692 | 2841 | |
| 2693 | 2842 | /** |
| 2694 | 2843 | * Writes data to a file, almost exactly like the file_put_contents() function. |
@@ -2712,19 +2861,22 @@ discard block |
||
| 2712 | 2861 | // Try to increase the memory limit - we don't want to run out of ram! |
| 2713 | 2862 | $mem_check = setMemoryLimit('128M'); |
| 2714 | 2863 | |
| 2715 | - if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) |
|
| 2716 | - $package_cache = array(); |
|
| 2717 | - else |
|
| 2718 | - $package_cache = false; |
|
| 2864 | + if (!empty($modSettings['package_disable_cache']) || $mem_check || stripos(PHP_OS, 'win') !== false) { |
|
| 2865 | + $package_cache = array(); |
|
| 2866 | + } else { |
|
| 2867 | + $package_cache = false; |
|
| 2868 | + } |
|
| 2719 | 2869 | } |
| 2720 | 2870 | |
| 2721 | - if (isset($package_ftp)) |
|
| 2722 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2871 | + if (isset($package_ftp)) { |
|
| 2872 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2873 | + } |
|
| 2723 | 2874 | |
| 2724 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2725 | - $package_ftp->create_file($ftp_file); |
|
| 2726 | - elseif (!file_exists($filename)) |
|
| 2727 | - @touch($filename); |
|
| 2875 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2876 | + $package_ftp->create_file($ftp_file); |
|
| 2877 | + } elseif (!file_exists($filename)) { |
|
| 2878 | + @touch($filename); |
|
| 2879 | + } |
|
| 2728 | 2880 | |
| 2729 | 2881 | package_chmod($filename); |
| 2730 | 2882 | |
@@ -2733,22 +2885,23 @@ discard block |
||
| 2733 | 2885 | $fp = @fopen($filename, in_array(substr($filename, -3), $text_filetypes) ? 'w' : 'wb'); |
| 2734 | 2886 | |
| 2735 | 2887 | // We should show an error message or attempt a rollback, no? |
| 2736 | - if (!$fp) |
|
| 2737 | - return false; |
|
| 2888 | + if (!$fp) { |
|
| 2889 | + return false; |
|
| 2890 | + } |
|
| 2738 | 2891 | |
| 2739 | 2892 | fwrite($fp, $data); |
| 2740 | 2893 | fclose($fp); |
| 2741 | - } |
|
| 2742 | - elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) |
|
| 2743 | - return strlen($data); |
|
| 2744 | - else |
|
| 2894 | + } elseif (strpos($filename, 'Packages/') !== false || $package_cache === false) { |
|
| 2895 | + return strlen($data); |
|
| 2896 | + } else |
|
| 2745 | 2897 | { |
| 2746 | 2898 | $package_cache[$filename] = $data; |
| 2747 | 2899 | |
| 2748 | 2900 | // Permission denied, eh? |
| 2749 | 2901 | $fp = @fopen($filename, 'r+'); |
| 2750 | - if (!$fp) |
|
| 2751 | - return false; |
|
| 2902 | + if (!$fp) { |
|
| 2903 | + return false; |
|
| 2904 | + } |
|
| 2752 | 2905 | fclose($fp); |
| 2753 | 2906 | } |
| 2754 | 2907 | |
@@ -2766,19 +2919,22 @@ discard block |
||
| 2766 | 2919 | global $package_ftp, $package_cache; |
| 2767 | 2920 | static $text_filetypes = array('php', 'txt', '.js', 'css', 'vbs', 'tml', 'htm'); |
| 2768 | 2921 | |
| 2769 | - if (empty($package_cache)) |
|
| 2770 | - return; |
|
| 2922 | + if (empty($package_cache)) { |
|
| 2923 | + return; |
|
| 2924 | + } |
|
| 2771 | 2925 | |
| 2772 | 2926 | // First, let's check permissions! |
| 2773 | 2927 | foreach ($package_cache as $filename => $data) |
| 2774 | 2928 | { |
| 2775 | - if (isset($package_ftp)) |
|
| 2776 | - $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2929 | + if (isset($package_ftp)) { |
|
| 2930 | + $ftp_file = strtr($filename, array($_SESSION['pack_ftp']['root'] => '')); |
|
| 2931 | + } |
|
| 2777 | 2932 | |
| 2778 | - if (!file_exists($filename) && isset($package_ftp)) |
|
| 2779 | - $package_ftp->create_file($ftp_file); |
|
| 2780 | - elseif (!file_exists($filename)) |
|
| 2781 | - @touch($filename); |
|
| 2933 | + if (!file_exists($filename) && isset($package_ftp)) { |
|
| 2934 | + $package_ftp->create_file($ftp_file); |
|
| 2935 | + } elseif (!file_exists($filename)) { |
|
| 2936 | + @touch($filename); |
|
| 2937 | + } |
|
| 2782 | 2938 | |
| 2783 | 2939 | $result = package_chmod($filename); |
| 2784 | 2940 | |
@@ -2832,8 +2988,9 @@ discard block |
||
| 2832 | 2988 | /** @var ftp_connection $package_ftp */ |
| 2833 | 2989 | global $package_ftp; |
| 2834 | 2990 | |
| 2835 | - if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') |
|
| 2836 | - return true; |
|
| 2991 | + if (file_exists($filename) && is_writable($filename) && $perm_state == 'writable') { |
|
| 2992 | + return true; |
|
| 2993 | + } |
|
| 2837 | 2994 | |
| 2838 | 2995 | // Start off checking without FTP. |
| 2839 | 2996 | if (!isset($package_ftp) || $package_ftp === false) |
@@ -2855,8 +3012,7 @@ discard block |
||
| 2855 | 3012 | |
| 2856 | 3013 | // Keep track of the writable status here. |
| 2857 | 3014 | $file_permissions = @fileperms($chmod_file); |
| 2858 | - } |
|
| 2859 | - else |
|
| 3015 | + } else |
|
| 2860 | 3016 | { |
| 2861 | 3017 | // This looks odd, but it's an attempt to work around PHP suExec. |
| 2862 | 3018 | if (!file_exists($chmod_file) && $perm_state == 'writable') |
@@ -2866,24 +3022,28 @@ discard block |
||
| 2866 | 3022 | mktree(dirname($chmod_file), 0755); |
| 2867 | 3023 | @touch($chmod_file); |
| 2868 | 3024 | smf_chmod($chmod_file, 0755); |
| 3025 | + } else { |
|
| 3026 | + $file_permissions = @fileperms($chmod_file); |
|
| 2869 | 3027 | } |
| 2870 | - else |
|
| 2871 | - $file_permissions = @fileperms($chmod_file); |
|
| 2872 | 3028 | } |
| 2873 | 3029 | |
| 2874 | 3030 | // This looks odd, but it's another attempt to work around PHP suExec. |
| 2875 | - if ($perm_state != 'writable') |
|
| 2876 | - smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 2877 | - else |
|
| 3031 | + if ($perm_state != 'writable') { |
|
| 3032 | + smf_chmod($chmod_file, $perm_state == 'execute' ? 0755 : 0644); |
|
| 3033 | + } else |
|
| 2878 | 3034 | { |
| 2879 | - if (!@is_writable($chmod_file)) |
|
| 2880 | - smf_chmod($chmod_file, 0755); |
|
| 2881 | - if (!@is_writable($chmod_file)) |
|
| 2882 | - smf_chmod($chmod_file, 0777); |
|
| 2883 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2884 | - smf_chmod($chmod_file, 0755); |
|
| 2885 | - if (!@is_writable(dirname($chmod_file))) |
|
| 2886 | - smf_chmod($chmod_file, 0777); |
|
| 3035 | + if (!@is_writable($chmod_file)) { |
|
| 3036 | + smf_chmod($chmod_file, 0755); |
|
| 3037 | + } |
|
| 3038 | + if (!@is_writable($chmod_file)) { |
|
| 3039 | + smf_chmod($chmod_file, 0777); |
|
| 3040 | + } |
|
| 3041 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3042 | + smf_chmod($chmod_file, 0755); |
|
| 3043 | + } |
|
| 3044 | + if (!@is_writable(dirname($chmod_file))) { |
|
| 3045 | + smf_chmod($chmod_file, 0777); |
|
| 3046 | + } |
|
| 2887 | 3047 | } |
| 2888 | 3048 | |
| 2889 | 3049 | // The ultimate writable test. |
@@ -2892,20 +3052,22 @@ discard block |
||
| 2892 | 3052 | $fp = is_dir($chmod_file) ? @opendir($chmod_file) : @fopen($chmod_file, 'rb'); |
| 2893 | 3053 | if (@is_writable($chmod_file) && $fp) |
| 2894 | 3054 | { |
| 2895 | - if (!is_dir($chmod_file)) |
|
| 2896 | - fclose($fp); |
|
| 2897 | - else |
|
| 2898 | - closedir($fp); |
|
| 3055 | + if (!is_dir($chmod_file)) { |
|
| 3056 | + fclose($fp); |
|
| 3057 | + } else { |
|
| 3058 | + closedir($fp); |
|
| 3059 | + } |
|
| 2899 | 3060 | |
| 2900 | 3061 | // It worked! |
| 2901 | - if ($track_change) |
|
| 2902 | - $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3062 | + if ($track_change) { |
|
| 3063 | + $_SESSION['pack_ftp']['original_perms'][$chmod_file] = $file_permissions; |
|
| 3064 | + } |
|
| 2903 | 3065 | |
| 2904 | 3066 | return true; |
| 2905 | 3067 | } |
| 3068 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) { |
|
| 3069 | + unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2906 | 3070 | } |
| 2907 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$chmod_file])) |
|
| 2908 | - unset($_SESSION['pack_ftp']['original_perms'][$chmod_file]); |
|
| 2909 | 3071 | } |
| 2910 | 3072 | |
| 2911 | 3073 | // If we're here we're a failure. |
@@ -2924,31 +3086,33 @@ discard block |
||
| 2924 | 3086 | mktree(dirname($filename), 0755); |
| 2925 | 3087 | $package_ftp->create_file($ftp_file); |
| 2926 | 3088 | $package_ftp->chmod($ftp_file, 0755); |
| 3089 | + } else { |
|
| 3090 | + $file_permissions = @fileperms($filename); |
|
| 2927 | 3091 | } |
| 2928 | - else |
|
| 2929 | - $file_permissions = @fileperms($filename); |
|
| 2930 | 3092 | |
| 2931 | 3093 | if ($perm_state != 'writable') |
| 2932 | 3094 | { |
| 2933 | 3095 | $package_ftp->chmod($ftp_file, $perm_state == 'execute' ? 0755 : 0644); |
| 2934 | - } |
|
| 2935 | - else |
|
| 3096 | + } else |
|
| 2936 | 3097 | { |
| 2937 | - if (!@is_writable($filename)) |
|
| 2938 | - $package_ftp->chmod($ftp_file, 0777); |
|
| 2939 | - if (!@is_writable(dirname($filename))) |
|
| 2940 | - $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3098 | + if (!@is_writable($filename)) { |
|
| 3099 | + $package_ftp->chmod($ftp_file, 0777); |
|
| 3100 | + } |
|
| 3101 | + if (!@is_writable(dirname($filename))) { |
|
| 3102 | + $package_ftp->chmod(dirname($ftp_file), 0777); |
|
| 3103 | + } |
|
| 2941 | 3104 | } |
| 2942 | 3105 | |
| 2943 | 3106 | if (@is_writable($filename)) |
| 2944 | 3107 | { |
| 2945 | - if ($track_change) |
|
| 2946 | - $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3108 | + if ($track_change) { |
|
| 3109 | + $_SESSION['pack_ftp']['original_perms'][$filename] = $file_permissions; |
|
| 3110 | + } |
|
| 2947 | 3111 | |
| 2948 | 3112 | return true; |
| 3113 | + } elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) { |
|
| 3114 | + unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2949 | 3115 | } |
| 2950 | - elseif ($perm_state != 'writable' && isset($_SESSION['pack_ftp']['original_perms'][$filename])) |
|
| 2951 | - unset($_SESSION['pack_ftp']['original_perms'][$filename]); |
|
| 2952 | 3116 | } |
| 2953 | 3117 | |
| 2954 | 3118 | // Oh dear, we failed if we get here. |
@@ -2966,11 +3130,13 @@ discard block |
||
| 2966 | 3130 | $n = strlen($pass); |
| 2967 | 3131 | |
| 2968 | 3132 | $salt = session_id(); |
| 2969 | - while (strlen($salt) < $n) |
|
| 2970 | - $salt .= session_id(); |
|
| 3133 | + while (strlen($salt) < $n) { |
|
| 3134 | + $salt .= session_id(); |
|
| 3135 | + } |
|
| 2971 | 3136 | |
| 2972 | - for ($i = 0; $i < $n; $i++) |
|
| 2973 | - $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3137 | + for ($i = 0; $i < $n; $i++) { |
|
| 3138 | + $pass{$i} = chr(ord($pass{$i}) ^ (ord($salt{$i}) - 32)); |
|
| 3139 | + } |
|
| 2974 | 3140 | |
| 2975 | 3141 | return $pass; |
| 2976 | 3142 | } |
@@ -2989,8 +3155,9 @@ discard block |
||
| 2989 | 3155 | $base_files = array('index.php', 'SSI.php', 'agreement.txt', 'cron.php', 'ssi_examples.php', 'ssi_examples.shtml', 'subscriptions.php'); |
| 2990 | 3156 | foreach ($base_files as $file) |
| 2991 | 3157 | { |
| 2992 | - if (file_exists($boarddir . '/' . $file)) |
|
| 2993 | - $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3158 | + if (file_exists($boarddir . '/' . $file)) { |
|
| 3159 | + $files[empty($_REQUEST['use_full_paths']) ? $file : $boarddir . '/' . $file] = $boarddir . '/' . $file; |
|
| 3160 | + } |
|
| 2994 | 3161 | } |
| 2995 | 3162 | |
| 2996 | 3163 | $dirs = array( |
@@ -3007,8 +3174,9 @@ discard block |
||
| 3007 | 3174 | 'theme_dir' => 'theme_dir', |
| 3008 | 3175 | ) |
| 3009 | 3176 | ); |
| 3010 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3011 | - $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3178 | + $dirs[$row['value']] = empty($_REQUEST['use_full_paths']) ? 'Themes/' . basename($row['value']) . '/' : strtr($row['value'] . '/', '\\', '/'); |
|
| 3179 | + } |
|
| 3012 | 3180 | $smcFunc['db_free_result']($request); |
| 3013 | 3181 | |
| 3014 | 3182 | try |
@@ -3023,11 +3191,13 @@ discard block |
||
| 3023 | 3191 | |
| 3024 | 3192 | foreach ($iter as $entry => $dir) |
| 3025 | 3193 | { |
| 3026 | - if ($dir->isDir()) |
|
| 3027 | - continue; |
|
| 3194 | + if ($dir->isDir()) { |
|
| 3195 | + continue; |
|
| 3196 | + } |
|
| 3028 | 3197 | |
| 3029 | - if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) |
|
| 3030 | - continue; |
|
| 3198 | + if (preg_match('~^(\.{1,2}|CVS|backup.*|help|images|.*\~)$~', $entry) != 0) { |
|
| 3199 | + continue; |
|
| 3200 | + } |
|
| 3031 | 3201 | |
| 3032 | 3202 | $files[empty($_REQUEST['use_full_paths']) ? str_replace(realpath($boarddir), '', $entry) : $entry] = $entry; |
| 3033 | 3203 | } |
@@ -3035,26 +3205,30 @@ discard block |
||
| 3035 | 3205 | $obj = new ArrayObject($files); |
| 3036 | 3206 | $iterator = $obj->getIterator(); |
| 3037 | 3207 | |
| 3038 | - if (!file_exists($packagesdir . '/backups')) |
|
| 3039 | - mktree($packagesdir . '/backups', 0777); |
|
| 3040 | - if (!is_writable($packagesdir . '/backups')) |
|
| 3041 | - package_chmod($packagesdir . '/backups'); |
|
| 3208 | + if (!file_exists($packagesdir . '/backups')) { |
|
| 3209 | + mktree($packagesdir . '/backups', 0777); |
|
| 3210 | + } |
|
| 3211 | + if (!is_writable($packagesdir . '/backups')) { |
|
| 3212 | + package_chmod($packagesdir . '/backups'); |
|
| 3213 | + } |
|
| 3042 | 3214 | $output_file = $packagesdir . '/backups/' . strftime('%Y-%m-%d_') . preg_replace('~[$\\\\/:<>|?*"\']~', '', $id); |
| 3043 | 3215 | $output_ext = '.tar'; |
| 3044 | 3216 | |
| 3045 | 3217 | if (file_exists($output_file . $output_ext)) |
| 3046 | 3218 | { |
| 3047 | 3219 | $i = 2; |
| 3048 | - while (file_exists($output_file . '_' . $i . $output_ext)) |
|
| 3049 | - $i++; |
|
| 3220 | + while (file_exists($output_file . '_' . $i . $output_ext)) { |
|
| 3221 | + $i++; |
|
| 3222 | + } |
|
| 3050 | 3223 | $output_file = $output_file . '_' . $i . $output_ext; |
| 3224 | + } else { |
|
| 3225 | + $output_file .= $output_ext; |
|
| 3051 | 3226 | } |
| 3052 | - else |
|
| 3053 | - $output_file .= $output_ext; |
|
| 3054 | 3227 | |
| 3055 | 3228 | @set_time_limit(300); |
| 3056 | - if (function_exists('apache_reset_timeout')) |
|
| 3057 | - @apache_reset_timeout(); |
|
| 3229 | + if (function_exists('apache_reset_timeout')) { |
|
| 3230 | + @apache_reset_timeout(); |
|
| 3231 | + } |
|
| 3058 | 3232 | |
| 3059 | 3233 | $a = new PharData($output_file); |
| 3060 | 3234 | $a->buildFromIterator($iterator); |
@@ -3066,8 +3240,7 @@ discard block |
||
| 3066 | 3240 | */ |
| 3067 | 3241 | unset($a); |
| 3068 | 3242 | unlink($output_file); |
| 3069 | - } |
|
| 3070 | - catch (Exception $e) |
|
| 3243 | + } catch (Exception $e) |
|
| 3071 | 3244 | { |
| 3072 | 3245 | log_error($e->getMessage(), 'backup'); |
| 3073 | 3246 | |
@@ -3099,32 +3272,35 @@ discard block |
||
| 3099 | 3272 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
| 3100 | 3273 | |
| 3101 | 3274 | // An FTP url. We should try connecting and RETRieving it... |
| 3102 | - if (empty($match[1])) |
|
| 3103 | - return false; |
|
| 3104 | - elseif ($match[1] == 'ftp') |
|
| 3275 | + if (empty($match[1])) { |
|
| 3276 | + return false; |
|
| 3277 | + } elseif ($match[1] == 'ftp') |
|
| 3105 | 3278 | { |
| 3106 | 3279 | // Include the file containing the ftp_connection class. |
| 3107 | 3280 | require_once($sourcedir . '/Class-Package.php'); |
| 3108 | 3281 | |
| 3109 | 3282 | // Establish a connection and attempt to enable passive mode. |
| 3110 | 3283 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
| 3111 | - if ($ftp->error !== false || !$ftp->passive()) |
|
| 3112 | - return false; |
|
| 3284 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
| 3285 | + return false; |
|
| 3286 | + } |
|
| 3113 | 3287 | |
| 3114 | 3288 | // I want that one *points*! |
| 3115 | 3289 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
| 3116 | 3290 | |
| 3117 | 3291 | // Since passive mode worked (or we would have returned already!) open the connection. |
| 3118 | 3292 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
| 3119 | - if (!$fp) |
|
| 3120 | - return false; |
|
| 3293 | + if (!$fp) { |
|
| 3294 | + return false; |
|
| 3295 | + } |
|
| 3121 | 3296 | |
| 3122 | 3297 | // The server should now say something in acknowledgement. |
| 3123 | 3298 | $ftp->check_response(150); |
| 3124 | 3299 | |
| 3125 | 3300 | $data = ''; |
| 3126 | - while (!feof($fp)) |
|
| 3127 | - $data .= fread($fp, 4096); |
|
| 3301 | + while (!feof($fp)) { |
|
| 3302 | + $data .= fread($fp, 4096); |
|
| 3303 | + } |
|
| 3128 | 3304 | fclose($fp); |
| 3129 | 3305 | |
| 3130 | 3306 | // All done, right? Good. |
@@ -3141,22 +3317,25 @@ discard block |
||
| 3141 | 3317 | $fetch_data->get_url_data($url, $post_data); |
| 3142 | 3318 | |
| 3143 | 3319 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
| 3144 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
| 3145 | - $data = $fetch_data->result('body'); |
|
| 3146 | - else |
|
| 3147 | - return false; |
|
| 3320 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
| 3321 | + $data = $fetch_data->result('body'); |
|
| 3322 | + } else { |
|
| 3323 | + return false; |
|
| 3324 | + } |
|
| 3148 | 3325 | } |
| 3149 | 3326 | // This is more likely; a standard HTTP URL. |
| 3150 | 3327 | elseif (isset($match[1]) && $match[1] == 'http') |
| 3151 | 3328 | { |
| 3152 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
| 3153 | - $fp = $keep_alive_fp; |
|
| 3329 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
| 3330 | + $fp = $keep_alive_fp; |
|
| 3331 | + } |
|
| 3154 | 3332 | if (empty($fp)) |
| 3155 | 3333 | { |
| 3156 | 3334 | // Open the socket on the port we want... |
| 3157 | 3335 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
| 3158 | - if (!$fp) |
|
| 3159 | - return false; |
|
| 3336 | + if (!$fp) { |
|
| 3337 | + return false; |
|
| 3338 | + } |
|
| 3160 | 3339 | } |
| 3161 | 3340 | |
| 3162 | 3341 | if ($keep_alive) |
@@ -3171,20 +3350,21 @@ discard block |
||
| 3171 | 3350 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
| 3172 | 3351 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3173 | 3352 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3174 | - if ($keep_alive) |
|
| 3175 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3176 | - else |
|
| 3177 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3178 | - } |
|
| 3179 | - else |
|
| 3353 | + if ($keep_alive) { |
|
| 3354 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
| 3355 | + } else { |
|
| 3356 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
| 3357 | + } |
|
| 3358 | + } else |
|
| 3180 | 3359 | { |
| 3181 | 3360 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
| 3182 | 3361 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
| 3183 | 3362 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
| 3184 | - if ($keep_alive) |
|
| 3185 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3186 | - else |
|
| 3187 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3363 | + if ($keep_alive) { |
|
| 3364 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
| 3365 | + } else { |
|
| 3366 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
| 3367 | + } |
|
| 3188 | 3368 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
| 3189 | 3369 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
| 3190 | 3370 | fwrite($fp, $post_data); |
@@ -3197,30 +3377,33 @@ discard block |
||
| 3197 | 3377 | { |
| 3198 | 3378 | $header = ''; |
| 3199 | 3379 | $location = ''; |
| 3200 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
| 3201 | - if (strpos($header, 'Location:') !== false) |
|
| 3380 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
| 3381 | + if (strpos($header, 'Location:') !== false) |
|
| 3202 | 3382 | $location = trim(substr($header, strpos($header, ':') + 1)); |
| 3383 | + } |
|
| 3203 | 3384 | |
| 3204 | - if (empty($location)) |
|
| 3205 | - return false; |
|
| 3206 | - else |
|
| 3385 | + if (empty($location)) { |
|
| 3386 | + return false; |
|
| 3387 | + } else |
|
| 3207 | 3388 | { |
| 3208 | - if (!$keep_alive) |
|
| 3209 | - fclose($fp); |
|
| 3389 | + if (!$keep_alive) { |
|
| 3390 | + fclose($fp); |
|
| 3391 | + } |
|
| 3210 | 3392 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
| 3211 | 3393 | } |
| 3212 | 3394 | } |
| 3213 | 3395 | |
| 3214 | 3396 | // Make sure we get a 200 OK. |
| 3215 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
| 3216 | - return false; |
|
| 3397 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
| 3398 | + return false; |
|
| 3399 | + } |
|
| 3217 | 3400 | |
| 3218 | 3401 | // Skip the headers... |
| 3219 | 3402 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
| 3220 | 3403 | { |
| 3221 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
| 3222 | - $content_length = $match[1]; |
|
| 3223 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3404 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
| 3405 | + $content_length = $match[1]; |
|
| 3406 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
| 3224 | 3407 | { |
| 3225 | 3408 | $keep_alive_dom = null; |
| 3226 | 3409 | $keep_alive = false; |
@@ -3232,19 +3415,20 @@ discard block |
||
| 3232 | 3415 | $data = ''; |
| 3233 | 3416 | if (isset($content_length)) |
| 3234 | 3417 | { |
| 3235 | - while (!feof($fp) && strlen($data) < $content_length) |
|
| 3236 | - $data .= fread($fp, $content_length - strlen($data)); |
|
| 3237 | - } |
|
| 3238 | - else |
|
| 3418 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
| 3419 | + $data .= fread($fp, $content_length - strlen($data)); |
|
| 3420 | + } |
|
| 3421 | + } else |
|
| 3239 | 3422 | { |
| 3240 | - while (!feof($fp)) |
|
| 3241 | - $data .= fread($fp, 4096); |
|
| 3423 | + while (!feof($fp)) { |
|
| 3424 | + $data .= fread($fp, 4096); |
|
| 3425 | + } |
|
| 3242 | 3426 | } |
| 3243 | 3427 | |
| 3244 | - if (!$keep_alive) |
|
| 3245 | - fclose($fp); |
|
| 3246 | - } |
|
| 3247 | - else |
|
| 3428 | + if (!$keep_alive) { |
|
| 3429 | + fclose($fp); |
|
| 3430 | + } |
|
| 3431 | + } else |
|
| 3248 | 3432 | { |
| 3249 | 3433 | // Umm, this shouldn't happen? |
| 3250 | 3434 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -15,8 +15,9 @@ discard block |
||
| 15 | 15 | * @version 2.1 Beta 3 |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | -if (!defined('SMF')) |
|
| 18 | +if (!defined('SMF')) { |
|
| 19 | 19 | die('No direct access...'); |
| 20 | +} |
|
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * This defines every profile field known to man. |
@@ -29,8 +30,9 @@ discard block |
||
| 29 | 30 | global $sourcedir, $profile_vars; |
| 30 | 31 | |
| 31 | 32 | // Don't load this twice! |
| 32 | - if (!empty($profile_fields) && !$force_reload) |
|
| 33 | - return; |
|
| 33 | + if (!empty($profile_fields) && !$force_reload) { |
|
| 34 | + return; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | /* This horrific array defines all the profile fields in the whole world! |
| 36 | 38 | In general each "field" has one array - the key of which is the database column name associated with said field. Each item |
@@ -103,13 +105,14 @@ discard block |
||
| 103 | 105 | if (isset($_POST['bday2'], $_POST['bday3']) && $value > 0 && $_POST['bday2'] > 0) |
| 104 | 106 | { |
| 105 | 107 | // Set to blank? |
| 106 | - if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) |
|
| 107 | - $value = '0001-01-01'; |
|
| 108 | - else |
|
| 109 | - $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01'; |
|
| 108 | + if ((int) $_POST['bday3'] == 1 && (int) $_POST['bday2'] == 1 && (int) $value == 1) { |
|
| 109 | + $value = '0001-01-01'; |
|
| 110 | + } else { |
|
| 111 | + $value = checkdate($value, $_POST['bday2'], $_POST['bday3'] < 4 ? 4 : $_POST['bday3']) ? sprintf('%04d-%02d-%02d', $_POST['bday3'] < 4 ? 4 : $_POST['bday3'], $_POST['bday1'], $_POST['bday2']) : '0001-01-01'; |
|
| 112 | + } |
|
| 113 | + } else { |
|
| 114 | + $value = '0001-01-01'; |
|
| 110 | 115 | } |
| 111 | - else |
|
| 112 | - $value = '0001-01-01'; |
|
| 113 | 116 | |
| 114 | 117 | $profile_vars['birthdate'] = $value; |
| 115 | 118 | $cur_profile['birthdate'] = $value; |
@@ -127,8 +130,7 @@ discard block |
||
| 127 | 130 | { |
| 128 | 131 | $value = checkdate($dates[2], $dates[3], $dates[1] < 4 ? 4 : $dates[1]) ? sprintf('%04d-%02d-%02d', $dates[1] < 4 ? 4 : $dates[1], $dates[2], $dates[3]) : '0001-01-01'; |
| 129 | 132 | return true; |
| 130 | - } |
|
| 131 | - else |
|
| 133 | + } else |
|
| 132 | 134 | { |
| 133 | 135 | $value = empty($cur_profile['birthdate']) ? '0001-01-01' : $cur_profile['birthdate']; |
| 134 | 136 | return false; |
@@ -150,10 +152,11 @@ discard block |
||
| 150 | 152 | return $txt['invalid_registration'] . ' ' . strftime('%d %b %Y ' . (strpos($user_info['time_format'], '%H') !== false ? '%I:%M:%S %p' : '%H:%M:%S'), forum_time(false)); |
| 151 | 153 | } |
| 152 | 154 | // As long as it doesn't equal "N/A"... |
| 153 | - elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) |
|
| 154 | - $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 155 | - else |
|
| 156 | - $value = $cur_profile['date_registered']; |
|
| 155 | + elseif ($value != $txt['not_applicable'] && $value != strtotime(strftime('%Y-%m-%d', $cur_profile['date_registered'] + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600))) { |
|
| 156 | + $value = $value - ($user_info['time_offset'] + $modSettings['time_offset']) * 3600; |
|
| 157 | + } else { |
|
| 158 | + $value = $cur_profile['date_registered']; |
|
| 159 | + } |
|
| 157 | 160 | |
| 158 | 161 | return true; |
| 159 | 162 | }, |
@@ -177,8 +180,9 @@ discard block |
||
| 177 | 180 | { |
| 178 | 181 | global $context, $old_profile, $profile_vars, $sourcedir, $modSettings; |
| 179 | 182 | |
| 180 | - if (strtolower($value) == strtolower($old_profile['email_address'])) |
|
| 181 | - return false; |
|
| 183 | + if (strtolower($value) == strtolower($old_profile['email_address'])) { |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 182 | 186 | |
| 183 | 187 | $isValid = profileValidateEmail($value, $context['id_member']); |
| 184 | 188 | |
@@ -254,11 +258,11 @@ discard block |
||
| 254 | 258 | |
| 255 | 259 | if (isset($context['profile_languages'][$value])) |
| 256 | 260 | { |
| 257 | - if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) |
|
| 258 | - $_SESSION['language'] = $value; |
|
| 261 | + if ($context['user']['is_owner'] && empty($context['password_auth_failed'])) { |
|
| 262 | + $_SESSION['language'] = $value; |
|
| 263 | + } |
|
| 259 | 264 | return true; |
| 260 | - } |
|
| 261 | - else |
|
| 265 | + } else |
|
| 262 | 266 | { |
| 263 | 267 | $value = $cur_profile['lngfile']; |
| 264 | 268 | return false; |
@@ -282,13 +286,14 @@ discard block |
||
| 282 | 286 | |
| 283 | 287 | // Maybe they are trying to change their password as well? |
| 284 | 288 | $resetPassword = true; |
| 285 | - if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) |
|
| 286 | - $resetPassword = false; |
|
| 289 | + if (isset($_POST['passwrd1']) && $_POST['passwrd1'] != '' && isset($_POST['passwrd2']) && $_POST['passwrd1'] == $_POST['passwrd2'] && validatePassword($_POST['passwrd1'], $value, array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])) == null) { |
|
| 290 | + $resetPassword = false; |
|
| 291 | + } |
|
| 287 | 292 | |
| 288 | 293 | // Do the reset... this will send them an email too. |
| 289 | - if ($resetPassword) |
|
| 290 | - resetPassword($context['id_member'], $value); |
|
| 291 | - elseif ($value !== null) |
|
| 294 | + if ($resetPassword) { |
|
| 295 | + resetPassword($context['id_member'], $value); |
|
| 296 | + } elseif ($value !== null) |
|
| 292 | 297 | { |
| 293 | 298 | validateUsername($context['id_member'], trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value))); |
| 294 | 299 | updateMemberData($context['id_member'], array('member_name' => $value)); |
@@ -312,20 +317,23 @@ discard block |
||
| 312 | 317 | 'input_validate' => function(&$value) use ($sourcedir, $user_info, $smcFunc, $cur_profile) |
| 313 | 318 | { |
| 314 | 319 | // If we didn't try it then ignore it! |
| 315 | - if ($value == '') |
|
| 316 | - return false; |
|
| 320 | + if ($value == '') { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 317 | 323 | |
| 318 | 324 | // Do the two entries for the password even match? |
| 319 | - if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) |
|
| 320 | - return 'bad_new_password'; |
|
| 325 | + if (!isset($_POST['passwrd2']) || $value != $_POST['passwrd2']) { |
|
| 326 | + return 'bad_new_password'; |
|
| 327 | + } |
|
| 321 | 328 | |
| 322 | 329 | // Let's get the validation function into play... |
| 323 | 330 | require_once($sourcedir . '/Subs-Auth.php'); |
| 324 | 331 | $passwordErrors = validatePassword($value, $cur_profile['member_name'], array($cur_profile['real_name'], $user_info['username'], $user_info['name'], $user_info['email'])); |
| 325 | 332 | |
| 326 | 333 | // Were there errors? |
| 327 | - if ($passwordErrors != null) |
|
| 328 | - return 'password_' . $passwordErrors; |
|
| 334 | + if ($passwordErrors != null) { |
|
| 335 | + return 'password_' . $passwordErrors; |
|
| 336 | + } |
|
| 329 | 337 | |
| 330 | 338 | // Set up the new password variable... ready for storage. |
| 331 | 339 | $value = hash_password($cur_profile['member_name'], un_htmlspecialchars($value)); |
@@ -350,8 +358,9 @@ discard block |
||
| 350 | 358 | 'permission' => 'profile_blurb', |
| 351 | 359 | 'input_validate' => function(&$value) use ($smcFunc) |
| 352 | 360 | { |
| 353 | - if ($smcFunc['strlen']($value) > 50) |
|
| 354 | - return 'personal_text_too_long'; |
|
| 361 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 362 | + return 'personal_text_too_long'; |
|
| 363 | + } |
|
| 355 | 364 | |
| 356 | 365 | return true; |
| 357 | 366 | }, |
@@ -386,10 +395,11 @@ discard block |
||
| 386 | 395 | 'permission' => 'moderate_forum', |
| 387 | 396 | 'input_validate' => function(&$value) |
| 388 | 397 | { |
| 389 | - if (!is_numeric($value)) |
|
| 390 | - return 'digits_only'; |
|
| 391 | - else |
|
| 392 | - $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 398 | + if (!is_numeric($value)) { |
|
| 399 | + return 'digits_only'; |
|
| 400 | + } else { |
|
| 401 | + $value = $value != '' ? strtr($value, array(',' => '', '.' => '', ' ' => '')) : 0; |
|
| 402 | + } |
|
| 393 | 403 | return true; |
| 394 | 404 | }, |
| 395 | 405 | ), |
@@ -405,15 +415,16 @@ discard block |
||
| 405 | 415 | { |
| 406 | 416 | $value = trim(preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $value)); |
| 407 | 417 | |
| 408 | - if (trim($value) == '') |
|
| 409 | - return 'no_name'; |
|
| 410 | - elseif ($smcFunc['strlen']($value) > 60) |
|
| 411 | - return 'name_too_long'; |
|
| 412 | - elseif ($cur_profile['real_name'] != $value) |
|
| 418 | + if (trim($value) == '') { |
|
| 419 | + return 'no_name'; |
|
| 420 | + } elseif ($smcFunc['strlen']($value) > 60) { |
|
| 421 | + return 'name_too_long'; |
|
| 422 | + } elseif ($cur_profile['real_name'] != $value) |
|
| 413 | 423 | { |
| 414 | 424 | require_once($sourcedir . '/Subs-Members.php'); |
| 415 | - if (isReservedName($value, $context['id_member'])) |
|
| 416 | - return 'name_taken'; |
|
| 425 | + if (isReservedName($value, $context['id_member'])) { |
|
| 426 | + return 'name_taken'; |
|
| 427 | + } |
|
| 417 | 428 | } |
| 418 | 429 | return true; |
| 419 | 430 | }, |
@@ -471,8 +482,9 @@ discard block |
||
| 471 | 482 | 'selected' => $set == $context['member']['smiley_set']['id'] |
| 472 | 483 | ); |
| 473 | 484 | |
| 474 | - if ($context['smiley_sets'][$i]['selected']) |
|
| 475 | - $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 485 | + if ($context['smiley_sets'][$i]['selected']) { |
|
| 486 | + $context['member']['smiley_set']['name'] = $set_names[$i]; |
|
| 487 | + } |
|
| 476 | 488 | } |
| 477 | 489 | return true; |
| 478 | 490 | }, |
@@ -481,8 +493,9 @@ discard block |
||
| 481 | 493 | global $modSettings; |
| 482 | 494 | |
| 483 | 495 | $smiley_sets = explode(',', $modSettings['smiley_sets_known']); |
| 484 | - if (!in_array($value, $smiley_sets) && $value != 'none') |
|
| 485 | - $value = ''; |
|
| 496 | + if (!in_array($value, $smiley_sets) && $value != 'none') { |
|
| 497 | + $value = ''; |
|
| 498 | + } |
|
| 486 | 499 | return true; |
| 487 | 500 | }, |
| 488 | 501 | ), |
@@ -497,8 +510,9 @@ discard block |
||
| 497 | 510 | loadLanguage('Settings'); |
| 498 | 511 | |
| 499 | 512 | $context['allow_no_censored'] = false; |
| 500 | - if ($user_info['is_admin'] || $context['user']['is_owner']) |
|
| 501 | - $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 513 | + if ($user_info['is_admin'] || $context['user']['is_owner']) { |
|
| 514 | + $context['allow_no_censored'] = !empty($modSettings['allow_no_censored']); |
|
| 515 | + } |
|
| 502 | 516 | |
| 503 | 517 | return true; |
| 504 | 518 | }, |
@@ -545,8 +559,9 @@ discard block |
||
| 545 | 559 | 'input_validate' => function($value) |
| 546 | 560 | { |
| 547 | 561 | $tz = smf_list_timezones(); |
| 548 | - if (!isset($tz[$value])) |
|
| 549 | - return 'bad_timezone'; |
|
| 562 | + if (!isset($tz[$value])) { |
|
| 563 | + return 'bad_timezone'; |
|
| 564 | + } |
|
| 550 | 565 | |
| 551 | 566 | return true; |
| 552 | 567 | }, |
@@ -561,8 +576,9 @@ discard block |
||
| 561 | 576 | 'enabled' => !empty($modSettings['titlesEnable']), |
| 562 | 577 | 'input_validate' => function(&$value) use ($smcFunc) |
| 563 | 578 | { |
| 564 | - if ($smcFunc['strlen']($value) > 50) |
|
| 565 | - return 'user_title_too_long'; |
|
| 579 | + if ($smcFunc['strlen']($value) > 50) { |
|
| 580 | + return 'user_title_too_long'; |
|
| 581 | + } |
|
| 566 | 582 | |
| 567 | 583 | return true; |
| 568 | 584 | }, |
@@ -584,10 +600,12 @@ discard block |
||
| 584 | 600 | // Fix the URL... |
| 585 | 601 | 'input_validate' => function(&$value) |
| 586 | 602 | { |
| 587 | - if (strlen(trim($value)) > 0 && strpos($value, '://') === false) |
|
| 588 | - $value = 'http://' . $value; |
|
| 589 | - if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) |
|
| 590 | - $value = ''; |
|
| 603 | + if (strlen(trim($value)) > 0 && strpos($value, '://') === false) { |
|
| 604 | + $value = 'http://' . $value; |
|
| 605 | + } |
|
| 606 | + if (strlen($value) < 8 || (substr($value, 0, 7) !== 'http://' && substr($value, 0, 8) !== 'https://')) { |
|
| 607 | + $value = ''; |
|
| 608 | + } |
|
| 591 | 609 | return true; |
| 592 | 610 | }, |
| 593 | 611 | 'link_with' => 'website', |
@@ -601,16 +619,19 @@ discard block |
||
| 601 | 619 | foreach ($profile_fields as $key => $field) |
| 602 | 620 | { |
| 603 | 621 | // Do we have permission to do this? |
| 604 | - if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) |
|
| 605 | - unset($profile_fields[$key]); |
|
| 622 | + if (isset($field['permission']) && !allowedTo(($context['user']['is_owner'] ? array($field['permission'] . '_own', $field['permission'] . '_any') : $field['permission'] . '_any')) && !allowedTo($field['permission'])) { |
|
| 623 | + unset($profile_fields[$key]); |
|
| 624 | + } |
|
| 606 | 625 | |
| 607 | 626 | // Is it enabled? |
| 608 | - if (isset($field['enabled']) && !$field['enabled']) |
|
| 609 | - unset($profile_fields[$key]); |
|
| 627 | + if (isset($field['enabled']) && !$field['enabled']) { |
|
| 628 | + unset($profile_fields[$key]); |
|
| 629 | + } |
|
| 610 | 630 | |
| 611 | 631 | // Is it specifically disabled? |
| 612 | - if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) |
|
| 613 | - unset($profile_fields[$key]); |
|
| 632 | + if (in_array($key, $disabled_fields) || (isset($field['link_with']) && in_array($field['link_with'], $disabled_fields))) { |
|
| 633 | + unset($profile_fields[$key]); |
|
| 634 | + } |
|
| 614 | 635 | } |
| 615 | 636 | } |
| 616 | 637 | |
@@ -635,9 +656,10 @@ discard block |
||
| 635 | 656 | loadProfileFields(true); |
| 636 | 657 | |
| 637 | 658 | // First check for any linked sets. |
| 638 | - foreach ($profile_fields as $key => $field) |
|
| 639 | - if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 659 | + foreach ($profile_fields as $key => $field) { |
|
| 660 | + if (isset($field['link_with']) && in_array($field['link_with'], $fields)) |
|
| 640 | 661 | $fields[] = $key; |
| 662 | + } |
|
| 641 | 663 | |
| 642 | 664 | $i = 0; |
| 643 | 665 | $last_type = ''; |
@@ -649,38 +671,46 @@ discard block |
||
| 649 | 671 | $cur_field = &$profile_fields[$field]; |
| 650 | 672 | |
| 651 | 673 | // Does it have a preload and does that preload succeed? |
| 652 | - if (isset($cur_field['preload']) && !$cur_field['preload']()) |
|
| 653 | - continue; |
|
| 674 | + if (isset($cur_field['preload']) && !$cur_field['preload']()) { |
|
| 675 | + continue; |
|
| 676 | + } |
|
| 654 | 677 | |
| 655 | 678 | // If this is anything but complex we need to do more cleaning! |
| 656 | 679 | if ($cur_field['type'] != 'callback' && $cur_field['type'] != 'hidden') |
| 657 | 680 | { |
| 658 | - if (!isset($cur_field['label'])) |
|
| 659 | - $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 681 | + if (!isset($cur_field['label'])) { |
|
| 682 | + $cur_field['label'] = isset($txt[$field]) ? $txt[$field] : $field; |
|
| 683 | + } |
|
| 660 | 684 | |
| 661 | 685 | // Everything has a value! |
| 662 | - if (!isset($cur_field['value'])) |
|
| 663 | - $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 686 | + if (!isset($cur_field['value'])) { |
|
| 687 | + $cur_field['value'] = isset($cur_profile[$field]) ? $cur_profile[$field] : ''; |
|
| 688 | + } |
|
| 664 | 689 | |
| 665 | 690 | // Any input attributes? |
| 666 | 691 | $cur_field['input_attr'] = !empty($cur_field['input_attr']) ? implode(',', $cur_field['input_attr']) : ''; |
| 667 | 692 | } |
| 668 | 693 | |
| 669 | 694 | // Was there an error with this field on posting? |
| 670 | - if (isset($context['profile_errors'][$field])) |
|
| 671 | - $cur_field['is_error'] = true; |
|
| 695 | + if (isset($context['profile_errors'][$field])) { |
|
| 696 | + $cur_field['is_error'] = true; |
|
| 697 | + } |
|
| 672 | 698 | |
| 673 | 699 | // Any javascript stuff? |
| 674 | - if (!empty($cur_field['js_submit'])) |
|
| 675 | - $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 676 | - if (!empty($cur_field['js'])) |
|
| 677 | - $context['profile_javascript'] .= $cur_field['js']; |
|
| 700 | + if (!empty($cur_field['js_submit'])) { |
|
| 701 | + $context['profile_onsubmit_javascript'] .= $cur_field['js_submit']; |
|
| 702 | + } |
|
| 703 | + if (!empty($cur_field['js'])) { |
|
| 704 | + $context['profile_javascript'] .= $cur_field['js']; |
|
| 705 | + } |
|
| 678 | 706 | |
| 679 | 707 | // Any template stuff? |
| 680 | - if (!empty($cur_field['prehtml'])) |
|
| 681 | - $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 682 | - if (!empty($cur_field['posthtml'])) |
|
| 683 | - $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 708 | + if (!empty($cur_field['prehtml'])) { |
|
| 709 | + $context['profile_prehtml'] .= $cur_field['prehtml']; |
|
| 710 | + } |
|
| 711 | + if (!empty($cur_field['posthtml'])) { |
|
| 712 | + $context['profile_posthtml'] .= $cur_field['posthtml']; |
|
| 713 | + } |
|
| 684 | 714 | |
| 685 | 715 | // Finally put it into context? |
| 686 | 716 | if ($cur_field['type'] != 'hidden') |
@@ -713,12 +743,14 @@ discard block |
||
| 713 | 743 | }, false);' : ''), true); |
| 714 | 744 | |
| 715 | 745 | // Any onsubmit javascript? |
| 716 | - if (!empty($context['profile_onsubmit_javascript'])) |
|
| 717 | - addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 746 | + if (!empty($context['profile_onsubmit_javascript'])) { |
|
| 747 | + addInlineJavaScript($context['profile_onsubmit_javascript'], true); |
|
| 748 | + } |
|
| 718 | 749 | |
| 719 | 750 | // Any totally custom stuff? |
| 720 | - if (!empty($context['profile_javascript'])) |
|
| 721 | - addInlineJavaScript($context['profile_javascript'], true); |
|
| 751 | + if (!empty($context['profile_javascript'])) { |
|
| 752 | + addInlineJavaScript($context['profile_javascript'], true); |
|
| 753 | + } |
|
| 722 | 754 | |
| 723 | 755 | // Free up some memory. |
| 724 | 756 | unset($profile_fields); |
@@ -739,8 +771,9 @@ discard block |
||
| 739 | 771 | |
| 740 | 772 | // This allows variables to call activities when they save - by default just to reload their settings |
| 741 | 773 | $context['profile_execute_on_save'] = array(); |
| 742 | - if ($context['user']['is_owner']) |
|
| 743 | - $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 774 | + if ($context['user']['is_owner']) { |
|
| 775 | + $context['profile_execute_on_save']['reload_user'] = 'profileReloadUser'; |
|
| 776 | + } |
|
| 744 | 777 | |
| 745 | 778 | // Assume we log nothing. |
| 746 | 779 | $context['log_changes'] = array(); |
@@ -748,8 +781,9 @@ discard block |
||
| 748 | 781 | // Cycle through the profile fields working out what to do! |
| 749 | 782 | foreach ($profile_fields as $key => $field) |
| 750 | 783 | { |
| 751 | - if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) |
|
| 752 | - continue; |
|
| 784 | + if (!isset($_POST[$key]) || !empty($field['is_dummy']) || (isset($_POST['preview_signature']) && $key == 'signature')) { |
|
| 785 | + continue; |
|
| 786 | + } |
|
| 753 | 787 | |
| 754 | 788 | // What gets updated? |
| 755 | 789 | $db_key = isset($field['save_key']) ? $field['save_key'] : $key; |
@@ -777,12 +811,13 @@ discard block |
||
| 777 | 811 | $field['cast_type'] = empty($field['cast_type']) ? $field['type'] : $field['cast_type']; |
| 778 | 812 | |
| 779 | 813 | // Finally, clean up certain types. |
| 780 | - if ($field['cast_type'] == 'int') |
|
| 781 | - $_POST[$key] = (int) $_POST[$key]; |
|
| 782 | - elseif ($field['cast_type'] == 'float') |
|
| 783 | - $_POST[$key] = (float) $_POST[$key]; |
|
| 784 | - elseif ($field['cast_type'] == 'check') |
|
| 785 | - $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 814 | + if ($field['cast_type'] == 'int') { |
|
| 815 | + $_POST[$key] = (int) $_POST[$key]; |
|
| 816 | + } elseif ($field['cast_type'] == 'float') { |
|
| 817 | + $_POST[$key] = (float) $_POST[$key]; |
|
| 818 | + } elseif ($field['cast_type'] == 'check') { |
|
| 819 | + $_POST[$key] = !empty($_POST[$key]) ? 1 : 0; |
|
| 820 | + } |
|
| 786 | 821 | |
| 787 | 822 | // If we got here we're doing OK. |
| 788 | 823 | if ($field['type'] != 'hidden' && (!isset($old_profile[$key]) || $_POST[$key] != $old_profile[$key])) |
@@ -793,11 +828,12 @@ discard block |
||
| 793 | 828 | $cur_profile[$key] = $_POST[$key]; |
| 794 | 829 | |
| 795 | 830 | // Are we logging it? |
| 796 | - if (!empty($field['log_change']) && isset($old_profile[$key])) |
|
| 797 | - $context['log_changes'][$key] = array( |
|
| 831 | + if (!empty($field['log_change']) && isset($old_profile[$key])) { |
|
| 832 | + $context['log_changes'][$key] = array( |
|
| 798 | 833 | 'previous' => $old_profile[$key], |
| 799 | 834 | 'new' => $_POST[$key], |
| 800 | 835 | ); |
| 836 | + } |
|
| 801 | 837 | } |
| 802 | 838 | |
| 803 | 839 | // Logging group changes are a bit different... |
@@ -830,10 +866,11 @@ discard block |
||
| 830 | 866 | { |
| 831 | 867 | foreach ($groups as $id => $group) |
| 832 | 868 | { |
| 833 | - if (isset($context['member_groups'][$group])) |
|
| 834 | - $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 835 | - else |
|
| 836 | - unset($additional_groups[$type][$id]); |
|
| 869 | + if (isset($context['member_groups'][$group])) { |
|
| 870 | + $additional_groups[$type][$id] = $context['member_groups'][$group]['name']; |
|
| 871 | + } else { |
|
| 872 | + unset($additional_groups[$type][$id]); |
|
| 873 | + } |
|
| 837 | 874 | } |
| 838 | 875 | $additional_groups[$type] = implode(', ', $additional_groups[$type]); |
| 839 | 876 | } |
@@ -844,10 +881,11 @@ discard block |
||
| 844 | 881 | } |
| 845 | 882 | |
| 846 | 883 | // @todo Temporary |
| 847 | - if ($context['user']['is_owner']) |
|
| 848 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 849 | - else |
|
| 850 | - $changeOther = allowedTo('profile_extra_any'); |
|
| 884 | + if ($context['user']['is_owner']) { |
|
| 885 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own')); |
|
| 886 | + } else { |
|
| 887 | + $changeOther = allowedTo('profile_extra_any'); |
|
| 888 | + } |
|
| 851 | 889 | if ($changeOther && empty($post_errors)) |
| 852 | 890 | { |
| 853 | 891 | makeThemeChanges($context['id_member'], isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
@@ -855,8 +893,9 @@ discard block |
||
| 855 | 893 | { |
| 856 | 894 | $custom_fields_errors = makeCustomFieldChanges($context['id_member'], $_REQUEST['sa'], false, true); |
| 857 | 895 | |
| 858 | - if (!empty($custom_fields_errors)) |
|
| 859 | - $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 896 | + if (!empty($custom_fields_errors)) { |
|
| 897 | + $post_errors = array_merge($post_errors, $custom_fields_errors); |
|
| 898 | + } |
|
| 860 | 899 | } |
| 861 | 900 | } |
| 862 | 901 | |
@@ -882,9 +921,9 @@ discard block |
||
| 882 | 921 | if ($context['user']['is_owner']) |
| 883 | 922 | { |
| 884 | 923 | $changeOther = allowedTo(array('profile_extra_any', 'profile_extra_own', 'profile_website_any', 'profile_website_own', 'profile_signature_any', 'profile_signature_own')); |
| 924 | + } else { |
|
| 925 | + $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 885 | 926 | } |
| 886 | - else |
|
| 887 | - $changeOther = allowedTo(array('profile_extra_any', 'profile_website_any', 'profile_signature_any')); |
|
| 888 | 927 | |
| 889 | 928 | // Arrays of all the changes - makes things easier. |
| 890 | 929 | $profile_bools = array(); |
@@ -895,22 +934,25 @@ discard block |
||
| 895 | 934 | 'ignore_boards', |
| 896 | 935 | ); |
| 897 | 936 | |
| 898 | - if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) |
|
| 899 | - $_POST['ignore_brd'] = array(); |
|
| 937 | + if (isset($_POST['sa']) && $_POST['sa'] == 'ignoreboards' && empty($_POST['ignore_brd'])) { |
|
| 938 | + $_POST['ignore_brd'] = array(); |
|
| 939 | + } |
|
| 900 | 940 | |
| 901 | 941 | unset($_POST['ignore_boards']); // Whatever it is set to is a dirty filthy thing. Kinda like our minds. |
| 902 | 942 | if (isset($_POST['ignore_brd'])) |
| 903 | 943 | { |
| 904 | - if (!is_array($_POST['ignore_brd'])) |
|
| 905 | - $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 944 | + if (!is_array($_POST['ignore_brd'])) { |
|
| 945 | + $_POST['ignore_brd'] = array($_POST['ignore_brd']); |
|
| 946 | + } |
|
| 906 | 947 | |
| 907 | 948 | foreach ($_POST['ignore_brd'] as $k => $d) |
| 908 | 949 | { |
| 909 | 950 | $d = (int) $d; |
| 910 | - if ($d != 0) |
|
| 911 | - $_POST['ignore_brd'][$k] = $d; |
|
| 912 | - else |
|
| 913 | - unset($_POST['ignore_brd'][$k]); |
|
| 951 | + if ($d != 0) { |
|
| 952 | + $_POST['ignore_brd'][$k] = $d; |
|
| 953 | + } else { |
|
| 954 | + unset($_POST['ignore_brd'][$k]); |
|
| 955 | + } |
|
| 914 | 956 | } |
| 915 | 957 | $_POST['ignore_boards'] = implode(',', $_POST['ignore_brd']); |
| 916 | 958 | unset($_POST['ignore_brd']); |
@@ -923,21 +965,26 @@ discard block |
||
| 923 | 965 | makeThemeChanges($memID, isset($_POST['id_theme']) ? (int) $_POST['id_theme'] : $old_profile['id_theme']); |
| 924 | 966 | //makeAvatarChanges($memID, $post_errors); |
| 925 | 967 | |
| 926 | - if (!empty($_REQUEST['sa'])) |
|
| 927 | - makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 968 | + if (!empty($_REQUEST['sa'])) { |
|
| 969 | + makeCustomFieldChanges($memID, $_REQUEST['sa'], false); |
|
| 970 | + } |
|
| 928 | 971 | |
| 929 | - foreach ($profile_bools as $var) |
|
| 930 | - if (isset($_POST[$var])) |
|
| 972 | + foreach ($profile_bools as $var) { |
|
| 973 | + if (isset($_POST[$var])) |
|
| 931 | 974 | $profile_vars[$var] = empty($_POST[$var]) ? '0' : '1'; |
| 932 | - foreach ($profile_ints as $var) |
|
| 933 | - if (isset($_POST[$var])) |
|
| 975 | + } |
|
| 976 | + foreach ($profile_ints as $var) { |
|
| 977 | + if (isset($_POST[$var])) |
|
| 934 | 978 | $profile_vars[$var] = $_POST[$var] != '' ? (int) $_POST[$var] : ''; |
| 935 | - foreach ($profile_floats as $var) |
|
| 936 | - if (isset($_POST[$var])) |
|
| 979 | + } |
|
| 980 | + foreach ($profile_floats as $var) { |
|
| 981 | + if (isset($_POST[$var])) |
|
| 937 | 982 | $profile_vars[$var] = (float) $_POST[$var]; |
| 938 | - foreach ($profile_strings as $var) |
|
| 939 | - if (isset($_POST[$var])) |
|
| 983 | + } |
|
| 984 | + foreach ($profile_strings as $var) { |
|
| 985 | + if (isset($_POST[$var])) |
|
| 940 | 986 | $profile_vars[$var] = $_POST[$var]; |
| 987 | + } |
|
| 941 | 988 | } |
| 942 | 989 | } |
| 943 | 990 | |
@@ -971,8 +1018,9 @@ discard block |
||
| 971 | 1018 | ); |
| 972 | 1019 | |
| 973 | 1020 | // Can't change reserved vars. |
| 974 | - if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) |
|
| 975 | - fatal_lang_error('no_access', false); |
|
| 1021 | + if ((isset($_POST['options']) && count(array_intersect(array_keys($_POST['options']), $reservedVars)) != 0) || (isset($_POST['default_options']) && count(array_intersect(array_keys($_POST['default_options']), $reservedVars)) != 0)) { |
|
| 1022 | + fatal_lang_error('no_access', false); |
|
| 1023 | + } |
|
| 976 | 1024 | |
| 977 | 1025 | // Don't allow any overriding of custom fields with default or non-default options. |
| 978 | 1026 | $request = $smcFunc['db_query']('', ' |
@@ -984,8 +1032,9 @@ discard block |
||
| 984 | 1032 | ) |
| 985 | 1033 | ); |
| 986 | 1034 | $custom_fields = array(); |
| 987 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 988 | - $custom_fields[] = $row['col_name']; |
|
| 1035 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1036 | + $custom_fields[] = $row['col_name']; |
|
| 1037 | + } |
|
| 989 | 1038 | $smcFunc['db_free_result']($request); |
| 990 | 1039 | |
| 991 | 1040 | // These are the theme changes... |
@@ -994,33 +1043,39 @@ discard block |
||
| 994 | 1043 | { |
| 995 | 1044 | foreach ($_POST['options'] as $opt => $val) |
| 996 | 1045 | { |
| 997 | - if (in_array($opt, $custom_fields)) |
|
| 998 | - continue; |
|
| 1046 | + if (in_array($opt, $custom_fields)) { |
|
| 1047 | + continue; |
|
| 1048 | + } |
|
| 999 | 1049 | |
| 1000 | 1050 | // These need to be controlled. |
| 1001 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1002 | - $val = max(0, min($val, 50)); |
|
| 1051 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1052 | + $val = max(0, min($val, 50)); |
|
| 1053 | + } |
|
| 1003 | 1054 | // We don't set this per theme anymore. |
| 1004 | - elseif ($opt == 'allow_no_censored') |
|
| 1005 | - continue; |
|
| 1055 | + elseif ($opt == 'allow_no_censored') { |
|
| 1056 | + continue; |
|
| 1057 | + } |
|
| 1006 | 1058 | |
| 1007 | 1059 | $themeSetArray[] = array($memID, $id_theme, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1008 | 1060 | } |
| 1009 | 1061 | } |
| 1010 | 1062 | |
| 1011 | 1063 | $erase_options = array(); |
| 1012 | - if (isset($_POST['default_options']) && is_array($_POST['default_options'])) |
|
| 1013 | - foreach ($_POST['default_options'] as $opt => $val) |
|
| 1064 | + if (isset($_POST['default_options']) && is_array($_POST['default_options'])) { |
|
| 1065 | + foreach ($_POST['default_options'] as $opt => $val) |
|
| 1014 | 1066 | { |
| 1015 | 1067 | if (in_array($opt, $custom_fields)) |
| 1016 | 1068 | continue; |
| 1069 | + } |
|
| 1017 | 1070 | |
| 1018 | 1071 | // These need to be controlled. |
| 1019 | - if ($opt == 'topics_per_page' || $opt == 'messages_per_page') |
|
| 1020 | - $val = max(0, min($val, 50)); |
|
| 1072 | + if ($opt == 'topics_per_page' || $opt == 'messages_per_page') { |
|
| 1073 | + $val = max(0, min($val, 50)); |
|
| 1074 | + } |
|
| 1021 | 1075 | // Only let admins and owners change the censor. |
| 1022 | - elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) |
|
| 1023 | - continue; |
|
| 1076 | + elseif ($opt == 'allow_no_censored' && !$user_info['is_admin'] && !$context['user']['is_owner']) { |
|
| 1077 | + continue; |
|
| 1078 | + } |
|
| 1024 | 1079 | |
| 1025 | 1080 | $themeSetArray[] = array($memID, 1, $opt, is_array($val) ? implode(',', $val) : $val); |
| 1026 | 1081 | $erase_options[] = $opt; |
@@ -1056,8 +1111,9 @@ discard block |
||
| 1056 | 1111 | |
| 1057 | 1112 | // Admins can choose any theme, even if it's not enabled... |
| 1058 | 1113 | $themes = allowedTo('admin_forum') ? explode(',', $modSettings['knownThemes']) : explode(',', $modSettings['enableThemes']); |
| 1059 | - foreach ($themes as $t) |
|
| 1060 | - cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1114 | + foreach ($themes as $t) { |
|
| 1115 | + cache_put_data('theme_settings-' . $t . ':' . $memID, null, 60); |
|
| 1116 | + } |
|
| 1061 | 1117 | } |
| 1062 | 1118 | } |
| 1063 | 1119 | |
@@ -1076,8 +1132,9 @@ discard block |
||
| 1076 | 1132 | if (isset($_POST['edit_notify_boards']) && !empty($_POST['notify_boards'])) |
| 1077 | 1133 | { |
| 1078 | 1134 | // Make sure only integers are deleted. |
| 1079 | - foreach ($_POST['notify_boards'] as $index => $id) |
|
| 1080 | - $_POST['notify_boards'][$index] = (int) $id; |
|
| 1135 | + foreach ($_POST['notify_boards'] as $index => $id) { |
|
| 1136 | + $_POST['notify_boards'][$index] = (int) $id; |
|
| 1137 | + } |
|
| 1081 | 1138 | |
| 1082 | 1139 | // id_board = 0 is reserved for topic notifications. |
| 1083 | 1140 | $_POST['notify_boards'] = array_diff($_POST['notify_boards'], array(0)); |
@@ -1096,8 +1153,9 @@ discard block |
||
| 1096 | 1153 | // We are editing topic notifications...... |
| 1097 | 1154 | elseif (isset($_POST['edit_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1098 | 1155 | { |
| 1099 | - foreach ($_POST['notify_topics'] as $index => $id) |
|
| 1100 | - $_POST['notify_topics'][$index] = (int) $id; |
|
| 1156 | + foreach ($_POST['notify_topics'] as $index => $id) { |
|
| 1157 | + $_POST['notify_topics'][$index] = (int) $id; |
|
| 1158 | + } |
|
| 1101 | 1159 | |
| 1102 | 1160 | // Make sure there are no zeros left. |
| 1103 | 1161 | $_POST['notify_topics'] = array_diff($_POST['notify_topics'], array(0)); |
@@ -1111,16 +1169,18 @@ discard block |
||
| 1111 | 1169 | 'selected_member' => $memID, |
| 1112 | 1170 | ) |
| 1113 | 1171 | ); |
| 1114 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1115 | - setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1172 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1173 | + setNotifyPrefs($memID, array('topic_notify_' . $topic => 0)); |
|
| 1174 | + } |
|
| 1116 | 1175 | } |
| 1117 | 1176 | |
| 1118 | 1177 | // We are removing topic preferences |
| 1119 | 1178 | elseif (isset($_POST['remove_notify_topics']) && !empty($_POST['notify_topics'])) |
| 1120 | 1179 | { |
| 1121 | 1180 | $prefs = array(); |
| 1122 | - foreach ($_POST['notify_topics'] as $topic) |
|
| 1123 | - $prefs[] = 'topic_notify_' . $topic; |
|
| 1181 | + foreach ($_POST['notify_topics'] as $topic) { |
|
| 1182 | + $prefs[] = 'topic_notify_' . $topic; |
|
| 1183 | + } |
|
| 1124 | 1184 | deleteNotifyPrefs($memID, $prefs); |
| 1125 | 1185 | } |
| 1126 | 1186 | |
@@ -1128,8 +1188,9 @@ discard block |
||
| 1128 | 1188 | elseif (isset($_POST['remove_notify_board']) && !empty($_POST['notify_boards'])) |
| 1129 | 1189 | { |
| 1130 | 1190 | $prefs = array(); |
| 1131 | - foreach ($_POST['notify_boards'] as $board) |
|
| 1132 | - $prefs[] = 'board_notify_' . $board; |
|
| 1191 | + foreach ($_POST['notify_boards'] as $board) { |
|
| 1192 | + $prefs[] = 'board_notify_' . $board; |
|
| 1193 | + } |
|
| 1133 | 1194 | deleteNotifyPrefs($memID, $prefs); |
| 1134 | 1195 | } |
| 1135 | 1196 | } |
@@ -1150,8 +1211,9 @@ discard block |
||
| 1150 | 1211 | |
| 1151 | 1212 | $errors = array(); |
| 1152 | 1213 | |
| 1153 | - if ($sanitize && isset($_POST['customfield'])) |
|
| 1154 | - $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1214 | + if ($sanitize && isset($_POST['customfield'])) { |
|
| 1215 | + $_POST['customfield'] = htmlspecialchars__recursive($_POST['customfield']); |
|
| 1216 | + } |
|
| 1155 | 1217 | |
| 1156 | 1218 | $where = $area == 'register' ? 'show_reg != 0' : 'show_profile = {string:area}'; |
| 1157 | 1219 | |
@@ -1176,48 +1238,49 @@ discard block |
||
| 1176 | 1238 | - The data is not invisible to users but editable by the owner (or if it is the user is not the owner) |
| 1177 | 1239 | - The area isn't registration, and if it is that the field is not supposed to be shown there. |
| 1178 | 1240 | */ |
| 1179 | - if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) |
|
| 1180 | - continue; |
|
| 1241 | + if ($row['private'] != 0 && !allowedTo('admin_forum') && ($memID != $user_info['id'] || $row['private'] != 2) && ($area != 'register' || $row['show_reg'] == 0)) { |
|
| 1242 | + continue; |
|
| 1243 | + } |
|
| 1181 | 1244 | |
| 1182 | 1245 | // Validate the user data. |
| 1183 | - if ($row['field_type'] == 'check') |
|
| 1184 | - $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1185 | - elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1246 | + if ($row['field_type'] == 'check') { |
|
| 1247 | + $value = isset($_POST['customfield'][$row['col_name']]) ? 1 : 0; |
|
| 1248 | + } elseif ($row['field_type'] == 'select' || $row['field_type'] == 'radio') |
|
| 1186 | 1249 | { |
| 1187 | 1250 | $value = $row['default_value']; |
| 1188 | - foreach (explode(',', $row['field_options']) as $k => $v) |
|
| 1189 | - if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1251 | + foreach (explode(',', $row['field_options']) as $k => $v) { |
|
| 1252 | + if (isset($_POST['customfield'][$row['col_name']]) && $_POST['customfield'][$row['col_name']] == $k) |
|
| 1190 | 1253 | $value = $v; |
| 1254 | + } |
|
| 1191 | 1255 | } |
| 1192 | 1256 | // Otherwise some form of text! |
| 1193 | 1257 | else |
| 1194 | 1258 | { |
| 1195 | 1259 | $value = isset($_POST['customfield'][$row['col_name']]) ? $_POST['customfield'][$row['col_name']] : ''; |
| 1196 | - if ($row['field_length']) |
|
| 1197 | - $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1260 | + if ($row['field_length']) { |
|
| 1261 | + $value = $smcFunc['substr']($value, 0, $row['field_length']); |
|
| 1262 | + } |
|
| 1198 | 1263 | |
| 1199 | 1264 | // Any masks? |
| 1200 | 1265 | if ($row['field_type'] == 'text' && !empty($row['mask']) && $row['mask'] != 'none') |
| 1201 | 1266 | { |
| 1202 | 1267 | if ($row['mask'] == 'email' && (!filter_var($value, FILTER_VALIDATE_EMAIL) || strlen($value) > 255)) |
| 1203 | 1268 | { |
| 1204 | - if ($returnErrors) |
|
| 1205 | - $errors[] = 'custom_field_mail_fail'; |
|
| 1206 | - |
|
| 1207 | - else |
|
| 1208 | - $value = ''; |
|
| 1209 | - } |
|
| 1210 | - elseif ($row['mask'] == 'number') |
|
| 1269 | + if ($returnErrors) { |
|
| 1270 | + $errors[] = 'custom_field_mail_fail'; |
|
| 1271 | + } else { |
|
| 1272 | + $value = ''; |
|
| 1273 | + } |
|
| 1274 | + } elseif ($row['mask'] == 'number') |
|
| 1211 | 1275 | { |
| 1212 | 1276 | $value = (int) $value; |
| 1213 | - } |
|
| 1214 | - elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1277 | + } elseif (substr($row['mask'], 0, 5) == 'regex' && trim($value) != '' && preg_match(substr($row['mask'], 5), $value) === 0) |
|
| 1215 | 1278 | { |
| 1216 | - if ($returnErrors) |
|
| 1217 | - $errors[] = 'custom_field_regex_fail'; |
|
| 1218 | - |
|
| 1219 | - else |
|
| 1220 | - $value = ''; |
|
| 1279 | + if ($returnErrors) { |
|
| 1280 | + $errors[] = 'custom_field_regex_fail'; |
|
| 1281 | + } else { |
|
| 1282 | + $value = ''; |
|
| 1283 | + } |
|
| 1221 | 1284 | } |
| 1222 | 1285 | } |
| 1223 | 1286 | } |
@@ -1243,8 +1306,9 @@ discard block |
||
| 1243 | 1306 | |
| 1244 | 1307 | $hook_errors = call_integration_hook('integrate_save_custom_profile_fields', array(&$changes, &$log_changes, &$errors, $returnErrors, $memID, $area, $sanitize)); |
| 1245 | 1308 | |
| 1246 | - if (!empty($hook_errors) && is_array($hook_errors)) |
|
| 1247 | - $errors = array_merge($errors, $hook_errors); |
|
| 1309 | + if (!empty($hook_errors) && is_array($hook_errors)) { |
|
| 1310 | + $errors = array_merge($errors, $hook_errors); |
|
| 1311 | + } |
|
| 1248 | 1312 | |
| 1249 | 1313 | // Make those changes! |
| 1250 | 1314 | if (!empty($changes) && empty($context['password_auth_failed']) && empty($errors)) |
@@ -1262,9 +1326,10 @@ discard block |
||
| 1262 | 1326 | } |
| 1263 | 1327 | } |
| 1264 | 1328 | |
| 1265 | - if ($returnErrors) |
|
| 1266 | - return $errors; |
|
| 1267 | -} |
|
| 1329 | + if ($returnErrors) { |
|
| 1330 | + return $errors; |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1268 | 1333 | |
| 1269 | 1334 | /** |
| 1270 | 1335 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1276,8 +1341,9 @@ discard block |
||
| 1276 | 1341 | global $context, $txt, $modSettings; |
| 1277 | 1342 | |
| 1278 | 1343 | // Do a quick check to ensure people aren't getting here illegally! |
| 1279 | - if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) |
|
| 1280 | - fatal_lang_error('no_access', false); |
|
| 1344 | + if (!$context['user']['is_owner'] || empty($modSettings['enable_buddylist'])) { |
|
| 1345 | + fatal_lang_error('no_access', false); |
|
| 1346 | + } |
|
| 1281 | 1347 | |
| 1282 | 1348 | // Can we email the user direct? |
| 1283 | 1349 | $context['can_moderate_forum'] = allowedTo('moderate_forum'); |
@@ -1307,9 +1373,10 @@ discard block |
||
| 1307 | 1373 | $context['sub_template'] = $subActions[$context['list_area']][0]; |
| 1308 | 1374 | $call = call_helper($subActions[$context['list_area']][0], true); |
| 1309 | 1375 | |
| 1310 | - if (!empty($call)) |
|
| 1311 | - call_user_func($call, $memID); |
|
| 1312 | -} |
|
| 1376 | + if (!empty($call)) { |
|
| 1377 | + call_user_func($call, $memID); |
|
| 1378 | + } |
|
| 1379 | + } |
|
| 1313 | 1380 | |
| 1314 | 1381 | /** |
| 1315 | 1382 | * Show all the users buddies, as well as a add/delete interface. |
@@ -1323,9 +1390,10 @@ discard block |
||
| 1323 | 1390 | |
| 1324 | 1391 | // For making changes! |
| 1325 | 1392 | $buddiesArray = explode(',', $user_profile[$memID]['buddy_list']); |
| 1326 | - foreach ($buddiesArray as $k => $dummy) |
|
| 1327 | - if ($dummy == '') |
|
| 1393 | + foreach ($buddiesArray as $k => $dummy) { |
|
| 1394 | + if ($dummy == '') |
|
| 1328 | 1395 | unset($buddiesArray[$k]); |
| 1396 | + } |
|
| 1329 | 1397 | |
| 1330 | 1398 | // Removing a buddy? |
| 1331 | 1399 | if (isset($_GET['remove'])) |
@@ -1337,10 +1405,11 @@ discard block |
||
| 1337 | 1405 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1338 | 1406 | |
| 1339 | 1407 | // Heh, I'm lazy, do it the easy way... |
| 1340 | - foreach ($buddiesArray as $key => $buddy) |
|
| 1341 | - if ($buddy == (int) $_GET['remove']) |
|
| 1408 | + foreach ($buddiesArray as $key => $buddy) { |
|
| 1409 | + if ($buddy == (int) $_GET['remove']) |
|
| 1342 | 1410 | { |
| 1343 | 1411 | unset($buddiesArray[$key]); |
| 1412 | + } |
|
| 1344 | 1413 | $_SESSION['prf-save'] = true; |
| 1345 | 1414 | } |
| 1346 | 1415 | |
@@ -1350,8 +1419,7 @@ discard block |
||
| 1350 | 1419 | |
| 1351 | 1420 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1352 | 1421 | redirectexit('action=profile;area=lists;sa=buddies;u=' . $memID); |
| 1353 | - } |
|
| 1354 | - elseif (isset($_POST['new_buddy'])) |
|
| 1422 | + } elseif (isset($_POST['new_buddy'])) |
|
| 1355 | 1423 | { |
| 1356 | 1424 | checkSession(); |
| 1357 | 1425 | |
@@ -1364,8 +1432,9 @@ discard block |
||
| 1364 | 1432 | { |
| 1365 | 1433 | $new_buddies[$k] = strtr(trim($new_buddies[$k]), array('\'' => ''')); |
| 1366 | 1434 | |
| 1367 | - if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1368 | - unset($new_buddies[$k]); |
|
| 1435 | + if (strlen($new_buddies[$k]) == 0 || in_array($new_buddies[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1436 | + unset($new_buddies[$k]); |
|
| 1437 | + } |
|
| 1369 | 1438 | } |
| 1370 | 1439 | |
| 1371 | 1440 | call_integration_hook('integrate_add_buddies', array($memID, &$new_buddies)); |
@@ -1385,16 +1454,18 @@ discard block |
||
| 1385 | 1454 | ) |
| 1386 | 1455 | ); |
| 1387 | 1456 | |
| 1388 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1389 | - $_SESSION['prf-save'] = true; |
|
| 1457 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1458 | + $_SESSION['prf-save'] = true; |
|
| 1459 | + } |
|
| 1390 | 1460 | |
| 1391 | 1461 | // Add the new member to the buddies array. |
| 1392 | 1462 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1393 | 1463 | { |
| 1394 | - if (in_array($row['id_member'], $buddiesArray)) |
|
| 1395 | - continue; |
|
| 1396 | - else |
|
| 1397 | - $buddiesArray[] = (int) $row['id_member']; |
|
| 1464 | + if (in_array($row['id_member'], $buddiesArray)) { |
|
| 1465 | + continue; |
|
| 1466 | + } else { |
|
| 1467 | + $buddiesArray[] = (int) $row['id_member']; |
|
| 1468 | + } |
|
| 1398 | 1469 | } |
| 1399 | 1470 | $smcFunc['db_free_result']($request); |
| 1400 | 1471 | |
@@ -1424,18 +1495,20 @@ discard block |
||
| 1424 | 1495 | |
| 1425 | 1496 | $context['custom_pf'] = array(); |
| 1426 | 1497 | $disabled_fields = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
| 1427 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1428 | - if (!isset($disabled_fields[$row['col_name']])) |
|
| 1498 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1499 | + if (!isset($disabled_fields[$row['col_name']])) |
|
| 1429 | 1500 | $context['custom_pf'][$row['col_name']] = array( |
| 1430 | 1501 | 'label' => $row['field_name'], |
| 1431 | 1502 | 'type' => $row['field_type'], |
| 1432 | 1503 | 'bbc' => !empty($row['bbc']), |
| 1433 | 1504 | 'enclose' => $row['enclose'], |
| 1434 | 1505 | ); |
| 1506 | + } |
|
| 1435 | 1507 | |
| 1436 | 1508 | // Gotta disable the gender option. |
| 1437 | - if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') |
|
| 1438 | - unset($context['custom_pf']['cust_gender']); |
|
| 1509 | + if (isset($context['custom_pf']['cust_gender']) && $context['custom_pf']['cust_gender'] == 'Disabled') { |
|
| 1510 | + unset($context['custom_pf']['cust_gender']); |
|
| 1511 | + } |
|
| 1439 | 1512 | |
| 1440 | 1513 | $smcFunc['db_free_result']($request); |
| 1441 | 1514 | |
@@ -1452,8 +1525,9 @@ discard block |
||
| 1452 | 1525 | 'buddy_list_count' => substr_count($user_profile[$memID]['buddy_list'], ',') + 1, |
| 1453 | 1526 | ) |
| 1454 | 1527 | ); |
| 1455 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1456 | - $buddies[] = $row['id_member']; |
|
| 1528 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1529 | + $buddies[] = $row['id_member']; |
|
| 1530 | + } |
|
| 1457 | 1531 | $smcFunc['db_free_result']($result); |
| 1458 | 1532 | } |
| 1459 | 1533 | |
@@ -1481,30 +1555,32 @@ discard block |
||
| 1481 | 1555 | continue; |
| 1482 | 1556 | } |
| 1483 | 1557 | |
| 1484 | - if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1485 | - $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1486 | - |
|
| 1487 | - elseif ($column['type'] == 'check') |
|
| 1488 | - $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1558 | + if ($column['bbc'] && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1559 | + $context['buddies'][$buddy]['options'][$key] = strip_tags(parse_bbc($context['buddies'][$buddy]['options'][$key])); |
|
| 1560 | + } elseif ($column['type'] == 'check') { |
|
| 1561 | + $context['buddies'][$buddy]['options'][$key] = $context['buddies'][$buddy]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
| 1562 | + } |
|
| 1489 | 1563 | |
| 1490 | 1564 | // Enclosing the user input within some other text? |
| 1491 | - if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) |
|
| 1492 | - $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1565 | + if (!empty($column['enclose']) && !empty($context['buddies'][$buddy]['options'][$key])) { |
|
| 1566 | + $context['buddies'][$buddy]['options'][$key] = strtr($column['enclose'], array( |
|
| 1493 | 1567 | '{SCRIPTURL}' => $scripturl, |
| 1494 | 1568 | '{IMAGES_URL}' => $settings['images_url'], |
| 1495 | 1569 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
| 1496 | 1570 | '{INPUT}' => $context['buddies'][$buddy]['options'][$key], |
| 1497 | 1571 | )); |
| 1572 | + } |
|
| 1498 | 1573 | } |
| 1499 | 1574 | } |
| 1500 | 1575 | } |
| 1501 | 1576 | |
| 1502 | 1577 | if (isset($_SESSION['prf-save'])) |
| 1503 | 1578 | { |
| 1504 | - if ($_SESSION['prf-save'] === true) |
|
| 1505 | - $context['saved_successful'] = true; |
|
| 1506 | - else |
|
| 1507 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1579 | + if ($_SESSION['prf-save'] === true) { |
|
| 1580 | + $context['saved_successful'] = true; |
|
| 1581 | + } else { |
|
| 1582 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1583 | + } |
|
| 1508 | 1584 | |
| 1509 | 1585 | unset($_SESSION['prf-save']); |
| 1510 | 1586 | } |
@@ -1524,9 +1600,10 @@ discard block |
||
| 1524 | 1600 | |
| 1525 | 1601 | // For making changes! |
| 1526 | 1602 | $ignoreArray = explode(',', $user_profile[$memID]['pm_ignore_list']); |
| 1527 | - foreach ($ignoreArray as $k => $dummy) |
|
| 1528 | - if ($dummy == '') |
|
| 1603 | + foreach ($ignoreArray as $k => $dummy) { |
|
| 1604 | + if ($dummy == '') |
|
| 1529 | 1605 | unset($ignoreArray[$k]); |
| 1606 | + } |
|
| 1530 | 1607 | |
| 1531 | 1608 | // Removing a member from the ignore list? |
| 1532 | 1609 | if (isset($_GET['remove'])) |
@@ -1536,10 +1613,11 @@ discard block |
||
| 1536 | 1613 | $_SESSION['prf-save'] = $txt['could_not_remove_person']; |
| 1537 | 1614 | |
| 1538 | 1615 | // Heh, I'm lazy, do it the easy way... |
| 1539 | - foreach ($ignoreArray as $key => $id_remove) |
|
| 1540 | - if ($id_remove == (int) $_GET['remove']) |
|
| 1616 | + foreach ($ignoreArray as $key => $id_remove) { |
|
| 1617 | + if ($id_remove == (int) $_GET['remove']) |
|
| 1541 | 1618 | { |
| 1542 | 1619 | unset($ignoreArray[$key]); |
| 1620 | + } |
|
| 1543 | 1621 | $_SESSION['prf-save'] = true; |
| 1544 | 1622 | } |
| 1545 | 1623 | |
@@ -1549,8 +1627,7 @@ discard block |
||
| 1549 | 1627 | |
| 1550 | 1628 | // Redirect off the page because we don't like all this ugly query stuff to stick in the history. |
| 1551 | 1629 | redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID); |
| 1552 | - } |
|
| 1553 | - elseif (isset($_POST['new_ignore'])) |
|
| 1630 | + } elseif (isset($_POST['new_ignore'])) |
|
| 1554 | 1631 | { |
| 1555 | 1632 | checkSession(); |
| 1556 | 1633 | // Prepare the string for extraction... |
@@ -1562,8 +1639,9 @@ discard block |
||
| 1562 | 1639 | { |
| 1563 | 1640 | $new_entries[$k] = strtr(trim($new_entries[$k]), array('\'' => ''')); |
| 1564 | 1641 | |
| 1565 | - if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) |
|
| 1566 | - unset($new_entries[$k]); |
|
| 1642 | + if (strlen($new_entries[$k]) == 0 || in_array($new_entries[$k], array($user_profile[$memID]['member_name'], $user_profile[$memID]['real_name']))) { |
|
| 1643 | + unset($new_entries[$k]); |
|
| 1644 | + } |
|
| 1567 | 1645 | } |
| 1568 | 1646 | |
| 1569 | 1647 | $_SESSION['prf-save'] = $txt['could_not_add_person']; |
@@ -1581,16 +1659,18 @@ discard block |
||
| 1581 | 1659 | ) |
| 1582 | 1660 | ); |
| 1583 | 1661 | |
| 1584 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1585 | - $_SESSION['prf-save'] = true; |
|
| 1662 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1663 | + $_SESSION['prf-save'] = true; |
|
| 1664 | + } |
|
| 1586 | 1665 | |
| 1587 | 1666 | // Add the new member to the buddies array. |
| 1588 | 1667 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1589 | 1668 | { |
| 1590 | - if (in_array($row['id_member'], $ignoreArray)) |
|
| 1591 | - continue; |
|
| 1592 | - else |
|
| 1593 | - $ignoreArray[] = (int) $row['id_member']; |
|
| 1669 | + if (in_array($row['id_member'], $ignoreArray)) { |
|
| 1670 | + continue; |
|
| 1671 | + } else { |
|
| 1672 | + $ignoreArray[] = (int) $row['id_member']; |
|
| 1673 | + } |
|
| 1594 | 1674 | } |
| 1595 | 1675 | $smcFunc['db_free_result']($request); |
| 1596 | 1676 | |
@@ -1619,8 +1699,9 @@ discard block |
||
| 1619 | 1699 | 'ignore_list_count' => substr_count($user_profile[$memID]['pm_ignore_list'], ',') + 1, |
| 1620 | 1700 | ) |
| 1621 | 1701 | ); |
| 1622 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
| 1623 | - $ignored[] = $row['id_member']; |
|
| 1702 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
| 1703 | + $ignored[] = $row['id_member']; |
|
| 1704 | + } |
|
| 1624 | 1705 | $smcFunc['db_free_result']($result); |
| 1625 | 1706 | } |
| 1626 | 1707 | |
@@ -1639,10 +1720,11 @@ discard block |
||
| 1639 | 1720 | |
| 1640 | 1721 | if (isset($_SESSION['prf-save'])) |
| 1641 | 1722 | { |
| 1642 | - if ($_SESSION['prf-save'] === true) |
|
| 1643 | - $context['saved_successful'] = true; |
|
| 1644 | - else |
|
| 1645 | - $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1723 | + if ($_SESSION['prf-save'] === true) { |
|
| 1724 | + $context['saved_successful'] = true; |
|
| 1725 | + } else { |
|
| 1726 | + $context['saved_failed'] = $_SESSION['prf-save']; |
|
| 1727 | + } |
|
| 1646 | 1728 | |
| 1647 | 1729 | unset($_SESSION['prf-save']); |
| 1648 | 1730 | } |
@@ -1658,8 +1740,9 @@ discard block |
||
| 1658 | 1740 | global $context, $txt; |
| 1659 | 1741 | |
| 1660 | 1742 | loadThemeOptions($memID); |
| 1661 | - if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) |
|
| 1662 | - loadCustomFields($memID, 'account'); |
|
| 1743 | + if (allowedTo(array('profile_identity_own', 'profile_identity_any', 'profile_password_own', 'profile_password_any'))) { |
|
| 1744 | + loadCustomFields($memID, 'account'); |
|
| 1745 | + } |
|
| 1663 | 1746 | |
| 1664 | 1747 | $context['sub_template'] = 'edit_options'; |
| 1665 | 1748 | $context['page_desc'] = $txt['account_info']; |
@@ -1686,8 +1769,9 @@ discard block |
||
| 1686 | 1769 | global $context, $txt; |
| 1687 | 1770 | |
| 1688 | 1771 | loadThemeOptions($memID); |
| 1689 | - if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) |
|
| 1690 | - loadCustomFields($memID, 'forumprofile'); |
|
| 1772 | + if (allowedTo(array('profile_forum_own', 'profile_forum_any'))) { |
|
| 1773 | + loadCustomFields($memID, 'forumprofile'); |
|
| 1774 | + } |
|
| 1691 | 1775 | |
| 1692 | 1776 | $context['sub_template'] = 'edit_options'; |
| 1693 | 1777 | $context['page_desc'] = $txt['forumProfile_info']; |
@@ -1720,18 +1804,21 @@ discard block |
||
| 1720 | 1804 | $dirs = array(); |
| 1721 | 1805 | $files = array(); |
| 1722 | 1806 | |
| 1723 | - if (!$dir) |
|
| 1724 | - return array(); |
|
| 1807 | + if (!$dir) { |
|
| 1808 | + return array(); |
|
| 1809 | + } |
|
| 1725 | 1810 | |
| 1726 | 1811 | while ($line = $dir->read()) |
| 1727 | 1812 | { |
| 1728 | - if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) |
|
| 1729 | - continue; |
|
| 1813 | + if (in_array($line, array('.', '..', 'blank.png', 'index.php'))) { |
|
| 1814 | + continue; |
|
| 1815 | + } |
|
| 1730 | 1816 | |
| 1731 | - if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) |
|
| 1732 | - $dirs[] = $line; |
|
| 1733 | - else |
|
| 1734 | - $files[] = $line; |
|
| 1817 | + if (is_dir($modSettings['avatar_directory'] . '/' . $directory . (!empty($directory) ? '/' : '') . $line)) { |
|
| 1818 | + $dirs[] = $line; |
|
| 1819 | + } else { |
|
| 1820 | + $files[] = $line; |
|
| 1821 | + } |
|
| 1735 | 1822 | } |
| 1736 | 1823 | $dir->close(); |
| 1737 | 1824 | |
@@ -1752,14 +1839,15 @@ discard block |
||
| 1752 | 1839 | foreach ($dirs as $line) |
| 1753 | 1840 | { |
| 1754 | 1841 | $tmp = getAvatars($directory . (!empty($directory) ? '/' : '') . $line, $level + 1); |
| 1755 | - if (!empty($tmp)) |
|
| 1756 | - $result[] = array( |
|
| 1842 | + if (!empty($tmp)) { |
|
| 1843 | + $result[] = array( |
|
| 1757 | 1844 | 'filename' => $smcFunc['htmlspecialchars']($line), |
| 1758 | 1845 | 'checked' => strpos($context['member']['avatar']['server_pic'], $line . '/') !== false, |
| 1759 | 1846 | 'name' => '[' . $smcFunc['htmlspecialchars'](str_replace('_', ' ', $line)) . ']', |
| 1760 | 1847 | 'is_dir' => true, |
| 1761 | 1848 | 'files' => $tmp |
| 1762 | 1849 | ); |
| 1850 | + } |
|
| 1763 | 1851 | unset($tmp); |
| 1764 | 1852 | } |
| 1765 | 1853 | |
@@ -1769,8 +1857,9 @@ discard block |
||
| 1769 | 1857 | $extension = substr(strrchr($line, '.'), 1); |
| 1770 | 1858 | |
| 1771 | 1859 | // Make sure it is an image. |
| 1772 | - if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) |
|
| 1773 | - continue; |
|
| 1860 | + if (strcasecmp($extension, 'gif') != 0 && strcasecmp($extension, 'jpg') != 0 && strcasecmp($extension, 'jpeg') != 0 && strcasecmp($extension, 'png') != 0 && strcasecmp($extension, 'bmp') != 0) { |
|
| 1861 | + continue; |
|
| 1862 | + } |
|
| 1774 | 1863 | |
| 1775 | 1864 | $result[] = array( |
| 1776 | 1865 | 'filename' => $smcFunc['htmlspecialchars']($line), |
@@ -1778,8 +1867,9 @@ discard block |
||
| 1778 | 1867 | 'name' => $smcFunc['htmlspecialchars'](str_replace('_', ' ', $filename)), |
| 1779 | 1868 | 'is_dir' => false |
| 1780 | 1869 | ); |
| 1781 | - if ($level == 1) |
|
| 1782 | - $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1870 | + if ($level == 1) { |
|
| 1871 | + $context['avatar_list'][] = $directory . '/' . $line; |
|
| 1872 | + } |
|
| 1783 | 1873 | } |
| 1784 | 1874 | |
| 1785 | 1875 | return $result; |
@@ -1798,8 +1888,9 @@ discard block |
||
| 1798 | 1888 | loadSubTemplate('options'); |
| 1799 | 1889 | |
| 1800 | 1890 | loadThemeOptions($memID); |
| 1801 | - if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) |
|
| 1802 | - loadCustomFields($memID, 'theme'); |
|
| 1891 | + if (allowedTo(array('profile_extra_own', 'profile_extra_any'))) { |
|
| 1892 | + loadCustomFields($memID, 'theme'); |
|
| 1893 | + } |
|
| 1803 | 1894 | |
| 1804 | 1895 | $context['sub_template'] = 'edit_options'; |
| 1805 | 1896 | $context['page_desc'] = $txt['theme_info']; |
@@ -1853,16 +1944,19 @@ discard block |
||
| 1853 | 1944 | { |
| 1854 | 1945 | global $txt, $context, $modSettings, $smcFunc, $sourcedir; |
| 1855 | 1946 | |
| 1856 | - if (!isset($context['token_check'])) |
|
| 1857 | - $context['token_check'] = 'profile-nt' . $memID; |
|
| 1947 | + if (!isset($context['token_check'])) { |
|
| 1948 | + $context['token_check'] = 'profile-nt' . $memID; |
|
| 1949 | + } |
|
| 1858 | 1950 | |
| 1859 | 1951 | is_not_guest(); |
| 1860 | - if (!$context['user']['is_owner']) |
|
| 1861 | - isAllowedTo('profile_extra_any'); |
|
| 1952 | + if (!$context['user']['is_owner']) { |
|
| 1953 | + isAllowedTo('profile_extra_any'); |
|
| 1954 | + } |
|
| 1862 | 1955 | |
| 1863 | 1956 | // Set the post action if we're coming from the profile... |
| 1864 | - if (!isset($context['action'])) |
|
| 1865 | - $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1957 | + if (!isset($context['action'])) { |
|
| 1958 | + $context['action'] = 'action=profile;area=notification;sa=alerts;u=' . $memID; |
|
| 1959 | + } |
|
| 1866 | 1960 | |
| 1867 | 1961 | // What options are set |
| 1868 | 1962 | loadThemeOptions($memID); |
@@ -1949,28 +2043,34 @@ discard block |
||
| 1949 | 2043 | ); |
| 1950 | 2044 | |
| 1951 | 2045 | // There are certain things that are disabled at the group level. |
| 1952 | - if (empty($modSettings['cal_enabled'])) |
|
| 1953 | - unset($alert_types['calendar']); |
|
| 2046 | + if (empty($modSettings['cal_enabled'])) { |
|
| 2047 | + unset($alert_types['calendar']); |
|
| 2048 | + } |
|
| 1954 | 2049 | |
| 1955 | 2050 | // Disable paid subscriptions at group level if they're disabled |
| 1956 | - if (empty($modSettings['paid_enabled'])) |
|
| 1957 | - unset($alert_types['paidsubs']); |
|
| 2051 | + if (empty($modSettings['paid_enabled'])) { |
|
| 2052 | + unset($alert_types['paidsubs']); |
|
| 2053 | + } |
|
| 1958 | 2054 | |
| 1959 | 2055 | // Disable membergroup requests at group level if they're disabled |
| 1960 | - if (empty($modSettings['show_group_membership'])) |
|
| 1961 | - unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2056 | + if (empty($modSettings['show_group_membership'])) { |
|
| 2057 | + unset($alert_types['groupr'], $alert_types['members']['request_group']); |
|
| 2058 | + } |
|
| 1962 | 2059 | |
| 1963 | 2060 | // Disable mentions if they're disabled |
| 1964 | - if (empty($modSettings['enable_mentions'])) |
|
| 1965 | - unset($alert_types['msg']['msg_mention']); |
|
| 2061 | + if (empty($modSettings['enable_mentions'])) { |
|
| 2062 | + unset($alert_types['msg']['msg_mention']); |
|
| 2063 | + } |
|
| 1966 | 2064 | |
| 1967 | 2065 | // Disable likes if they're disabled |
| 1968 | - if (empty($modSettings['enable_likes'])) |
|
| 1969 | - unset($alert_types['msg']['msg_like']); |
|
| 2066 | + if (empty($modSettings['enable_likes'])) { |
|
| 2067 | + unset($alert_types['msg']['msg_like']); |
|
| 2068 | + } |
|
| 1970 | 2069 | |
| 1971 | 2070 | // Disable buddy requests if they're disabled |
| 1972 | - if (empty($modSettings['enable_buddylist'])) |
|
| 1973 | - unset($alert_types['members']['buddy_request']); |
|
| 2071 | + if (empty($modSettings['enable_buddylist'])) { |
|
| 2072 | + unset($alert_types['members']['buddy_request']); |
|
| 2073 | + } |
|
| 1974 | 2074 | |
| 1975 | 2075 | // Now, now, we could pass this through global but we should really get into the habit of |
| 1976 | 2076 | // passing content to hooks, not expecting hooks to splatter everything everywhere. |
@@ -1998,15 +2098,17 @@ discard block |
||
| 1998 | 2098 | $perms_cache['manage_membergroups'] = in_array($memID, $members); |
| 1999 | 2099 | } |
| 2000 | 2100 | |
| 2001 | - if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) |
|
| 2002 | - unset($alert_types['members']['request_group']); |
|
| 2101 | + if (!($perms_cache['manage_membergroups'] || $can_mod != 0)) { |
|
| 2102 | + unset($alert_types['members']['request_group']); |
|
| 2103 | + } |
|
| 2003 | 2104 | |
| 2004 | 2105 | foreach ($alert_types as $group => $items) |
| 2005 | 2106 | { |
| 2006 | 2107 | foreach ($items as $alert_key => $alert_value) |
| 2007 | 2108 | { |
| 2008 | - if (!isset($alert_value['permission'])) |
|
| 2009 | - continue; |
|
| 2109 | + if (!isset($alert_value['permission'])) { |
|
| 2110 | + continue; |
|
| 2111 | + } |
|
| 2010 | 2112 | if (!isset($perms_cache[$alert_value['permission']['name']])) |
| 2011 | 2113 | { |
| 2012 | 2114 | $in_board = !empty($alert_value['permission']['is_board']) ? 0 : null; |
@@ -2014,12 +2116,14 @@ discard block |
||
| 2014 | 2116 | $perms_cache[$alert_value['permission']['name']] = in_array($memID, $members); |
| 2015 | 2117 | } |
| 2016 | 2118 | |
| 2017 | - if (!$perms_cache[$alert_value['permission']['name']]) |
|
| 2018 | - unset ($alert_types[$group][$alert_key]); |
|
| 2119 | + if (!$perms_cache[$alert_value['permission']['name']]) { |
|
| 2120 | + unset ($alert_types[$group][$alert_key]); |
|
| 2121 | + } |
|
| 2019 | 2122 | } |
| 2020 | 2123 | |
| 2021 | - if (empty($alert_types[$group])) |
|
| 2022 | - unset ($alert_types[$group]); |
|
| 2124 | + if (empty($alert_types[$group])) { |
|
| 2125 | + unset ($alert_types[$group]); |
|
| 2126 | + } |
|
| 2023 | 2127 | } |
| 2024 | 2128 | } |
| 2025 | 2129 | |
@@ -2051,9 +2155,9 @@ discard block |
||
| 2051 | 2155 | $update_prefs[$this_option[1]] = !empty($_POST['opt_' . $this_option[1]]) ? 1 : 0; |
| 2052 | 2156 | break; |
| 2053 | 2157 | case 'select': |
| 2054 | - if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) |
|
| 2055 | - $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2056 | - else |
|
| 2158 | + if (isset($_POST['opt_' . $this_option[1]], $this_option['opts'][$_POST['opt_' . $this_option[1]]])) { |
|
| 2159 | + $update_prefs[$this_option[1]] = $_POST['opt_' . $this_option[1]]; |
|
| 2160 | + } else |
|
| 2057 | 2161 | { |
| 2058 | 2162 | // We didn't have a sane value. Let's grab the first item from the possibles. |
| 2059 | 2163 | $keys = array_keys($this_option['opts']); |
@@ -2073,23 +2177,28 @@ discard block |
||
| 2073 | 2177 | $this_value = 0; |
| 2074 | 2178 | foreach ($context['alert_bits'] as $type => $bitvalue) |
| 2075 | 2179 | { |
| 2076 | - if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') |
|
| 2077 | - $this_value |= $bitvalue; |
|
| 2180 | + if ($this_options[$type] == 'yes' && !empty($_POST[$type . '_' . $item_key]) || $this_options[$type] == 'always') { |
|
| 2181 | + $this_value |= $bitvalue; |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) { |
|
| 2185 | + $update_prefs[$item_key] = $this_value; |
|
| 2078 | 2186 | } |
| 2079 | - if (!isset($context['alert_prefs'][$item_key]) || $context['alert_prefs'][$item_key] != $this_value) |
|
| 2080 | - $update_prefs[$item_key] = $this_value; |
|
| 2081 | 2187 | } |
| 2082 | 2188 | } |
| 2083 | 2189 | |
| 2084 | - if (!empty($_POST['opt_alert_timeout'])) |
|
| 2085 | - $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2190 | + if (!empty($_POST['opt_alert_timeout'])) { |
|
| 2191 | + $update_prefs['alert_timeout'] = $context['member']['alert_timeout'] = (int) $_POST['opt_alert_timeout']; |
|
| 2192 | + } |
|
| 2086 | 2193 | |
| 2087 | - if (!empty($_POST['notify_announcements'])) |
|
| 2088 | - $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2194 | + if (!empty($_POST['notify_announcements'])) { |
|
| 2195 | + $update_prefs['announcements'] = $context['member']['notify_announcements'] = (int) $_POST['notify_announcements']; |
|
| 2196 | + } |
|
| 2089 | 2197 | |
| 2090 | 2198 | setNotifyPrefs((int) $memID, $update_prefs); |
| 2091 | - foreach ($update_prefs as $pref => $value) |
|
| 2092 | - $context['alert_prefs'][$pref] = $value; |
|
| 2199 | + foreach ($update_prefs as $pref => $value) { |
|
| 2200 | + $context['alert_prefs'][$pref] = $value; |
|
| 2201 | + } |
|
| 2093 | 2202 | |
| 2094 | 2203 | makeNotificationChanges($memID); |
| 2095 | 2204 | |
@@ -2119,8 +2228,9 @@ discard block |
||
| 2119 | 2228 | |
| 2120 | 2229 | // Now we're all set up. |
| 2121 | 2230 | is_not_guest(); |
| 2122 | - if (!$context['user']['is_owner']) |
|
| 2123 | - fatal_error('no_access'); |
|
| 2231 | + if (!$context['user']['is_owner']) { |
|
| 2232 | + fatal_error('no_access'); |
|
| 2233 | + } |
|
| 2124 | 2234 | |
| 2125 | 2235 | checkSession('get'); |
| 2126 | 2236 | |
@@ -2152,8 +2262,9 @@ discard block |
||
| 2152 | 2262 | { |
| 2153 | 2263 | global $smcFunc; |
| 2154 | 2264 | |
| 2155 | - if (empty($toMark) || empty($memID)) |
|
| 2156 | - return false; |
|
| 2265 | + if (empty($toMark) || empty($memID)) { |
|
| 2266 | + return false; |
|
| 2267 | + } |
|
| 2157 | 2268 | |
| 2158 | 2269 | $toMark = (array) $toMark; |
| 2159 | 2270 | |
@@ -2187,8 +2298,9 @@ discard block |
||
| 2187 | 2298 | { |
| 2188 | 2299 | global $smcFunc; |
| 2189 | 2300 | |
| 2190 | - if (empty($toDelete)) |
|
| 2191 | - return false; |
|
| 2301 | + if (empty($toDelete)) { |
|
| 2302 | + return false; |
|
| 2303 | + } |
|
| 2192 | 2304 | |
| 2193 | 2305 | $toDelete = (array) $toDelete; |
| 2194 | 2306 | |
@@ -2223,8 +2335,9 @@ discard block |
||
| 2223 | 2335 | { |
| 2224 | 2336 | global $smcFunc; |
| 2225 | 2337 | |
| 2226 | - if (empty($memID)) |
|
| 2227 | - return false; |
|
| 2338 | + if (empty($memID)) { |
|
| 2339 | + return false; |
|
| 2340 | + } |
|
| 2228 | 2341 | |
| 2229 | 2342 | $request = $smcFunc['db_query']('', ' |
| 2230 | 2343 | SELECT id_alert |
@@ -2301,8 +2414,9 @@ discard block |
||
| 2301 | 2414 | { |
| 2302 | 2415 | $link = $topic['link']; |
| 2303 | 2416 | |
| 2304 | - if ($topic['new']) |
|
| 2305 | - $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2417 | + if ($topic['new']) { |
|
| 2418 | + $link .= ' <a href="' . $topic['new_href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2419 | + } |
|
| 2306 | 2420 | |
| 2307 | 2421 | $link .= '<br><span class="smalltext"><em>' . $txt['in'] . ' ' . $topic['board_link'] . '</em></span>'; |
| 2308 | 2422 | |
@@ -2453,8 +2567,9 @@ discard block |
||
| 2453 | 2567 | { |
| 2454 | 2568 | $link = $board['link']; |
| 2455 | 2569 | |
| 2456 | - if ($board['new']) |
|
| 2457 | - $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2570 | + if ($board['new']) { |
|
| 2571 | + $link .= ' <a href="' . $board['href'] . '"><span class="new_posts">' . $txt['new'] . '</span></a>'; |
|
| 2572 | + } |
|
| 2458 | 2573 | |
| 2459 | 2574 | return $link; |
| 2460 | 2575 | }, |
@@ -2654,8 +2769,8 @@ discard block |
||
| 2654 | 2769 | ) |
| 2655 | 2770 | ); |
| 2656 | 2771 | $notification_boards = array(); |
| 2657 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 2658 | - $notification_boards[] = array( |
|
| 2772 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 2773 | + $notification_boards[] = array( |
|
| 2659 | 2774 | 'id' => $row['id_board'], |
| 2660 | 2775 | 'name' => $row['name'], |
| 2661 | 2776 | 'href' => $scripturl . '?board=' . $row['id_board'] . '.0', |
@@ -2663,6 +2778,7 @@ discard block |
||
| 2663 | 2778 | 'new' => $row['board_read'] < $row['id_msg_updated'], |
| 2664 | 2779 | 'notify_pref' => isset($prefs['board_notify_' . $row['id_board']]) ? $prefs['board_notify_' . $row['id_board']] : (!empty($prefs['board_notify']) ? $prefs['board_notify'] : 0), |
| 2665 | 2780 | ); |
| 2781 | + } |
|
| 2666 | 2782 | $smcFunc['db_free_result']($request); |
| 2667 | 2783 | |
| 2668 | 2784 | return $notification_boards; |
@@ -2677,17 +2793,18 @@ discard block |
||
| 2677 | 2793 | { |
| 2678 | 2794 | global $context, $options, $cur_profile, $smcFunc; |
| 2679 | 2795 | |
| 2680 | - if (isset($_POST['default_options'])) |
|
| 2681 | - $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2796 | + if (isset($_POST['default_options'])) { |
|
| 2797 | + $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; |
|
| 2798 | + } |
|
| 2682 | 2799 | |
| 2683 | 2800 | if ($context['user']['is_owner']) |
| 2684 | 2801 | { |
| 2685 | 2802 | $context['member']['options'] = $options; |
| 2686 | - if (isset($_POST['options']) && is_array($_POST['options'])) |
|
| 2687 | - foreach ($_POST['options'] as $k => $v) |
|
| 2803 | + if (isset($_POST['options']) && is_array($_POST['options'])) { |
|
| 2804 | + foreach ($_POST['options'] as $k => $v) |
|
| 2688 | 2805 | $context['member']['options'][$k] = $v; |
| 2689 | - } |
|
| 2690 | - else |
|
| 2806 | + } |
|
| 2807 | + } else |
|
| 2691 | 2808 | { |
| 2692 | 2809 | $request = $smcFunc['db_query']('', ' |
| 2693 | 2810 | SELECT id_member, variable, value |
@@ -2708,8 +2825,9 @@ discard block |
||
| 2708 | 2825 | continue; |
| 2709 | 2826 | } |
| 2710 | 2827 | |
| 2711 | - if (isset($_POST['options'][$row['variable']])) |
|
| 2712 | - $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2828 | + if (isset($_POST['options'][$row['variable']])) { |
|
| 2829 | + $row['value'] = $_POST['options'][$row['variable']]; |
|
| 2830 | + } |
|
| 2713 | 2831 | $context['member']['options'][$row['variable']] = $row['value']; |
| 2714 | 2832 | } |
| 2715 | 2833 | $smcFunc['db_free_result']($request); |
@@ -2717,8 +2835,9 @@ discard block |
||
| 2717 | 2835 | // Load up the default theme options for any missing. |
| 2718 | 2836 | foreach ($temp as $k => $v) |
| 2719 | 2837 | { |
| 2720 | - if (!isset($context['member']['options'][$k])) |
|
| 2721 | - $context['member']['options'][$k] = $v; |
|
| 2838 | + if (!isset($context['member']['options'][$k])) { |
|
| 2839 | + $context['member']['options'][$k] = $v; |
|
| 2840 | + } |
|
| 2722 | 2841 | } |
| 2723 | 2842 | } |
| 2724 | 2843 | } |
@@ -2733,8 +2852,9 @@ discard block |
||
| 2733 | 2852 | global $context, $modSettings, $smcFunc, $cur_profile, $sourcedir; |
| 2734 | 2853 | |
| 2735 | 2854 | // Have the admins enabled this option? |
| 2736 | - if (empty($modSettings['allow_ignore_boards'])) |
|
| 2737 | - fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2855 | + if (empty($modSettings['allow_ignore_boards'])) { |
|
| 2856 | + fatal_lang_error('ignoreboards_disallowed', 'user'); |
|
| 2857 | + } |
|
| 2738 | 2858 | |
| 2739 | 2859 | // Find all the boards this user is allowed to see. |
| 2740 | 2860 | $request = $smcFunc['db_query']('order_by_board_order', ' |
@@ -2754,12 +2874,13 @@ discard block |
||
| 2754 | 2874 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2755 | 2875 | { |
| 2756 | 2876 | // This category hasn't been set up yet.. |
| 2757 | - if (!isset($context['categories'][$row['id_cat']])) |
|
| 2758 | - $context['categories'][$row['id_cat']] = array( |
|
| 2877 | + if (!isset($context['categories'][$row['id_cat']])) { |
|
| 2878 | + $context['categories'][$row['id_cat']] = array( |
|
| 2759 | 2879 | 'id' => $row['id_cat'], |
| 2760 | 2880 | 'name' => $row['cat_name'], |
| 2761 | 2881 | 'boards' => array() |
| 2762 | 2882 | ); |
| 2883 | + } |
|
| 2763 | 2884 | |
| 2764 | 2885 | // Set this board up, and let the template know when it's a child. (indent them..) |
| 2765 | 2886 | $context['categories'][$row['id_cat']]['boards'][$row['id_board']] = array( |
@@ -2789,18 +2910,20 @@ discard block |
||
| 2789 | 2910 | } |
| 2790 | 2911 | |
| 2791 | 2912 | $max_boards = ceil(count($temp_boards) / 2); |
| 2792 | - if ($max_boards == 1) |
|
| 2793 | - $max_boards = 2; |
|
| 2913 | + if ($max_boards == 1) { |
|
| 2914 | + $max_boards = 2; |
|
| 2915 | + } |
|
| 2794 | 2916 | |
| 2795 | 2917 | // Now, alternate them so they can be shown left and right ;). |
| 2796 | 2918 | $context['board_columns'] = array(); |
| 2797 | 2919 | for ($i = 0; $i < $max_boards; $i++) |
| 2798 | 2920 | { |
| 2799 | 2921 | $context['board_columns'][] = $temp_boards[$i]; |
| 2800 | - if (isset($temp_boards[$i + $max_boards])) |
|
| 2801 | - $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2802 | - else |
|
| 2803 | - $context['board_columns'][] = array(); |
|
| 2922 | + if (isset($temp_boards[$i + $max_boards])) { |
|
| 2923 | + $context['board_columns'][] = $temp_boards[$i + $max_boards]; |
|
| 2924 | + } else { |
|
| 2925 | + $context['board_columns'][] = array(); |
|
| 2926 | + } |
|
| 2804 | 2927 | } |
| 2805 | 2928 | |
| 2806 | 2929 | loadThemeOptions($memID); |
@@ -2869,8 +2992,9 @@ discard block |
||
| 2869 | 2992 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2870 | 2993 | { |
| 2871 | 2994 | // We should skip the administrator group if they don't have the admin_forum permission! |
| 2872 | - if ($row['id_group'] == 1 && !allowedTo('admin_forum')) |
|
| 2873 | - continue; |
|
| 2995 | + if ($row['id_group'] == 1 && !allowedTo('admin_forum')) { |
|
| 2996 | + continue; |
|
| 2997 | + } |
|
| 2874 | 2998 | |
| 2875 | 2999 | $context['member_groups'][$row['id_group']] = array( |
| 2876 | 3000 | 'id' => $row['id_group'], |
@@ -2916,16 +3040,17 @@ discard block |
||
| 2916 | 3040 | $context['max_signature_length'] = $context['signature_limits']['max_length']; |
| 2917 | 3041 | // Warning message for signature image limits? |
| 2918 | 3042 | $context['signature_warning'] = ''; |
| 2919 | - if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) |
|
| 2920 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 2921 | - elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) |
|
| 2922 | - $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3043 | + if ($context['signature_limits']['max_image_width'] && $context['signature_limits']['max_image_height']) { |
|
| 3044 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_size'], $context['signature_limits']['max_image_width'], $context['signature_limits']['max_image_height']); |
|
| 3045 | + } elseif ($context['signature_limits']['max_image_width'] || $context['signature_limits']['max_image_height']) { |
|
| 3046 | + $context['signature_warning'] = sprintf($txt['profile_error_signature_max_image_' . ($context['signature_limits']['max_image_width'] ? 'width' : 'height')], $context['signature_limits'][$context['signature_limits']['max_image_width'] ? 'max_image_width' : 'max_image_height']); |
|
| 3047 | + } |
|
| 2923 | 3048 | |
| 2924 | 3049 | $context['show_spellchecking'] = !empty($modSettings['enableSpellChecking']) && (function_exists('pspell_new') || (function_exists('enchant_broker_init') && ($txt['lang_charset'] == 'UTF-8' || function_exists('iconv')))); |
| 2925 | 3050 | |
| 2926 | - if (empty($context['do_preview'])) |
|
| 2927 | - $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 2928 | - else |
|
| 3051 | + if (empty($context['do_preview'])) { |
|
| 3052 | + $context['member']['signature'] = empty($cur_profile['signature']) ? '' : str_replace(array('<br>', '<', '>', '"', '\''), array("\n", '<', '>', '"', '''), $cur_profile['signature']); |
|
| 3053 | + } else |
|
| 2929 | 3054 | { |
| 2930 | 3055 | $signature = !empty($_POST['signature']) ? $_POST['signature'] : ''; |
| 2931 | 3056 | $validation = profileValidateSignature($signature); |
@@ -2935,8 +3060,9 @@ discard block |
||
| 2935 | 3060 | $context['post_errors'] = array(); |
| 2936 | 3061 | } |
| 2937 | 3062 | $context['post_errors'][] = 'signature_not_yet_saved'; |
| 2938 | - if ($validation !== true && $validation !== false) |
|
| 2939 | - $context['post_errors'][] = $validation; |
|
| 3063 | + if ($validation !== true && $validation !== false) { |
|
| 3064 | + $context['post_errors'][] = $validation; |
|
| 3065 | + } |
|
| 2940 | 3066 | |
| 2941 | 3067 | censorText($context['member']['signature']); |
| 2942 | 3068 | $context['member']['current_signature'] = $context['member']['signature']; |
@@ -2946,8 +3072,9 @@ discard block |
||
| 2946 | 3072 | } |
| 2947 | 3073 | |
| 2948 | 3074 | // Load the spell checker? |
| 2949 | - if ($context['show_spellchecking']) |
|
| 2950 | - loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3075 | + if ($context['show_spellchecking']) { |
|
| 3076 | + loadJavaScriptFile('spellcheck.js', array('defer' => false), 'smf_spellcheck'); |
|
| 3077 | + } |
|
| 2951 | 3078 | |
| 2952 | 3079 | return true; |
| 2953 | 3080 | } |
@@ -2981,8 +3108,7 @@ discard block |
||
| 2981 | 3108 | 'external' => $cur_profile['avatar'] == 'gravatar://' || empty($modSettings['gravatarAllowExtraEmail']) || !empty($modSettings['gravatarOverride']) ? $cur_profile['email_address'] : substr($cur_profile['avatar'], 11) |
| 2982 | 3109 | ); |
| 2983 | 3110 | $context['member']['avatar']['href'] = get_gravatar_url($context['member']['avatar']['external']); |
| 2984 | - } |
|
| 2985 | - elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 3111 | + } elseif ($cur_profile['avatar'] == '' && $cur_profile['id_attach'] > 0 && $context['member']['avatar']['allow_upload']) |
|
| 2986 | 3112 | { |
| 2987 | 3113 | $context['member']['avatar'] += array( |
| 2988 | 3114 | 'choice' => 'upload', |
@@ -2992,33 +3118,34 @@ discard block |
||
| 2992 | 3118 | $context['member']['avatar']['href'] = empty($cur_profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $cur_profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $cur_profile['filename']; |
| 2993 | 3119 | } |
| 2994 | 3120 | // Use "avatar_original" here so we show what the user entered even if the image proxy is enabled |
| 2995 | - elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) |
|
| 2996 | - $context['member']['avatar'] += array( |
|
| 3121 | + elseif ((stristr($cur_profile['avatar'], 'http://') || stristr($cur_profile['avatar'], 'https://')) && $context['member']['avatar']['allow_external']) { |
|
| 3122 | + $context['member']['avatar'] += array( |
|
| 2997 | 3123 | 'choice' => 'external', |
| 2998 | 3124 | 'server_pic' => 'blank.png', |
| 2999 | 3125 | 'external' => $cur_profile['avatar_original'] |
| 3000 | 3126 | ); |
| 3001 | - elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) |
|
| 3002 | - $context['member']['avatar'] += array( |
|
| 3127 | + } elseif ($cur_profile['avatar'] != '' && file_exists($modSettings['avatar_directory'] . '/' . $cur_profile['avatar']) && $context['member']['avatar']['allow_server_stored']) { |
|
| 3128 | + $context['member']['avatar'] += array( |
|
| 3003 | 3129 | 'choice' => 'server_stored', |
| 3004 | 3130 | 'server_pic' => $cur_profile['avatar'] == '' ? 'blank.png' : $cur_profile['avatar'], |
| 3005 | 3131 | 'external' => 'http://' |
| 3006 | 3132 | ); |
| 3007 | - else |
|
| 3008 | - $context['member']['avatar'] += array( |
|
| 3133 | + } else { |
|
| 3134 | + $context['member']['avatar'] += array( |
|
| 3009 | 3135 | 'choice' => 'none', |
| 3010 | 3136 | 'server_pic' => 'blank.png', |
| 3011 | 3137 | 'external' => 'http://' |
| 3012 | 3138 | ); |
| 3139 | + } |
|
| 3013 | 3140 | |
| 3014 | 3141 | // Get a list of all the avatars. |
| 3015 | 3142 | if ($context['member']['avatar']['allow_server_stored']) |
| 3016 | 3143 | { |
| 3017 | 3144 | $context['avatar_list'] = array(); |
| 3018 | 3145 | $context['avatars'] = is_dir($modSettings['avatar_directory']) ? getAvatars('', 0) : array(); |
| 3146 | + } else { |
|
| 3147 | + $context['avatars'] = array(); |
|
| 3019 | 3148 | } |
| 3020 | - else |
|
| 3021 | - $context['avatars'] = array(); |
|
| 3022 | 3149 | |
| 3023 | 3150 | // Second level selected avatar... |
| 3024 | 3151 | $context['avatar_selected'] = substr(strrchr($context['member']['avatar']['server_pic'], '/'), 1); |
@@ -3047,19 +3174,22 @@ discard block |
||
| 3047 | 3174 | ) |
| 3048 | 3175 | ); |
| 3049 | 3176 | $protected_groups = array(1); |
| 3050 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 3051 | - $protected_groups[] = $row['id_group']; |
|
| 3177 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 3178 | + $protected_groups[] = $row['id_group']; |
|
| 3179 | + } |
|
| 3052 | 3180 | $smcFunc['db_free_result']($request); |
| 3053 | 3181 | |
| 3054 | 3182 | $protected_groups = array_unique($protected_groups); |
| 3055 | 3183 | } |
| 3056 | 3184 | |
| 3057 | 3185 | // The account page allows the change of your id_group - but not to a protected group! |
| 3058 | - if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) |
|
| 3059 | - $value = (int) $value; |
|
| 3186 | + if (empty($protected_groups) || count(array_intersect(array((int) $value, $old_profile['id_group']), $protected_groups)) == 0) { |
|
| 3187 | + $value = (int) $value; |
|
| 3188 | + } |
|
| 3060 | 3189 | // ... otherwise it's the old group sir. |
| 3061 | - else |
|
| 3062 | - $value = $old_profile['id_group']; |
|
| 3190 | + else { |
|
| 3191 | + $value = $old_profile['id_group']; |
|
| 3192 | + } |
|
| 3063 | 3193 | |
| 3064 | 3194 | // Find the additional membergroups (if any) |
| 3065 | 3195 | if (isset($_POST['additional_groups']) && is_array($_POST['additional_groups'])) |
@@ -3068,16 +3198,18 @@ discard block |
||
| 3068 | 3198 | foreach ($_POST['additional_groups'] as $group_id) |
| 3069 | 3199 | { |
| 3070 | 3200 | $group_id = (int) $group_id; |
| 3071 | - if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) |
|
| 3072 | - $additional_groups[] = $group_id; |
|
| 3201 | + if (!empty($group_id) && (empty($protected_groups) || !in_array($group_id, $protected_groups))) { |
|
| 3202 | + $additional_groups[] = $group_id; |
|
| 3203 | + } |
|
| 3073 | 3204 | } |
| 3074 | 3205 | |
| 3075 | 3206 | // Put the protected groups back in there if you don't have permission to take them away. |
| 3076 | 3207 | $old_additional_groups = explode(',', $old_profile['additional_groups']); |
| 3077 | 3208 | foreach ($old_additional_groups as $group_id) |
| 3078 | 3209 | { |
| 3079 | - if (!empty($protected_groups) && in_array($group_id, $protected_groups)) |
|
| 3080 | - $additional_groups[] = $group_id; |
|
| 3210 | + if (!empty($protected_groups) && in_array($group_id, $protected_groups)) { |
|
| 3211 | + $additional_groups[] = $group_id; |
|
| 3212 | + } |
|
| 3081 | 3213 | } |
| 3082 | 3214 | |
| 3083 | 3215 | if (implode(',', $additional_groups) !== $old_profile['additional_groups']) |
@@ -3109,18 +3241,20 @@ discard block |
||
| 3109 | 3241 | list ($another) = $smcFunc['db_fetch_row']($request); |
| 3110 | 3242 | $smcFunc['db_free_result']($request); |
| 3111 | 3243 | |
| 3112 | - if (empty($another)) |
|
| 3113 | - fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3244 | + if (empty($another)) { |
|
| 3245 | + fatal_lang_error('at_least_one_admin', 'critical'); |
|
| 3246 | + } |
|
| 3114 | 3247 | } |
| 3115 | 3248 | } |
| 3116 | 3249 | |
| 3117 | 3250 | // If we are changing group status, update permission cache as necessary. |
| 3118 | 3251 | if ($value != $old_profile['id_group'] || isset($profile_vars['additional_groups'])) |
| 3119 | 3252 | { |
| 3120 | - if ($context['user']['is_owner']) |
|
| 3121 | - $_SESSION['mc']['time'] = 0; |
|
| 3122 | - else |
|
| 3123 | - updateSettings(array('settings_updated' => time())); |
|
| 3253 | + if ($context['user']['is_owner']) { |
|
| 3254 | + $_SESSION['mc']['time'] = 0; |
|
| 3255 | + } else { |
|
| 3256 | + updateSettings(array('settings_updated' => time())); |
|
| 3257 | + } |
|
| 3124 | 3258 | } |
| 3125 | 3259 | |
| 3126 | 3260 | // Announce to any hooks that we have changed groups, but don't allow them to change it. |
@@ -3141,8 +3275,9 @@ discard block |
||
| 3141 | 3275 | global $modSettings, $sourcedir, $smcFunc, $profile_vars, $cur_profile, $context; |
| 3142 | 3276 | |
| 3143 | 3277 | $memID = $context['id_member']; |
| 3144 | - if (empty($memID) && !empty($context['password_auth_failed'])) |
|
| 3145 | - return false; |
|
| 3278 | + if (empty($memID) && !empty($context['password_auth_failed'])) { |
|
| 3279 | + return false; |
|
| 3280 | + } |
|
| 3146 | 3281 | |
| 3147 | 3282 | require_once($sourcedir . '/ManageAttachments.php'); |
| 3148 | 3283 | |
@@ -3153,8 +3288,9 @@ discard block |
||
| 3153 | 3288 | $downloadedExternalAvatar = false; |
| 3154 | 3289 | if ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && strlen($_POST['userpicpersonal']) > 7 && !empty($modSettings['avatar_download_external'])) |
| 3155 | 3290 | { |
| 3156 | - if (!is_writable($uploadDir)) |
|
| 3157 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3291 | + if (!is_writable($uploadDir)) { |
|
| 3292 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3293 | + } |
|
| 3158 | 3294 | |
| 3159 | 3295 | require_once($sourcedir . '/Subs-Package.php'); |
| 3160 | 3296 | |
@@ -3198,19 +3334,18 @@ discard block |
||
| 3198 | 3334 | |
| 3199 | 3335 | // Get rid of their old avatar. (if uploaded.) |
| 3200 | 3336 | removeAttachments(array('id_member' => $memID)); |
| 3201 | - } |
|
| 3202 | - elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3337 | + } elseif ($value == 'gravatar' && !empty($modSettings['gravatarEnabled'])) |
|
| 3203 | 3338 | { |
| 3204 | 3339 | // One wasn't specified, or it's not allowed to use extra email addresses, or it's not a valid one, reset to default Gravatar. |
| 3205 | - if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) |
|
| 3206 | - $profile_vars['avatar'] = 'gravatar://'; |
|
| 3207 | - else |
|
| 3208 | - $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3340 | + if (empty($_POST['gravatarEmail']) || empty($modSettings['gravatarAllowExtraEmail']) || !filter_var($_POST['gravatarEmail'], FILTER_VALIDATE_EMAIL)) { |
|
| 3341 | + $profile_vars['avatar'] = 'gravatar://'; |
|
| 3342 | + } else { |
|
| 3343 | + $profile_vars['avatar'] = 'gravatar://' . ($_POST['gravatarEmail'] != $cur_profile['email_address'] ? $_POST['gravatarEmail'] : ''); |
|
| 3344 | + } |
|
| 3209 | 3345 | |
| 3210 | 3346 | // Get rid of their old avatar. (if uploaded.) |
| 3211 | 3347 | removeAttachments(array('id_member' => $memID)); |
| 3212 | - } |
|
| 3213 | - elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3348 | + } elseif ($value == 'external' && allowedTo('profile_remote_avatar') && (stripos($_POST['userpicpersonal'], 'http://') === 0 || stripos($_POST['userpicpersonal'], 'https://') === 0) && empty($modSettings['avatar_download_external'])) |
|
| 3214 | 3349 | { |
| 3215 | 3350 | // We need these clean... |
| 3216 | 3351 | $cur_profile['id_attach'] = 0; |
@@ -3222,11 +3357,13 @@ discard block |
||
| 3222 | 3357 | |
| 3223 | 3358 | $profile_vars['avatar'] = str_replace(' ', '%20', preg_replace('~action(?:=|%3d)(?!dlattach)~i', 'action-', $_POST['userpicpersonal'])); |
| 3224 | 3359 | |
| 3225 | - if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') |
|
| 3226 | - $profile_vars['avatar'] = ''; |
|
| 3360 | + if ($profile_vars['avatar'] == 'http://' || $profile_vars['avatar'] == 'http:///') { |
|
| 3361 | + $profile_vars['avatar'] = ''; |
|
| 3362 | + } |
|
| 3227 | 3363 | // Trying to make us do something we'll regret? |
| 3228 | - elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') |
|
| 3229 | - return 'bad_avatar_invalid_url'; |
|
| 3364 | + elseif (substr($profile_vars['avatar'], 0, 7) != 'http://' && substr($profile_vars['avatar'], 0, 8) != 'https://') { |
|
| 3365 | + return 'bad_avatar_invalid_url'; |
|
| 3366 | + } |
|
| 3230 | 3367 | // Should we check dimensions? |
| 3231 | 3368 | elseif (!empty($modSettings['avatar_max_height_external']) || !empty($modSettings['avatar_max_width_external'])) |
| 3232 | 3369 | { |
@@ -3236,9 +3373,9 @@ discard block |
||
| 3236 | 3373 | if (is_array($sizes) && (($sizes[0] > $modSettings['avatar_max_width_external'] && !empty($modSettings['avatar_max_width_external'])) || ($sizes[1] > $modSettings['avatar_max_height_external'] && !empty($modSettings['avatar_max_height_external'])))) |
| 3237 | 3374 | { |
| 3238 | 3375 | // Houston, we have a problem. The avatar is too large!! |
| 3239 | - if ($modSettings['avatar_action_too_large'] == 'option_refuse') |
|
| 3240 | - return 'bad_avatar_too_large'; |
|
| 3241 | - elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3376 | + if ($modSettings['avatar_action_too_large'] == 'option_refuse') { |
|
| 3377 | + return 'bad_avatar_too_large'; |
|
| 3378 | + } elseif ($modSettings['avatar_action_too_large'] == 'option_download_and_resize') |
|
| 3242 | 3379 | { |
| 3243 | 3380 | // @todo remove this if appropriate |
| 3244 | 3381 | require_once($sourcedir . '/Subs-Graphics.php'); |
@@ -3248,26 +3385,27 @@ discard block |
||
| 3248 | 3385 | $cur_profile['id_attach'] = $modSettings['new_avatar_data']['id']; |
| 3249 | 3386 | $cur_profile['filename'] = $modSettings['new_avatar_data']['filename']; |
| 3250 | 3387 | $cur_profile['attachment_type'] = $modSettings['new_avatar_data']['type']; |
| 3388 | + } else { |
|
| 3389 | + return 'bad_avatar'; |
|
| 3251 | 3390 | } |
| 3252 | - else |
|
| 3253 | - return 'bad_avatar'; |
|
| 3254 | 3391 | } |
| 3255 | 3392 | } |
| 3256 | 3393 | } |
| 3257 | - } |
|
| 3258 | - elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3394 | + } elseif (($value == 'upload' && allowedTo('profile_upload_avatar')) || $downloadedExternalAvatar) |
|
| 3259 | 3395 | { |
| 3260 | 3396 | if ((isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != '') || $downloadedExternalAvatar) |
| 3261 | 3397 | { |
| 3262 | 3398 | // Get the dimensions of the image. |
| 3263 | 3399 | if (!$downloadedExternalAvatar) |
| 3264 | 3400 | { |
| 3265 | - if (!is_writable($uploadDir)) |
|
| 3266 | - fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3401 | + if (!is_writable($uploadDir)) { |
|
| 3402 | + fatal_lang_error('attachments_no_write', 'critical'); |
|
| 3403 | + } |
|
| 3267 | 3404 | |
| 3268 | 3405 | $new_filename = $uploadDir . '/' . getAttachmentFilename('avatar_tmp_' . $memID, false, null, true); |
| 3269 | - if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) |
|
| 3270 | - fatal_lang_error('attach_timeout', 'critical'); |
|
| 3406 | + if (!move_uploaded_file($_FILES['attachment']['tmp_name'], $new_filename)) { |
|
| 3407 | + fatal_lang_error('attach_timeout', 'critical'); |
|
| 3408 | + } |
|
| 3271 | 3409 | |
| 3272 | 3410 | $_FILES['attachment']['tmp_name'] = $new_filename; |
| 3273 | 3411 | } |
@@ -3380,17 +3518,19 @@ discard block |
||
| 3380 | 3518 | $profile_vars['avatar'] = ''; |
| 3381 | 3519 | |
| 3382 | 3520 | // Delete any temporary file. |
| 3383 | - if (file_exists($_FILES['attachment']['tmp_name'])) |
|
| 3384 | - @unlink($_FILES['attachment']['tmp_name']); |
|
| 3521 | + if (file_exists($_FILES['attachment']['tmp_name'])) { |
|
| 3522 | + @unlink($_FILES['attachment']['tmp_name']); |
|
| 3523 | + } |
|
| 3385 | 3524 | } |
| 3386 | 3525 | // Selected the upload avatar option and had one already uploaded before or didn't upload one. |
| 3387 | - else |
|
| 3526 | + else { |
|
| 3527 | + $profile_vars['avatar'] = ''; |
|
| 3528 | + } |
|
| 3529 | + } elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) { |
|
| 3530 | + $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3531 | + } else { |
|
| 3388 | 3532 | $profile_vars['avatar'] = ''; |
| 3389 | 3533 | } |
| 3390 | - elseif ($value == 'gravatar' && allowedTo('profile_gravatar_avatar')) |
|
| 3391 | - $profile_vars['avatar'] = 'gravatar://www.gravatar.com/avatar/' . md5(strtolower(trim($cur_profile['email_address']))); |
|
| 3392 | - else |
|
| 3393 | - $profile_vars['avatar'] = ''; |
|
| 3394 | 3534 | |
| 3395 | 3535 | // Setup the profile variables so it shows things right on display! |
| 3396 | 3536 | $cur_profile['avatar'] = $profile_vars['avatar']; |
@@ -3438,9 +3578,9 @@ discard block |
||
| 3438 | 3578 | $smiley_parsed = $unparsed_signature; |
| 3439 | 3579 | parsesmileys($smiley_parsed); |
| 3440 | 3580 | $smiley_count = substr_count(strtolower($smiley_parsed), '<img') - substr_count(strtolower($unparsed_signature), '<img'); |
| 3441 | - if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) |
|
| 3442 | - return 'signature_allow_smileys'; |
|
| 3443 | - elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3581 | + if (!empty($sig_limits[4]) && $sig_limits[4] == -1 && $smiley_count > 0) { |
|
| 3582 | + return 'signature_allow_smileys'; |
|
| 3583 | + } elseif (!empty($sig_limits[4]) && $sig_limits[4] > 0 && $smiley_count > $sig_limits[4]) |
|
| 3444 | 3584 | { |
| 3445 | 3585 | $txt['profile_error_signature_max_smileys'] = sprintf($txt['profile_error_signature_max_smileys'], $sig_limits[4]); |
| 3446 | 3586 | return 'signature_max_smileys'; |
@@ -3453,14 +3593,15 @@ discard block |
||
| 3453 | 3593 | { |
| 3454 | 3594 | $limit_broke = 0; |
| 3455 | 3595 | // Attempt to allow all sizes of abuse, so to speak. |
| 3456 | - if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) |
|
| 3457 | - $limit_broke = $sig_limits[7] . 'px'; |
|
| 3458 | - elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) |
|
| 3459 | - $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3460 | - elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) |
|
| 3461 | - $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3462 | - elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) |
|
| 3463 | - $limit_broke = 'large'; |
|
| 3596 | + if ($matches[2][$ind] == 'px' && $size > $sig_limits[7]) { |
|
| 3597 | + $limit_broke = $sig_limits[7] . 'px'; |
|
| 3598 | + } elseif ($matches[2][$ind] == 'pt' && $size > ($sig_limits[7] * 0.75)) { |
|
| 3599 | + $limit_broke = ((int) $sig_limits[7] * 0.75) . 'pt'; |
|
| 3600 | + } elseif ($matches[2][$ind] == 'em' && $size > ((float) $sig_limits[7] / 16)) { |
|
| 3601 | + $limit_broke = ((float) $sig_limits[7] / 16) . 'em'; |
|
| 3602 | + } elseif ($matches[2][$ind] != 'px' && $matches[2][$ind] != 'pt' && $matches[2][$ind] != 'em' && $sig_limits[7] < 18) { |
|
| 3603 | + $limit_broke = 'large'; |
|
| 3604 | + } |
|
| 3464 | 3605 | |
| 3465 | 3606 | if ($limit_broke) |
| 3466 | 3607 | { |
@@ -3502,24 +3643,26 @@ discard block |
||
| 3502 | 3643 | $width = -1; $height = -1; |
| 3503 | 3644 | |
| 3504 | 3645 | // Does it have predefined restraints? Width first. |
| 3505 | - if ($matches[6][$key]) |
|
| 3506 | - $matches[2][$key] = $matches[6][$key]; |
|
| 3646 | + if ($matches[6][$key]) { |
|
| 3647 | + $matches[2][$key] = $matches[6][$key]; |
|
| 3648 | + } |
|
| 3507 | 3649 | if ($matches[2][$key] && $sig_limits[5] && $matches[2][$key] > $sig_limits[5]) |
| 3508 | 3650 | { |
| 3509 | 3651 | $width = $sig_limits[5]; |
| 3510 | 3652 | $matches[4][$key] = $matches[4][$key] * ($width / $matches[2][$key]); |
| 3653 | + } elseif ($matches[2][$key]) { |
|
| 3654 | + $width = $matches[2][$key]; |
|
| 3511 | 3655 | } |
| 3512 | - elseif ($matches[2][$key]) |
|
| 3513 | - $width = $matches[2][$key]; |
|
| 3514 | 3656 | // ... and height. |
| 3515 | 3657 | if ($matches[4][$key] && $sig_limits[6] && $matches[4][$key] > $sig_limits[6]) |
| 3516 | 3658 | { |
| 3517 | 3659 | $height = $sig_limits[6]; |
| 3518 | - if ($width != -1) |
|
| 3519 | - $width = $width * ($height / $matches[4][$key]); |
|
| 3660 | + if ($width != -1) { |
|
| 3661 | + $width = $width * ($height / $matches[4][$key]); |
|
| 3662 | + } |
|
| 3663 | + } elseif ($matches[4][$key]) { |
|
| 3664 | + $height = $matches[4][$key]; |
|
| 3520 | 3665 | } |
| 3521 | - elseif ($matches[4][$key]) |
|
| 3522 | - $height = $matches[4][$key]; |
|
| 3523 | 3666 | |
| 3524 | 3667 | // If the dimensions are still not fixed - we need to check the actual image. |
| 3525 | 3668 | if (($width == -1 && $sig_limits[5]) || ($height == -1 && $sig_limits[6])) |
@@ -3537,21 +3680,24 @@ discard block |
||
| 3537 | 3680 | if ($sizes[1] > $sig_limits[6] && $sig_limits[6]) |
| 3538 | 3681 | { |
| 3539 | 3682 | $height = $sig_limits[6]; |
| 3540 | - if ($width == -1) |
|
| 3541 | - $width = $sizes[0]; |
|
| 3683 | + if ($width == -1) { |
|
| 3684 | + $width = $sizes[0]; |
|
| 3685 | + } |
|
| 3542 | 3686 | $width = $width * ($height / $sizes[1]); |
| 3687 | + } elseif ($width != -1) { |
|
| 3688 | + $height = $sizes[1]; |
|
| 3543 | 3689 | } |
| 3544 | - elseif ($width != -1) |
|
| 3545 | - $height = $sizes[1]; |
|
| 3546 | 3690 | } |
| 3547 | 3691 | } |
| 3548 | 3692 | |
| 3549 | 3693 | // Did we come up with some changes? If so remake the string. |
| 3550 | - if ($width != -1 || $height != -1) |
|
| 3551 | - $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3694 | + if ($width != -1 || $height != -1) { |
|
| 3695 | + $replaces[$image] = '[img' . ($width != -1 ? ' width=' . round($width) : '') . ($height != -1 ? ' height=' . round($height) : '') . ']' . $matches[7][$key] . '[/img]'; |
|
| 3696 | + } |
|
| 3697 | + } |
|
| 3698 | + if (!empty($replaces)) { |
|
| 3699 | + $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3552 | 3700 | } |
| 3553 | - if (!empty($replaces)) |
|
| 3554 | - $value = str_replace(array_keys($replaces), array_values($replaces), $value); |
|
| 3555 | 3701 | } |
| 3556 | 3702 | } |
| 3557 | 3703 | |
@@ -3595,10 +3741,12 @@ discard block |
||
| 3595 | 3741 | $email = strtr($email, array(''' => '\'')); |
| 3596 | 3742 | |
| 3597 | 3743 | // Check the name and email for validity. |
| 3598 | - if (trim($email) == '') |
|
| 3599 | - return 'no_email'; |
|
| 3600 | - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) |
|
| 3601 | - return 'bad_email'; |
|
| 3744 | + if (trim($email) == '') { |
|
| 3745 | + return 'no_email'; |
|
| 3746 | + } |
|
| 3747 | + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
|
| 3748 | + return 'bad_email'; |
|
| 3749 | + } |
|
| 3602 | 3750 | |
| 3603 | 3751 | // Email addresses should be and stay unique. |
| 3604 | 3752 | $request = $smcFunc['db_query']('', ' |
@@ -3613,8 +3761,9 @@ discard block |
||
| 3613 | 3761 | ) |
| 3614 | 3762 | ); |
| 3615 | 3763 | |
| 3616 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
| 3617 | - return 'email_taken'; |
|
| 3764 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
| 3765 | + return 'email_taken'; |
|
| 3766 | + } |
|
| 3618 | 3767 | $smcFunc['db_free_result']($request); |
| 3619 | 3768 | |
| 3620 | 3769 | return true; |
@@ -3627,8 +3776,9 @@ discard block |
||
| 3627 | 3776 | { |
| 3628 | 3777 | global $modSettings, $context, $cur_profile; |
| 3629 | 3778 | |
| 3630 | - if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') |
|
| 3631 | - setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3779 | + if (isset($_POST['passwrd2']) && $_POST['passwrd2'] != '') { |
|
| 3780 | + setLoginCookie(60 * $modSettings['cookieTime'], $context['id_member'], hash_salt($_POST['passwrd1'], $cur_profile['password_salt'])); |
|
| 3781 | + } |
|
| 3632 | 3782 | |
| 3633 | 3783 | loadUserSettings(); |
| 3634 | 3784 | writeLog(); |
@@ -3644,8 +3794,9 @@ discard block |
||
| 3644 | 3794 | require_once($sourcedir . '/Subs-Post.php'); |
| 3645 | 3795 | |
| 3646 | 3796 | // Shouldn't happen but just in case. |
| 3647 | - if (empty($profile_vars['email_address'])) |
|
| 3648 | - return; |
|
| 3797 | + if (empty($profile_vars['email_address'])) { |
|
| 3798 | + return; |
|
| 3799 | + } |
|
| 3649 | 3800 | |
| 3650 | 3801 | $replacements = array( |
| 3651 | 3802 | 'ACTIVATIONLINK' => $scripturl . '?action=activate;u=' . $context['id_member'] . ';code=' . $profile_vars['validation_code'], |
@@ -3668,8 +3819,9 @@ discard block |
||
| 3668 | 3819 | $_SESSION['log_time'] = 0; |
| 3669 | 3820 | $_SESSION['login_' . $cookiename] = json_encode(array(0, '', 0)); |
| 3670 | 3821 | |
| 3671 | - if (isset($_COOKIE[$cookiename])) |
|
| 3672 | - $_COOKIE[$cookiename] = ''; |
|
| 3822 | + if (isset($_COOKIE[$cookiename])) { |
|
| 3823 | + $_COOKIE[$cookiename] = ''; |
|
| 3824 | + } |
|
| 3673 | 3825 | |
| 3674 | 3826 | loadUserSettings(); |
| 3675 | 3827 | |
@@ -3702,11 +3854,13 @@ discard block |
||
| 3702 | 3854 | $groups[] = $curMember['id_group']; |
| 3703 | 3855 | |
| 3704 | 3856 | // Ensure the query doesn't croak! |
| 3705 | - if (empty($groups)) |
|
| 3706 | - $groups = array(0); |
|
| 3857 | + if (empty($groups)) { |
|
| 3858 | + $groups = array(0); |
|
| 3859 | + } |
|
| 3707 | 3860 | // Just to be sure... |
| 3708 | - foreach ($groups as $k => $v) |
|
| 3709 | - $groups[$k] = (int) $v; |
|
| 3861 | + foreach ($groups as $k => $v) { |
|
| 3862 | + $groups[$k] = (int) $v; |
|
| 3863 | + } |
|
| 3710 | 3864 | |
| 3711 | 3865 | // Get all the membergroups they can join. |
| 3712 | 3866 | $request = $smcFunc['db_query']('', ' |
@@ -3736,12 +3890,14 @@ discard block |
||
| 3736 | 3890 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 3737 | 3891 | { |
| 3738 | 3892 | // Can they edit their primary group? |
| 3739 | - if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) |
|
| 3740 | - $context['can_edit_primary'] = true; |
|
| 3893 | + if (($row['id_group'] == $context['primary_group'] && $row['group_type'] > 1) || ($row['hidden'] != 2 && $context['primary_group'] == 0 && in_array($row['id_group'], $groups))) { |
|
| 3894 | + $context['can_edit_primary'] = true; |
|
| 3895 | + } |
|
| 3741 | 3896 | |
| 3742 | 3897 | // If they can't manage (protected) groups, and it's not publically joinable or already assigned, they can't see it. |
| 3743 | - if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) |
|
| 3744 | - continue; |
|
| 3898 | + if (((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) && $row['id_group'] != $context['primary_group']) { |
|
| 3899 | + continue; |
|
| 3900 | + } |
|
| 3745 | 3901 | |
| 3746 | 3902 | $context['groups'][in_array($row['id_group'], $groups) ? 'member' : 'available'][$row['id_group']] = array( |
| 3747 | 3903 | 'id' => $row['id_group'], |
@@ -3770,13 +3926,15 @@ discard block |
||
| 3770 | 3926 | ); |
| 3771 | 3927 | |
| 3772 | 3928 | // No changing primary one unless you have enough groups! |
| 3773 | - if (count($context['groups']['member']) < 2) |
|
| 3774 | - $context['can_edit_primary'] = false; |
|
| 3929 | + if (count($context['groups']['member']) < 2) { |
|
| 3930 | + $context['can_edit_primary'] = false; |
|
| 3931 | + } |
|
| 3775 | 3932 | |
| 3776 | 3933 | // In the special case that someone is requesting membership of a group, setup some special context vars. |
| 3777 | - if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) |
|
| 3778 | - $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3779 | -} |
|
| 3934 | + if (isset($_REQUEST['request']) && isset($context['groups']['available'][(int) $_REQUEST['request']]) && $context['groups']['available'][(int) $_REQUEST['request']]['type'] == 2) { |
|
| 3935 | + $context['group_request'] = $context['groups']['available'][(int) $_REQUEST['request']]; |
|
| 3936 | + } |
|
| 3937 | + } |
|
| 3780 | 3938 | |
| 3781 | 3939 | /** |
| 3782 | 3940 | * This function actually makes all the group changes |
@@ -3791,10 +3949,12 @@ discard block |
||
| 3791 | 3949 | global $user_info, $context, $user_profile, $modSettings, $smcFunc; |
| 3792 | 3950 | |
| 3793 | 3951 | // Let's be extra cautious... |
| 3794 | - if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) |
|
| 3795 | - isAllowedTo('manage_membergroups'); |
|
| 3796 | - if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) |
|
| 3797 | - fatal_lang_error('no_access', false); |
|
| 3952 | + if (!$context['user']['is_owner'] || empty($modSettings['show_group_membership'])) { |
|
| 3953 | + isAllowedTo('manage_membergroups'); |
|
| 3954 | + } |
|
| 3955 | + if (!isset($_REQUEST['gid']) && !isset($_POST['primary'])) { |
|
| 3956 | + fatal_lang_error('no_access', false); |
|
| 3957 | + } |
|
| 3798 | 3958 | |
| 3799 | 3959 | checkSession(isset($_GET['gid']) ? 'get' : 'post'); |
| 3800 | 3960 | |
@@ -3813,8 +3973,9 @@ discard block |
||
| 3813 | 3973 | $foundTarget = $changeType == 'primary' && $group_id == 0 ? true : false; |
| 3814 | 3974 | |
| 3815 | 3975 | // Sanity check!! |
| 3816 | - if ($group_id == 1) |
|
| 3817 | - isAllowedTo('admin_forum'); |
|
| 3976 | + if ($group_id == 1) { |
|
| 3977 | + isAllowedTo('admin_forum'); |
|
| 3978 | + } |
|
| 3818 | 3979 | // Protected groups too! |
| 3819 | 3980 | else |
| 3820 | 3981 | { |
@@ -3831,8 +3992,9 @@ discard block |
||
| 3831 | 3992 | list ($is_protected) = $smcFunc['db_fetch_row']($request); |
| 3832 | 3993 | $smcFunc['db_free_result']($request); |
| 3833 | 3994 | |
| 3834 | - if ($is_protected == 1) |
|
| 3835 | - isAllowedTo('admin_forum'); |
|
| 3995 | + if ($is_protected == 1) { |
|
| 3996 | + isAllowedTo('admin_forum'); |
|
| 3997 | + } |
|
| 3836 | 3998 | } |
| 3837 | 3999 | |
| 3838 | 4000 | // What ever we are doing, we need to determine if changing primary is possible! |
@@ -3854,36 +4016,43 @@ discard block |
||
| 3854 | 4016 | $group_name = $row['group_name']; |
| 3855 | 4017 | |
| 3856 | 4018 | // Does the group type match what we're doing - are we trying to request a non-requestable group? |
| 3857 | - if ($changeType == 'request' && $row['group_type'] != 2) |
|
| 3858 | - fatal_lang_error('no_access', false); |
|
| 4019 | + if ($changeType == 'request' && $row['group_type'] != 2) { |
|
| 4020 | + fatal_lang_error('no_access', false); |
|
| 4021 | + } |
|
| 3859 | 4022 | // What about leaving a requestable group we are not a member of? |
| 3860 | - elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) |
|
| 3861 | - fatal_lang_error('no_access', false); |
|
| 3862 | - elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) |
|
| 3863 | - fatal_lang_error('no_access', false); |
|
| 4023 | + elseif ($changeType == 'free' && $row['group_type'] == 2 && $old_profile['id_group'] != $row['id_group'] && !isset($addGroups[$row['id_group']])) { |
|
| 4024 | + fatal_lang_error('no_access', false); |
|
| 4025 | + } elseif ($changeType == 'free' && $row['group_type'] != 3 && $row['group_type'] != 2) { |
|
| 4026 | + fatal_lang_error('no_access', false); |
|
| 4027 | + } |
|
| 3864 | 4028 | |
| 3865 | 4029 | // We can't change the primary group if this is hidden! |
| 3866 | - if ($row['hidden'] == 2) |
|
| 3867 | - $canChangePrimary = false; |
|
| 4030 | + if ($row['hidden'] == 2) { |
|
| 4031 | + $canChangePrimary = false; |
|
| 4032 | + } |
|
| 3868 | 4033 | } |
| 3869 | 4034 | |
| 3870 | 4035 | // If this is their old primary, can we change it? |
| 3871 | - if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) |
|
| 3872 | - $canChangePrimary = 1; |
|
| 4036 | + if ($row['id_group'] == $old_profile['id_group'] && ($row['group_type'] > 1 || $context['can_manage_membergroups']) && $canChangePrimary !== false) { |
|
| 4037 | + $canChangePrimary = 1; |
|
| 4038 | + } |
|
| 3873 | 4039 | |
| 3874 | 4040 | // If we are not doing a force primary move, don't do it automatically if current primary is not 0. |
| 3875 | - if ($changeType != 'primary' && $old_profile['id_group'] != 0) |
|
| 3876 | - $canChangePrimary = false; |
|
| 4041 | + if ($changeType != 'primary' && $old_profile['id_group'] != 0) { |
|
| 4042 | + $canChangePrimary = false; |
|
| 4043 | + } |
|
| 3877 | 4044 | |
| 3878 | 4045 | // If this is the one we are acting on, can we even act? |
| 3879 | - if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) |
|
| 3880 | - $canChangePrimary = false; |
|
| 4046 | + if ((!$context['can_manage_protected'] && $row['group_type'] == 1) || (!$context['can_manage_membergroups'] && $row['group_type'] == 0)) { |
|
| 4047 | + $canChangePrimary = false; |
|
| 4048 | + } |
|
| 3881 | 4049 | } |
| 3882 | 4050 | $smcFunc['db_free_result']($request); |
| 3883 | 4051 | |
| 3884 | 4052 | // Didn't find the target? |
| 3885 | - if (!$foundTarget) |
|
| 3886 | - fatal_lang_error('no_access', false); |
|
| 4053 | + if (!$foundTarget) { |
|
| 4054 | + fatal_lang_error('no_access', false); |
|
| 4055 | + } |
|
| 3887 | 4056 | |
| 3888 | 4057 | // Final security check, don't allow users to promote themselves to admin. |
| 3889 | 4058 | if ($context['can_manage_membergroups'] && !allowedTo('admin_forum')) |
@@ -3903,8 +4072,9 @@ discard block |
||
| 3903 | 4072 | list ($disallow) = $smcFunc['db_fetch_row']($request); |
| 3904 | 4073 | $smcFunc['db_free_result']($request); |
| 3905 | 4074 | |
| 3906 | - if ($disallow) |
|
| 3907 | - isAllowedTo('admin_forum'); |
|
| 4075 | + if ($disallow) { |
|
| 4076 | + isAllowedTo('admin_forum'); |
|
| 4077 | + } |
|
| 3908 | 4078 | } |
| 3909 | 4079 | |
| 3910 | 4080 | // If we're requesting, add the note then return. |
@@ -3922,8 +4092,9 @@ discard block |
||
| 3922 | 4092 | 'status_open' => 0, |
| 3923 | 4093 | ) |
| 3924 | 4094 | ); |
| 3925 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 3926 | - fatal_lang_error('profile_error_already_requested_group'); |
|
| 4095 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 4096 | + fatal_lang_error('profile_error_already_requested_group'); |
|
| 4097 | + } |
|
| 3927 | 4098 | $smcFunc['db_free_result']($request); |
| 3928 | 4099 | |
| 3929 | 4100 | // Log the request. |
@@ -3957,10 +4128,11 @@ discard block |
||
| 3957 | 4128 | // Are we leaving? |
| 3958 | 4129 | if ($old_profile['id_group'] == $group_id || isset($addGroups[$group_id])) |
| 3959 | 4130 | { |
| 3960 | - if ($old_profile['id_group'] == $group_id) |
|
| 3961 | - $newPrimary = 0; |
|
| 3962 | - else |
|
| 3963 | - unset($addGroups[$group_id]); |
|
| 4131 | + if ($old_profile['id_group'] == $group_id) { |
|
| 4132 | + $newPrimary = 0; |
|
| 4133 | + } else { |
|
| 4134 | + unset($addGroups[$group_id]); |
|
| 4135 | + } |
|
| 3964 | 4136 | } |
| 3965 | 4137 | // ... if not, must be joining. |
| 3966 | 4138 | else |
@@ -3968,36 +4140,42 @@ discard block |
||
| 3968 | 4140 | // Can we change the primary, and do we want to? |
| 3969 | 4141 | if ($canChangePrimary) |
| 3970 | 4142 | { |
| 3971 | - if ($old_profile['id_group'] != 0) |
|
| 3972 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 4143 | + if ($old_profile['id_group'] != 0) { |
|
| 4144 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4145 | + } |
|
| 3973 | 4146 | $newPrimary = $group_id; |
| 3974 | 4147 | } |
| 3975 | 4148 | // Otherwise it's an additional group... |
| 3976 | - else |
|
| 3977 | - $addGroups[$group_id] = -1; |
|
| 4149 | + else { |
|
| 4150 | + $addGroups[$group_id] = -1; |
|
| 4151 | + } |
|
| 3978 | 4152 | } |
| 3979 | 4153 | } |
| 3980 | 4154 | // Finally, we must be setting the primary. |
| 3981 | 4155 | elseif ($canChangePrimary) |
| 3982 | 4156 | { |
| 3983 | - if ($old_profile['id_group'] != 0) |
|
| 3984 | - $addGroups[$old_profile['id_group']] = -1; |
|
| 3985 | - if (isset($addGroups[$group_id])) |
|
| 3986 | - unset($addGroups[$group_id]); |
|
| 4157 | + if ($old_profile['id_group'] != 0) { |
|
| 4158 | + $addGroups[$old_profile['id_group']] = -1; |
|
| 4159 | + } |
|
| 4160 | + if (isset($addGroups[$group_id])) { |
|
| 4161 | + unset($addGroups[$group_id]); |
|
| 4162 | + } |
|
| 3987 | 4163 | $newPrimary = $group_id; |
| 3988 | 4164 | } |
| 3989 | 4165 | |
| 3990 | 4166 | // Finally, we can make the changes! |
| 3991 | - foreach ($addGroups as $id => $dummy) |
|
| 3992 | - if (empty($id)) |
|
| 4167 | + foreach ($addGroups as $id => $dummy) { |
|
| 4168 | + if (empty($id)) |
|
| 3993 | 4169 | unset($addGroups[$id]); |
| 4170 | + } |
|
| 3994 | 4171 | $addGroups = implode(',', array_flip($addGroups)); |
| 3995 | 4172 | |
| 3996 | 4173 | // Ensure that we don't cache permissions if the group is changing. |
| 3997 | - if ($context['user']['is_owner']) |
|
| 3998 | - $_SESSION['mc']['time'] = 0; |
|
| 3999 | - else |
|
| 4000 | - updateSettings(array('settings_updated' => time())); |
|
| 4174 | + if ($context['user']['is_owner']) { |
|
| 4175 | + $_SESSION['mc']['time'] = 0; |
|
| 4176 | + } else { |
|
| 4177 | + updateSettings(array('settings_updated' => time())); |
|
| 4178 | + } |
|
| 4001 | 4179 | |
| 4002 | 4180 | updateMemberData($memID, array('id_group' => $newPrimary, 'additional_groups' => $addGroups)); |
| 4003 | 4181 | |
@@ -4020,8 +4198,9 @@ discard block |
||
| 4020 | 4198 | if (empty($user_settings['tfa_secret']) && $context['user']['is_owner']) |
| 4021 | 4199 | { |
| 4022 | 4200 | // Check to ensure we're forcing SSL for authentication |
| 4023 | - if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) |
|
| 4024 | - fatal_lang_error('login_ssl_required'); |
|
| 4201 | + if (!empty($modSettings['force_ssl']) && empty($maintenance) && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')) { |
|
| 4202 | + fatal_lang_error('login_ssl_required'); |
|
| 4203 | + } |
|
| 4025 | 4204 | |
| 4026 | 4205 | // In some cases (forced 2FA or backup code) they would be forced to be redirected here, |
| 4027 | 4206 | // we do not want too much AJAX to confuse them. |
@@ -4058,8 +4237,7 @@ discard block |
||
| 4058 | 4237 | $context['sub_template'] = 'tfasetup_backup'; |
| 4059 | 4238 | |
| 4060 | 4239 | return; |
| 4061 | - } |
|
| 4062 | - else |
|
| 4240 | + } else |
|
| 4063 | 4241 | { |
| 4064 | 4242 | $context['tfa_secret'] = $_SESSION['tfa_secret']; |
| 4065 | 4243 | $context['tfa_error'] = !$valid_code; |
@@ -4067,8 +4245,7 @@ discard block |
||
| 4067 | 4245 | $context['tfa_pass_value'] = $_POST['passwd']; |
| 4068 | 4246 | $context['tfa_value'] = $_POST['tfa_code']; |
| 4069 | 4247 | } |
| 4070 | - } |
|
| 4071 | - else |
|
| 4248 | + } else |
|
| 4072 | 4249 | { |
| 4073 | 4250 | $totp = new \TOTP\Auth(); |
| 4074 | 4251 | $secret = $totp->generateCode(); |
@@ -4078,17 +4255,16 @@ discard block |
||
| 4078 | 4255 | } |
| 4079 | 4256 | |
| 4080 | 4257 | $context['tfa_qr_url'] = $totp->getQrCodeUrl($context['forum_name'] . ':' . $user_info['name'], $context['tfa_secret']); |
| 4081 | - } |
|
| 4082 | - elseif (isset($_REQUEST['disable'])) |
|
| 4258 | + } elseif (isset($_REQUEST['disable'])) |
|
| 4083 | 4259 | { |
| 4084 | 4260 | updateMemberData($memID, array( |
| 4085 | 4261 | 'tfa_secret' => '', |
| 4086 | 4262 | 'tfa_backup' => '', |
| 4087 | 4263 | )); |
| 4088 | 4264 | redirectexit('action=profile;area=account;u=' . $memID); |
| 4265 | + } else { |
|
| 4266 | + redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4267 | + } |
|
| 4089 | 4268 | } |
| 4090 | - else |
|
| 4091 | - redirectexit('action=profile;area=account;u=' . $memID); |
|
| 4092 | -} |
|
| 4093 | 4269 | |
| 4094 | 4270 | ?> |
| 4095 | 4271 | \ No newline at end of file |
@@ -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 | * Finds or repairs errors in the database to fix possible problems. |
@@ -50,8 +51,9 @@ discard block |
||
| 50 | 51 | ); |
| 51 | 52 | |
| 52 | 53 | // Start displaying errors without fixing them. |
| 53 | - if (isset($_GET['fixErrors'])) |
|
| 54 | - checkSession('get'); |
|
| 54 | + if (isset($_GET['fixErrors'])) { |
|
| 55 | + checkSession('get'); |
|
| 56 | + } |
|
| 55 | 57 | |
| 56 | 58 | // Will want this. |
| 57 | 59 | loadForumTests(); |
@@ -69,11 +71,11 @@ discard block |
||
| 69 | 71 | $_SESSION['repairboards_to_fix'] = $context['to_fix']; |
| 70 | 72 | $_SESSION['repairboards_to_fix2'] = null; |
| 71 | 73 | |
| 72 | - if (empty($context['repair_errors'])) |
|
| 73 | - $context['repair_errors'][] = '???'; |
|
| 74 | + if (empty($context['repair_errors'])) { |
|
| 75 | + $context['repair_errors'][] = '???'; |
|
| 76 | + } |
|
| 74 | 77 | } |
| 75 | - } |
|
| 76 | - else |
|
| 78 | + } else |
|
| 77 | 79 | { |
| 78 | 80 | $context['error_search'] = false; |
| 79 | 81 | $context['to_fix'] = isset($_SESSION['repairboards_to_fix']) ? $_SESSION['repairboards_to_fix'] : array(); |
@@ -120,16 +122,19 @@ discard block |
||
| 120 | 122 | |
| 121 | 123 | // More time, I need more time! |
| 122 | 124 | @set_time_limit(600); |
| 123 | - if (function_exists('apache_reset_timeout')) |
|
| 124 | - @apache_reset_timeout(); |
|
| 125 | + if (function_exists('apache_reset_timeout')) { |
|
| 126 | + @apache_reset_timeout(); |
|
| 127 | + } |
|
| 125 | 128 | |
| 126 | 129 | // Errr, wait. How much time has this taken already? |
| 127 | - if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) |
|
| 128 | - return; |
|
| 130 | + if (!$force && time() - array_sum(explode(' ', $time_start)) < 3) { |
|
| 131 | + return; |
|
| 132 | + } |
|
| 129 | 133 | |
| 130 | 134 | // Restore the query cache if interested. |
| 131 | - if (!empty($db_temp_cache)) |
|
| 132 | - $db_cache = $db_temp_cache; |
|
| 135 | + if (!empty($db_temp_cache)) { |
|
| 136 | + $db_cache = $db_temp_cache; |
|
| 137 | + } |
|
| 133 | 138 | |
| 134 | 139 | $context['continue_get_data'] = '?action=admin;area=repairboards' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 135 | 140 | $context['page_title'] = $txt['not_done_title']; |
@@ -138,10 +143,11 @@ discard block |
||
| 138 | 143 | $context['sub_template'] = 'not_done'; |
| 139 | 144 | |
| 140 | 145 | // Change these two if more steps are added! |
| 141 | - if (empty($max_substep)) |
|
| 142 | - $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 143 | - else |
|
| 144 | - $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 146 | + if (empty($max_substep)) { |
|
| 147 | + $context['continue_percent'] = round(($_GET['step'] * 100) / $context['total_steps']); |
|
| 148 | + } else { |
|
| 149 | + $context['continue_percent'] = round((($_GET['step'] + ($_GET['substep'] / $max_substep)) * 100) / $context['total_steps']); |
|
| 150 | + } |
|
| 145 | 151 | |
| 146 | 152 | // Never more than 100%! |
| 147 | 153 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -612,8 +618,9 @@ discard block |
||
| 612 | 618 | $row['myid_last_msg'] = (int) $row['myid_last_msg']; |
| 613 | 619 | |
| 614 | 620 | // Not really a problem? |
| 615 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 616 | - return false; |
|
| 621 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 622 | + return false; |
|
| 623 | + } |
|
| 617 | 624 | |
| 618 | 625 | $memberStartedID = (int) getMsgMemberID($row['myid_first_msg']); |
| 619 | 626 | $memberUpdatedID = (int) getMsgMemberID($row['myid_last_msg']); |
@@ -637,15 +644,19 @@ discard block |
||
| 637 | 644 | 'message_function' => function ($row) use ($txt, &$context) |
| 638 | 645 | { |
| 639 | 646 | // A pretend error? |
| 640 | - if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) |
|
| 641 | - return false; |
|
| 647 | + if ($row['myid_first_msg'] == $row['myid_first_msg'] && $row['myid_first_msg'] == $row['myid_first_msg'] && $row['approved'] == $row['firstmsg_approved']) { |
|
| 648 | + return false; |
|
| 649 | + } |
|
| 642 | 650 | |
| 643 | - if ($row['id_first_msg'] != $row['myid_first_msg']) |
|
| 644 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 645 | - if ($row['id_last_msg'] != $row['myid_last_msg']) |
|
| 646 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 647 | - if ($row['approved'] != $row['firstmsg_approved']) |
|
| 648 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 651 | + if ($row['id_first_msg'] != $row['myid_first_msg']) { |
|
| 652 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_1'], $row['id_topic'], $row['id_first_msg']); |
|
| 653 | + } |
|
| 654 | + if ($row['id_last_msg'] != $row['myid_last_msg']) { |
|
| 655 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_2'], $row['id_topic'], $row['id_last_msg']); |
|
| 656 | + } |
|
| 657 | + if ($row['approved'] != $row['firstmsg_approved']) { |
|
| 658 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_5'], $row['id_topic']); |
|
| 659 | + } |
|
| 649 | 660 | |
| 650 | 661 | return true; |
| 651 | 662 | }, |
@@ -675,8 +686,9 @@ discard block |
||
| 675 | 686 | $row['my_num_replies'] = (int) $row['my_num_replies']; |
| 676 | 687 | |
| 677 | 688 | // Not really a problem? |
| 678 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 679 | - return false; |
|
| 689 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 690 | + return false; |
|
| 691 | + } |
|
| 680 | 692 | |
| 681 | 693 | $smcFunc['db_query']('', ' |
| 682 | 694 | UPDATE {db_prefix}topics |
@@ -695,11 +707,13 @@ discard block |
||
| 695 | 707 | global $txt, $context; |
| 696 | 708 | |
| 697 | 709 | // Just joking? |
| 698 | - if ($row['my_num_replies'] == $row['num_replies']) |
|
| 699 | - return false; |
|
| 710 | + if ($row['my_num_replies'] == $row['num_replies']) { |
|
| 711 | + return false; |
|
| 712 | + } |
|
| 700 | 713 | |
| 701 | - if ($row['num_replies'] != $row['my_num_replies']) |
|
| 702 | - $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 714 | + if ($row['num_replies'] != $row['my_num_replies']) { |
|
| 715 | + $context['repair_errors'][] = sprintf($txt['repair_stats_topics_3'], $row['id_topic'], $row['num_replies']); |
|
| 716 | + } |
|
| 703 | 717 | |
| 704 | 718 | return true; |
| 705 | 719 | |
@@ -1290,8 +1304,9 @@ discard block |
||
| 1290 | 1304 | $inserts = array(); |
| 1291 | 1305 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1292 | 1306 | { |
| 1293 | - foreach (text2words($row['subject']) as $word) |
|
| 1294 | - $inserts[] = array($word, $row['id_topic']); |
|
| 1307 | + foreach (text2words($row['subject']) as $word) { |
|
| 1308 | + $inserts[] = array($word, $row['id_topic']); |
|
| 1309 | + } |
|
| 1295 | 1310 | if (count($inserts) > 500) |
| 1296 | 1311 | { |
| 1297 | 1312 | $smcFunc['db_insert']('ignore', |
@@ -1305,13 +1320,14 @@ discard block |
||
| 1305 | 1320 | |
| 1306 | 1321 | } |
| 1307 | 1322 | |
| 1308 | - if (!empty($inserts)) |
|
| 1309 | - $smcFunc['db_insert']('ignore', |
|
| 1323 | + if (!empty($inserts)) { |
|
| 1324 | + $smcFunc['db_insert']('ignore', |
|
| 1310 | 1325 | '{db_prefix}log_search_subjects', |
| 1311 | 1326 | array('word' => 'string', 'id_topic' => 'int'), |
| 1312 | 1327 | $inserts, |
| 1313 | 1328 | array('word', 'id_topic') |
| 1314 | 1329 | ); |
| 1330 | + } |
|
| 1315 | 1331 | |
| 1316 | 1332 | }, |
| 1317 | 1333 | 'message_function' => function ($row) |
@@ -1581,8 +1597,9 @@ discard block |
||
| 1581 | 1597 | $current_step++; |
| 1582 | 1598 | |
| 1583 | 1599 | // Already done this? |
| 1584 | - if ($_GET['step'] > $current_step) |
|
| 1585 | - continue; |
|
| 1600 | + if ($_GET['step'] > $current_step) { |
|
| 1601 | + continue; |
|
| 1602 | + } |
|
| 1586 | 1603 | |
| 1587 | 1604 | // If we're fixing it but it ain't broke why try? |
| 1588 | 1605 | if ($do_fix && !in_array($error_type, $to_fix)) |
@@ -1611,14 +1628,16 @@ discard block |
||
| 1611 | 1628 | while (!$done) |
| 1612 | 1629 | { |
| 1613 | 1630 | // Make sure there's at least one ID to test. |
| 1614 | - if (isset($test['substeps']) && empty($step_max)) |
|
| 1615 | - break; |
|
| 1631 | + if (isset($test['substeps']) && empty($step_max)) { |
|
| 1632 | + break; |
|
| 1633 | + } |
|
| 1616 | 1634 | |
| 1617 | 1635 | // What is the testing query (Changes if we are testing or fixing) |
| 1618 | - if (!$do_fix) |
|
| 1619 | - $test_query = 'check_query'; |
|
| 1620 | - else |
|
| 1621 | - $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1636 | + if (!$do_fix) { |
|
| 1637 | + $test_query = 'check_query'; |
|
| 1638 | + } else { |
|
| 1639 | + $test_query = isset($test['fix_query']) ? 'fix_query' : 'check_query'; |
|
| 1640 | + } |
|
| 1622 | 1641 | |
| 1623 | 1642 | // Do the test... |
| 1624 | 1643 | $request = $smcFunc['db_query']('', |
@@ -1628,10 +1647,11 @@ discard block |
||
| 1628 | 1647 | ); |
| 1629 | 1648 | |
| 1630 | 1649 | // Does it need a fix? |
| 1631 | - if (!empty($test['check_type']) && $test['check_type'] == 'count') |
|
| 1632 | - list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1633 | - else |
|
| 1634 | - $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1650 | + if (!empty($test['check_type']) && $test['check_type'] == 'count') { |
|
| 1651 | + list ($needs_fix) = $smcFunc['db_fetch_row']($request); |
|
| 1652 | + } else { |
|
| 1653 | + $needs_fix = $smcFunc['db_num_rows']($request); |
|
| 1654 | + } |
|
| 1635 | 1655 | |
| 1636 | 1656 | $total_queries++; |
| 1637 | 1657 | |
@@ -1643,8 +1663,9 @@ discard block |
||
| 1643 | 1663 | // Assume need to fix. |
| 1644 | 1664 | $found_errors = true; |
| 1645 | 1665 | |
| 1646 | - if (isset($test['message'])) |
|
| 1647 | - $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1666 | + if (isset($test['message'])) { |
|
| 1667 | + $context['repair_errors'][] = $txt[$test['message']]; |
|
| 1668 | + } |
|
| 1648 | 1669 | |
| 1649 | 1670 | // One per row! |
| 1650 | 1671 | elseif (isset($test['messages'])) |
@@ -1654,10 +1675,11 @@ discard block |
||
| 1654 | 1675 | $variables = $test['messages']; |
| 1655 | 1676 | foreach ($variables as $k => $v) |
| 1656 | 1677 | { |
| 1657 | - if ($k == 0 && isset($txt[$v])) |
|
| 1658 | - $variables[$k] = $txt[$v]; |
|
| 1659 | - elseif ($k > 0 && isset($row[$v])) |
|
| 1660 | - $variables[$k] = $row[$v]; |
|
| 1678 | + if ($k == 0 && isset($txt[$v])) { |
|
| 1679 | + $variables[$k] = $txt[$v]; |
|
| 1680 | + } elseif ($k > 0 && isset($row[$v])) { |
|
| 1681 | + $variables[$k] = $row[$v]; |
|
| 1682 | + } |
|
| 1661 | 1683 | } |
| 1662 | 1684 | $context['repair_errors'][] = call_user_func_array('sprintf', $variables); |
| 1663 | 1685 | } |
@@ -1668,13 +1690,15 @@ discard block |
||
| 1668 | 1690 | { |
| 1669 | 1691 | // Find out if there are actually errors. |
| 1670 | 1692 | $found_errors = false; |
| 1671 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1672 | - $found_errors |= $test['message_function']($row); |
|
| 1693 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1694 | + $found_errors |= $test['message_function']($row); |
|
| 1695 | + } |
|
| 1673 | 1696 | } |
| 1674 | 1697 | |
| 1675 | 1698 | // Actually have something to fix? |
| 1676 | - if ($found_errors) |
|
| 1677 | - $to_fix[] = $error_type; |
|
| 1699 | + if ($found_errors) { |
|
| 1700 | + $to_fix[] = $error_type; |
|
| 1701 | + } |
|
| 1678 | 1702 | } |
| 1679 | 1703 | |
| 1680 | 1704 | // We want to fix, we need to fix - so work out what exactly to do! |
@@ -1684,8 +1708,9 @@ discard block |
||
| 1684 | 1708 | if (isset($test['fix_collect'])) |
| 1685 | 1709 | { |
| 1686 | 1710 | $ids = array(); |
| 1687 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1688 | - $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1711 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1712 | + $ids[] = $row[$test['fix_collect']['index']]; |
|
| 1713 | + } |
|
| 1689 | 1714 | if (!empty($ids)) |
| 1690 | 1715 | { |
| 1691 | 1716 | // Fix it! |
@@ -1694,30 +1719,34 @@ discard block |
||
| 1694 | 1719 | } |
| 1695 | 1720 | |
| 1696 | 1721 | // Simply executing a fix it query? |
| 1697 | - elseif (isset($test['fix_it_query'])) |
|
| 1698 | - $smcFunc['db_query']('', |
|
| 1722 | + elseif (isset($test['fix_it_query'])) { |
|
| 1723 | + $smcFunc['db_query']('', |
|
| 1699 | 1724 | $test['fix_it_query'], |
| 1700 | 1725 | array( |
| 1701 | 1726 | ) |
| 1702 | 1727 | ); |
| 1728 | + } |
|
| 1703 | 1729 | |
| 1704 | 1730 | // Do we have some processing to do? |
| 1705 | 1731 | elseif (isset($test['fix_processing'])) |
| 1706 | 1732 | { |
| 1707 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1708 | - $test['fix_processing']($row); |
|
| 1733 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1734 | + $test['fix_processing']($row); |
|
| 1735 | + } |
|
| 1709 | 1736 | } |
| 1710 | 1737 | |
| 1711 | 1738 | // What about the full set of processing? |
| 1712 | - elseif (isset($test['fix_full_processing'])) |
|
| 1713 | - $test['fix_full_processing']($request); |
|
| 1739 | + elseif (isset($test['fix_full_processing'])) { |
|
| 1740 | + $test['fix_full_processing']($request); |
|
| 1741 | + } |
|
| 1714 | 1742 | |
| 1715 | 1743 | // Do we have other things we need to fix as a result? |
| 1716 | 1744 | if (!empty($test['force_fix'])) |
| 1717 | 1745 | { |
| 1718 | - foreach ($test['force_fix'] as $item) |
|
| 1719 | - if (!in_array($item, $to_fix)) |
|
| 1746 | + foreach ($test['force_fix'] as $item) { |
|
| 1747 | + if (!in_array($item, $to_fix)) |
|
| 1720 | 1748 | $to_fix[] = $item; |
| 1749 | + } |
|
| 1721 | 1750 | } |
| 1722 | 1751 | } |
| 1723 | 1752 | } |
@@ -1735,16 +1764,17 @@ discard block |
||
| 1735 | 1764 | if ($_GET['substep'] <= $step_max) |
| 1736 | 1765 | { |
| 1737 | 1766 | pauseRepairProcess($to_fix, $error_type, $step_max); |
| 1767 | + } else { |
|
| 1768 | + $done = true; |
|
| 1738 | 1769 | } |
| 1739 | - else |
|
| 1740 | - $done = true; |
|
| 1770 | + } else { |
|
| 1771 | + $done = true; |
|
| 1741 | 1772 | } |
| 1742 | - else |
|
| 1743 | - $done = true; |
|
| 1744 | 1773 | |
| 1745 | 1774 | // Don't allow more than 1000 queries at a time. |
| 1746 | - if ($total_queries >= 1000) |
|
| 1747 | - pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1775 | + if ($total_queries >= 1000) { |
|
| 1776 | + pauseRepairProcess($to_fix, $error_type, $step_max, true); |
|
| 1777 | + } |
|
| 1748 | 1778 | } |
| 1749 | 1779 | |
| 1750 | 1780 | // Keep going. |
@@ -1757,8 +1787,9 @@ discard block |
||
| 1757 | 1787 | if ($do_fix) |
| 1758 | 1788 | { |
| 1759 | 1789 | $key = array_search($error_type, $to_fix); |
| 1760 | - if ($key !== false && isset($to_fix[$key])) |
|
| 1761 | - unset($to_fix[$key]); |
|
| 1790 | + if ($key !== false && isset($to_fix[$key])) { |
|
| 1791 | + unset($to_fix[$key]); |
|
| 1792 | + } |
|
| 1762 | 1793 | } |
| 1763 | 1794 | |
| 1764 | 1795 | // Are we done? |
@@ -1781,10 +1812,11 @@ discard block |
||
| 1781 | 1812 | static $createOnce = false; |
| 1782 | 1813 | |
| 1783 | 1814 | // Have we already created it? |
| 1784 | - if ($createOnce) |
|
| 1785 | - return; |
|
| 1786 | - else |
|
| 1787 | - $createOnce = true; |
|
| 1815 | + if ($createOnce) { |
|
| 1816 | + return; |
|
| 1817 | + } else { |
|
| 1818 | + $createOnce = true; |
|
| 1819 | + } |
|
| 1788 | 1820 | |
| 1789 | 1821 | // Back to the forum's default language. |
| 1790 | 1822 | loadLanguage('Admin', $language); |
@@ -1799,8 +1831,9 @@ discard block |
||
| 1799 | 1831 | 'cat_name' => $txt['salvaged_category_name'], |
| 1800 | 1832 | ) |
| 1801 | 1833 | ); |
| 1802 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1803 | - list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1834 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1835 | + list ($salvageCatID) = $smcFunc['db_fetch_row']($result); |
|
| 1836 | + } |
|
| 1804 | 1837 | $smcFunc['db_free_result']($result); |
| 1805 | 1838 | |
| 1806 | 1839 | if (empty($salvageCatID)) |
@@ -1832,8 +1865,9 @@ discard block |
||
| 1832 | 1865 | 'board_name' => $txt['salvaged_board_name'], |
| 1833 | 1866 | ) |
| 1834 | 1867 | ); |
| 1835 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1836 | - list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1868 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1869 | + list ($salvageBoardID) = $smcFunc['db_fetch_row']($result); |
|
| 1870 | + } |
|
| 1837 | 1871 | $smcFunc['db_free_result']($result); |
| 1838 | 1872 | |
| 1839 | 1873 | if (empty($salvageBoardID)) |