@@ -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 $db_show_debug, $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 | * View the forum's error log. |
@@ -30,8 +31,9 @@ discard block |
||
| 30 | 31 | global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc; |
| 31 | 32 | |
| 32 | 33 | // Viewing contents of a file? |
| 33 | - if (isset($_GET['file'])) |
|
| 34 | - return ViewFile(); |
|
| 34 | + if (isset($_GET['file'])) { |
|
| 35 | + return ViewFile(); |
|
| 36 | + } |
|
| 35 | 37 | |
| 36 | 38 | // Check for the administrative permission to do this. |
| 37 | 39 | isAllowedTo('admin_forum'); |
@@ -85,8 +87,8 @@ discard block |
||
| 85 | 87 | ); |
| 86 | 88 | |
| 87 | 89 | // Set up the filtering... |
| 88 | - if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) |
|
| 89 | - $filter = array( |
|
| 90 | + if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) { |
|
| 91 | + $filter = array( |
|
| 90 | 92 | 'variable' => $_GET['filter'], |
| 91 | 93 | 'value' => array( |
| 92 | 94 | 'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']), |
@@ -94,10 +96,12 @@ discard block |
||
| 94 | 96 | 'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'], |
| 95 | 97 | 'entity' => $filters[$_GET['filter']]['txt'] |
| 96 | 98 | ); |
| 99 | + } |
|
| 97 | 100 | |
| 98 | 101 | // Deleting, are we? |
| 99 | - if (isset($_POST['delall']) || isset($_POST['delete'])) |
|
| 100 | - deleteErrors(); |
|
| 102 | + if (isset($_POST['delall']) || isset($_POST['delete'])) { |
|
| 103 | + deleteErrors(); |
|
| 104 | + } |
|
| 101 | 105 | |
| 102 | 106 | // Just how many errors are there? |
| 103 | 107 | $result = $smcFunc['db_query']('', ' |
@@ -112,12 +116,14 @@ discard block |
||
| 112 | 116 | $smcFunc['db_free_result']($result); |
| 113 | 117 | |
| 114 | 118 | // If this filter is empty... |
| 115 | - if ($num_errors == 0 && isset($filter)) |
|
| 116 | - redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
| 119 | + if ($num_errors == 0 && isset($filter)) { |
|
| 120 | + redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | 123 | // Clean up start. |
| 119 | - if (!isset($_GET['start']) || $_GET['start'] < 0) |
|
| 120 | - $_GET['start'] = 0; |
|
| 124 | + if (!isset($_GET['start']) || $_GET['start'] < 0) { |
|
| 125 | + $_GET['start'] = 0; |
|
| 126 | + } |
|
| 121 | 127 | |
| 122 | 128 | // Do we want to reverse error listing? |
| 123 | 129 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
@@ -127,9 +133,9 @@ discard block |
||
| 127 | 133 | $context['start'] = $_GET['start']; |
| 128 | 134 | |
| 129 | 135 | // Update the error count |
| 130 | - if (!isset($filter)) |
|
| 131 | - $context['num_errors'] = $num_errors; |
|
| 132 | - else |
|
| 136 | + if (!isset($filter)) { |
|
| 137 | + $context['num_errors'] = $num_errors; |
|
| 138 | + } else |
|
| 133 | 139 | { |
| 134 | 140 | // We want all errors, not just the number of filtered messages... |
| 135 | 141 | $query = $smcFunc['db_query']('', ' |
@@ -161,8 +167,9 @@ discard block |
||
| 161 | 167 | for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++) |
| 162 | 168 | { |
| 163 | 169 | $search_message = preg_replace('~<span class="remove">(.+?)</span>~', '%', $smcFunc['db_escape_wildcard_string']($row['message'])); |
| 164 | - if ($search_message == $filter['value']['sql']) |
|
| 165 | - $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
| 170 | + if ($search_message == $filter['value']['sql']) { |
|
| 171 | + $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
| 172 | + } |
|
| 166 | 173 | $show_message = strtr(strtr(preg_replace('~<span class="remove">(.+?)</span>~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '<', '>' => '>', '"' => '"')), array("\n" => '<br>')); |
| 167 | 174 | |
| 168 | 175 | $context['errors'][$row['id_error']] = array( |
@@ -221,8 +228,9 @@ discard block |
||
| 221 | 228 | 'members' => count($members), |
| 222 | 229 | ) |
| 223 | 230 | ); |
| 224 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 225 | - $members[$row['id_member']] = $row; |
|
| 231 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 232 | + $members[$row['id_member']] = $row; |
|
| 233 | + } |
|
| 226 | 234 | $smcFunc['db_free_result']($request); |
| 227 | 235 | |
| 228 | 236 | // This is a guest... |
@@ -254,20 +262,18 @@ discard block |
||
| 254 | 262 | $id = $filter['value']['sql']; |
| 255 | 263 | loadMemberData($id, false, 'minimal'); |
| 256 | 264 | $context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>'; |
| 257 | - } |
|
| 258 | - elseif ($filter['variable'] == 'url') |
|
| 259 | - $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
| 260 | - elseif ($filter['variable'] == 'message') |
|
| 265 | + } elseif ($filter['variable'] == 'url') { |
|
| 266 | + $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
| 267 | + } elseif ($filter['variable'] == 'message') |
|
| 261 | 268 | { |
| 262 | 269 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
| 263 | 270 | $context['filter']['value']['html'] = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $context['filter']['value']['html']); |
| 264 | - } |
|
| 265 | - elseif ($filter['variable'] == 'error_type') |
|
| 271 | + } elseif ($filter['variable'] == 'error_type') |
|
| 266 | 272 | { |
| 267 | 273 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
| 274 | + } else { |
|
| 275 | + $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
| 268 | 276 | } |
| 269 | - else |
|
| 270 | - $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
| 271 | 277 | } |
| 272 | 278 | |
| 273 | 279 | $context['error_types'] = array(); |
@@ -308,10 +314,11 @@ discard block |
||
| 308 | 314 | $context['error_types']['all']['label'] .= ' (' . $sum . ')'; |
| 309 | 315 | |
| 310 | 316 | // Finally, work out what is the last tab! |
| 311 | - if (isset($context['error_types'][$sum])) |
|
| 312 | - $context['error_types'][$sum]['is_last'] = true; |
|
| 313 | - else |
|
| 314 | - $context['error_types']['all']['is_last'] = true; |
|
| 317 | + if (isset($context['error_types'][$sum])) { |
|
| 318 | + $context['error_types'][$sum]['is_last'] = true; |
|
| 319 | + } else { |
|
| 320 | + $context['error_types']['all']['is_last'] = true; |
|
| 321 | + } |
|
| 315 | 322 | |
| 316 | 323 | // And this is pretty basic ;). |
| 317 | 324 | $context['page_title'] = $txt['errlog']; |
@@ -337,21 +344,23 @@ discard block |
||
| 337 | 344 | validateToken('admin-el'); |
| 338 | 345 | |
| 339 | 346 | // Delete all or just some? |
| 340 | - if (isset($_POST['delall']) && !isset($filter)) |
|
| 341 | - $smcFunc['db_query']('truncate_table', ' |
|
| 347 | + if (isset($_POST['delall']) && !isset($filter)) { |
|
| 348 | + $smcFunc['db_query']('truncate_table', ' |
|
| 342 | 349 | TRUNCATE {db_prefix}log_errors', |
| 343 | 350 | array( |
| 344 | 351 | ) |
| 345 | 352 | ); |
| 353 | + } |
|
| 346 | 354 | // Deleting all with a filter? |
| 347 | - elseif (isset($_POST['delall']) && isset($filter)) |
|
| 348 | - $smcFunc['db_query']('', ' |
|
| 355 | + elseif (isset($_POST['delall']) && isset($filter)) { |
|
| 356 | + $smcFunc['db_query']('', ' |
|
| 349 | 357 | DELETE FROM {db_prefix}log_errors |
| 350 | 358 | WHERE ' . $filter['variable'] . ' LIKE {string:filter}', |
| 351 | 359 | array( |
| 352 | 360 | 'filter' => $filter['value']['sql'], |
| 353 | 361 | ) |
| 354 | 362 | ); |
| 363 | + } |
|
| 355 | 364 | // Just specific errors? |
| 356 | 365 | elseif (!empty($_POST['delete'])) |
| 357 | 366 | { |
@@ -397,15 +406,17 @@ discard block |
||
| 397 | 406 | $line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0; |
| 398 | 407 | |
| 399 | 408 | // Make sure the file we are looking for is one they are allowed to look at |
| 400 | - if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) |
|
| 401 | - fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
| 409 | + if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) { |
|
| 410 | + fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
| 411 | + } |
|
| 402 | 412 | |
| 403 | 413 | // get the min and max lines |
| 404 | 414 | $min = $line - 20 <= 0 ? 1 : $line - 20; |
| 405 | 415 | $max = $line + 21; // One additional line to make everything work out correctly |
| 406 | 416 | |
| 407 | - if ($max <= 0 || $min >= $max) |
|
| 408 | - fatal_lang_error('error_bad_line'); |
|
| 417 | + if ($max <= 0 || $min >= $max) { |
|
| 418 | + fatal_lang_error('error_bad_line'); |
|
| 419 | + } |
|
| 409 | 420 | |
| 410 | 421 | $file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file))))); |
| 411 | 422 | |
@@ -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 | * Ban center. The main entrance point for all ban center functions. |
@@ -120,10 +121,11 @@ discard block |
||
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | // Create a date string so we don't overload them with date info. |
| 123 | - if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) |
|
| 124 | - $context['ban_time_format'] = $user_info['time_format']; |
|
| 125 | - else |
|
| 126 | - $context['ban_time_format'] = $matches[0]; |
|
| 124 | + if (preg_match('~%[AaBbCcDdeGghjmuYy](?:[^%]*%[AaBbCcDdeGghjmuYy])*~', $user_info['time_format'], $matches) == 0 || empty($matches[0])) { |
|
| 125 | + $context['ban_time_format'] = $user_info['time_format']; |
|
| 126 | + } else { |
|
| 127 | + $context['ban_time_format'] = $matches[0]; |
|
| 128 | + } |
|
| 127 | 129 | |
| 128 | 130 | $listOptions = array( |
| 129 | 131 | 'id' => 'ban_list', |
@@ -201,16 +203,19 @@ discard block |
||
| 201 | 203 | 'function' => function($rowData) use ($txt) |
| 202 | 204 | { |
| 203 | 205 | // This ban never expires...whahaha. |
| 204 | - if ($rowData['expire_time'] === null) |
|
| 205 | - return $txt['never']; |
|
| 206 | + if ($rowData['expire_time'] === null) { |
|
| 207 | + return $txt['never']; |
|
| 208 | + } |
|
| 206 | 209 | |
| 207 | 210 | // This ban has already expired. |
| 208 | - elseif ($rowData['expire_time'] < time()) |
|
| 209 | - return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
| 211 | + elseif ($rowData['expire_time'] < time()) { |
|
| 212 | + return sprintf('<span class="red">%1$s</span>', $txt['ban_expired']); |
|
| 213 | + } |
|
| 210 | 214 | |
| 211 | 215 | // Still need to wait a few days for this ban to expire. |
| 212 | - else |
|
| 213 | - return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
| 216 | + else { |
|
| 217 | + return sprintf('%1$d %2$s', ceil(($rowData['expire_time'] - time()) / (60 * 60 * 24)), $txt['ban_days']); |
|
| 218 | + } |
|
| 214 | 219 | }, |
| 215 | 220 | ), |
| 216 | 221 | 'sort' => array( |
@@ -309,8 +314,9 @@ discard block |
||
| 309 | 314 | ) |
| 310 | 315 | ); |
| 311 | 316 | $bans = array(); |
| 312 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 313 | - $bans[] = $row; |
|
| 317 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 318 | + $bans[] = $row; |
|
| 319 | + } |
|
| 314 | 320 | |
| 315 | 321 | $smcFunc['db_free_result']($request); |
| 316 | 322 | |
@@ -352,8 +358,9 @@ discard block |
||
| 352 | 358 | { |
| 353 | 359 | global $txt, $modSettings, $context, $scripturl, $smcFunc, $sourcedir; |
| 354 | 360 | |
| 355 | - if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) |
|
| 356 | - BanEdit2(); |
|
| 361 | + if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && empty($context['ban_errors'])) { |
|
| 362 | + BanEdit2(); |
|
| 363 | + } |
|
| 357 | 364 | |
| 358 | 365 | $ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0); |
| 359 | 366 | |
@@ -364,10 +371,10 @@ discard block |
||
| 364 | 371 | |
| 365 | 372 | if (!empty($context['ban_errors'])) |
| 366 | 373 | { |
| 367 | - foreach ($context['ban_errors'] as $error) |
|
| 368 | - $context['error_messages'][$error] = $txt[$error]; |
|
| 369 | - } |
|
| 370 | - else |
|
| 374 | + foreach ($context['ban_errors'] as $error) { |
|
| 375 | + $context['error_messages'][$error] = $txt[$error]; |
|
| 376 | + } |
|
| 377 | + } else |
|
| 371 | 378 | { |
| 372 | 379 | // If we're editing an existing ban, get it from the database. |
| 373 | 380 | if (!empty($ban_group_id)) |
@@ -403,12 +410,13 @@ discard block |
||
| 403 | 410 | 'data' => array( |
| 404 | 411 | 'function' => function($ban_item) use ($txt) |
| 405 | 412 | { |
| 406 | - if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) |
|
| 407 | - return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
| 408 | - elseif ($ban_item['type'] == 'user') |
|
| 409 | - return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
| 410 | - else |
|
| 411 | - return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
| 413 | + if (in_array($ban_item['type'], array('ip', 'hostname', 'email'))) { |
|
| 414 | + return '<strong>' . $txt[$ban_item['type']] . ':</strong> ' . $ban_item[$ban_item['type']]; |
|
| 415 | + } elseif ($ban_item['type'] == 'user') { |
|
| 416 | + return '<strong>' . $txt['username'] . ':</strong> ' . $ban_item['user']['link']; |
|
| 417 | + } else { |
|
| 418 | + return '<strong>' . $txt['unknown'] . ':</strong> ' . $ban_item['no_bantype_selected']; |
|
| 419 | + } |
|
| 412 | 420 | }, |
| 413 | 421 | 'style' => 'text-align: left;', |
| 414 | 422 | ), |
@@ -546,8 +554,9 @@ discard block |
||
| 546 | 554 | $context['ban']['from_user'] = true; |
| 547 | 555 | |
| 548 | 556 | // Would be nice if we could also ban the hostname. |
| 549 | - if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) |
|
| 550 | - $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
| 557 | + if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) { |
|
| 558 | + $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']); |
|
| 559 | + } |
|
| 551 | 560 | |
| 552 | 561 | $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
| 553 | 562 | } |
@@ -615,8 +624,9 @@ discard block |
||
| 615 | 624 | 'items_per_page' => $items_per_page, |
| 616 | 625 | ) |
| 617 | 626 | ); |
| 618 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 619 | - fatal_lang_error('ban_not_found', false); |
|
| 627 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 628 | + fatal_lang_error('ban_not_found', false); |
|
| 629 | + } |
|
| 620 | 630 | |
| 621 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 622 | 632 | { |
@@ -653,18 +663,15 @@ discard block |
||
| 653 | 663 | { |
| 654 | 664 | $ban_items[$row['id_ban']]['type'] = 'ip'; |
| 655 | 665 | $ban_items[$row['id_ban']]['ip'] = range2ip($row['ip_low'], $row['ip_high']); |
| 656 | - } |
|
| 657 | - elseif (!empty($row['hostname'])) |
|
| 666 | + } elseif (!empty($row['hostname'])) |
|
| 658 | 667 | { |
| 659 | 668 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
| 660 | 669 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
| 661 | - } |
|
| 662 | - elseif (!empty($row['email_address'])) |
|
| 670 | + } elseif (!empty($row['email_address'])) |
|
| 663 | 671 | { |
| 664 | 672 | $ban_items[$row['id_ban']]['type'] = 'email'; |
| 665 | 673 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
| 666 | - } |
|
| 667 | - elseif (!empty($row['id_member'])) |
|
| 674 | + } elseif (!empty($row['id_member'])) |
|
| 668 | 675 | { |
| 669 | 676 | $ban_items[$row['id_ban']]['type'] = 'user'; |
| 670 | 677 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -730,9 +737,10 @@ discard block |
||
| 730 | 737 | $search_list += array('ips_in_messages' => 'banLoadAdditionalIPsMember', 'ips_in_errors' => 'banLoadAdditionalIPsError'); |
| 731 | 738 | |
| 732 | 739 | $return = array(); |
| 733 | - foreach ($search_list as $key => $callable) |
|
| 734 | - if (is_callable($callable)) |
|
| 740 | + foreach ($search_list as $key => $callable) { |
|
| 741 | + if (is_callable($callable)) |
|
| 735 | 742 | $return[$key] = call_user_func($callable, $member_id); |
| 743 | + } |
|
| 736 | 744 | |
| 737 | 745 | return $return; |
| 738 | 746 | } |
@@ -757,8 +765,9 @@ discard block |
||
| 757 | 765 | 'current_user' => $member_id, |
| 758 | 766 | ) |
| 759 | 767 | ); |
| 760 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 761 | - $message_ips[] = inet_dtop($row['poster_ip']); |
|
| 768 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 769 | + $message_ips[] = inet_dtop($row['poster_ip']); |
|
| 770 | + } |
|
| 762 | 771 | $smcFunc['db_free_result']($request); |
| 763 | 772 | |
| 764 | 773 | return $message_ips; |
@@ -783,8 +792,9 @@ discard block |
||
| 783 | 792 | 'current_user' => $member_id, |
| 784 | 793 | ) |
| 785 | 794 | ); |
| 786 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 787 | - $error_ips[] = inet_dtop($row['ip']); |
|
| 795 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 796 | + $error_ips[] = inet_dtop($row['ip']); |
|
| 797 | + } |
|
| 788 | 798 | $smcFunc['db_free_result']($request); |
| 789 | 799 | |
| 790 | 800 | return $error_ips; |
@@ -825,11 +835,13 @@ discard block |
||
| 825 | 835 | $ban_info['cannot']['login'] = !empty($ban_info['full_ban']) || empty($_POST['cannot_login']) ? 0 : 1; |
| 826 | 836 | |
| 827 | 837 | // Adding a new ban group |
| 828 | - if (empty($_REQUEST['bg'])) |
|
| 829 | - $ban_group_id = insertBanGroup($ban_info); |
|
| 838 | + if (empty($_REQUEST['bg'])) { |
|
| 839 | + $ban_group_id = insertBanGroup($ban_info); |
|
| 840 | + } |
|
| 830 | 841 | // Editing an existing ban group |
| 831 | - else |
|
| 832 | - $ban_group_id = updateBanGroup($ban_info); |
|
| 842 | + else { |
|
| 843 | + $ban_group_id = updateBanGroup($ban_info); |
|
| 844 | + } |
|
| 833 | 845 | |
| 834 | 846 | if (is_numeric($ban_group_id)) |
| 835 | 847 | { |
@@ -840,9 +852,10 @@ discard block |
||
| 840 | 852 | $context['ban'] = $ban_info; |
| 841 | 853 | } |
| 842 | 854 | |
| 843 | - if (isset($_POST['ban_suggestions'])) |
|
| 844 | - // @TODO: is $_REQUEST['bi'] ever set? |
|
| 855 | + if (isset($_POST['ban_suggestions'])) { |
|
| 856 | + // @TODO: is $_REQUEST['bi'] ever set? |
|
| 845 | 857 | $saved_triggers = saveTriggers($_POST['ban_suggestions'], $ban_info['id'], isset($_REQUEST['u']) ? (int) $_REQUEST['u'] : 0, isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0); |
| 858 | + } |
|
| 846 | 859 | |
| 847 | 860 | // Something went wrong somewhere... Oh well, let's go back. |
| 848 | 861 | if (!empty($context['ban_errors'])) |
@@ -852,8 +865,9 @@ discard block |
||
| 852 | 865 | $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u'])); |
| 853 | 866 | |
| 854 | 867 | // Not strictly necessary, but it's nice |
| 855 | - if (!empty($context['ban_suggestions']['member']['id'])) |
|
| 856 | - $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
| 868 | + if (!empty($context['ban_suggestions']['member']['id'])) { |
|
| 869 | + $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']); |
|
| 870 | + } |
|
| 857 | 871 | return BanEdit(); |
| 858 | 872 | } |
| 859 | 873 | $context['ban_suggestions']['saved_triggers'] = !empty($saved_triggers) ? $saved_triggers : array(); |
@@ -900,10 +914,11 @@ discard block |
||
| 900 | 914 | |
| 901 | 915 | foreach ($suggestions as $key => $value) |
| 902 | 916 | { |
| 903 | - if (is_array($value)) |
|
| 904 | - $triggers[$key] = $value; |
|
| 905 | - else |
|
| 906 | - $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
| 917 | + if (is_array($value)) { |
|
| 918 | + $triggers[$key] = $value; |
|
| 919 | + } else { |
|
| 920 | + $triggers[$value] = !empty($_POST[$value]) ? $_POST[$value] : ''; |
|
| 921 | + } |
|
| 907 | 922 | } |
| 908 | 923 | |
| 909 | 924 | $ban_triggers = validateTriggers($triggers); |
@@ -911,16 +926,18 @@ discard block |
||
| 911 | 926 | // Time to save! |
| 912 | 927 | if (!empty($ban_triggers['ban_triggers']) && empty($context['ban_errors'])) |
| 913 | 928 | { |
| 914 | - if (empty($ban_id)) |
|
| 915 | - addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
| 916 | - else |
|
| 917 | - updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
| 929 | + if (empty($ban_id)) { |
|
| 930 | + addTriggers($ban_group, $ban_triggers['ban_triggers'], $ban_triggers['log_info']); |
|
| 931 | + } else { |
|
| 932 | + updateTriggers($ban_id, $ban_group, array_shift($ban_triggers['ban_triggers']), $ban_triggers['log_info']); |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + if (!empty($context['ban_errors'])) { |
|
| 936 | + return $triggers; |
|
| 937 | + } else { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 918 | 940 | } |
| 919 | - if (!empty($context['ban_errors'])) |
|
| 920 | - return $triggers; |
|
| 921 | - else |
|
| 922 | - return false; |
|
| 923 | -} |
|
| 924 | 941 | |
| 925 | 942 | /** |
| 926 | 943 | * This function removes a bunch of triggers based on ids |
@@ -934,14 +951,17 @@ discard block |
||
| 934 | 951 | { |
| 935 | 952 | global $smcFunc, $scripturl; |
| 936 | 953 | |
| 937 | - if ($group_id !== false) |
|
| 938 | - $group_id = (int) $group_id; |
|
| 954 | + if ($group_id !== false) { |
|
| 955 | + $group_id = (int) $group_id; |
|
| 956 | + } |
|
| 939 | 957 | |
| 940 | - if (empty($group_id) && empty($items_ids)) |
|
| 941 | - return false; |
|
| 958 | + if (empty($group_id) && empty($items_ids)) { |
|
| 959 | + return false; |
|
| 960 | + } |
|
| 942 | 961 | |
| 943 | - if (!is_array($items_ids)) |
|
| 944 | - $items_ids = array($items_ids); |
|
| 962 | + if (!is_array($items_ids)) { |
|
| 963 | + $items_ids = array($items_ids); |
|
| 964 | + } |
|
| 945 | 965 | |
| 946 | 966 | $log_info = array(); |
| 947 | 967 | $ban_items = array(); |
@@ -979,8 +999,7 @@ discard block |
||
| 979 | 999 | 'bantype' => ($is_range ? 'ip_range' : 'main_ip'), |
| 980 | 1000 | 'value' => $ban_items[$row['id_ban']]['ip'], |
| 981 | 1001 | ); |
| 982 | - } |
|
| 983 | - elseif (!empty($row['hostname'])) |
|
| 1002 | + } elseif (!empty($row['hostname'])) |
|
| 984 | 1003 | { |
| 985 | 1004 | $ban_items[$row['id_ban']]['type'] = 'hostname'; |
| 986 | 1005 | $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']); |
@@ -988,8 +1007,7 @@ discard block |
||
| 988 | 1007 | 'bantype' => 'hostname', |
| 989 | 1008 | 'value' => $row['hostname'], |
| 990 | 1009 | ); |
| 991 | - } |
|
| 992 | - elseif (!empty($row['email_address'])) |
|
| 1010 | + } elseif (!empty($row['email_address'])) |
|
| 993 | 1011 | { |
| 994 | 1012 | $ban_items[$row['id_ban']]['type'] = 'email'; |
| 995 | 1013 | $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']); |
@@ -997,8 +1015,7 @@ discard block |
||
| 997 | 1015 | 'bantype' => 'email', |
| 998 | 1016 | 'value' => $ban_items[$row['id_ban']]['email'], |
| 999 | 1017 | ); |
| 1000 | - } |
|
| 1001 | - elseif (!empty($row['id_member'])) |
|
| 1018 | + } elseif (!empty($row['id_member'])) |
|
| 1002 | 1019 | { |
| 1003 | 1020 | $ban_items[$row['id_ban']]['type'] = 'user'; |
| 1004 | 1021 | $ban_items[$row['id_ban']]['user'] = array( |
@@ -1031,8 +1048,7 @@ discard block |
||
| 1031 | 1048 | 'ban_group' => $group_id, |
| 1032 | 1049 | ) |
| 1033 | 1050 | ); |
| 1034 | - } |
|
| 1035 | - elseif (!empty($items_ids)) |
|
| 1051 | + } elseif (!empty($items_ids)) |
|
| 1036 | 1052 | { |
| 1037 | 1053 | $smcFunc['db_query']('', ' |
| 1038 | 1054 | DELETE FROM {db_prefix}ban_items |
@@ -1057,13 +1073,15 @@ discard block |
||
| 1057 | 1073 | { |
| 1058 | 1074 | global $smcFunc; |
| 1059 | 1075 | |
| 1060 | - if (!is_array($group_ids)) |
|
| 1061 | - $group_ids = array($group_ids); |
|
| 1076 | + if (!is_array($group_ids)) { |
|
| 1077 | + $group_ids = array($group_ids); |
|
| 1078 | + } |
|
| 1062 | 1079 | |
| 1063 | 1080 | $group_ids = array_unique($group_ids); |
| 1064 | 1081 | |
| 1065 | - if (empty($group_ids)) |
|
| 1066 | - return false; |
|
| 1082 | + if (empty($group_ids)) { |
|
| 1083 | + return false; |
|
| 1084 | + } |
|
| 1067 | 1085 | |
| 1068 | 1086 | $smcFunc['db_query']('', ' |
| 1069 | 1087 | DELETE FROM {db_prefix}ban_groups |
@@ -1087,21 +1105,23 @@ discard block |
||
| 1087 | 1105 | { |
| 1088 | 1106 | global $smcFunc; |
| 1089 | 1107 | |
| 1090 | - if (empty($ids)) |
|
| 1091 | - $smcFunc['db_query']('truncate_table', ' |
|
| 1108 | + if (empty($ids)) { |
|
| 1109 | + $smcFunc['db_query']('truncate_table', ' |
|
| 1092 | 1110 | TRUNCATE {db_prefix}log_banned', |
| 1093 | 1111 | array( |
| 1094 | 1112 | ) |
| 1095 | 1113 | ); |
| 1096 | - else |
|
| 1114 | + } else |
|
| 1097 | 1115 | { |
| 1098 | - if (!is_array($ids)) |
|
| 1099 | - $ids = array($ids); |
|
| 1116 | + if (!is_array($ids)) { |
|
| 1117 | + $ids = array($ids); |
|
| 1118 | + } |
|
| 1100 | 1119 | |
| 1101 | 1120 | $ids = array_unique($ids); |
| 1102 | 1121 | |
| 1103 | - if (empty($ids)) |
|
| 1104 | - return false; |
|
| 1122 | + if (empty($ids)) { |
|
| 1123 | + return false; |
|
| 1124 | + } |
|
| 1105 | 1125 | |
| 1106 | 1126 | $smcFunc['db_query']('', ' |
| 1107 | 1127 | DELETE FROM {db_prefix}log_banned |
@@ -1127,8 +1147,9 @@ discard block |
||
| 1127 | 1147 | { |
| 1128 | 1148 | global $context, $smcFunc; |
| 1129 | 1149 | |
| 1130 | - if (empty($triggers)) |
|
| 1131 | - $context['ban_erros'][] = 'ban_empty_triggers'; |
|
| 1150 | + if (empty($triggers)) { |
|
| 1151 | + $context['ban_erros'][] = 'ban_empty_triggers'; |
|
| 1152 | + } |
|
| 1132 | 1153 | |
| 1133 | 1154 | $ban_triggers = array(); |
| 1134 | 1155 | $log_info = array(); |
@@ -1137,39 +1158,39 @@ discard block |
||
| 1137 | 1158 | { |
| 1138 | 1159 | if (!empty($value)) |
| 1139 | 1160 | { |
| 1140 | - if ($key == 'member') |
|
| 1141 | - continue; |
|
| 1161 | + if ($key == 'member') { |
|
| 1162 | + continue; |
|
| 1163 | + } |
|
| 1142 | 1164 | |
| 1143 | 1165 | if ($key == 'main_ip') |
| 1144 | 1166 | { |
| 1145 | 1167 | $value = trim($value); |
| 1146 | 1168 | $ip_parts = ip2range($value); |
| 1147 | - if (!checkExistingTriggerIP($ip_parts, $value)) |
|
| 1148 | - $context['ban_erros'][] = 'invalid_ip'; |
|
| 1149 | - else |
|
| 1169 | + if (!checkExistingTriggerIP($ip_parts, $value)) { |
|
| 1170 | + $context['ban_erros'][] = 'invalid_ip'; |
|
| 1171 | + } else |
|
| 1150 | 1172 | { |
| 1151 | 1173 | $ban_triggers['main_ip'] = array( |
| 1152 | 1174 | 'ip_low' => $ip_parts['low'], |
| 1153 | 1175 | 'ip_high' => $ip_parts['high'] |
| 1154 | 1176 | ); |
| 1155 | 1177 | } |
| 1156 | - } |
|
| 1157 | - elseif ($key == 'hostname') |
|
| 1178 | + } elseif ($key == 'hostname') |
|
| 1158 | 1179 | { |
| 1159 | - if (preg_match('/[^\w.\-*]/', $value) == 1) |
|
| 1160 | - $context['ban_erros'][] = 'invalid_hostname'; |
|
| 1161 | - else |
|
| 1180 | + if (preg_match('/[^\w.\-*]/', $value) == 1) { |
|
| 1181 | + $context['ban_erros'][] = 'invalid_hostname'; |
|
| 1182 | + } else |
|
| 1162 | 1183 | { |
| 1163 | 1184 | // Replace the * wildcard by a MySQL wildcard %. |
| 1164 | 1185 | $value = substr(str_replace('*', '%', $value), 0, 255); |
| 1165 | 1186 | |
| 1166 | 1187 | $ban_triggers['hostname']['hostname'] = $value; |
| 1167 | 1188 | } |
| 1168 | - } |
|
| 1169 | - elseif ($key == 'email') |
|
| 1189 | + } elseif ($key == 'email') |
|
| 1170 | 1190 | { |
| 1171 | - if (preg_match('/[^\w.\-\+*@]/', $value) == 1) |
|
| 1172 | - $context['ban_erros'][] = 'invalid_email'; |
|
| 1191 | + if (preg_match('/[^\w.\-\+*@]/', $value) == 1) { |
|
| 1192 | + $context['ban_erros'][] = 'invalid_email'; |
|
| 1193 | + } |
|
| 1173 | 1194 | |
| 1174 | 1195 | // Check the user is not banning an admin. |
| 1175 | 1196 | $request = $smcFunc['db_query']('', ' |
@@ -1183,15 +1204,15 @@ discard block |
||
| 1183 | 1204 | 'email' => $value, |
| 1184 | 1205 | ) |
| 1185 | 1206 | ); |
| 1186 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1187 | - $context['ban_erros'][] = 'no_ban_admin'; |
|
| 1207 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1208 | + $context['ban_erros'][] = 'no_ban_admin'; |
|
| 1209 | + } |
|
| 1188 | 1210 | $smcFunc['db_free_result']($request); |
| 1189 | 1211 | |
| 1190 | 1212 | $value = substr(strtolower(str_replace('*', '%', $value)), 0, 255); |
| 1191 | 1213 | |
| 1192 | 1214 | $ban_triggers['email']['email_address'] = $value; |
| 1193 | - } |
|
| 1194 | - elseif ($key == 'user') |
|
| 1215 | + } elseif ($key == 'user') |
|
| 1195 | 1216 | { |
| 1196 | 1217 | $user = preg_replace('~&#(\d{4,5}|[2-9]\d{2,4}|1[2-9]\d);~', '&#$1;', $smcFunc['htmlspecialchars']($value, ENT_QUOTES)); |
| 1197 | 1218 | |
@@ -1205,8 +1226,9 @@ discard block |
||
| 1205 | 1226 | 'username' => $user, |
| 1206 | 1227 | ) |
| 1207 | 1228 | ); |
| 1208 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1209 | - $context['ban_erros'][] = 'invalid_username'; |
|
| 1229 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1230 | + $context['ban_erros'][] = 'invalid_username'; |
|
| 1231 | + } |
|
| 1210 | 1232 | list ($value, $isAdmin) = $smcFunc['db_fetch_row']($request); |
| 1211 | 1233 | $smcFunc['db_free_result']($request); |
| 1212 | 1234 | |
@@ -1214,25 +1236,25 @@ discard block |
||
| 1214 | 1236 | { |
| 1215 | 1237 | unset($value); |
| 1216 | 1238 | $context['ban_erros'][] = 'no_ban_admin'; |
| 1239 | + } else { |
|
| 1240 | + $ban_triggers['user']['id_member'] = $value; |
|
| 1217 | 1241 | } |
| 1218 | - else |
|
| 1219 | - $ban_triggers['user']['id_member'] = $value; |
|
| 1220 | - } |
|
| 1221 | - elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1242 | + } elseif (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1222 | 1243 | { |
| 1223 | 1244 | // Special case, those two are arrays themselves |
| 1224 | 1245 | $values = array_unique($value); |
| 1225 | 1246 | // Don't add the main IP again. |
| 1226 | - if (isset($triggers['main_ip'])) |
|
| 1227 | - $values = array_diff($values, array($triggers['main_ip'])); |
|
| 1247 | + if (isset($triggers['main_ip'])) { |
|
| 1248 | + $values = array_diff($values, array($triggers['main_ip'])); |
|
| 1249 | + } |
|
| 1228 | 1250 | unset($value); |
| 1229 | 1251 | foreach ($values as $val) |
| 1230 | 1252 | { |
| 1231 | 1253 | $val = trim($val); |
| 1232 | 1254 | $ip_parts = ip2range($val); |
| 1233 | - if (!checkExistingTriggerIP($ip_parts, $val)) |
|
| 1234 | - $context['ban_erros'][] = 'invalid_ip'; |
|
| 1235 | - else |
|
| 1255 | + if (!checkExistingTriggerIP($ip_parts, $val)) { |
|
| 1256 | + $context['ban_erros'][] = 'invalid_ip'; |
|
| 1257 | + } else |
|
| 1236 | 1258 | { |
| 1237 | 1259 | $ban_triggers[$key][] = array( |
| 1238 | 1260 | 'ip_low' => $ip_parts['low'], |
@@ -1245,15 +1267,16 @@ discard block |
||
| 1245 | 1267 | ); |
| 1246 | 1268 | } |
| 1247 | 1269 | } |
| 1270 | + } else { |
|
| 1271 | + $context['ban_erros'][] = 'no_bantype_selected'; |
|
| 1248 | 1272 | } |
| 1249 | - else |
|
| 1250 | - $context['ban_erros'][] = 'no_bantype_selected'; |
|
| 1251 | 1273 | |
| 1252 | - if (isset($value) && !is_array($value)) |
|
| 1253 | - $log_info[] = array( |
|
| 1274 | + if (isset($value) && !is_array($value)) { |
|
| 1275 | + $log_info[] = array( |
|
| 1254 | 1276 | 'value' => $value, |
| 1255 | 1277 | 'bantype' => $key, |
| 1256 | 1278 | ); |
| 1279 | + } |
|
| 1257 | 1280 | } |
| 1258 | 1281 | } |
| 1259 | 1282 | return array('ban_triggers' => $ban_triggers, 'log_info' => $log_info); |
@@ -1273,8 +1296,9 @@ discard block |
||
| 1273 | 1296 | { |
| 1274 | 1297 | global $smcFunc, $context; |
| 1275 | 1298 | |
| 1276 | - if (empty($group_id)) |
|
| 1277 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1299 | + if (empty($group_id)) { |
|
| 1300 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1301 | + } |
|
| 1278 | 1302 | |
| 1279 | 1303 | // Preset all values that are required. |
| 1280 | 1304 | $values = array( |
@@ -1299,18 +1323,21 @@ discard block |
||
| 1299 | 1323 | foreach ($triggers as $key => $trigger) |
| 1300 | 1324 | { |
| 1301 | 1325 | // Exceptions, exceptions, exceptions...always exceptions... :P |
| 1302 | - if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) |
|
| 1303 | - foreach ($trigger as $real_trigger) |
|
| 1326 | + if (in_array($key, array('ips_in_messages', 'ips_in_errors'))) { |
|
| 1327 | + foreach ($trigger as $real_trigger) |
|
| 1304 | 1328 | $insertTriggers[] = array_merge($values, $real_trigger); |
| 1305 | - else |
|
| 1306 | - $insertTriggers[] = array_merge($values, $trigger); |
|
| 1329 | + } else { |
|
| 1330 | + $insertTriggers[] = array_merge($values, $trigger); |
|
| 1331 | + } |
|
| 1307 | 1332 | } |
| 1308 | 1333 | |
| 1309 | - if (empty($insertTriggers)) |
|
| 1310 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1334 | + if (empty($insertTriggers)) { |
|
| 1335 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1336 | + } |
|
| 1311 | 1337 | |
| 1312 | - if (!empty($context['ban_errors'])) |
|
| 1313 | - return false; |
|
| 1338 | + if (!empty($context['ban_errors'])) { |
|
| 1339 | + return false; |
|
| 1340 | + } |
|
| 1314 | 1341 | |
| 1315 | 1342 | $smcFunc['db_insert']('', |
| 1316 | 1343 | '{db_prefix}ban_items', |
@@ -1338,15 +1365,19 @@ discard block |
||
| 1338 | 1365 | { |
| 1339 | 1366 | global $smcFunc, $context; |
| 1340 | 1367 | |
| 1341 | - if (empty($ban_item)) |
|
| 1342 | - $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
| 1343 | - if (empty($group_id)) |
|
| 1344 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1345 | - if (empty($trigger)) |
|
| 1346 | - $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1368 | + if (empty($ban_item)) { |
|
| 1369 | + $context['ban_errors'][] = 'ban_ban_item_empty'; |
|
| 1370 | + } |
|
| 1371 | + if (empty($group_id)) { |
|
| 1372 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1373 | + } |
|
| 1374 | + if (empty($trigger)) { |
|
| 1375 | + $context['ban_errors'][] = 'ban_no_triggers'; |
|
| 1376 | + } |
|
| 1347 | 1377 | |
| 1348 | - if (!empty($context['ban_errors'])) |
|
| 1349 | - return; |
|
| 1378 | + if (!empty($context['ban_errors'])) { |
|
| 1379 | + return; |
|
| 1380 | + } |
|
| 1350 | 1381 | |
| 1351 | 1382 | // Preset all values that are required. |
| 1352 | 1383 | $values = array( |
@@ -1387,8 +1418,9 @@ discard block |
||
| 1387 | 1418 | */ |
| 1388 | 1419 | function logTriggersUpdates($logs, $new = true, $removal = false) |
| 1389 | 1420 | { |
| 1390 | - if (empty($logs)) |
|
| 1391 | - return; |
|
| 1421 | + if (empty($logs)) { |
|
| 1422 | + return; |
|
| 1423 | + } |
|
| 1392 | 1424 | |
| 1393 | 1425 | $log_name_map = array( |
| 1394 | 1426 | 'main_ip' => 'ip_range', |
@@ -1399,14 +1431,15 @@ discard block |
||
| 1399 | 1431 | ); |
| 1400 | 1432 | |
| 1401 | 1433 | // Log the addion of the ban entries into the moderation log. |
| 1402 | - foreach ($logs as $log) |
|
| 1403 | - logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
| 1434 | + foreach ($logs as $log) { |
|
| 1435 | + logAction('ban' . ($removal == true ? 'remove' : ''), array( |
|
| 1404 | 1436 | $log_name_map[$log['bantype']] => $log['value'], |
| 1405 | 1437 | 'new' => empty($new) ? 0 : 1, |
| 1406 | 1438 | 'remove' => empty($removal) ? 0 : 1, |
| 1407 | 1439 | 'type' => $log['bantype'], |
| 1408 | 1440 | )); |
| 1409 | -} |
|
| 1441 | + } |
|
| 1442 | + } |
|
| 1410 | 1443 | |
| 1411 | 1444 | /** |
| 1412 | 1445 | * Updates an existing ban group |
@@ -1420,12 +1453,15 @@ discard block |
||
| 1420 | 1453 | { |
| 1421 | 1454 | global $smcFunc, $context; |
| 1422 | 1455 | |
| 1423 | - if (empty($ban_info['name'])) |
|
| 1424 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1425 | - if (empty($ban_info['id'])) |
|
| 1426 | - $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1427 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
| 1428 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1456 | + if (empty($ban_info['name'])) { |
|
| 1457 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1458 | + } |
|
| 1459 | + if (empty($ban_info['id'])) { |
|
| 1460 | + $context['ban_errors'][] = 'ban_id_empty'; |
|
| 1461 | + } |
|
| 1462 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
| 1463 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1464 | + } |
|
| 1429 | 1465 | |
| 1430 | 1466 | if (!empty($ban_info['id'])) |
| 1431 | 1467 | { |
@@ -1440,8 +1476,9 @@ discard block |
||
| 1440 | 1476 | ) |
| 1441 | 1477 | ); |
| 1442 | 1478 | |
| 1443 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1444 | - $context['ban_errors'][] = 'ban_not_found'; |
|
| 1479 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1480 | + $context['ban_errors'][] = 'ban_not_found'; |
|
| 1481 | + } |
|
| 1445 | 1482 | $smcFunc['db_free_result']($request); |
| 1446 | 1483 | } |
| 1447 | 1484 | |
@@ -1459,13 +1496,15 @@ discard block |
||
| 1459 | 1496 | 'new_ban_name' => $ban_info['name'], |
| 1460 | 1497 | ) |
| 1461 | 1498 | ); |
| 1462 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
| 1463 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1499 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
| 1500 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1501 | + } |
|
| 1464 | 1502 | $smcFunc['db_free_result']($request); |
| 1465 | 1503 | } |
| 1466 | 1504 | |
| 1467 | - if (!empty($context['ban_errors'])) |
|
| 1468 | - return $ban_info['id']; |
|
| 1505 | + if (!empty($context['ban_errors'])) { |
|
| 1506 | + return $ban_info['id']; |
|
| 1507 | + } |
|
| 1469 | 1508 | |
| 1470 | 1509 | $smcFunc['db_query']('', ' |
| 1471 | 1510 | UPDATE {db_prefix}ban_groups |
@@ -1509,10 +1548,12 @@ discard block |
||
| 1509 | 1548 | { |
| 1510 | 1549 | global $smcFunc, $context; |
| 1511 | 1550 | |
| 1512 | - if (empty($ban_info['name'])) |
|
| 1513 | - $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1514 | - if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) |
|
| 1515 | - $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1551 | + if (empty($ban_info['name'])) { |
|
| 1552 | + $context['ban_errors'][] = 'ban_name_empty'; |
|
| 1553 | + } |
|
| 1554 | + if (empty($ban_info['cannot']['access']) && empty($ban_info['cannot']['register']) && empty($ban_info['cannot']['post']) && empty($ban_info['cannot']['login'])) { |
|
| 1555 | + $context['ban_errors'][] = 'ban_unknown_restriction_type'; |
|
| 1556 | + } |
|
| 1516 | 1557 | |
| 1517 | 1558 | if (!empty($ban_info['name'])) |
| 1518 | 1559 | { |
@@ -1527,13 +1568,15 @@ discard block |
||
| 1527 | 1568 | ) |
| 1528 | 1569 | ); |
| 1529 | 1570 | |
| 1530 | - if ($smcFunc['db_num_rows']($request) == 1) |
|
| 1531 | - $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1571 | + if ($smcFunc['db_num_rows']($request) == 1) { |
|
| 1572 | + $context['ban_errors'][] = 'ban_name_exists'; |
|
| 1573 | + } |
|
| 1532 | 1574 | $smcFunc['db_free_result']($request); |
| 1533 | 1575 | } |
| 1534 | 1576 | |
| 1535 | - if (!empty($context['ban_errors'])) |
|
| 1536 | - return; |
|
| 1577 | + if (!empty($context['ban_errors'])) { |
|
| 1578 | + return; |
|
| 1579 | + } |
|
| 1537 | 1580 | |
| 1538 | 1581 | // Yes yes, we're ready to add now. |
| 1539 | 1582 | $ban_info['id'] = $smcFunc['db_insert']('', |
@@ -1550,8 +1593,9 @@ discard block |
||
| 1550 | 1593 | 1 |
| 1551 | 1594 | ); |
| 1552 | 1595 | |
| 1553 | - if (empty($ban_info['id'])) |
|
| 1554 | - $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
| 1596 | + if (empty($ban_info['id'])) { |
|
| 1597 | + $context['ban_errors'][] = 'impossible_insert_new_bangroup'; |
|
| 1598 | + } |
|
| 1555 | 1599 | |
| 1556 | 1600 | return $ban_info['id']; |
| 1557 | 1601 | } |
@@ -1576,24 +1620,24 @@ discard block |
||
| 1576 | 1620 | $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0; |
| 1577 | 1621 | $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0; |
| 1578 | 1622 | |
| 1579 | - if (empty($ban_group)) |
|
| 1580 | - fatal_lang_error('ban_not_found', false); |
|
| 1623 | + if (empty($ban_group)) { |
|
| 1624 | + fatal_lang_error('ban_not_found', false); |
|
| 1625 | + } |
|
| 1581 | 1626 | |
| 1582 | 1627 | if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) |
| 1583 | 1628 | { |
| 1584 | 1629 | saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id); |
| 1585 | 1630 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
| 1586 | - } |
|
| 1587 | - elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
| 1631 | + } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) |
|
| 1588 | 1632 | { |
| 1589 | 1633 | // The first replaces the old one, the others are added new (simplification, otherwise it would require another query and some work...) |
| 1590 | 1634 | saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id); |
| 1591 | - if (!empty($_POST['ban_suggestions'])) |
|
| 1592 | - saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
| 1635 | + if (!empty($_POST['ban_suggestions'])) { |
|
| 1636 | + saveTriggers($_POST['ban_suggestions'], $ban_group); |
|
| 1637 | + } |
|
| 1593 | 1638 | |
| 1594 | 1639 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
| 1595 | - } |
|
| 1596 | - elseif (isset($_POST['edit_trigger'])) |
|
| 1640 | + } elseif (isset($_POST['edit_trigger'])) |
|
| 1597 | 1641 | { |
| 1598 | 1642 | removeBanTriggers($ban_id); |
| 1599 | 1643 | redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : '')); |
@@ -1624,8 +1668,7 @@ discard block |
||
| 1624 | 1668 | ), |
| 1625 | 1669 | 'is_new' => true, |
| 1626 | 1670 | ); |
| 1627 | - } |
|
| 1628 | - else |
|
| 1671 | + } else |
|
| 1629 | 1672 | { |
| 1630 | 1673 | $request = $smcFunc['db_query']('', ' |
| 1631 | 1674 | SELECT |
@@ -1642,8 +1685,9 @@ discard block |
||
| 1642 | 1685 | 'ban_group' => $ban_group, |
| 1643 | 1686 | ) |
| 1644 | 1687 | ); |
| 1645 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
| 1646 | - fatal_lang_error('ban_not_found', false); |
|
| 1688 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
| 1689 | + fatal_lang_error('ban_not_found', false); |
|
| 1690 | + } |
|
| 1647 | 1691 | $row = $smcFunc['db_fetch_assoc']($request); |
| 1648 | 1692 | $smcFunc['db_free_result']($request); |
| 1649 | 1693 | |
@@ -1692,8 +1736,9 @@ discard block |
||
| 1692 | 1736 | removeBanTriggers($_POST['remove']); |
| 1693 | 1737 | |
| 1694 | 1738 | // Rehabilitate some members. |
| 1695 | - if ($_REQUEST['entity'] == 'member') |
|
| 1696 | - updateBanMembers(); |
|
| 1739 | + if ($_REQUEST['entity'] == 'member') { |
|
| 1740 | + updateBanMembers(); |
|
| 1741 | + } |
|
| 1697 | 1742 | |
| 1698 | 1743 | // Make sure the ban cache is refreshed. |
| 1699 | 1744 | updateSettings(array('banLastUpdated' => time())); |
@@ -1806,8 +1851,7 @@ discard block |
||
| 1806 | 1851 | 'default' => 'bi.ip_low, bi.ip_high, bi.ip_low', |
| 1807 | 1852 | 'reverse' => 'bi.ip_low DESC, bi.ip_high DESC', |
| 1808 | 1853 | ); |
| 1809 | - } |
|
| 1810 | - elseif ($context['selected_entity'] === 'hostname') |
|
| 1854 | + } elseif ($context['selected_entity'] === 'hostname') |
|
| 1811 | 1855 | { |
| 1812 | 1856 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1813 | 1857 | 'function' => function($rowData) use ($smcFunc) |
@@ -1819,8 +1863,7 @@ discard block |
||
| 1819 | 1863 | 'default' => 'bi.hostname', |
| 1820 | 1864 | 'reverse' => 'bi.hostname DESC', |
| 1821 | 1865 | ); |
| 1822 | - } |
|
| 1823 | - elseif ($context['selected_entity'] === 'email') |
|
| 1866 | + } elseif ($context['selected_entity'] === 'email') |
|
| 1824 | 1867 | { |
| 1825 | 1868 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1826 | 1869 | 'function' => function($rowData) use ($smcFunc) |
@@ -1832,8 +1875,7 @@ discard block |
||
| 1832 | 1875 | 'default' => 'bi.email_address', |
| 1833 | 1876 | 'reverse' => 'bi.email_address DESC', |
| 1834 | 1877 | ); |
| 1835 | - } |
|
| 1836 | - elseif ($context['selected_entity'] === 'member') |
|
| 1878 | + } elseif ($context['selected_entity'] === 'member') |
|
| 1837 | 1879 | { |
| 1838 | 1880 | $listOptions['columns']['banned_entity']['data'] = array( |
| 1839 | 1881 | 'sprintf' => array( |
@@ -1897,8 +1939,9 @@ discard block |
||
| 1897 | 1939 | ) |
| 1898 | 1940 | ); |
| 1899 | 1941 | $ban_triggers = array(); |
| 1900 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1901 | - $ban_triggers[] = $row; |
|
| 1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1943 | + $ban_triggers[] = $row; |
|
| 1944 | + } |
|
| 1902 | 1945 | $smcFunc['db_free_result']($request); |
| 1903 | 1946 | |
| 1904 | 1947 | return $ban_triggers; |
@@ -1954,8 +1997,9 @@ discard block |
||
| 1954 | 1997 | validateToken('admin-bl'); |
| 1955 | 1998 | |
| 1956 | 1999 | // 'Delete all entries' button was pressed. |
| 1957 | - if (!empty($_POST['removeAll'])) |
|
| 1958 | - removeBanLogs(); |
|
| 2000 | + if (!empty($_POST['removeAll'])) { |
|
| 2001 | + removeBanLogs(); |
|
| 2002 | + } |
|
| 1959 | 2003 | // 'Delete selection' button was pressed. |
| 1960 | 2004 | else |
| 1961 | 2005 | { |
@@ -2164,12 +2208,15 @@ discard block |
||
| 2164 | 2208 | $low = inet_dtop($low); |
| 2165 | 2209 | $high = inet_dtop($high); |
| 2166 | 2210 | |
| 2167 | - if ($low == '255.255.255.255') return 'unknown'; |
|
| 2168 | - if ($low == $high) |
|
| 2169 | - return $low; |
|
| 2170 | - else |
|
| 2171 | - return $low . '-' . $high; |
|
| 2172 | -} |
|
| 2211 | + if ($low == '255.255.255.255') { |
|
| 2212 | + return 'unknown'; |
|
| 2213 | + } |
|
| 2214 | + if ($low == $high) { |
|
| 2215 | + return $low; |
|
| 2216 | + } else { |
|
| 2217 | + return $low . '-' . $high; |
|
| 2218 | + } |
|
| 2219 | + } |
|
| 2173 | 2220 | |
| 2174 | 2221 | /** |
| 2175 | 2222 | * Checks whether a given IP range already exists in the trigger list. |
@@ -2245,15 +2292,17 @@ discard block |
||
| 2245 | 2292 | $memberEmailWild = array(); |
| 2246 | 2293 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 2247 | 2294 | { |
| 2248 | - if ($row['id_member']) |
|
| 2249 | - $memberIDs[$row['id_member']] = $row['id_member']; |
|
| 2295 | + if ($row['id_member']) { |
|
| 2296 | + $memberIDs[$row['id_member']] = $row['id_member']; |
|
| 2297 | + } |
|
| 2250 | 2298 | if ($row['email_address']) |
| 2251 | 2299 | { |
| 2252 | 2300 | // Does it have a wildcard - if so we can't do a IN on it. |
| 2253 | - if (strpos($row['email_address'], '%') !== false) |
|
| 2254 | - $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
| 2255 | - else |
|
| 2256 | - $memberEmails[$row['email_address']] = $row['email_address']; |
|
| 2301 | + if (strpos($row['email_address'], '%') !== false) { |
|
| 2302 | + $memberEmailWild[$row['email_address']] = $row['email_address']; |
|
| 2303 | + } else { |
|
| 2304 | + $memberEmails[$row['email_address']] = $row['email_address']; |
|
| 2305 | + } |
|
| 2257 | 2306 | } |
| 2258 | 2307 | } |
| 2259 | 2308 | $smcFunc['db_free_result']($request); |
@@ -2304,14 +2353,15 @@ discard block |
||
| 2304 | 2353 | } |
| 2305 | 2354 | |
| 2306 | 2355 | // We welcome our new members in the realm of the banned. |
| 2307 | - if (!empty($newMembers)) |
|
| 2308 | - $smcFunc['db_query']('', ' |
|
| 2356 | + if (!empty($newMembers)) { |
|
| 2357 | + $smcFunc['db_query']('', ' |
|
| 2309 | 2358 | DELETE FROM {db_prefix}log_online |
| 2310 | 2359 | WHERE id_member IN ({array_int:new_banned_members})', |
| 2311 | 2360 | array( |
| 2312 | 2361 | 'new_banned_members' => $newMembers, |
| 2313 | 2362 | ) |
| 2314 | 2363 | ); |
| 2364 | + } |
|
| 2315 | 2365 | |
| 2316 | 2366 | // Find members that are wrongfully marked as banned. |
| 2317 | 2367 | $request = $smcFunc['db_query']('', ' |
@@ -2338,9 +2388,10 @@ discard block |
||
| 2338 | 2388 | } |
| 2339 | 2389 | $smcFunc['db_free_result']($request); |
| 2340 | 2390 | |
| 2341 | - if (!empty($updates)) |
|
| 2342 | - foreach ($updates as $newStatus => $members) |
|
| 2391 | + if (!empty($updates)) { |
|
| 2392 | + foreach ($updates as $newStatus => $members) |
|
| 2343 | 2393 | updateMemberData($members, array('is_activated' => $newStatus)); |
| 2394 | + } |
|
| 2344 | 2395 | |
| 2345 | 2396 | // Update the latest member and our total members as banning may change them. |
| 2346 | 2397 | updateStats('member'); |
@@ -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 | * Sets and call a function based on the given subaction. Acts as a dispatcher function. |
@@ -54,8 +55,9 @@ discard block |
||
| 54 | 55 | ); |
| 55 | 56 | |
| 56 | 57 | // This comes under the umbrella of moderating posts. |
| 57 | - if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1') |
|
| 58 | - isAllowedTo('moderate_forum'); |
|
| 58 | + if ($context['report_type'] == 'members' || $user_info['mod_cache']['bq'] == '0=1') { |
|
| 59 | + isAllowedTo('moderate_forum'); |
|
| 60 | + } |
|
| 59 | 61 | |
| 60 | 62 | $subActions = array( |
| 61 | 63 | 'show' => 'ShowReports', |
@@ -70,11 +72,11 @@ discard block |
||
| 70 | 72 | call_integration_hook('integrate_reported_' . $context['report_type'], array(&$subActions)); |
| 71 | 73 | |
| 72 | 74 | // By default we call the open sub-action. |
| 73 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 74 | - $context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES); |
|
| 75 | - |
|
| 76 | - else |
|
| 77 | - $context['sub_action'] = 'show'; |
|
| 75 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 76 | + $context['sub_action'] = $smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_REQUEST['sa']), ENT_QUOTES); |
|
| 77 | + } else { |
|
| 78 | + $context['sub_action'] = 'show'; |
|
| 79 | + } |
|
| 78 | 80 | |
| 79 | 81 | // Hi Ho Silver Away! |
| 80 | 82 | call_helper($subActions[$context['sub_action']]); |
@@ -116,11 +118,13 @@ discard block |
||
| 116 | 118 | |
| 117 | 119 | // All the ones to update... |
| 118 | 120 | $toClose = array(); |
| 119 | - foreach ($_POST['close'] as $rid) |
|
| 120 | - $toClose[] = (int) $rid; |
|
| 121 | + foreach ($_POST['close'] as $rid) { |
|
| 122 | + $toClose[] = (int) $rid; |
|
| 123 | + } |
|
| 121 | 124 | |
| 122 | - if (!empty($toClose)) |
|
| 123 | - updateReport('closed', 1, $toClose); |
|
| 125 | + if (!empty($toClose)) { |
|
| 126 | + updateReport('closed', 1, $toClose); |
|
| 127 | + } |
|
| 124 | 128 | |
| 125 | 129 | // Set the confirmation message. |
| 126 | 130 | $_SESSION['rc_confirmation'] = 'close_all'; |
@@ -175,8 +179,9 @@ discard block |
||
| 175 | 179 | global $context, $sourcedir, $scripturl, $txt; |
| 176 | 180 | |
| 177 | 181 | // Have to at least give us something to work with. |
| 178 | - if (empty($_REQUEST['rid'])) |
|
| 179 | - fatal_lang_error('mc_reportedp_none_found'); |
|
| 182 | + if (empty($_REQUEST['rid'])) { |
|
| 183 | + fatal_lang_error('mc_reportedp_none_found'); |
|
| 184 | + } |
|
| 180 | 185 | |
| 181 | 186 | // Integers only please |
| 182 | 187 | $report_id = (int) $_REQUEST['rid']; |
@@ -184,8 +189,9 @@ discard block |
||
| 184 | 189 | // Get the report details. |
| 185 | 190 | $report = getReportDetails($report_id); |
| 186 | 191 | |
| 187 | - if (!$report) |
|
| 188 | - fatal_lang_error('mc_no_modreport_found'); |
|
| 192 | + if (!$report) { |
|
| 193 | + fatal_lang_error('mc_no_modreport_found'); |
|
| 194 | + } |
|
| 189 | 195 | |
| 190 | 196 | // Build the report data - basic details first, then extra stuff based on the type |
| 191 | 197 | $context['report'] = array( |
@@ -211,8 +217,7 @@ discard block |
||
| 211 | 217 | 'href' => $scripturl . '?action=profile;u=' . $report['id_user'], |
| 212 | 218 | ), |
| 213 | 219 | ); |
| 214 | - } |
|
| 215 | - else |
|
| 220 | + } else |
|
| 216 | 221 | { |
| 217 | 222 | $extraDetails = array( |
| 218 | 223 | 'topic_id' => $report['id_topic'], |
@@ -235,8 +240,9 @@ discard block |
||
| 235 | 240 | |
| 236 | 241 | $reportComments = getReportComments($report_id); |
| 237 | 242 | |
| 238 | - if (!empty($reportComments)) |
|
| 239 | - $context['report'] = array_merge($context['report'], $reportComments); |
|
| 243 | + if (!empty($reportComments)) { |
|
| 244 | + $context['report'] = array_merge($context['report'], $reportComments); |
|
| 245 | + } |
|
| 240 | 246 | |
| 241 | 247 | // What have the other moderators done to this message? |
| 242 | 248 | require_once($sourcedir . '/Modlog.php'); |
@@ -257,8 +263,7 @@ discard block |
||
| 257 | 263 | 1, |
| 258 | 264 | true, |
| 259 | 265 | ); |
| 260 | - } |
|
| 261 | - else |
|
| 266 | + } else |
|
| 262 | 267 | { |
| 263 | 268 | $params = array( |
| 264 | 269 | 'lm.id_topic = {int:id_topic} |
@@ -358,16 +363,16 @@ discard block |
||
| 358 | 363 | createList($listOptions); |
| 359 | 364 | |
| 360 | 365 | // Make sure to get the correct tab selected. |
| 361 | - if ($context['report']['closed']) |
|
| 362 | - $context[$context['moderation_menu_name']]['current_subsection'] = 'closed'; |
|
| 366 | + if ($context['report']['closed']) { |
|
| 367 | + $context[$context['moderation_menu_name']]['current_subsection'] = 'closed'; |
|
| 368 | + } |
|
| 363 | 369 | |
| 364 | 370 | // Finally we are done :P |
| 365 | 371 | if ($context['report_type'] == 'members') |
| 366 | 372 | { |
| 367 | 373 | $context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']); |
| 368 | 374 | $context['sub_template'] = 'viewmemberreport'; |
| 369 | - } |
|
| 370 | - else |
|
| 375 | + } else |
|
| 371 | 376 | { |
| 372 | 377 | $context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']); |
| 373 | 378 | $context['sub_template'] = 'viewmodreport'; |
@@ -390,8 +395,9 @@ discard block |
||
| 390 | 395 | global $smcFunc, $scripturl, $user_info, $context; |
| 391 | 396 | |
| 392 | 397 | // The report ID is a must. |
| 393 | - if (empty($_REQUEST['rid'])) |
|
| 394 | - fatal_lang_error('mc_reportedp_none_found'); |
|
| 398 | + if (empty($_REQUEST['rid'])) { |
|
| 399 | + fatal_lang_error('mc_reportedp_none_found'); |
|
| 400 | + } |
|
| 395 | 401 | |
| 396 | 402 | // Integers only please. |
| 397 | 403 | $report_id = (int) $_REQUEST['rid']; |
@@ -416,8 +422,9 @@ discard block |
||
| 416 | 422 | checkSession('get'); |
| 417 | 423 | validateToken('mod-reportC-delete', 'get'); |
| 418 | 424 | |
| 419 | - if (empty($_REQUEST['mid'])) |
|
| 420 | - fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 425 | + if (empty($_REQUEST['mid'])) { |
|
| 426 | + fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 427 | + } |
|
| 421 | 428 | |
| 422 | 429 | $comment_id = (int) $_REQUEST['mid']; |
| 423 | 430 | |
@@ -425,15 +432,17 @@ discard block |
||
| 425 | 432 | $comment = getCommentModDetails($comment_id); |
| 426 | 433 | |
| 427 | 434 | // Perhaps somebody else already deleted this fine gem... |
| 428 | - if (empty($comment)) |
|
| 429 | - fatal_lang_error('report_action_message_delete_issue'); |
|
| 435 | + if (empty($comment)) { |
|
| 436 | + fatal_lang_error('report_action_message_delete_issue'); |
|
| 437 | + } |
|
| 430 | 438 | |
| 431 | 439 | // Can you actually do this? |
| 432 | 440 | $comment_owner = $user_info['id'] == $comment['id_member']; |
| 433 | 441 | |
| 434 | 442 | // Nope! sorry. |
| 435 | - if (!allowedTo('admin_forum') && !$comment_owner) |
|
| 436 | - fatal_lang_error('report_action_message_delete_cannot'); |
|
| 443 | + if (!allowedTo('admin_forum') && !$comment_owner) { |
|
| 444 | + fatal_lang_error('report_action_message_delete_cannot'); |
|
| 445 | + } |
|
| 437 | 446 | |
| 438 | 447 | // All good! |
| 439 | 448 | deleteModComment($comment_id); |
@@ -458,11 +467,13 @@ discard block |
||
| 458 | 467 | checkSession(isset($_REQUEST['save']) ? 'post' : 'get'); |
| 459 | 468 | |
| 460 | 469 | // The report ID is a must. |
| 461 | - if (empty($_REQUEST['rid'])) |
|
| 462 | - fatal_lang_error('mc_reportedp_none_found'); |
|
| 470 | + if (empty($_REQUEST['rid'])) { |
|
| 471 | + fatal_lang_error('mc_reportedp_none_found'); |
|
| 472 | + } |
|
| 463 | 473 | |
| 464 | - if (empty($_REQUEST['mid'])) |
|
| 465 | - fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 474 | + if (empty($_REQUEST['mid'])) { |
|
| 475 | + fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 476 | + } |
|
| 466 | 477 | |
| 467 | 478 | // Integers only please. |
| 468 | 479 | $context['report_id'] = (int) $_REQUEST['rid']; |
@@ -470,8 +481,9 @@ discard block |
||
| 470 | 481 | |
| 471 | 482 | $context['comment'] = getCommentModDetails($context['comment_id']); |
| 472 | 483 | |
| 473 | - if (empty($context['comment'])) |
|
| 474 | - fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 484 | + if (empty($context['comment'])) { |
|
| 485 | + fatal_lang_error('mc_reportedp_comment_none_found'); |
|
| 486 | + } |
|
| 475 | 487 | |
| 476 | 488 | // Set up the comforting bits... |
| 477 | 489 | $context['page_title'] = $txt['mc_reported_posts']; |
@@ -482,15 +494,17 @@ discard block |
||
| 482 | 494 | validateToken('mod-reportC-edit'); |
| 483 | 495 | |
| 484 | 496 | // Make sure there is some data to edit on the DB. |
| 485 | - if (empty($context['comment'])) |
|
| 486 | - fatal_lang_error('report_action_message_edit_issue'); |
|
| 497 | + if (empty($context['comment'])) { |
|
| 498 | + fatal_lang_error('report_action_message_edit_issue'); |
|
| 499 | + } |
|
| 487 | 500 | |
| 488 | 501 | // Still there, good, now lets see if you can actually edit it... |
| 489 | 502 | $comment_owner = $user_info['id'] == $context['comment']['id_member']; |
| 490 | 503 | |
| 491 | 504 | // So, you aren't neither an admin or the comment owner huh? that's too bad. |
| 492 | - if (!allowedTo('admin_forum') && !$comment_owner) |
|
| 493 | - fatal_lang_error('report_action_message_edit_cannot'); |
|
| 505 | + if (!allowedTo('admin_forum') && !$comment_owner) { |
|
| 506 | + fatal_lang_error('report_action_message_edit_cannot'); |
|
| 507 | + } |
|
| 494 | 508 | |
| 495 | 509 | // All good! |
| 496 | 510 | $edited_comment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment'])); |
@@ -516,8 +530,9 @@ discard block |
||
| 516 | 530 | checkSession('get'); |
| 517 | 531 | |
| 518 | 532 | // We need to do something! |
| 519 | - if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed']))) |
|
| 520 | - fatal_lang_error('mc_reportedp_none_found'); |
|
| 533 | + if (empty($_GET['rid']) && (!isset($_GET['ignore']) || !isset($_GET['closed']))) { |
|
| 534 | + fatal_lang_error('mc_reportedp_none_found'); |
|
| 535 | + } |
|
| 521 | 536 | |
| 522 | 537 | // What are we gonna do? |
| 523 | 538 | $action = isset($_GET['ignore']) ? 'ignore' : 'closed'; |
@@ -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 | * Sets the SMF-style login cookie and session based on the id_member and password passed. |
@@ -43,8 +44,9 @@ discard block |
||
| 43 | 44 | $array = smf_json_decode($_COOKIE[$cookiename], true); |
| 44 | 45 | |
| 45 | 46 | // Legacy format |
| 46 | - if (is_null($array)) |
|
| 47 | - $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 47 | + if (is_null($array)) { |
|
| 48 | + $array = safe_unserialize($_COOKIE[$cookiename]); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | // Out with the old, in with the new! |
| 50 | 52 | if (isset($array[3]) && $array[3] != $cookie_state) |
@@ -62,8 +64,9 @@ discard block |
||
| 62 | 64 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 63 | 65 | |
| 64 | 66 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 65 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 66 | - smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 67 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 68 | + smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 69 | + } |
|
| 67 | 70 | |
| 68 | 71 | // Any alias URLs? This is mainly for use with frames, etc. |
| 69 | 72 | if (!empty($modSettings['forum_alias_urls'])) |
@@ -79,8 +82,9 @@ discard block |
||
| 79 | 82 | |
| 80 | 83 | $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); |
| 81 | 84 | |
| 82 | - if ($cookie_url[0] == '') |
|
| 83 | - $cookie_url[0] = strtok($alias, '/'); |
|
| 85 | + if ($cookie_url[0] == '') { |
|
| 86 | + $cookie_url[0] = strtok($alias, '/'); |
|
| 87 | + } |
|
| 84 | 88 | |
| 85 | 89 | smf_setcookie($cookiename, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 86 | 90 | } |
@@ -126,8 +130,9 @@ discard block |
||
| 126 | 130 | $identifier = $cookiename . '_tfa'; |
| 127 | 131 | $cookie_state = (empty($modSettings['localCookies']) ? 0 : 1) | (empty($modSettings['globalCookies']) ? 0 : 2); |
| 128 | 132 | |
| 129 | - if ($preserve) |
|
| 130 | - $cookie_length = 81600 * 30; |
|
| 133 | + if ($preserve) { |
|
| 134 | + $cookie_length = 81600 * 30; |
|
| 135 | + } |
|
| 131 | 136 | |
| 132 | 137 | // Get the data and path to set it on. |
| 133 | 138 | $data = json_encode(empty($id) ? array(0, '', 0, $cookie_state, false) : array($id, $secret, time() + $cookie_length, $cookie_state, $preserve)); |
@@ -137,8 +142,9 @@ discard block |
||
| 137 | 142 | smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], $cookie_url[0]); |
| 138 | 143 | |
| 139 | 144 | // If subdomain-independent cookies are on, unset the subdomain-dependent cookie too. |
| 140 | - if (empty($id) && !empty($modSettings['globalCookies'])) |
|
| 141 | - smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 145 | + if (empty($id) && !empty($modSettings['globalCookies'])) { |
|
| 146 | + smf_setcookie($identifier, $data, time() + $cookie_length, $cookie_url[1], ''); |
|
| 147 | + } |
|
| 142 | 148 | |
| 143 | 149 | $_COOKIE[$identifier] = $data; |
| 144 | 150 | } |
@@ -160,23 +166,28 @@ discard block |
||
| 160 | 166 | $parsed_url = parse_url($boardurl); |
| 161 | 167 | |
| 162 | 168 | // Is local cookies off? |
| 163 | - if (empty($parsed_url['path']) || !$local) |
|
| 164 | - $parsed_url['path'] = ''; |
|
| 169 | + if (empty($parsed_url['path']) || !$local) { |
|
| 170 | + $parsed_url['path'] = ''; |
|
| 171 | + } |
|
| 165 | 172 | |
| 166 | - if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) |
|
| 167 | - $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 173 | + if (!empty($modSettings['globalCookiesDomain']) && strpos($boardurl, $modSettings['globalCookiesDomain']) !== false) { |
|
| 174 | + $parsed_url['host'] = $modSettings['globalCookiesDomain']; |
|
| 175 | + } |
|
| 168 | 176 | |
| 169 | 177 | // Globalize cookies across domains (filter out IP-addresses)? |
| 170 | - elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) |
|
| 171 | - $parsed_url['host'] = '.' . $parts[1]; |
|
| 178 | + elseif ($global && preg_match('~^\d{1,3}(\.\d{1,3}){3}$~', $parsed_url['host']) == 0 && preg_match('~(?:[^\.]+\.)?([^\.]{2,}\..+)\z~i', $parsed_url['host'], $parts) == 1) { |
|
| 179 | + $parsed_url['host'] = '.' . $parts[1]; |
|
| 180 | + } |
|
| 172 | 181 | |
| 173 | 182 | // We shouldn't use a host at all if both options are off. |
| 174 | - elseif (!$local && !$global) |
|
| 175 | - $parsed_url['host'] = ''; |
|
| 183 | + elseif (!$local && !$global) { |
|
| 184 | + $parsed_url['host'] = ''; |
|
| 185 | + } |
|
| 176 | 186 | |
| 177 | 187 | // The host also shouldn't be set if there aren't any dots in it. |
| 178 | - elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) |
|
| 179 | - $parsed_url['host'] = ''; |
|
| 188 | + elseif (!isset($parsed_url['host']) || strpos($parsed_url['host'], '.') === false) { |
|
| 189 | + $parsed_url['host'] = ''; |
|
| 190 | + } |
|
| 180 | 191 | |
| 181 | 192 | return array($parsed_url['host'], $parsed_url['path'] . '/'); |
| 182 | 193 | } |
@@ -195,8 +206,9 @@ discard block |
||
| 195 | 206 | createToken('login'); |
| 196 | 207 | |
| 197 | 208 | // Never redirect to an attachment |
| 198 | - if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) |
|
| 199 | - $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 209 | + if (strpos($_SERVER['REQUEST_URL'], 'dlattach') === false) { |
|
| 210 | + $_SESSION['login_url'] = $_SERVER['REQUEST_URL']; |
|
| 211 | + } |
|
| 200 | 212 | |
| 201 | 213 | $context['sub_template'] = 'kick_guest'; |
| 202 | 214 | $context['page_title'] = $txt['login']; |
@@ -251,10 +263,12 @@ discard block |
||
| 251 | 263 | $txt['security_wrong'] = sprintf($txt['security_wrong'], isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $txt['unknown'], $_SERVER['HTTP_USER_AGENT'], $user_info['ip']); |
| 252 | 264 | log_error($txt['security_wrong'], 'critical'); |
| 253 | 265 | |
| 254 | - if (isset($_POST[$type . '_hash_pass'])) |
|
| 255 | - unset($_POST[$type . '_hash_pass']); |
|
| 256 | - if (isset($_POST[$type . '_pass'])) |
|
| 257 | - unset($_POST[$type . '_pass']); |
|
| 266 | + if (isset($_POST[$type . '_hash_pass'])) { |
|
| 267 | + unset($_POST[$type . '_hash_pass']); |
|
| 268 | + } |
|
| 269 | + if (isset($_POST[$type . '_pass'])) { |
|
| 270 | + unset($_POST[$type . '_pass']); |
|
| 271 | + } |
|
| 258 | 272 | |
| 259 | 273 | $context['incorrect_password'] = true; |
| 260 | 274 | } |
@@ -267,15 +281,17 @@ discard block |
||
| 267 | 281 | |
| 268 | 282 | // Now go through $_POST. Make sure the session hash is sent. |
| 269 | 283 | $_POST[$context['session_var']] = $context['session_id']; |
| 270 | - foreach ($_POST as $k => $v) |
|
| 271 | - $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 284 | + foreach ($_POST as $k => $v) { |
|
| 285 | + $context['post_data'] .= adminLogin_outputPostVars($k, $v); |
|
| 286 | + } |
|
| 272 | 287 | |
| 273 | 288 | // Now we'll use the admin_login sub template of the Login template. |
| 274 | 289 | $context['sub_template'] = 'admin_login'; |
| 275 | 290 | |
| 276 | 291 | // And title the page something like "Login". |
| 277 | - if (!isset($context['page_title'])) |
|
| 278 | - $context['page_title'] = $txt['login']; |
|
| 292 | + if (!isset($context['page_title'])) { |
|
| 293 | + $context['page_title'] = $txt['login']; |
|
| 294 | + } |
|
| 279 | 295 | |
| 280 | 296 | // The type of action. |
| 281 | 297 | $context['sessionCheckType'] = $type; |
@@ -298,14 +314,15 @@ discard block |
||
| 298 | 314 | { |
| 299 | 315 | global $smcFunc; |
| 300 | 316 | |
| 301 | - if (!is_array($v)) |
|
| 302 | - return ' |
|
| 317 | + if (!is_array($v)) { |
|
| 318 | + return ' |
|
| 303 | 319 | <input type="hidden" name="' . $smcFunc['htmlspecialchars']($k) . '" value="' . strtr($v, array('"' => '"', '<' => '<', '>' => '>')) . '">'; |
| 304 | - else |
|
| 320 | + } else |
|
| 305 | 321 | { |
| 306 | 322 | $ret = ''; |
| 307 | - foreach ($v as $k2 => $v2) |
|
| 308 | - $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 323 | + foreach ($v as $k2 => $v2) { |
|
| 324 | + $ret .= adminLogin_outputPostVars($k . '[' . $k2 . ']', $v2); |
|
| 325 | + } |
|
| 309 | 326 | |
| 310 | 327 | return $ret; |
| 311 | 328 | } |
@@ -332,18 +349,20 @@ discard block |
||
| 332 | 349 | foreach ($get as $k => $v) |
| 333 | 350 | { |
| 334 | 351 | // Only if it's not already in the $scripturl! |
| 335 | - if (!isset($temp[$k])) |
|
| 336 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 352 | + if (!isset($temp[$k])) { |
|
| 353 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 354 | + } |
|
| 337 | 355 | // If it changed, put it out there, but with an ampersand. |
| 338 | - elseif ($temp[$k] != $get[$k]) |
|
| 339 | - $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 356 | + elseif ($temp[$k] != $get[$k]) { |
|
| 357 | + $query_string .= urlencode($k) . '=' . urlencode($v) . '&'; |
|
| 358 | + } |
|
| 340 | 359 | } |
| 341 | - } |
|
| 342 | - else |
|
| 360 | + } else |
|
| 343 | 361 | { |
| 344 | 362 | // Add up all the data from $_GET into get_data. |
| 345 | - foreach ($get as $k => $v) |
|
| 346 | - $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 363 | + foreach ($get as $k => $v) { |
|
| 364 | + $query_string .= urlencode($k) . '=' . urlencode($v) . ';'; |
|
| 365 | + } |
|
| 347 | 366 | } |
| 348 | 367 | |
| 349 | 368 | $query_string = substr($query_string, 0, -1); |
@@ -366,8 +385,9 @@ discard block |
||
| 366 | 385 | global $scripturl, $user_info, $smcFunc; |
| 367 | 386 | |
| 368 | 387 | // If it's not already an array, make it one. |
| 369 | - if (!is_array($names)) |
|
| 370 | - $names = explode(',', $names); |
|
| 388 | + if (!is_array($names)) { |
|
| 389 | + $names = explode(',', $names); |
|
| 390 | + } |
|
| 371 | 391 | |
| 372 | 392 | $maybe_email = false; |
| 373 | 393 | foreach ($names as $i => $name) |
@@ -378,10 +398,11 @@ discard block |
||
| 378 | 398 | $maybe_email |= strpos($name, '@') !== false; |
| 379 | 399 | |
| 380 | 400 | // Make it so standard wildcards will work. (* and ?) |
| 381 | - if ($use_wildcards) |
|
| 382 | - $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 383 | - else |
|
| 384 | - $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 401 | + if ($use_wildcards) { |
|
| 402 | + $names[$i] = strtr($names[$i], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '\'' => ''')); |
|
| 403 | + } else { |
|
| 404 | + $names[$i] = strtr($names[$i], array('\'' => ''')); |
|
| 405 | + } |
|
| 385 | 406 | } |
| 386 | 407 | |
| 387 | 408 | // What are we using to compare? |
@@ -391,11 +412,12 @@ discard block |
||
| 391 | 412 | $results = array(); |
| 392 | 413 | |
| 393 | 414 | // This ensures you can't search someones email address if you can't see it. |
| 394 | - if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) |
|
| 395 | - $email_condition = ' |
|
| 415 | + if (($use_wildcards || $maybe_email) && allowedTo('moderate_forum')) { |
|
| 416 | + $email_condition = ' |
|
| 396 | 417 | OR (email_address ' . $comparison . ' \'' . implode('\') OR (email_address ' . $comparison . ' \'', $names) . '\')'; |
| 397 | - else |
|
| 398 | - $email_condition = ''; |
|
| 418 | + } else { |
|
| 419 | + $email_condition = ''; |
|
| 420 | + } |
|
| 399 | 421 | |
| 400 | 422 | // Get the case of the columns right - but only if we need to as things like MySQL will go slow needlessly otherwise. |
| 401 | 423 | $member_name = $smcFunc['db_case_sensitive'] ? 'LOWER(member_name)' : 'member_name'; |
@@ -453,10 +475,11 @@ discard block |
||
| 453 | 475 | $context['template_layers'] = array(); |
| 454 | 476 | $context['sub_template'] = 'find_members'; |
| 455 | 477 | |
| 456 | - if (isset($_REQUEST['search'])) |
|
| 457 | - $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 458 | - else |
|
| 459 | - $_REQUEST['start'] = 0; |
|
| 478 | + if (isset($_REQUEST['search'])) { |
|
| 479 | + $context['last_search'] = $smcFunc['htmlspecialchars']($_REQUEST['search'], ENT_QUOTES); |
|
| 480 | + } else { |
|
| 481 | + $_REQUEST['start'] = 0; |
|
| 482 | + } |
|
| 460 | 483 | |
| 461 | 484 | // Allow the user to pass the input to be added to to the box. |
| 462 | 485 | $context['input_box_name'] = isset($_REQUEST['input']) && preg_match('~^[\w-]+$~', $_REQUEST['input']) === 1 ? $_REQUEST['input'] : 'to'; |
@@ -497,10 +520,10 @@ discard block |
||
| 497 | 520 | ); |
| 498 | 521 | |
| 499 | 522 | $context['results'] = array_slice($context['results'], $_REQUEST['start'], 7); |
| 523 | + } else { |
|
| 524 | + $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 525 | + } |
|
| 500 | 526 | } |
| 501 | - else |
|
| 502 | - $context['links']['up'] = $scripturl . '?action=pm;sa=send' . (empty($_REQUEST['u']) ? '' : ';u=' . $_REQUEST['u']); |
|
| 503 | -} |
|
| 504 | 527 | |
| 505 | 528 | /** |
| 506 | 529 | * Outputs each member name on its own line. |
@@ -516,8 +539,9 @@ discard block |
||
| 516 | 539 | $_REQUEST['search'] = trim($smcFunc['strtolower']($_REQUEST['search'])); |
| 517 | 540 | $_REQUEST['search'] = strtr($_REQUEST['search'], array('%' => '\%', '_' => '\_', '*' => '%', '?' => '_', '&' => '&')); |
| 518 | 541 | |
| 519 | - if (function_exists('iconv')) |
|
| 520 | - header('Content-Type: text/plain; charset=UTF-8'); |
|
| 542 | + if (function_exists('iconv')) { |
|
| 543 | + header('Content-Type: text/plain; charset=UTF-8'); |
|
| 544 | + } |
|
| 521 | 545 | |
| 522 | 546 | $request = $smcFunc['db_query']('', ' |
| 523 | 547 | SELECT real_name |
@@ -537,14 +561,16 @@ discard block |
||
| 537 | 561 | if (function_exists('iconv')) |
| 538 | 562 | { |
| 539 | 563 | $utf8 = iconv($txt['lang_character_set'], 'UTF-8', $row['real_name']); |
| 540 | - if ($utf8) |
|
| 541 | - $row['real_name'] = $utf8; |
|
| 564 | + if ($utf8) { |
|
| 565 | + $row['real_name'] = $utf8; |
|
| 566 | + } |
|
| 542 | 567 | } |
| 543 | 568 | |
| 544 | 569 | $row['real_name'] = strtr($row['real_name'], array('&' => '&', '<' => '<', '>' => '>', '"' => '"')); |
| 545 | 570 | |
| 546 | - if (preg_match('~&#\d+;~', $row['real_name']) != 0) |
|
| 547 | - $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 571 | + if (preg_match('~&#\d+;~', $row['real_name']) != 0) { |
|
| 572 | + $row['real_name'] = preg_replace_callback('~&#(\d+);~', 'fixchar__callback', $row['real_name']); |
|
| 573 | + } |
|
| 548 | 574 | |
| 549 | 575 | echo $row['real_name'], "\n"; |
| 550 | 576 | } |
@@ -601,9 +627,9 @@ discard block |
||
| 601 | 627 | |
| 602 | 628 | // Update the database... |
| 603 | 629 | updateMemberData($memID, array('member_name' => $user, 'passwd' => $newPassword_sha1)); |
| 630 | + } else { |
|
| 631 | + updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 604 | 632 | } |
| 605 | - else |
|
| 606 | - updateMemberData($memID, array('passwd' => $newPassword_sha1)); |
|
| 607 | 633 | |
| 608 | 634 | call_integration_hook('integrate_reset_pass', array($old_user, $user, $newPassword)); |
| 609 | 635 | |
@@ -634,31 +660,37 @@ discard block |
||
| 634 | 660 | $errors = array(); |
| 635 | 661 | |
| 636 | 662 | // Don't use too long a name. |
| 637 | - if ($smcFunc['strlen']($username) > 25) |
|
| 638 | - $errors[] = array('lang', 'error_long_name'); |
|
| 663 | + if ($smcFunc['strlen']($username) > 25) { |
|
| 664 | + $errors[] = array('lang', 'error_long_name'); |
|
| 665 | + } |
|
| 639 | 666 | |
| 640 | 667 | // No name?! How can you register with no name? |
| 641 | - if ($username == '') |
|
| 642 | - $errors[] = array('lang', 'need_username'); |
|
| 668 | + if ($username == '') { |
|
| 669 | + $errors[] = array('lang', 'need_username'); |
|
| 670 | + } |
|
| 643 | 671 | |
| 644 | 672 | // Only these characters are permitted. |
| 645 | - if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) |
|
| 646 | - $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 673 | + if (in_array($username, array('_', '|')) || preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $username)) != 0 || strpos($username, '[code') !== false || strpos($username, '[/code') !== false) { |
|
| 674 | + $errors[] = array('lang', 'error_invalid_characters_username'); |
|
| 675 | + } |
|
| 647 | 676 | |
| 648 | - if (stristr($username, $txt['guest_title']) !== false) |
|
| 649 | - $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 677 | + if (stristr($username, $txt['guest_title']) !== false) { |
|
| 678 | + $errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title'])); |
|
| 679 | + } |
|
| 650 | 680 | |
| 651 | 681 | if ($check_reserved_name) |
| 652 | 682 | { |
| 653 | 683 | require_once($sourcedir . '/Subs-Members.php'); |
| 654 | - if (isReservedName($username, $memID, false)) |
|
| 655 | - $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 684 | + if (isReservedName($username, $memID, false)) { |
|
| 685 | + $errors[] = array('done', '(' . $smcFunc['htmlspecialchars']($username) . ') ' . $txt['name_in_use']); |
|
| 686 | + } |
|
| 656 | 687 | } |
| 657 | 688 | |
| 658 | - if ($return_error) |
|
| 659 | - return $errors; |
|
| 660 | - elseif (empty($errors)) |
|
| 661 | - return null; |
|
| 689 | + if ($return_error) { |
|
| 690 | + return $errors; |
|
| 691 | + } elseif (empty($errors)) { |
|
| 692 | + return null; |
|
| 693 | + } |
|
| 662 | 694 | |
| 663 | 695 | loadLanguage('Errors'); |
| 664 | 696 | $error = $errors[0]; |
@@ -684,22 +716,26 @@ discard block |
||
| 684 | 716 | global $modSettings, $smcFunc; |
| 685 | 717 | |
| 686 | 718 | // Perform basic requirements first. |
| 687 | - if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) |
|
| 688 | - return 'short'; |
|
| 719 | + if ($smcFunc['strlen']($password) < (empty($modSettings['password_strength']) ? 4 : 8)) { |
|
| 720 | + return 'short'; |
|
| 721 | + } |
|
| 689 | 722 | |
| 690 | 723 | // Is this enough? |
| 691 | - if (empty($modSettings['password_strength'])) |
|
| 692 | - return null; |
|
| 724 | + if (empty($modSettings['password_strength'])) { |
|
| 725 | + return null; |
|
| 726 | + } |
|
| 693 | 727 | |
| 694 | 728 | // Otherwise, perform the medium strength test - checking if password appears in the restricted string. |
| 695 | - if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) |
|
| 696 | - return 'restricted_words'; |
|
| 697 | - elseif ($smcFunc['strpos']($password, $username) !== false) |
|
| 698 | - return 'restricted_words'; |
|
| 729 | + if (preg_match('~\b' . preg_quote($password, '~') . '\b~', implode(' ', $restrict_in)) != 0) { |
|
| 730 | + return 'restricted_words'; |
|
| 731 | + } elseif ($smcFunc['strpos']($password, $username) !== false) { |
|
| 732 | + return 'restricted_words'; |
|
| 733 | + } |
|
| 699 | 734 | |
| 700 | 735 | // If just medium, we're done. |
| 701 | - if ($modSettings['password_strength'] == 1) |
|
| 702 | - return null; |
|
| 736 | + if ($modSettings['password_strength'] == 1) { |
|
| 737 | + return null; |
|
| 738 | + } |
|
| 703 | 739 | |
| 704 | 740 | // Otherwise, hard test next, check for numbers and letters, uppercase too. |
| 705 | 741 | $good = preg_match('~(\D\d|\d\D)~', $password) != 0; |
@@ -731,14 +767,16 @@ discard block |
||
| 731 | 767 | ) |
| 732 | 768 | ); |
| 733 | 769 | $groups = array(); |
| 734 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 735 | - $groups[] = $row['id_group']; |
|
| 770 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 771 | + $groups[] = $row['id_group']; |
|
| 772 | + } |
|
| 736 | 773 | $smcFunc['db_free_result']($request); |
| 737 | 774 | |
| 738 | - if (empty($groups)) |
|
| 739 | - $group_query = '0=1'; |
|
| 740 | - else |
|
| 741 | - $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 775 | + if (empty($groups)) { |
|
| 776 | + $group_query = '0=1'; |
|
| 777 | + } else { |
|
| 778 | + $group_query = 'id_group IN (' . implode(',', $groups) . ')'; |
|
| 779 | + } |
|
| 742 | 780 | } |
| 743 | 781 | |
| 744 | 782 | // Then, same again, just the boards this time! |
@@ -748,10 +786,11 @@ discard block |
||
| 748 | 786 | { |
| 749 | 787 | $boards = boardsAllowedTo('moderate_board', true); |
| 750 | 788 | |
| 751 | - if (empty($boards)) |
|
| 752 | - $board_query = '0=1'; |
|
| 753 | - else |
|
| 754 | - $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 789 | + if (empty($boards)) { |
|
| 790 | + $board_query = '0=1'; |
|
| 791 | + } else { |
|
| 792 | + $board_query = 'id_board IN (' . implode(',', $boards) . ')'; |
|
| 793 | + } |
|
| 755 | 794 | } |
| 756 | 795 | |
| 757 | 796 | // What boards are they the moderator of? |
@@ -766,8 +805,9 @@ discard block |
||
| 766 | 805 | 'current_member' => $user_info['id'], |
| 767 | 806 | ) |
| 768 | 807 | ); |
| 769 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 770 | - $boards_mod[] = $row['id_board']; |
|
| 808 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 809 | + $boards_mod[] = $row['id_board']; |
|
| 810 | + } |
|
| 771 | 811 | $smcFunc['db_free_result']($request); |
| 772 | 812 | |
| 773 | 813 | // Can any of the groups they're in moderate any of the boards? |
@@ -779,8 +819,9 @@ discard block |
||
| 779 | 819 | 'groups' => $user_info['groups'], |
| 780 | 820 | ) |
| 781 | 821 | ); |
| 782 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 783 | - $boards_mod[] = $row['id_board']; |
|
| 822 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 823 | + $boards_mod[] = $row['id_board']; |
|
| 824 | + } |
|
| 784 | 825 | $smcFunc['db_free_result']($request); |
| 785 | 826 | |
| 786 | 827 | // Just in case we've got duplicates here... |
@@ -825,10 +866,12 @@ discard block |
||
| 825 | 866 | global $modSettings; |
| 826 | 867 | |
| 827 | 868 | // In case a customization wants to override the default settings |
| 828 | - if ($httponly === null) |
|
| 829 | - $httponly = !empty($modSettings['httponlyCookies']); |
|
| 830 | - if ($secure === null) |
|
| 831 | - $secure = !empty($modSettings['secureCookies']); |
|
| 869 | + if ($httponly === null) { |
|
| 870 | + $httponly = !empty($modSettings['httponlyCookies']); |
|
| 871 | + } |
|
| 872 | + if ($secure === null) { |
|
| 873 | + $secure = !empty($modSettings['secureCookies']); |
|
| 874 | + } |
|
| 832 | 875 | |
| 833 | 876 | // Intercept cookie? |
| 834 | 877 | call_integration_hook('integrate_cookie', array($name, $value, $expire, $path, $domain, $secure, $httponly)); |
@@ -848,8 +891,9 @@ discard block |
||
| 848 | 891 | function hash_password($username, $password, $cost = null) |
| 849 | 892 | { |
| 850 | 893 | global $sourcedir, $smcFunc, $modSettings; |
| 851 | - if (!function_exists('password_hash')) |
|
| 852 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 894 | + if (!function_exists('password_hash')) { |
|
| 895 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 896 | + } |
|
| 853 | 897 | |
| 854 | 898 | $cost = empty($cost) ? (empty($modSettings['bcrypt_hash_cost']) ? 10 : $modSettings['bcrypt_hash_cost']) : $cost; |
| 855 | 899 | |
@@ -881,8 +925,9 @@ discard block |
||
| 881 | 925 | function hash_verify_password($username, $password, $hash) |
| 882 | 926 | { |
| 883 | 927 | global $sourcedir, $smcFunc; |
| 884 | - if (!function_exists('password_verify')) |
|
| 885 | - require_once($sourcedir . '/Subs-Password.php'); |
|
| 928 | + if (!function_exists('password_verify')) { |
|
| 929 | + require_once($sourcedir . '/Subs-Password.php'); |
|
| 930 | + } |
|
| 886 | 931 | |
| 887 | 932 | return password_verify($smcFunc['strtolower']($username) . $password, $hash); |
| 888 | 933 | } |
@@ -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 | * Class xmlArray |
@@ -65,8 +66,9 @@ discard block |
||
| 65 | 66 | } |
| 66 | 67 | |
| 67 | 68 | // Is the input an array? (ie. passed from file()?) |
| 68 | - if (is_array($data)) |
|
| 69 | - $data = implode('', $data); |
|
| 69 | + if (is_array($data)) { |
|
| 70 | + $data = implode('', $data); |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Remove any xml declaration or doctype, and parse out comments and CDATA. |
| 72 | 74 | $data = preg_replace('/<!--.*?-->/s', '', $this->_to_cdata(preg_replace(array('/^<\?xml.+?\?' . '>/is', '/<!DOCTYPE[^>]+?' . '>/s'), '', $data))); |
@@ -101,8 +103,9 @@ discard block |
||
| 101 | 103 | // Get the element, in array form. |
| 102 | 104 | $array = $this->path($path); |
| 103 | 105 | |
| 104 | - if ($array === false) |
|
| 105 | - return false; |
|
| 106 | + if ($array === false) { |
|
| 107 | + return false; |
|
| 108 | + } |
|
| 106 | 109 | |
| 107 | 110 | // Getting elements into this is a bit complicated... |
| 108 | 111 | if ($get_elements && !is_string($array)) |
@@ -113,8 +116,9 @@ discard block |
||
| 113 | 116 | foreach ($array->array as $val) |
| 114 | 117 | { |
| 115 | 118 | // Skip the name and any attributes. |
| 116 | - if (is_array($val)) |
|
| 117 | - $temp .= $this->_xml($val, null); |
|
| 119 | + if (is_array($val)) { |
|
| 120 | + $temp .= $this->_xml($val, null); |
|
| 121 | + } |
|
| 118 | 122 | } |
| 119 | 123 | |
| 120 | 124 | // Just get the XML data and then take out the CDATAs. |
@@ -156,32 +160,35 @@ discard block |
||
| 156 | 160 | elseif (substr($el, 0, 1) == '@') |
| 157 | 161 | { |
| 158 | 162 | // It simplifies things if the attribute is already there ;). |
| 159 | - if (isset($array[$el])) |
|
| 160 | - return $array[$el]; |
|
| 161 | - else |
|
| 163 | + if (isset($array[$el])) { |
|
| 164 | + return $array[$el]; |
|
| 165 | + } else |
|
| 162 | 166 | { |
| 163 | 167 | $trace = debug_backtrace(); |
| 164 | 168 | $i = 0; |
| 165 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 166 | - $i++; |
|
| 169 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 170 | + $i++; |
|
| 171 | + } |
|
| 167 | 172 | $debug = ' (from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line'] . ')'; |
| 168 | 173 | |
| 169 | 174 | // Cause an error. |
| 170 | - if ($this->debug_level & E_NOTICE) |
|
| 171 | - trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 175 | + if ($this->debug_level & E_NOTICE) { |
|
| 176 | + trigger_error('Undefined XML attribute: ' . substr($el, 1) . $debug, E_USER_NOTICE); |
|
| 177 | + } |
|
| 172 | 178 | return false; |
| 173 | 179 | } |
| 180 | + } else { |
|
| 181 | + $lvl = null; |
|
| 174 | 182 | } |
| 175 | - else |
|
| 176 | - $lvl = null; |
|
| 177 | 183 | |
| 178 | 184 | // Find this element. |
| 179 | 185 | $array = $this->_path($array, $el, $lvl); |
| 180 | 186 | } |
| 181 | 187 | |
| 182 | 188 | // Clean up after $lvl, for $return_full. |
| 183 | - if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) |
|
| 184 | - $array = array('name' => $el . '[]', $array); |
|
| 189 | + if ($return_full && (!isset($array['name']) || substr($array['name'], -1) != ']')) { |
|
| 190 | + $array = array('name' => $el . '[]', $array); |
|
| 191 | + } |
|
| 185 | 192 | |
| 186 | 193 | // Create the right type of class... |
| 187 | 194 | $newClass = get_class($this); |
@@ -216,10 +223,11 @@ discard block |
||
| 216 | 223 | $el = substr($el, 0, strpos($el, '[')); |
| 217 | 224 | } |
| 218 | 225 | // Find an attribute. |
| 219 | - elseif (substr($el, 0, 1) == '@') |
|
| 220 | - return isset($array[$el]); |
|
| 221 | - else |
|
| 222 | - $lvl = null; |
|
| 226 | + elseif (substr($el, 0, 1) == '@') { |
|
| 227 | + return isset($array[$el]); |
|
| 228 | + } else { |
|
| 229 | + $lvl = null; |
|
| 230 | + } |
|
| 223 | 231 | |
| 224 | 232 | // Find this element. |
| 225 | 233 | $array = $this->_path($array, $el, $lvl, true); |
@@ -244,8 +252,9 @@ discard block |
||
| 244 | 252 | $i = 0; |
| 245 | 253 | foreach ($temp->array as $item) |
| 246 | 254 | { |
| 247 | - if (is_array($item)) |
|
| 248 | - $i++; |
|
| 255 | + if (is_array($item)) { |
|
| 256 | + $i++; |
|
| 257 | + } |
|
| 249 | 258 | } |
| 250 | 259 | |
| 251 | 260 | return $i; |
@@ -269,8 +278,9 @@ discard block |
||
| 269 | 278 | foreach ($xml->array as $val) |
| 270 | 279 | { |
| 271 | 280 | // Skip these, they aren't elements. |
| 272 | - if (!is_array($val) || $val['name'] == '!') |
|
| 273 | - continue; |
|
| 281 | + if (!is_array($val) || $val['name'] == '!') { |
|
| 282 | + continue; |
|
| 283 | + } |
|
| 274 | 284 | |
| 275 | 285 | // Create the right type of class... |
| 276 | 286 | $newClass = get_class($this); |
@@ -297,14 +307,16 @@ discard block |
||
| 297 | 307 | $path = $this->path($path); |
| 298 | 308 | |
| 299 | 309 | // The path was not found |
| 300 | - if ($path === false) |
|
| 301 | - return false; |
|
| 310 | + if ($path === false) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 302 | 313 | |
| 303 | 314 | $path = $path->array; |
| 304 | 315 | } |
| 305 | 316 | // Just use the current array. |
| 306 | - else |
|
| 307 | - $path = $this->array; |
|
| 317 | + else { |
|
| 318 | + $path = $this->array; |
|
| 319 | + } |
|
| 308 | 320 | |
| 309 | 321 | // Add the xml declaration to the front. |
| 310 | 322 | return '<?xml version="1.0"?' . '>' . $this->_xml($path, 0); |
@@ -326,14 +338,16 @@ discard block |
||
| 326 | 338 | $path = $this->path($path); |
| 327 | 339 | |
| 328 | 340 | // The path was not found |
| 329 | - if ($path === false) |
|
| 330 | - return false; |
|
| 341 | + if ($path === false) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 331 | 344 | |
| 332 | 345 | $path = $path->array; |
| 333 | 346 | } |
| 334 | 347 | // No, so just use the current array. |
| 335 | - else |
|
| 336 | - $path = $this->array; |
|
| 348 | + else { |
|
| 349 | + $path = $this->array; |
|
| 350 | + } |
|
| 337 | 351 | |
| 338 | 352 | return $this->_array($path); |
| 339 | 353 | } |
@@ -355,8 +369,9 @@ discard block |
||
| 355 | 369 | { |
| 356 | 370 | // Find and remove the next tag. |
| 357 | 371 | preg_match('/\A<([\w\-:]+)((?:\s+.+?)?)([\s]?\/)?' . '>/', $data, $match); |
| 358 | - if (isset($match[0])) |
|
| 359 | - $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 372 | + if (isset($match[0])) { |
|
| 373 | + $data = preg_replace('/' . preg_quote($match[0], '/') . '/s', '', $data, 1); |
|
| 374 | + } |
|
| 360 | 375 | |
| 361 | 376 | // Didn't find a tag? Keep looping.... |
| 362 | 377 | if (!isset($match[1]) || $match[1] == '') |
@@ -367,11 +382,12 @@ discard block |
||
| 367 | 382 | $text_value = $this->_from_cdata($data); |
| 368 | 383 | $data = ''; |
| 369 | 384 | |
| 370 | - if ($text_value != '') |
|
| 371 | - $current[] = array( |
|
| 385 | + if ($text_value != '') { |
|
| 386 | + $current[] = array( |
|
| 372 | 387 | 'name' => '!', |
| 373 | 388 | 'value' => $text_value |
| 374 | 389 | ); |
| 390 | + } |
|
| 375 | 391 | } |
| 376 | 392 | // If the < isn't immediately next to the current position... more data. |
| 377 | 393 | elseif (strpos($data, '<') > 0) |
@@ -379,11 +395,12 @@ discard block |
||
| 379 | 395 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<'))); |
| 380 | 396 | $data = substr($data, strpos($data, '<')); |
| 381 | 397 | |
| 382 | - if ($text_value != '') |
|
| 383 | - $current[] = array( |
|
| 398 | + if ($text_value != '') { |
|
| 399 | + $current[] = array( |
|
| 384 | 400 | 'name' => '!', |
| 385 | 401 | 'value' => $text_value |
| 386 | 402 | ); |
| 403 | + } |
|
| 387 | 404 | } |
| 388 | 405 | // If we're looking at a </something> with no start, kill it. |
| 389 | 406 | elseif (strpos($data, '<') !== false && strpos($data, '<') == 0) |
@@ -393,22 +410,23 @@ discard block |
||
| 393 | 410 | $text_value = $this->_from_cdata(substr($data, 0, strpos($data, '<', 1))); |
| 394 | 411 | $data = substr($data, strpos($data, '<', 1)); |
| 395 | 412 | |
| 396 | - if ($text_value != '') |
|
| 397 | - $current[] = array( |
|
| 413 | + if ($text_value != '') { |
|
| 414 | + $current[] = array( |
|
| 398 | 415 | 'name' => '!', |
| 399 | 416 | 'value' => $text_value |
| 400 | 417 | ); |
| 401 | - } |
|
| 402 | - else |
|
| 418 | + } |
|
| 419 | + } else |
|
| 403 | 420 | { |
| 404 | 421 | $text_value = $this->_from_cdata($data); |
| 405 | 422 | $data = ''; |
| 406 | 423 | |
| 407 | - if ($text_value != '') |
|
| 408 | - $current[] = array( |
|
| 424 | + if ($text_value != '') { |
|
| 425 | + $current[] = array( |
|
| 409 | 426 | 'name' => '!', |
| 410 | 427 | 'value' => $text_value |
| 411 | 428 | ); |
| 429 | + } |
|
| 412 | 430 | } |
| 413 | 431 | } |
| 414 | 432 | |
@@ -425,8 +443,9 @@ discard block |
||
| 425 | 443 | { |
| 426 | 444 | // Because PHP 5.2.0+ seems to croak using regex, we'll have to do this the less fun way. |
| 427 | 445 | $last_tag_end = strpos($data, '</' . $match[1] . '>'); |
| 428 | - if ($last_tag_end === false) |
|
| 429 | - continue; |
|
| 446 | + if ($last_tag_end === false) { |
|
| 447 | + continue; |
|
| 448 | + } |
|
| 430 | 449 | |
| 431 | 450 | $offset = 0; |
| 432 | 451 | while (1 == 1) |
@@ -434,16 +453,17 @@ discard block |
||
| 434 | 453 | // Where is the next start tag? |
| 435 | 454 | $next_tag_start = strpos($data, '<' . $match[1], $offset); |
| 436 | 455 | // If the next start tag is after the last end tag then we've found the right close. |
| 437 | - if ($next_tag_start === false || $next_tag_start > $last_tag_end) |
|
| 438 | - break; |
|
| 456 | + if ($next_tag_start === false || $next_tag_start > $last_tag_end) { |
|
| 457 | + break; |
|
| 458 | + } |
|
| 439 | 459 | |
| 440 | 460 | // If not then find the next ending tag. |
| 441 | 461 | $next_tag_end = strpos($data, '</' . $match[1] . '>', $offset); |
| 442 | 462 | |
| 443 | 463 | // Didn't find one? Then just use the last and sod it. |
| 444 | - if ($next_tag_end === false) |
|
| 445 | - break; |
|
| 446 | - else |
|
| 464 | + if ($next_tag_end === false) { |
|
| 465 | + break; |
|
| 466 | + } else |
|
| 447 | 467 | { |
| 448 | 468 | $last_tag_end = $next_tag_end; |
| 449 | 469 | $offset = $next_tag_start + 1; |
@@ -457,16 +477,17 @@ discard block |
||
| 457 | 477 | if (!empty($inner_match)) |
| 458 | 478 | { |
| 459 | 479 | // Parse the inner data. |
| 460 | - if (strpos($inner_match, '<') !== false) |
|
| 461 | - $el += $this->_parse($inner_match); |
|
| 462 | - elseif (trim($inner_match) != '') |
|
| 480 | + if (strpos($inner_match, '<') !== false) { |
|
| 481 | + $el += $this->_parse($inner_match); |
|
| 482 | + } elseif (trim($inner_match) != '') |
|
| 463 | 483 | { |
| 464 | 484 | $text_value = $this->_from_cdata($inner_match); |
| 465 | - if ($text_value != '') |
|
| 466 | - $el[] = array( |
|
| 485 | + if ($text_value != '') { |
|
| 486 | + $el[] = array( |
|
| 467 | 487 | 'name' => '!', |
| 468 | 488 | 'value' => $text_value |
| 469 | 489 | ); |
| 490 | + } |
|
| 470 | 491 | } |
| 471 | 492 | } |
| 472 | 493 | } |
@@ -478,8 +499,9 @@ discard block |
||
| 478 | 499 | preg_match_all('/([\w:]+)="(.+?)"/', $match[2], $attr, PREG_SET_ORDER); |
| 479 | 500 | |
| 480 | 501 | // Set them as @attribute-name. |
| 481 | - foreach ($attr as $match_attr) |
|
| 482 | - $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 502 | + foreach ($attr as $match_attr) { |
|
| 503 | + $el['@' . $match_attr[1]] = $match_attr[2]; |
|
| 504 | + } |
|
| 483 | 505 | } |
| 484 | 506 | } |
| 485 | 507 | |
@@ -503,16 +525,18 @@ discard block |
||
| 503 | 525 | if (is_array($array) && !isset($array['name'])) |
| 504 | 526 | { |
| 505 | 527 | $temp = ''; |
| 506 | - foreach ($array as $val) |
|
| 507 | - $temp .= $this->_xml($val, $indent); |
|
| 528 | + foreach ($array as $val) { |
|
| 529 | + $temp .= $this->_xml($val, $indent); |
|
| 530 | + } |
|
| 508 | 531 | return $temp; |
| 509 | 532 | } |
| 510 | 533 | |
| 511 | 534 | // This is just text! |
| 512 | - if ($array['name'] == '!') |
|
| 513 | - return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 514 | - elseif (substr($array['name'], -2) == '[]') |
|
| 515 | - $array['name'] = substr($array['name'], 0, -2); |
|
| 535 | + if ($array['name'] == '!') { |
|
| 536 | + return $indentation . '<![CDATA[' . $array['value'] . ']]>'; |
|
| 537 | + } elseif (substr($array['name'], -2) == '[]') { |
|
| 538 | + $array['name'] = substr($array['name'], 0, -2); |
|
| 539 | + } |
|
| 516 | 540 | |
| 517 | 541 | // Start the element. |
| 518 | 542 | $output = $indentation . '<' . $array['name']; |
@@ -523,9 +547,9 @@ discard block |
||
| 523 | 547 | // Run through and recursively output all the elements or attrbutes inside this. |
| 524 | 548 | foreach ($array as $k => $v) |
| 525 | 549 | { |
| 526 | - if (substr($k, 0, 1) == '@') |
|
| 527 | - $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 528 | - elseif (is_array($v)) |
|
| 550 | + if (substr($k, 0, 1) == '@') { |
|
| 551 | + $output .= ' ' . substr($k, 1) . '="' . $v . '"'; |
|
| 552 | + } elseif (is_array($v)) |
|
| 529 | 553 | { |
| 530 | 554 | $output_el .= $this->_xml($v, $indent === null ? null : $indent + 1); |
| 531 | 555 | $inside_elements = true; |
@@ -533,10 +557,11 @@ discard block |
||
| 533 | 557 | } |
| 534 | 558 | |
| 535 | 559 | // Indent, if necessary.... then close the tag. |
| 536 | - if ($inside_elements) |
|
| 537 | - $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 538 | - else |
|
| 539 | - $output .= ' />'; |
|
| 560 | + if ($inside_elements) { |
|
| 561 | + $output .= '>' . $output_el . $indentation . '</' . $array['name'] . '>'; |
|
| 562 | + } else { |
|
| 563 | + $output .= ' />'; |
|
| 564 | + } |
|
| 540 | 565 | |
| 541 | 566 | return $output; |
| 542 | 567 | } |
@@ -553,19 +578,22 @@ discard block |
||
| 553 | 578 | $text = ''; |
| 554 | 579 | foreach ($array as $value) |
| 555 | 580 | { |
| 556 | - if (!is_array($value) || !isset($value['name'])) |
|
| 557 | - continue; |
|
| 581 | + if (!is_array($value) || !isset($value['name'])) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 558 | 584 | |
| 559 | - if ($value['name'] == '!') |
|
| 560 | - $text .= $value['value']; |
|
| 561 | - else |
|
| 562 | - $return[$value['name']] = $this->_array($value); |
|
| 585 | + if ($value['name'] == '!') { |
|
| 586 | + $text .= $value['value']; |
|
| 587 | + } else { |
|
| 588 | + $return[$value['name']] = $this->_array($value); |
|
| 589 | + } |
|
| 563 | 590 | } |
| 564 | 591 | |
| 565 | - if (empty($return)) |
|
| 566 | - return $text; |
|
| 567 | - else |
|
| 568 | - return $return; |
|
| 592 | + if (empty($return)) { |
|
| 593 | + return $text; |
|
| 594 | + } else { |
|
| 595 | + return $return; |
|
| 596 | + } |
|
| 569 | 597 | } |
| 570 | 598 | |
| 571 | 599 | /** |
@@ -583,24 +611,28 @@ discard block |
||
| 583 | 611 | foreach ($parts as $part) |
| 584 | 612 | { |
| 585 | 613 | // Handle XML comments. |
| 586 | - if (!$inCdata && $part === '<!--') |
|
| 587 | - $inComment = true; |
|
| 588 | - if ($inComment && $part === '-->') |
|
| 589 | - $inComment = false; |
|
| 590 | - elseif ($inComment) |
|
| 591 | - continue; |
|
| 614 | + if (!$inCdata && $part === '<!--') { |
|
| 615 | + $inComment = true; |
|
| 616 | + } |
|
| 617 | + if ($inComment && $part === '-->') { |
|
| 618 | + $inComment = false; |
|
| 619 | + } elseif ($inComment) { |
|
| 620 | + continue; |
|
| 621 | + } |
|
| 592 | 622 | |
| 593 | 623 | // Handle Cdata blocks. |
| 594 | - elseif (!$inComment && $part === '<![CDATA[') |
|
| 595 | - $inCdata = true; |
|
| 596 | - elseif ($inCdata && $part === ']]>') |
|
| 597 | - $inCdata = false; |
|
| 598 | - elseif ($inCdata) |
|
| 599 | - $output .= htmlentities($part, ENT_QUOTES); |
|
| 624 | + elseif (!$inComment && $part === '<![CDATA[') { |
|
| 625 | + $inCdata = true; |
|
| 626 | + } elseif ($inCdata && $part === ']]>') { |
|
| 627 | + $inCdata = false; |
|
| 628 | + } elseif ($inCdata) { |
|
| 629 | + $output .= htmlentities($part, ENT_QUOTES); |
|
| 630 | + } |
|
| 600 | 631 | |
| 601 | 632 | // Everything else is kept as is. |
| 602 | - else |
|
| 603 | - $output .= $part; |
|
| 633 | + else { |
|
| 634 | + $output .= $part; |
|
| 635 | + } |
|
| 604 | 636 | } |
| 605 | 637 | |
| 606 | 638 | return $output; |
@@ -635,22 +667,26 @@ discard block |
||
| 635 | 667 | protected function _fetch($array) |
| 636 | 668 | { |
| 637 | 669 | // Don't return anything if this is just a string. |
| 638 | - if (is_string($array)) |
|
| 639 | - return ''; |
|
| 670 | + if (is_string($array)) { |
|
| 671 | + return ''; |
|
| 672 | + } |
|
| 640 | 673 | |
| 641 | 674 | $temp = ''; |
| 642 | 675 | foreach ($array as $text) |
| 643 | 676 | { |
| 644 | 677 | // This means it's most likely an attribute or the name itself. |
| 645 | - if (!isset($text['name'])) |
|
| 646 | - continue; |
|
| 678 | + if (!isset($text['name'])) { |
|
| 679 | + continue; |
|
| 680 | + } |
|
| 647 | 681 | |
| 648 | 682 | // This is text! |
| 649 | - if ($text['name'] == '!') |
|
| 650 | - $temp .= $text['value']; |
|
| 683 | + if ($text['name'] == '!') { |
|
| 684 | + $temp .= $text['value']; |
|
| 685 | + } |
|
| 651 | 686 | // Another element - dive in ;). |
| 652 | - else |
|
| 653 | - $temp .= $this->_fetch($text); |
|
| 687 | + else { |
|
| 688 | + $temp .= $this->_fetch($text); |
|
| 689 | + } |
|
| 654 | 690 | } |
| 655 | 691 | |
| 656 | 692 | // Return all the bits and pieces we've put together. |
@@ -669,12 +705,14 @@ discard block |
||
| 669 | 705 | protected function _path($array, $path, $level, $no_error = false) |
| 670 | 706 | { |
| 671 | 707 | // Is $array even an array? It might be false! |
| 672 | - if (!is_array($array)) |
|
| 673 | - return false; |
|
| 708 | + if (!is_array($array)) { |
|
| 709 | + return false; |
|
| 710 | + } |
|
| 674 | 711 | |
| 675 | 712 | // Asking for *no* path? |
| 676 | - if ($path == '' || $path == '.') |
|
| 677 | - return $array; |
|
| 713 | + if ($path == '' || $path == '.') { |
|
| 714 | + return $array; |
|
| 715 | + } |
|
| 678 | 716 | $paths = explode('|', $path); |
| 679 | 717 | |
| 680 | 718 | // A * means all elements of any name. |
@@ -685,16 +723,18 @@ discard block |
||
| 685 | 723 | // Check each element. |
| 686 | 724 | foreach ($array as $value) |
| 687 | 725 | { |
| 688 | - if (!is_array($value) || $value['name'] === '!') |
|
| 689 | - continue; |
|
| 726 | + if (!is_array($value) || $value['name'] === '!') { |
|
| 727 | + continue; |
|
| 728 | + } |
|
| 690 | 729 | |
| 691 | 730 | if ($show_all || in_array($value['name'], $paths)) |
| 692 | 731 | { |
| 693 | 732 | // Skip elements before "the one". |
| 694 | - if ($level !== null && $level > 0) |
|
| 695 | - $level--; |
|
| 696 | - else |
|
| 697 | - $results[] = $value; |
|
| 733 | + if ($level !== null && $level > 0) { |
|
| 734 | + $level--; |
|
| 735 | + } else { |
|
| 736 | + $results[] = $value; |
|
| 737 | + } |
|
| 698 | 738 | } |
| 699 | 739 | } |
| 700 | 740 | |
@@ -703,21 +743,25 @@ discard block |
||
| 703 | 743 | { |
| 704 | 744 | $trace = debug_backtrace(); |
| 705 | 745 | $i = 0; |
| 706 | - while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) |
|
| 707 | - $i++; |
|
| 746 | + while ($i < count($trace) && isset($trace[$i]['class']) && $trace[$i]['class'] == get_class($this)) { |
|
| 747 | + $i++; |
|
| 748 | + } |
|
| 708 | 749 | $debug = ' from ' . $trace[$i - 1]['file'] . ' on line ' . $trace[$i - 1]['line']; |
| 709 | 750 | |
| 710 | 751 | // Cause an error. |
| 711 | - if ($this->debug_level & E_NOTICE && !$no_error) |
|
| 712 | - trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 752 | + if ($this->debug_level & E_NOTICE && !$no_error) { |
|
| 753 | + trigger_error('Undefined XML element: ' . $path . $debug, E_USER_NOTICE); |
|
| 754 | + } |
|
| 713 | 755 | return false; |
| 714 | 756 | } |
| 715 | 757 | // Only one result. |
| 716 | - elseif (count($results) == 1 || $level !== null) |
|
| 717 | - return $results[0]; |
|
| 758 | + elseif (count($results) == 1 || $level !== null) { |
|
| 759 | + return $results[0]; |
|
| 760 | + } |
|
| 718 | 761 | // Return the result set. |
| 719 | - else |
|
| 720 | - return $results + array('name' => $path . '[]'); |
|
| 762 | + else { |
|
| 763 | + return $results + array('name' => $path . '[]'); |
|
| 764 | + } |
|
| 721 | 765 | } |
| 722 | 766 | } |
| 723 | 767 | |
@@ -764,8 +808,9 @@ discard block |
||
| 764 | 808 | $this->error = false; |
| 765 | 809 | $this->pasv = array(); |
| 766 | 810 | |
| 767 | - if ($ftp_server !== null) |
|
| 768 | - $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 811 | + if ($ftp_server !== null) { |
|
| 812 | + $this->connect($ftp_server, $ftp_port, $ftp_user, $ftp_pass); |
|
| 813 | + } |
|
| 769 | 814 | } |
| 770 | 815 | |
| 771 | 816 | /** |
@@ -778,14 +823,16 @@ discard block |
||
| 778 | 823 | */ |
| 779 | 824 | public function connect($ftp_server, $ftp_port = 21, $ftp_user = 'anonymous', $ftp_pass = '[email protected]') |
| 780 | 825 | { |
| 781 | - if (strpos($ftp_server, 'ftp://') === 0) |
|
| 782 | - $ftp_server = substr($ftp_server, 6); |
|
| 783 | - elseif (strpos($ftp_server, 'ftps://') === 0) |
|
| 784 | - $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 785 | - if (strpos($ftp_server, 'http://') === 0) |
|
| 786 | - $ftp_server = substr($ftp_server, 7); |
|
| 787 | - elseif (strpos($ftp_server, 'https://') === 0) |
|
| 788 | - $ftp_server = substr($ftp_server, 8); |
|
| 826 | + if (strpos($ftp_server, 'ftp://') === 0) { |
|
| 827 | + $ftp_server = substr($ftp_server, 6); |
|
| 828 | + } elseif (strpos($ftp_server, 'ftps://') === 0) { |
|
| 829 | + $ftp_server = 'ssl://' . substr($ftp_server, 7); |
|
| 830 | + } |
|
| 831 | + if (strpos($ftp_server, 'http://') === 0) { |
|
| 832 | + $ftp_server = substr($ftp_server, 7); |
|
| 833 | + } elseif (strpos($ftp_server, 'https://') === 0) { |
|
| 834 | + $ftp_server = substr($ftp_server, 8); |
|
| 835 | + } |
|
| 789 | 836 | $ftp_server = strtr($ftp_server, array('/' => '', ':' => '', '@' => '')); |
| 790 | 837 | |
| 791 | 838 | // Connect to the FTP server. |
@@ -834,12 +881,14 @@ discard block |
||
| 834 | 881 | */ |
| 835 | 882 | public function chdir($ftp_path) |
| 836 | 883 | { |
| 837 | - if (!is_resource($this->connection)) |
|
| 838 | - return false; |
|
| 884 | + if (!is_resource($this->connection)) { |
|
| 885 | + return false; |
|
| 886 | + } |
|
| 839 | 887 | |
| 840 | 888 | // No slash on the end, please... |
| 841 | - if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') |
|
| 842 | - $ftp_path = substr($ftp_path, 0, -1); |
|
| 889 | + if ($ftp_path !== '/' && substr($ftp_path, -1) === '/') { |
|
| 890 | + $ftp_path = substr($ftp_path, 0, -1); |
|
| 891 | + } |
|
| 843 | 892 | |
| 844 | 893 | fwrite($this->connection, 'CWD ' . $ftp_path . "\r\n"); |
| 845 | 894 | if (!$this->check_response(250)) |
@@ -860,11 +909,13 @@ discard block |
||
| 860 | 909 | */ |
| 861 | 910 | public function chmod($ftp_file, $chmod) |
| 862 | 911 | { |
| 863 | - if (!is_resource($this->connection)) |
|
| 864 | - return false; |
|
| 912 | + if (!is_resource($this->connection)) { |
|
| 913 | + return false; |
|
| 914 | + } |
|
| 865 | 915 | |
| 866 | - if ($ftp_file == '') |
|
| 867 | - $ftp_file = '.'; |
|
| 916 | + if ($ftp_file == '') { |
|
| 917 | + $ftp_file = '.'; |
|
| 918 | + } |
|
| 868 | 919 | |
| 869 | 920 | // Do we have a file or a dir? |
| 870 | 921 | $is_dir = is_dir($ftp_file); |
@@ -880,9 +931,7 @@ discard block |
||
| 880 | 931 | { |
| 881 | 932 | $is_writable = true; |
| 882 | 933 | break; |
| 883 | - } |
|
| 884 | - |
|
| 885 | - else |
|
| 934 | + } else |
|
| 886 | 935 | { |
| 887 | 936 | // Convert the chmod value from octal (0777) to text ("777"). |
| 888 | 937 | fwrite($this->connection, 'SITE CHMOD ' . decoct($val) . ' ' . $ftp_file . "\r\n"); |
@@ -905,8 +954,9 @@ discard block |
||
| 905 | 954 | public function unlink($ftp_file) |
| 906 | 955 | { |
| 907 | 956 | // We are actually connected, right? |
| 908 | - if (!is_resource($this->connection)) |
|
| 909 | - return false; |
|
| 957 | + if (!is_resource($this->connection)) { |
|
| 958 | + return false; |
|
| 959 | + } |
|
| 910 | 960 | |
| 911 | 961 | // Delete file X. |
| 912 | 962 | fwrite($this->connection, 'DELE ' . $ftp_file . "\r\n"); |
@@ -935,9 +985,9 @@ discard block |
||
| 935 | 985 | { |
| 936 | 986 | // Wait for a response that isn't continued with -, but don't wait too long. |
| 937 | 987 | $time = time(); |
| 938 | - do |
|
| 939 | - $this->last_message = fgets($this->connection, 1024); |
|
| 940 | - while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 988 | + do { |
|
| 989 | + $this->last_message = fgets($this->connection, 1024); |
|
| 990 | + } while ((strlen($this->last_message) < 4 || strpos($this->last_message, ' ') === 0 || strpos($this->last_message, ' ', 3) !== 3) && time() - $time < 5); |
|
| 941 | 991 | |
| 942 | 992 | // Was the desired response returned? |
| 943 | 993 | return is_array($desired) ? in_array(substr($this->last_message, 0, 3), $desired) : substr($this->last_message, 0, 3) == $desired; |
@@ -951,15 +1001,16 @@ discard block |
||
| 951 | 1001 | public function passive() |
| 952 | 1002 | { |
| 953 | 1003 | // We can't create a passive data connection without a primary one first being there. |
| 954 | - if (!is_resource($this->connection)) |
|
| 955 | - return false; |
|
| 1004 | + if (!is_resource($this->connection)) { |
|
| 1005 | + return false; |
|
| 1006 | + } |
|
| 956 | 1007 | |
| 957 | 1008 | // Request a passive connection - this means, we'll talk to you, you don't talk to us. |
| 958 | 1009 | @fwrite($this->connection, 'PASV' . "\r\n"); |
| 959 | 1010 | $time = time(); |
| 960 | - do |
|
| 961 | - $response = fgets($this->connection, 1024); |
|
| 962 | - while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 1011 | + do { |
|
| 1012 | + $response = fgets($this->connection, 1024); |
|
| 1013 | + } while (strpos($response, ' ', 3) !== 3 && time() - $time < 5); |
|
| 963 | 1014 | |
| 964 | 1015 | // If it's not 227, we weren't given an IP and port, which means it failed. |
| 965 | 1016 | if (strpos($response, '227 ') !== 0) |
@@ -990,12 +1041,14 @@ discard block |
||
| 990 | 1041 | public function create_file($ftp_file) |
| 991 | 1042 | { |
| 992 | 1043 | // First, we have to be connected... very important. |
| 993 | - if (!is_resource($this->connection)) |
|
| 994 | - return false; |
|
| 1044 | + if (!is_resource($this->connection)) { |
|
| 1045 | + return false; |
|
| 1046 | + } |
|
| 995 | 1047 | |
| 996 | 1048 | // I'd like one passive mode, please! |
| 997 | - if (!$this->passive()) |
|
| 998 | - return false; |
|
| 1049 | + if (!$this->passive()) { |
|
| 1050 | + return false; |
|
| 1051 | + } |
|
| 999 | 1052 | |
| 1000 | 1053 | // Seems logical enough, so far... |
| 1001 | 1054 | fwrite($this->connection, 'STOR ' . $ftp_file . "\r\n"); |
@@ -1030,12 +1083,14 @@ discard block |
||
| 1030 | 1083 | public function list_dir($ftp_path = '', $search = false) |
| 1031 | 1084 | { |
| 1032 | 1085 | // Are we even connected...? |
| 1033 | - if (!is_resource($this->connection)) |
|
| 1034 | - return false; |
|
| 1086 | + if (!is_resource($this->connection)) { |
|
| 1087 | + return false; |
|
| 1088 | + } |
|
| 1035 | 1089 | |
| 1036 | 1090 | // Passive... non-agressive... |
| 1037 | - if (!$this->passive()) |
|
| 1038 | - return false; |
|
| 1091 | + if (!$this->passive()) { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1039 | 1094 | |
| 1040 | 1095 | // Get the listing! |
| 1041 | 1096 | fwrite($this->connection, 'LIST -1' . ($search ? 'R' : '') . ($ftp_path == '' ? '' : ' ' . $ftp_path) . "\r\n"); |
@@ -1051,8 +1106,9 @@ discard block |
||
| 1051 | 1106 | |
| 1052 | 1107 | // Read in the file listing. |
| 1053 | 1108 | $data = ''; |
| 1054 | - while (!feof($fp)) |
|
| 1055 | - $data .= fread($fp, 4096); |
|
| 1109 | + while (!feof($fp)) { |
|
| 1110 | + $data .= fread($fp, 4096); |
|
| 1111 | + } |
|
| 1056 | 1112 | fclose($fp); |
| 1057 | 1113 | |
| 1058 | 1114 | // Everything go okay? |
@@ -1074,21 +1130,23 @@ discard block |
||
| 1074 | 1130 | */ |
| 1075 | 1131 | public function locate($file, $listing = null) |
| 1076 | 1132 | { |
| 1077 | - if ($listing === null) |
|
| 1078 | - $listing = $this->list_dir('', true); |
|
| 1133 | + if ($listing === null) { |
|
| 1134 | + $listing = $this->list_dir('', true); |
|
| 1135 | + } |
|
| 1079 | 1136 | $listing = explode("\n", $listing); |
| 1080 | 1137 | |
| 1081 | 1138 | @fwrite($this->connection, 'PWD' . "\r\n"); |
| 1082 | 1139 | $time = time(); |
| 1083 | - do |
|
| 1084 | - $response = fgets($this->connection, 1024); |
|
| 1085 | - while ($response[3] != ' ' && time() - $time < 5); |
|
| 1140 | + do { |
|
| 1141 | + $response = fgets($this->connection, 1024); |
|
| 1142 | + } while ($response[3] != ' ' && time() - $time < 5); |
|
| 1086 | 1143 | |
| 1087 | 1144 | // Check for 257! |
| 1088 | - if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) |
|
| 1089 | - $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1090 | - else |
|
| 1091 | - $current_dir = ''; |
|
| 1145 | + if (preg_match('~^257 "(.+?)" ~', $response, $match) != 0) { |
|
| 1146 | + $current_dir = strtr($match[1], array('""' => '"')); |
|
| 1147 | + } else { |
|
| 1148 | + $current_dir = ''; |
|
| 1149 | + } |
|
| 1092 | 1150 | |
| 1093 | 1151 | for ($i = 0, $n = count($listing); $i < $n; $i++) |
| 1094 | 1152 | { |
@@ -1101,12 +1159,15 @@ discard block |
||
| 1101 | 1159 | // Okay, this file's name is: |
| 1102 | 1160 | $listing[$i] = $current_dir . '/' . trim(strlen($listing[$i]) > 30 ? strrchr($listing[$i], ' ') : $listing[$i]); |
| 1103 | 1161 | |
| 1104 | - if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) |
|
| 1105 | - return $listing[$i]; |
|
| 1106 | - if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) |
|
| 1107 | - return $listing[$i]; |
|
| 1108 | - if (basename($listing[$i]) == $file || $listing[$i] == $file) |
|
| 1109 | - return $listing[$i]; |
|
| 1162 | + if ($file[0] == '*' && substr($listing[$i], -(strlen($file) - 1)) == substr($file, 1)) { |
|
| 1163 | + return $listing[$i]; |
|
| 1164 | + } |
|
| 1165 | + if (substr($file, -1) == '*' && substr($listing[$i], 0, strlen($file) - 1) == substr($file, 0, -1)) { |
|
| 1166 | + return $listing[$i]; |
|
| 1167 | + } |
|
| 1168 | + if (basename($listing[$i]) == $file || $listing[$i] == $file) { |
|
| 1169 | + return $listing[$i]; |
|
| 1170 | + } |
|
| 1110 | 1171 | } |
| 1111 | 1172 | |
| 1112 | 1173 | return false; |
@@ -1121,8 +1182,9 @@ discard block |
||
| 1121 | 1182 | public function create_dir($ftp_dir) |
| 1122 | 1183 | { |
| 1123 | 1184 | // We must be connected to the server to do something. |
| 1124 | - if (!is_resource($this->connection)) |
|
| 1125 | - return false; |
|
| 1185 | + if (!is_resource($this->connection)) { |
|
| 1186 | + return false; |
|
| 1187 | + } |
|
| 1126 | 1188 | |
| 1127 | 1189 | // Make this new beautiful directory! |
| 1128 | 1190 | fwrite($this->connection, 'MKD ' . $ftp_dir . "\r\n"); |
@@ -1154,35 +1216,40 @@ discard block |
||
| 1154 | 1216 | |
| 1155 | 1217 | $path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => '')); |
| 1156 | 1218 | |
| 1157 | - if (substr($path, -1) == '/') |
|
| 1158 | - $path = substr($path, 0, -1); |
|
| 1219 | + if (substr($path, -1) == '/') { |
|
| 1220 | + $path = substr($path, 0, -1); |
|
| 1221 | + } |
|
| 1159 | 1222 | |
| 1160 | - if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) |
|
| 1161 | - $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1223 | + if (strlen(dirname($_SERVER['PHP_SELF'])) > 1) { |
|
| 1224 | + $path .= dirname($_SERVER['PHP_SELF']); |
|
| 1225 | + } |
|
| 1226 | + } elseif (strpos($filesystem_path, '/var/www/') === 0) { |
|
| 1227 | + $path = substr($filesystem_path, 8); |
|
| 1228 | + } else { |
|
| 1229 | + $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1162 | 1230 | } |
| 1163 | - elseif (strpos($filesystem_path, '/var/www/') === 0) |
|
| 1164 | - $path = substr($filesystem_path, 8); |
|
| 1165 | - else |
|
| 1166 | - $path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => '')); |
|
| 1231 | + } else { |
|
| 1232 | + $path = ''; |
|
| 1167 | 1233 | } |
| 1168 | - else |
|
| 1169 | - $path = ''; |
|
| 1170 | 1234 | |
| 1171 | 1235 | if (is_resource($this->connection) && $this->list_dir($path) == '') |
| 1172 | 1236 | { |
| 1173 | 1237 | $data = $this->list_dir('', true); |
| 1174 | 1238 | |
| 1175 | - if ($lookup_file === null) |
|
| 1176 | - $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1239 | + if ($lookup_file === null) { |
|
| 1240 | + $lookup_file = $_SERVER['PHP_SELF']; |
|
| 1241 | + } |
|
| 1177 | 1242 | |
| 1178 | 1243 | $found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data)); |
| 1179 | - if ($found_path == false) |
|
| 1180 | - $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1181 | - if ($found_path != false) |
|
| 1182 | - $path = $found_path; |
|
| 1244 | + if ($found_path == false) { |
|
| 1245 | + $found_path = dirname($this->locate(basename($lookup_file))); |
|
| 1246 | + } |
|
| 1247 | + if ($found_path != false) { |
|
| 1248 | + $path = $found_path; |
|
| 1249 | + } |
|
| 1250 | + } elseif (is_resource($this->connection)) { |
|
| 1251 | + $found_path = true; |
|
| 1183 | 1252 | } |
| 1184 | - elseif (is_resource($this->connection)) |
|
| 1185 | - $found_path = true; |
|
| 1186 | 1253 | |
| 1187 | 1254 | return array($username, $path, isset($found_path)); |
| 1188 | 1255 | } |
@@ -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 | * The main 'Attachments and Avatars' management function. |
@@ -63,10 +64,11 @@ discard block |
||
| 63 | 64 | call_integration_hook('integrate_manage_attachments', array(&$subActions)); |
| 64 | 65 | |
| 65 | 66 | // Pick the correct sub-action. |
| 66 | - if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) |
|
| 67 | - $context['sub_action'] = $_REQUEST['sa']; |
|
| 68 | - else |
|
| 69 | - $context['sub_action'] = 'browse'; |
|
| 67 | + if (isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']])) { |
|
| 68 | + $context['sub_action'] = $_REQUEST['sa']; |
|
| 69 | + } else { |
|
| 70 | + $context['sub_action'] = 'browse'; |
|
| 71 | + } |
|
| 70 | 72 | |
| 71 | 73 | // Default page title is good. |
| 72 | 74 | $context['page_title'] = $txt['attachments_avatars']; |
@@ -94,20 +96,20 @@ discard block |
||
| 94 | 96 | $context['attachmentUploadDir'] = $modSettings['attachmentUploadDir'][$modSettings['currentAttachmentUploadDir']]; |
| 95 | 97 | |
| 96 | 98 | // If not set, show a default path for the base directory |
| 97 | - if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) |
|
| 98 | - if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | + if (!isset($_GET['save']) && empty($modSettings['basedirectory_for_attachments'])) { |
|
| 100 | + if (is_dir($modSettings['attachmentUploadDir'][1])) |
|
| 99 | 101 | $modSettings['basedirectory_for_attachments'] = $modSettings['attachmentUploadDir'][1]; |
| 100 | - |
|
| 101 | - else |
|
| 102 | - $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 102 | + } else { |
|
| 103 | + $modSettings['basedirectory_for_attachments'] = $context['attachmentUploadDir']; |
|
| 104 | + } |
|
| 103 | 105 | |
| 104 | 106 | $context['valid_upload_dir'] = is_dir($context['attachmentUploadDir']) && is_writable($context['attachmentUploadDir']); |
| 105 | 107 | |
| 106 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 107 | - $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 108 | - |
|
| 109 | - else |
|
| 110 | - $context['valid_basedirectory'] = true; |
|
| 108 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 109 | + $context['valid_basedirectory'] = !empty($modSettings['basedirectory_for_attachments']) && is_writable($modSettings['basedirectory_for_attachments']); |
|
| 110 | + } else { |
|
| 111 | + $context['valid_basedirectory'] = true; |
|
| 112 | + } |
|
| 111 | 113 | |
| 112 | 114 | // A bit of razzle dazzle with the $txt strings. :) |
| 113 | 115 | $txt['attachment_path'] = $context['attachmentUploadDir']; |
@@ -185,8 +187,9 @@ discard block |
||
| 185 | 187 | |
| 186 | 188 | call_integration_hook('integrate_modify_attachment_settings', array(&$config_vars)); |
| 187 | 189 | |
| 188 | - if ($return_config) |
|
| 189 | - return $config_vars; |
|
| 190 | + if ($return_config) { |
|
| 191 | + return $config_vars; |
|
| 192 | + } |
|
| 190 | 193 | |
| 191 | 194 | // These are very likely to come in handy! (i.e. without them we're doomed!) |
| 192 | 195 | require_once($sourcedir . '/ManagePermissions.php'); |
@@ -197,21 +200,24 @@ discard block |
||
| 197 | 200 | { |
| 198 | 201 | checkSession(); |
| 199 | 202 | |
| 200 | - if (isset($_POST['attachmentUploadDir'])) |
|
| 201 | - unset($_POST['attachmentUploadDir']); |
|
| 203 | + if (isset($_POST['attachmentUploadDir'])) { |
|
| 204 | + unset($_POST['attachmentUploadDir']); |
|
| 205 | + } |
|
| 202 | 206 | |
| 203 | 207 | if (!empty($_POST['use_subdirectories_for_attachments'])) |
| 204 | 208 | { |
| 205 | - if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) |
|
| 206 | - $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 209 | + if (isset($_POST['use_subdirectories_for_attachments']) && empty($_POST['basedirectory_for_attachments'])) { |
|
| 210 | + $_POST['basedirectory_for_attachments'] = (!empty($modSettings['basedirectory_for_attachments']) ? ($modSettings['basedirectory_for_attachments']) : $boarddir); |
|
| 211 | + } |
|
| 207 | 212 | |
| 208 | 213 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($modSettings['attachment_basedirectories'])) |
| 209 | 214 | { |
| 210 | - if (!is_array($modSettings['attachment_basedirectories'])) |
|
| 211 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 215 | + if (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 216 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 212 | 220 | } |
| 213 | - else |
|
| 214 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 215 | 221 | |
| 216 | 222 | if (!empty($_POST['use_subdirectories_for_attachments']) && !empty($_POST['basedirectory_for_attachments']) && !in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
| 217 | 223 | { |
@@ -219,8 +225,9 @@ discard block |
||
| 219 | 225 | |
| 220 | 226 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachmentUploadDir'])) |
| 221 | 227 | { |
| 222 | - if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) |
|
| 223 | - $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 228 | + if (!automanage_attachments_create_directory($_POST['basedirectory_for_attachments'])) { |
|
| 229 | + $_POST['basedirectory_for_attachments'] = $modSettings['basedirectory_for_attachments']; |
|
| 230 | + } |
|
| 224 | 231 | } |
| 225 | 232 | |
| 226 | 233 | if (!in_array($_POST['basedirectory_for_attachments'], $modSettings['attachment_basedirectories'])) |
@@ -336,8 +343,9 @@ discard block |
||
| 336 | 343 | |
| 337 | 344 | call_integration_hook('integrate_modify_avatar_settings', array(&$config_vars)); |
| 338 | 345 | |
| 339 | - if ($return_config) |
|
| 340 | - return $config_vars; |
|
| 346 | + if ($return_config) { |
|
| 347 | + return $config_vars; |
|
| 348 | + } |
|
| 341 | 349 | |
| 342 | 350 | // We need this file for the settings template. |
| 343 | 351 | require_once($sourcedir . '/ManageServer.php'); |
@@ -348,17 +356,21 @@ discard block |
||
| 348 | 356 | checkSession(); |
| 349 | 357 | |
| 350 | 358 | // These settings cannot be left empty! |
| 351 | - if (empty($_POST['custom_avatar_dir'])) |
|
| 352 | - $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 359 | + if (empty($_POST['custom_avatar_dir'])) { |
|
| 360 | + $_POST['custom_avatar_dir'] = $boarddir . '/custom_avatar'; |
|
| 361 | + } |
|
| 353 | 362 | |
| 354 | - if (empty($_POST['custom_avatar_url'])) |
|
| 355 | - $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 363 | + if (empty($_POST['custom_avatar_url'])) { |
|
| 364 | + $_POST['custom_avatar_url'] = $boardurl . '/custom_avatar'; |
|
| 365 | + } |
|
| 356 | 366 | |
| 357 | - if (empty($_POST['avatar_directory'])) |
|
| 358 | - $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 367 | + if (empty($_POST['avatar_directory'])) { |
|
| 368 | + $_POST['avatar_directory'] = $boarddir . '/avatars'; |
|
| 369 | + } |
|
| 359 | 370 | |
| 360 | - if (empty($_POST['avatar_url'])) |
|
| 361 | - $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 371 | + if (empty($_POST['avatar_url'])) { |
|
| 372 | + $_POST['avatar_url'] = $boardurl . '/avatars'; |
|
| 373 | + } |
|
| 362 | 374 | |
| 363 | 375 | call_integration_hook('integrate_save_avatar_settings'); |
| 364 | 376 | |
@@ -406,11 +418,13 @@ discard block |
||
| 406 | 418 | $list_title = $txt['attachment_manager_browse_files'] . ': '; |
| 407 | 419 | foreach ($titles as $browse_type => $details) |
| 408 | 420 | { |
| 409 | - if ($browse_type != 'attachments') |
|
| 410 | - $list_title .= ' | '; |
|
| 421 | + if ($browse_type != 'attachments') { |
|
| 422 | + $list_title .= ' | '; |
|
| 423 | + } |
|
| 411 | 424 | |
| 412 | - if ($context['browse_type'] == $browse_type) |
|
| 413 | - $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 425 | + if ($context['browse_type'] == $browse_type) { |
|
| 426 | + $list_title .= '<img src="' . $settings['images_url'] . '/selected.png" alt=">"> '; |
|
| 427 | + } |
|
| 414 | 428 | |
| 415 | 429 | $list_title .= '<a href="' . $scripturl . $details[0] . '">' . $details[1] . '</a>'; |
| 416 | 430 | } |
@@ -446,28 +460,33 @@ discard block |
||
| 446 | 460 | $link = '<a href="'; |
| 447 | 461 | |
| 448 | 462 | // In case of a custom avatar URL attachments have a fixed directory. |
| 449 | - if ($rowData['attachment_type'] == 1) |
|
| 450 | - $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 463 | + if ($rowData['attachment_type'] == 1) { |
|
| 464 | + $link .= sprintf('%1$s/%2$s', $modSettings['custom_avatar_url'], $rowData['filename']); |
|
| 465 | + } |
|
| 451 | 466 | |
| 452 | 467 | // By default avatars are downloaded almost as attachments. |
| 453 | - elseif ($context['browse_type'] == 'avatars') |
|
| 454 | - $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 468 | + elseif ($context['browse_type'] == 'avatars') { |
|
| 469 | + $link .= sprintf('%1$s?action=dlattach;type=avatar;attach=%2$d', $scripturl, $rowData['id_attach']); |
|
| 470 | + } |
|
| 455 | 471 | |
| 456 | 472 | // Normal attachments are always linked to a topic ID. |
| 457 | - else |
|
| 458 | - $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 473 | + else { |
|
| 474 | + $link .= sprintf('%1$s?action=dlattach;topic=%2$d.0;attach=%3$d', $scripturl, $rowData['id_topic'], $rowData['id_attach']); |
|
| 475 | + } |
|
| 459 | 476 | |
| 460 | 477 | $link .= '"'; |
| 461 | 478 | |
| 462 | 479 | // Show a popup on click if it's a picture and we know its dimensions. |
| 463 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 464 | - $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 480 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 481 | + $link .= sprintf(' onclick="return reqWin(this.href' . ($rowData['attachment_type'] == 1 ? '' : ' + \';image\'') . ', %1$d, %2$d, true);"', $rowData['width'] + 20, $rowData['height'] + 20); |
|
| 482 | + } |
|
| 465 | 483 | |
| 466 | 484 | $link .= sprintf('>%1$s</a>', preg_replace('~&#(\\\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\\\1;', $smcFunc['htmlspecialchars']($rowData['filename']))); |
| 467 | 485 | |
| 468 | 486 | // Show the dimensions. |
| 469 | - if (!empty($rowData['width']) && !empty($rowData['height'])) |
|
| 470 | - $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 487 | + if (!empty($rowData['width']) && !empty($rowData['height'])) { |
|
| 488 | + $link .= sprintf(' <span class="smalltext">%1$dx%2$d</span>', $rowData['width'], $rowData['height']); |
|
| 489 | + } |
|
| 471 | 490 | |
| 472 | 491 | return $link; |
| 473 | 492 | }, |
@@ -500,12 +519,14 @@ discard block |
||
| 500 | 519 | 'function' => function($rowData) use ($scripturl, $smcFunc) |
| 501 | 520 | { |
| 502 | 521 | // In case of an attachment, return the poster of the attachment. |
| 503 | - if (empty($rowData['id_member'])) |
|
| 504 | - return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 522 | + if (empty($rowData['id_member'])) { |
|
| 523 | + return $smcFunc['htmlspecialchars']($rowData['poster_name']); |
|
| 524 | + } |
|
| 505 | 525 | |
| 506 | 526 | // Otherwise it must be an avatar, return the link to the owner of it. |
| 507 | - else |
|
| 508 | - return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 527 | + else { |
|
| 528 | + return sprintf('<a href="%1$s?action=profile;u=%2$d">%3$s</a>', $scripturl, $rowData['id_member'], $rowData['poster_name']); |
|
| 529 | + } |
|
| 509 | 530 | }, |
| 510 | 531 | ), |
| 511 | 532 | 'sort' => array( |
@@ -524,8 +545,9 @@ discard block |
||
| 524 | 545 | $date = empty($rowData['poster_time']) ? $txt['never'] : timeformat($rowData['poster_time']); |
| 525 | 546 | |
| 526 | 547 | // Add a link to the topic in case of an attachment. |
| 527 | - if ($context['browse_type'] !== 'avatars') |
|
| 528 | - $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 548 | + if ($context['browse_type'] !== 'avatars') { |
|
| 549 | + $date .= sprintf('<br>%1$s <a href="%2$s?topic=%3$d.msg%4$d#msg%4$d">%5$s</a>', $txt['in'], $scripturl, $rowData['id_topic'], $rowData['id_msg'], $rowData['subject']); |
|
| 550 | + } |
|
| 529 | 551 | |
| 530 | 552 | return $date; |
| 531 | 553 | }, |
@@ -610,8 +632,8 @@ discard block |
||
| 610 | 632 | global $smcFunc, $txt; |
| 611 | 633 | |
| 612 | 634 | // Choose a query depending on what we are viewing. |
| 613 | - if ($browse_type === 'avatars') |
|
| 614 | - $request = $smcFunc['db_query']('', ' |
|
| 635 | + if ($browse_type === 'avatars') { |
|
| 636 | + $request = $smcFunc['db_query']('', ' |
|
| 615 | 637 | SELECT |
| 616 | 638 | {string:blank_text} AS id_msg, COALESCE(mem.real_name, {string:not_applicable_text}) AS poster_name, |
| 617 | 639 | mem.last_login AS poster_time, 0 AS id_topic, a.id_member, a.id_attach, a.filename, a.file_hash, a.attachment_type, |
@@ -630,8 +652,8 @@ discard block |
||
| 630 | 652 | 'per_page' => $items_per_page, |
| 631 | 653 | ) |
| 632 | 654 | ); |
| 633 | - else |
|
| 634 | - $request = $smcFunc['db_query']('', ' |
|
| 655 | + } else { |
|
| 656 | + $request = $smcFunc['db_query']('', ' |
|
| 635 | 657 | SELECT |
| 636 | 658 | m.id_msg, COALESCE(mem.real_name, m.poster_name) AS poster_name, m.poster_time, m.id_topic, m.id_member, |
| 637 | 659 | a.id_attach, a.filename, a.file_hash, a.attachment_type, a.size, a.width, a.height, a.downloads, mf.subject, t.id_board |
@@ -650,9 +672,11 @@ discard block |
||
| 650 | 672 | 'per_page' => $items_per_page, |
| 651 | 673 | ) |
| 652 | 674 | ); |
| 675 | + } |
|
| 653 | 676 | $files = array(); |
| 654 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 655 | - $files[] = $row; |
|
| 677 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 678 | + $files[] = $row; |
|
| 679 | + } |
|
| 656 | 680 | $smcFunc['db_free_result']($request); |
| 657 | 681 | |
| 658 | 682 | return $files; |
@@ -670,8 +694,8 @@ discard block |
||
| 670 | 694 | global $smcFunc; |
| 671 | 695 | |
| 672 | 696 | // Depending on the type of file, different queries are used. |
| 673 | - if ($browse_type === 'avatars') |
|
| 674 | - $request = $smcFunc['db_query']('', ' |
|
| 697 | + if ($browse_type === 'avatars') { |
|
| 698 | + $request = $smcFunc['db_query']('', ' |
|
| 675 | 699 | SELECT COUNT(*) |
| 676 | 700 | FROM {db_prefix}attachments |
| 677 | 701 | WHERE id_member != {int:guest_id_member}', |
@@ -679,8 +703,8 @@ discard block |
||
| 679 | 703 | 'guest_id_member' => 0, |
| 680 | 704 | ) |
| 681 | 705 | ); |
| 682 | - else |
|
| 683 | - $request = $smcFunc['db_query']('', ' |
|
| 706 | + } else { |
|
| 707 | + $request = $smcFunc['db_query']('', ' |
|
| 684 | 708 | SELECT COUNT(*) AS num_attach |
| 685 | 709 | FROM {db_prefix}attachments AS a |
| 686 | 710 | INNER JOIN {db_prefix}messages AS m ON (m.id_msg = a.id_msg) |
@@ -693,6 +717,7 @@ discard block |
||
| 693 | 717 | 'guest_id_member' => 0, |
| 694 | 718 | ) |
| 695 | 719 | ); |
| 720 | + } |
|
| 696 | 721 | |
| 697 | 722 | list ($num_files) = $smcFunc['db_fetch_row']($request); |
| 698 | 723 | $smcFunc['db_free_result']($request); |
@@ -775,12 +800,14 @@ discard block |
||
| 775 | 800 | $current_dir_size /= 1024; |
| 776 | 801 | |
| 777 | 802 | // If they specified a limit only.... |
| 778 | - if (!empty($modSettings['attachmentDirSizeLimit'])) |
|
| 779 | - $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 803 | + if (!empty($modSettings['attachmentDirSizeLimit'])) { |
|
| 804 | + $context['attachment_space'] = comma_format(max($modSettings['attachmentDirSizeLimit'] - $current_dir_size, 0), 2); |
|
| 805 | + } |
|
| 780 | 806 | $context['attachment_current_size'] = comma_format($current_dir_size, 2); |
| 781 | 807 | |
| 782 | - if (!empty($modSettings['attachmentDirFileLimit'])) |
|
| 783 | - $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 808 | + if (!empty($modSettings['attachmentDirFileLimit'])) { |
|
| 809 | + $context['attachment_files'] = comma_format(max($modSettings['attachmentDirFileLimit'] - $current_dir_files, 0), 0); |
|
| 810 | + } |
|
| 784 | 811 | $context['attachment_current_files'] = comma_format($current_dir_files, 0); |
| 785 | 812 | |
| 786 | 813 | $context['attach_multiple_dirs'] = count($attach_dirs) > 1 ? true : false; |
@@ -817,8 +844,8 @@ discard block |
||
| 817 | 844 | $messages = removeAttachments(array('attachment_type' => 0, 'poster_time' => (time() - 24 * 60 * 60 * $_POST['age'])), 'messages', true); |
| 818 | 845 | |
| 819 | 846 | // Update the messages to reflect the change. |
| 820 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 821 | - $smcFunc['db_query']('', ' |
|
| 847 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 848 | + $smcFunc['db_query']('', ' |
|
| 822 | 849 | UPDATE {db_prefix}messages |
| 823 | 850 | SET body = CONCAT(body, {string:notice}) |
| 824 | 851 | WHERE id_msg IN ({array_int:messages})', |
@@ -827,8 +854,8 @@ discard block |
||
| 827 | 854 | 'notice' => '<br><br>' . $_POST['notice'], |
| 828 | 855 | ) |
| 829 | 856 | ); |
| 830 | - } |
|
| 831 | - else |
|
| 857 | + } |
|
| 858 | + } else |
|
| 832 | 859 | { |
| 833 | 860 | // Remove all the old avatars. |
| 834 | 861 | removeAttachments(array('not_id_member' => 0, 'last_login' => (time() - 24 * 60 * 60 * $_POST['age'])), 'members'); |
@@ -853,8 +880,8 @@ discard block |
||
| 853 | 880 | $messages = removeAttachments(array('attachment_type' => 0, 'size' => 1024 * $_POST['size']), 'messages', true); |
| 854 | 881 | |
| 855 | 882 | // And make a note on the post. |
| 856 | - if (!empty($messages) && !empty($_POST['notice'])) |
|
| 857 | - $smcFunc['db_query']('', ' |
|
| 883 | + if (!empty($messages) && !empty($_POST['notice'])) { |
|
| 884 | + $smcFunc['db_query']('', ' |
|
| 858 | 885 | UPDATE {db_prefix}messages |
| 859 | 886 | SET body = CONCAT(body, {string:notice}) |
| 860 | 887 | WHERE id_msg IN ({array_int:messages})', |
@@ -863,6 +890,7 @@ discard block |
||
| 863 | 890 | 'notice' => '<br><br>' . $_POST['notice'], |
| 864 | 891 | ) |
| 865 | 892 | ); |
| 893 | + } |
|
| 866 | 894 | |
| 867 | 895 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 868 | 896 | } |
@@ -882,16 +910,17 @@ discard block |
||
| 882 | 910 | { |
| 883 | 911 | $attachments = array(); |
| 884 | 912 | // There must be a quicker way to pass this safety test?? |
| 885 | - foreach ($_POST['remove'] as $removeID => $dummy) |
|
| 886 | - $attachments[] = (int) $removeID; |
|
| 913 | + foreach ($_POST['remove'] as $removeID => $dummy) { |
|
| 914 | + $attachments[] = (int) $removeID; |
|
| 915 | + } |
|
| 887 | 916 | |
| 888 | 917 | // If the attachments are from a 3rd party, let them remove it. Hooks should remove their ids from the array. |
| 889 | 918 | $filesRemoved = false; |
| 890 | 919 | call_integration_hook('integrate_attachment_remove', array(&$filesRemoved, $attachments)); |
| 891 | 920 | |
| 892 | - if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) |
|
| 893 | - removeAttachments(array('id_attach' => $attachments)); |
|
| 894 | - else if (!empty($attachments)) |
|
| 921 | + if ($_REQUEST['type'] == 'avatars' && !empty($attachments)) { |
|
| 922 | + removeAttachments(array('id_attach' => $attachments)); |
|
| 923 | + } else if (!empty($attachments)) |
|
| 895 | 924 | { |
| 896 | 925 | $messages = removeAttachments(array('id_attach' => $attachments), 'messages', true); |
| 897 | 926 | |
@@ -930,12 +959,13 @@ discard block |
||
| 930 | 959 | |
| 931 | 960 | $messages = removeAttachments(array('attachment_type' => 0), '', true); |
| 932 | 961 | |
| 933 | - if (!isset($_POST['notice'])) |
|
| 934 | - $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 962 | + if (!isset($_POST['notice'])) { |
|
| 963 | + $_POST['notice'] = $txt['attachment_delete_admin']; |
|
| 964 | + } |
|
| 935 | 965 | |
| 936 | 966 | // Add the notice on the end of the changed messages. |
| 937 | - if (!empty($messages)) |
|
| 938 | - $smcFunc['db_query']('', ' |
|
| 967 | + if (!empty($messages)) { |
|
| 968 | + $smcFunc['db_query']('', ' |
|
| 939 | 969 | UPDATE {db_prefix}messages |
| 940 | 970 | SET body = CONCAT(body, {string:deleted_message}) |
| 941 | 971 | WHERE id_msg IN ({array_int:messages})', |
@@ -944,6 +974,7 @@ discard block |
||
| 944 | 974 | 'deleted_message' => '<br><br>' . $_POST['notice'], |
| 945 | 975 | ) |
| 946 | 976 | ); |
| 977 | + } |
|
| 947 | 978 | |
| 948 | 979 | redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
| 949 | 980 | } |
@@ -982,24 +1013,26 @@ discard block |
||
| 982 | 1013 | $is_not = substr($real_type, 0, 4) == 'not_'; |
| 983 | 1014 | $type = $is_not ? substr($real_type, 4) : $real_type; |
| 984 | 1015 | |
| 985 | - if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) |
|
| 986 | - $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 987 | - elseif ($type == 'attachment_type') |
|
| 988 | - $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 989 | - elseif ($type == 'poster_time') |
|
| 990 | - $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 991 | - elseif ($type == 'last_login') |
|
| 992 | - $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 993 | - elseif ($type == 'size') |
|
| 994 | - $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 995 | - elseif ($type == 'id_topic') |
|
| 996 | - $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1016 | + if (in_array($type, array('id_member', 'id_attach', 'id_msg'))) { |
|
| 1017 | + $new_condition[] = 'a.' . $type . ($is_not ? ' NOT' : '') . ' IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1018 | + } elseif ($type == 'attachment_type') { |
|
| 1019 | + $new_condition[] = 'a.attachment_type = {int:' . $real_type . '}'; |
|
| 1020 | + } elseif ($type == 'poster_time') { |
|
| 1021 | + $new_condition[] = 'm.poster_time < {int:' . $real_type . '}'; |
|
| 1022 | + } elseif ($type == 'last_login') { |
|
| 1023 | + $new_condition[] = 'mem.last_login < {int:' . $real_type . '}'; |
|
| 1024 | + } elseif ($type == 'size') { |
|
| 1025 | + $new_condition[] = 'a.size > {int:' . $real_type . '}'; |
|
| 1026 | + } elseif ($type == 'id_topic') { |
|
| 1027 | + $new_condition[] = 'm.id_topic IN (' . (is_array($restriction) ? '{array_int:' . $real_type . '}' : '{int:' . $real_type . '}') . ')'; |
|
| 1028 | + } |
|
| 997 | 1029 | |
| 998 | 1030 | // Add the parameter! |
| 999 | 1031 | $query_parameter[$real_type] = $restriction; |
| 1000 | 1032 | |
| 1001 | - if ($type == 'do_logging') |
|
| 1002 | - $do_logging = $condition['id_attach']; |
|
| 1033 | + if ($type == 'do_logging') { |
|
| 1034 | + $do_logging = $condition['id_attach']; |
|
| 1035 | + } |
|
| 1003 | 1036 | } |
| 1004 | 1037 | $condition = implode(' AND ', $new_condition); |
| 1005 | 1038 | } |
@@ -1031,15 +1064,15 @@ discard block |
||
| 1031 | 1064 | // wasn't it obvious? :P |
| 1032 | 1065 | // @todo look again at this. |
| 1033 | 1066 | @unlink($modSettings['custom_avatar_dir'] . '/' . $row['filename']); |
| 1034 | - } |
|
| 1035 | - else |
|
| 1067 | + } else |
|
| 1036 | 1068 | { |
| 1037 | 1069 | $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
| 1038 | 1070 | @unlink($filename); |
| 1039 | 1071 | |
| 1040 | 1072 | // If this was a thumb, the parent attachment should know about it. |
| 1041 | - if (!empty($row['id_parent'])) |
|
| 1042 | - $parents[] = $row['id_parent']; |
|
| 1073 | + if (!empty($row['id_parent'])) { |
|
| 1074 | + $parents[] = $row['id_parent']; |
|
| 1075 | + } |
|
| 1043 | 1076 | |
| 1044 | 1077 | // If this attachments has a thumb, remove it as well. |
| 1045 | 1078 | if (!empty($row['id_thumb']) && $autoThumbRemoval) |
@@ -1051,8 +1084,9 @@ discard block |
||
| 1051 | 1084 | } |
| 1052 | 1085 | |
| 1053 | 1086 | // Make a list. |
| 1054 | - if ($return_affected_messages && empty($row['attachment_type'])) |
|
| 1055 | - $msgs[] = $row['id_msg']; |
|
| 1087 | + if ($return_affected_messages && empty($row['attachment_type'])) { |
|
| 1088 | + $msgs[] = $row['id_msg']; |
|
| 1089 | + } |
|
| 1056 | 1090 | |
| 1057 | 1091 | $attach[] = $row['id_attach']; |
| 1058 | 1092 | } |
@@ -1060,8 +1094,8 @@ discard block |
||
| 1060 | 1094 | |
| 1061 | 1095 | // Removed attachments don't have to be updated anymore. |
| 1062 | 1096 | $parents = array_diff($parents, $attach); |
| 1063 | - if (!empty($parents)) |
|
| 1064 | - $smcFunc['db_query']('', ' |
|
| 1097 | + if (!empty($parents)) { |
|
| 1098 | + $smcFunc['db_query']('', ' |
|
| 1065 | 1099 | UPDATE {db_prefix}attachments |
| 1066 | 1100 | SET id_thumb = {int:no_thumb} |
| 1067 | 1101 | WHERE id_attach IN ({array_int:parent_attachments})', |
@@ -1070,6 +1104,7 @@ discard block |
||
| 1070 | 1104 | 'no_thumb' => 0, |
| 1071 | 1105 | ) |
| 1072 | 1106 | ); |
| 1107 | + } |
|
| 1073 | 1108 | |
| 1074 | 1109 | if (!empty($do_logging)) |
| 1075 | 1110 | { |
@@ -1086,31 +1121,34 @@ discard block |
||
| 1086 | 1121 | ) |
| 1087 | 1122 | ); |
| 1088 | 1123 | |
| 1089 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1090 | - logAction( |
|
| 1124 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1125 | + logAction( |
|
| 1091 | 1126 | 'remove_attach', |
| 1092 | 1127 | array( |
| 1093 | 1128 | 'message' => $row['id_msg'], |
| 1094 | 1129 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1095 | 1130 | ) |
| 1096 | 1131 | ); |
| 1132 | + } |
|
| 1097 | 1133 | $smcFunc['db_free_result']($request); |
| 1098 | 1134 | } |
| 1099 | 1135 | |
| 1100 | - if (!empty($attach)) |
|
| 1101 | - $smcFunc['db_query']('', ' |
|
| 1136 | + if (!empty($attach)) { |
|
| 1137 | + $smcFunc['db_query']('', ' |
|
| 1102 | 1138 | DELETE FROM {db_prefix}attachments |
| 1103 | 1139 | WHERE id_attach IN ({array_int:attachment_list})', |
| 1104 | 1140 | array( |
| 1105 | 1141 | 'attachment_list' => $attach, |
| 1106 | 1142 | ) |
| 1107 | 1143 | ); |
| 1144 | + } |
|
| 1108 | 1145 | |
| 1109 | 1146 | call_integration_hook('integrate_remove_attachments', array($attach)); |
| 1110 | 1147 | |
| 1111 | - if ($return_affected_messages) |
|
| 1112 | - return array_unique($msgs); |
|
| 1113 | -} |
|
| 1148 | + if ($return_affected_messages) { |
|
| 1149 | + return array_unique($msgs); |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1114 | 1152 | |
| 1115 | 1153 | /** |
| 1116 | 1154 | * This function should find attachments in the database that no longer exist and clear them, and fix filesize issues. |
@@ -1122,8 +1160,9 @@ discard block |
||
| 1122 | 1160 | checkSession('get'); |
| 1123 | 1161 | |
| 1124 | 1162 | // If we choose cancel, redirect right back. |
| 1125 | - if (isset($_POST['cancel'])) |
|
| 1126 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1163 | + if (isset($_POST['cancel'])) { |
|
| 1164 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1165 | + } |
|
| 1127 | 1166 | |
| 1128 | 1167 | // Try give us a while to sort this out... |
| 1129 | 1168 | @set_time_limit(600); |
@@ -1140,13 +1179,15 @@ discard block |
||
| 1140 | 1179 | if (isset($_GET['fixErrors'])) |
| 1141 | 1180 | { |
| 1142 | 1181 | // Nothing? |
| 1143 | - if (empty($_POST['to_fix'])) |
|
| 1144 | - redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1182 | + if (empty($_POST['to_fix'])) { |
|
| 1183 | + redirectexit('action=admin;area=manageattachments;sa=maintenance'); |
|
| 1184 | + } |
|
| 1145 | 1185 | |
| 1146 | 1186 | $_SESSION['attachments_to_fix'] = array(); |
| 1147 | 1187 | // @todo No need to do this I think. |
| 1148 | - foreach ($_POST['to_fix'] as $value) |
|
| 1149 | - $_SESSION['attachments_to_fix'][] = $value; |
|
| 1188 | + foreach ($_POST['to_fix'] as $value) { |
|
| 1189 | + $_SESSION['attachments_to_fix'][] = $value; |
|
| 1190 | + } |
|
| 1150 | 1191 | } |
| 1151 | 1192 | } |
| 1152 | 1193 | |
@@ -1213,13 +1254,14 @@ discard block |
||
| 1213 | 1254 | } |
| 1214 | 1255 | } |
| 1215 | 1256 | } |
| 1216 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1217 | - $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1257 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1258 | + $to_fix[] = 'missing_thumbnail_parent'; |
|
| 1259 | + } |
|
| 1218 | 1260 | $smcFunc['db_free_result']($result); |
| 1219 | 1261 | |
| 1220 | 1262 | // Do we need to delete what we have? |
| 1221 | - if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) |
|
| 1222 | - $smcFunc['db_query']('', ' |
|
| 1263 | + if ($fix_errors && !empty($to_remove) && in_array('missing_thumbnail_parent', $to_fix)) { |
|
| 1264 | + $smcFunc['db_query']('', ' |
|
| 1223 | 1265 | DELETE FROM {db_prefix}attachments |
| 1224 | 1266 | WHERE id_attach IN ({array_int:to_remove}) |
| 1225 | 1267 | AND attachment_type = {int:attachment_type}', |
@@ -1228,6 +1270,7 @@ discard block |
||
| 1228 | 1270 | 'attachment_type' => 3, |
| 1229 | 1271 | ) |
| 1230 | 1272 | ); |
| 1273 | + } |
|
| 1231 | 1274 | |
| 1232 | 1275 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1233 | 1276 | } |
@@ -1272,13 +1315,14 @@ discard block |
||
| 1272 | 1315 | $to_update[] = $row['id_attach']; |
| 1273 | 1316 | $context['repair_errors']['parent_missing_thumbnail']++; |
| 1274 | 1317 | } |
| 1275 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1276 | - $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1318 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1319 | + $to_fix[] = 'parent_missing_thumbnail'; |
|
| 1320 | + } |
|
| 1277 | 1321 | $smcFunc['db_free_result']($result); |
| 1278 | 1322 | |
| 1279 | 1323 | // Do we need to delete what we have? |
| 1280 | - if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) |
|
| 1281 | - $smcFunc['db_query']('', ' |
|
| 1324 | + if ($fix_errors && !empty($to_update) && in_array('parent_missing_thumbnail', $to_fix)) { |
|
| 1325 | + $smcFunc['db_query']('', ' |
|
| 1282 | 1326 | UPDATE {db_prefix}attachments |
| 1283 | 1327 | SET id_thumb = {int:no_thumb} |
| 1284 | 1328 | WHERE id_attach IN ({array_int:to_update})', |
@@ -1287,6 +1331,7 @@ discard block |
||
| 1287 | 1331 | 'no_thumb' => 0, |
| 1288 | 1332 | ) |
| 1289 | 1333 | ); |
| 1334 | + } |
|
| 1290 | 1335 | |
| 1291 | 1336 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1292 | 1337 | } |
@@ -1324,10 +1369,11 @@ discard block |
||
| 1324 | 1369 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
| 1325 | 1370 | { |
| 1326 | 1371 | // Get the filename. |
| 1327 | - if ($row['attachment_type'] == 1) |
|
| 1328 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1329 | - else |
|
| 1330 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1372 | + if ($row['attachment_type'] == 1) { |
|
| 1373 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1374 | + } else { |
|
| 1375 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1376 | + } |
|
| 1331 | 1377 | |
| 1332 | 1378 | // File doesn't exist? |
| 1333 | 1379 | if (!file_exists($filename)) |
@@ -1339,15 +1385,16 @@ discard block |
||
| 1339 | 1385 | $attachment_name = $row['id_attach'] . '_' . $row['file_hash'] . '.dat'; |
| 1340 | 1386 | |
| 1341 | 1387 | // Loop through the other folders. |
| 1342 | - foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
|
| 1343 | - if (file_exists($dir . '/' . $attachment_name)) |
|
| 1388 | + foreach ($modSettings['attachmentUploadDir'] as $id => $dir) { |
|
| 1389 | + if (file_exists($dir . '/' . $attachment_name)) |
|
| 1344 | 1390 | { |
| 1345 | 1391 | $context['repair_errors']['wrong_folder']++; |
| 1392 | + } |
|
| 1346 | 1393 | $errors_found[] = 'wrong_folder'; |
| 1347 | 1394 | |
| 1348 | 1395 | // Are we going to fix this now? |
| 1349 | - if ($fix_errors && in_array('wrong_folder', $to_fix)) |
|
| 1350 | - $smcFunc['db_query']('', ' |
|
| 1396 | + if ($fix_errors && in_array('wrong_folder', $to_fix)) { |
|
| 1397 | + $smcFunc['db_query']('', ' |
|
| 1351 | 1398 | UPDATE {db_prefix}attachments |
| 1352 | 1399 | SET id_folder = {int:new_folder} |
| 1353 | 1400 | WHERE id_attach = {int:id_attach}', |
@@ -1356,6 +1403,7 @@ discard block |
||
| 1356 | 1403 | 'id_attach' => $row['id_attach'], |
| 1357 | 1404 | ) |
| 1358 | 1405 | ); |
| 1406 | + } |
|
| 1359 | 1407 | |
| 1360 | 1408 | continue 2; |
| 1361 | 1409 | } |
@@ -1364,8 +1412,7 @@ discard block |
||
| 1364 | 1412 | $to_remove[] = $row['id_attach']; |
| 1365 | 1413 | $context['repair_errors']['file_missing_on_disk']++; |
| 1366 | 1414 | $errors_found[] = 'file_missing_on_disk'; |
| 1367 | - } |
|
| 1368 | - elseif (filesize($filename) == 0) |
|
| 1415 | + } elseif (filesize($filename) == 0) |
|
| 1369 | 1416 | { |
| 1370 | 1417 | $context['repair_errors']['file_size_of_zero']++; |
| 1371 | 1418 | $errors_found[] = 'file_size_of_zero'; |
@@ -1376,8 +1423,7 @@ discard block |
||
| 1376 | 1423 | $to_remove[] = $row['id_attach']; |
| 1377 | 1424 | @unlink($filename); |
| 1378 | 1425 | } |
| 1379 | - } |
|
| 1380 | - elseif (filesize($filename) != $row['size']) |
|
| 1426 | + } elseif (filesize($filename) != $row['size']) |
|
| 1381 | 1427 | { |
| 1382 | 1428 | $context['repair_errors']['file_wrong_size']++; |
| 1383 | 1429 | $errors_found[] = 'file_wrong_size'; |
@@ -1398,14 +1444,18 @@ discard block |
||
| 1398 | 1444 | } |
| 1399 | 1445 | } |
| 1400 | 1446 | |
| 1401 | - if (in_array('file_missing_on_disk', $errors_found)) |
|
| 1402 | - $to_fix[] = 'file_missing_on_disk'; |
|
| 1403 | - if (in_array('file_size_of_zero', $errors_found)) |
|
| 1404 | - $to_fix[] = 'file_size_of_zero'; |
|
| 1405 | - if (in_array('file_wrong_size', $errors_found)) |
|
| 1406 | - $to_fix[] = 'file_wrong_size'; |
|
| 1407 | - if (in_array('wrong_folder', $errors_found)) |
|
| 1408 | - $to_fix[] = 'wrong_folder'; |
|
| 1447 | + if (in_array('file_missing_on_disk', $errors_found)) { |
|
| 1448 | + $to_fix[] = 'file_missing_on_disk'; |
|
| 1449 | + } |
|
| 1450 | + if (in_array('file_size_of_zero', $errors_found)) { |
|
| 1451 | + $to_fix[] = 'file_size_of_zero'; |
|
| 1452 | + } |
|
| 1453 | + if (in_array('file_wrong_size', $errors_found)) { |
|
| 1454 | + $to_fix[] = 'file_wrong_size'; |
|
| 1455 | + } |
|
| 1456 | + if (in_array('wrong_folder', $errors_found)) { |
|
| 1457 | + $to_fix[] = 'wrong_folder'; |
|
| 1458 | + } |
|
| 1409 | 1459 | $smcFunc['db_free_result']($result); |
| 1410 | 1460 | |
| 1411 | 1461 | // Do we need to delete what we have? |
@@ -1475,20 +1525,22 @@ discard block |
||
| 1475 | 1525 | // If we are repairing remove the file from disk now. |
| 1476 | 1526 | if ($fix_errors && in_array('avatar_no_member', $to_fix)) |
| 1477 | 1527 | { |
| 1478 | - if ($row['attachment_type'] == 1) |
|
| 1479 | - $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1480 | - else |
|
| 1481 | - $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1528 | + if ($row['attachment_type'] == 1) { |
|
| 1529 | + $filename = $modSettings['custom_avatar_dir'] . '/' . $row['filename']; |
|
| 1530 | + } else { |
|
| 1531 | + $filename = getAttachmentFilename($row['filename'], $row['id_attach'], $row['id_folder'], false, $row['file_hash']); |
|
| 1532 | + } |
|
| 1482 | 1533 | @unlink($filename); |
| 1483 | 1534 | } |
| 1484 | 1535 | } |
| 1485 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1486 | - $to_fix[] = 'avatar_no_member'; |
|
| 1536 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1537 | + $to_fix[] = 'avatar_no_member'; |
|
| 1538 | + } |
|
| 1487 | 1539 | $smcFunc['db_free_result']($result); |
| 1488 | 1540 | |
| 1489 | 1541 | // Do we need to delete what we have? |
| 1490 | - if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) |
|
| 1491 | - $smcFunc['db_query']('', ' |
|
| 1542 | + if ($fix_errors && !empty($to_remove) && in_array('avatar_no_member', $to_fix)) { |
|
| 1543 | + $smcFunc['db_query']('', ' |
|
| 1492 | 1544 | DELETE FROM {db_prefix}attachments |
| 1493 | 1545 | WHERE id_attach IN ({array_int:to_remove}) |
| 1494 | 1546 | AND id_member != {int:no_member} |
@@ -1499,6 +1551,7 @@ discard block |
||
| 1499 | 1551 | 'no_msg' => 0, |
| 1500 | 1552 | ) |
| 1501 | 1553 | ); |
| 1554 | + } |
|
| 1502 | 1555 | |
| 1503 | 1556 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1504 | 1557 | } |
@@ -1558,13 +1611,14 @@ discard block |
||
| 1558 | 1611 | @unlink($filename); |
| 1559 | 1612 | } |
| 1560 | 1613 | } |
| 1561 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
| 1562 | - $to_fix[] = 'attachment_no_msg'; |
|
| 1614 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
| 1615 | + $to_fix[] = 'attachment_no_msg'; |
|
| 1616 | + } |
|
| 1563 | 1617 | $smcFunc['db_free_result']($result); |
| 1564 | 1618 | |
| 1565 | 1619 | // Do we need to delete what we have? |
| 1566 | - if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) |
|
| 1567 | - $smcFunc['db_query']('', ' |
|
| 1620 | + if ($fix_errors && !empty($to_remove) && in_array('attachment_no_msg', $to_fix)) { |
|
| 1621 | + $smcFunc['db_query']('', ' |
|
| 1568 | 1622 | DELETE FROM {db_prefix}attachments |
| 1569 | 1623 | WHERE id_attach IN ({array_int:to_remove}) |
| 1570 | 1624 | AND id_member = {int:no_member} |
@@ -1575,6 +1629,7 @@ discard block |
||
| 1575 | 1629 | 'attach_thumb' => array(0,3), |
| 1576 | 1630 | ) |
| 1577 | 1631 | ); |
| 1632 | + } |
|
| 1578 | 1633 | |
| 1579 | 1634 | pauseAttachmentMaintenance($to_fix, $thumbnails); |
| 1580 | 1635 | } |
@@ -1598,8 +1653,9 @@ discard block |
||
| 1598 | 1653 | { |
| 1599 | 1654 | while ($file = readdir($dir)) |
| 1600 | 1655 | { |
| 1601 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 1602 | - continue; |
|
| 1656 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 1657 | + continue; |
|
| 1658 | + } |
|
| 1603 | 1659 | |
| 1604 | 1660 | if ($files_checked <= $current_check) |
| 1605 | 1661 | { |
@@ -1607,8 +1663,9 @@ discard block |
||
| 1607 | 1663 | if (strpos($file, 'post_tmp_') !== false) |
| 1608 | 1664 | { |
| 1609 | 1665 | // Temp file is more than 5 hours old! |
| 1610 | - if (filemtime($attach_dir . '/' . $file) < time() - 18000) |
|
| 1611 | - @unlink($attach_dir . '/' . $file); |
|
| 1666 | + if (filemtime($attach_dir . '/' . $file) < time() - 18000) { |
|
| 1667 | + @unlink($attach_dir . '/' . $file); |
|
| 1668 | + } |
|
| 1612 | 1669 | } |
| 1613 | 1670 | // That should be an attachment, let's check if we have it in the database |
| 1614 | 1671 | elseif (strpos($file, '_') !== false) |
@@ -1630,8 +1687,7 @@ discard block |
||
| 1630 | 1687 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1631 | 1688 | { |
| 1632 | 1689 | @unlink($attach_dir . '/' . $file); |
| 1633 | - } |
|
| 1634 | - else |
|
| 1690 | + } else |
|
| 1635 | 1691 | { |
| 1636 | 1692 | $context['repair_errors']['files_without_attachment']++; |
| 1637 | 1693 | $to_fix[] = 'files_without_attachment'; |
@@ -1639,14 +1695,12 @@ discard block |
||
| 1639 | 1695 | } |
| 1640 | 1696 | $smcFunc['db_free_result']($request); |
| 1641 | 1697 | } |
| 1642 | - } |
|
| 1643 | - else |
|
| 1698 | + } else |
|
| 1644 | 1699 | { |
| 1645 | 1700 | if ($fix_errors && in_array('files_without_attachment', $to_fix)) |
| 1646 | 1701 | { |
| 1647 | 1702 | @unlink($attach_dir . '/' . $file); |
| 1648 | - } |
|
| 1649 | - else |
|
| 1703 | + } else |
|
| 1650 | 1704 | { |
| 1651 | 1705 | $context['repair_errors']['files_without_attachment']++; |
| 1652 | 1706 | $to_fix[] = 'files_without_attachment'; |
@@ -1655,8 +1709,9 @@ discard block |
||
| 1655 | 1709 | } |
| 1656 | 1710 | $current_check++; |
| 1657 | 1711 | $_GET['substep'] = $current_check; |
| 1658 | - if ($current_check - $files_checked >= $max_checks) |
|
| 1659 | - pauseAttachmentMaintenance($to_fix); |
|
| 1712 | + if ($current_check - $files_checked >= $max_checks) { |
|
| 1713 | + pauseAttachmentMaintenance($to_fix); |
|
| 1714 | + } |
|
| 1660 | 1715 | } |
| 1661 | 1716 | closedir($dir); |
| 1662 | 1717 | } |
@@ -1692,12 +1747,14 @@ discard block |
||
| 1692 | 1747 | |
| 1693 | 1748 | // Try get more time... |
| 1694 | 1749 | @set_time_limit(600); |
| 1695 | - if (function_exists('apache_reset_timeout')) |
|
| 1696 | - @apache_reset_timeout(); |
|
| 1750 | + if (function_exists('apache_reset_timeout')) { |
|
| 1751 | + @apache_reset_timeout(); |
|
| 1752 | + } |
|
| 1697 | 1753 | |
| 1698 | 1754 | // Have we already used our maximum time? |
| 1699 | - if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) |
|
| 1700 | - return; |
|
| 1755 | + if (time() - array_sum(explode(' ', $time_start)) < 3 || $context['starting_substep'] == $_GET['substep']) { |
|
| 1756 | + return; |
|
| 1757 | + } |
|
| 1701 | 1758 | |
| 1702 | 1759 | $context['continue_get_data'] = '?action=admin;area=manageattachments;sa=repair' . (isset($_GET['fixErrors']) ? ';fixErrors' : '') . ';step=' . $_GET['step'] . ';substep=' . $_GET['substep'] . ';' . $context['session_var'] . '=' . $context['session_id']; |
| 1703 | 1760 | $context['page_title'] = $txt['not_done_title']; |
@@ -1709,10 +1766,11 @@ discard block |
||
| 1709 | 1766 | $context[$context['admin_menu_name']]['current_subsection'] = 'maintenance'; |
| 1710 | 1767 | |
| 1711 | 1768 | // Change these two if more steps are added! |
| 1712 | - if (empty($max_substep)) |
|
| 1713 | - $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1714 | - else |
|
| 1715 | - $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1769 | + if (empty($max_substep)) { |
|
| 1770 | + $context['continue_percent'] = round(($_GET['step'] * 100) / 25); |
|
| 1771 | + } else { |
|
| 1772 | + $context['continue_percent'] = round(($_GET['step'] * 100 + ($_GET['substep'] * 100) / $max_substep) / 25); |
|
| 1773 | + } |
|
| 1716 | 1774 | |
| 1717 | 1775 | // Never more than 100%! |
| 1718 | 1776 | $context['continue_percent'] = min($context['continue_percent'], 100); |
@@ -1754,15 +1812,17 @@ discard block |
||
| 1754 | 1812 | 'attachment_type' => 0, |
| 1755 | 1813 | ) |
| 1756 | 1814 | ); |
| 1757 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1758 | - $attachments[] = $row['id_attach']; |
|
| 1815 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1816 | + $attachments[] = $row['id_attach']; |
|
| 1817 | + } |
|
| 1759 | 1818 | $smcFunc['db_free_result']($request); |
| 1819 | + } elseif (!empty($_GET['aid'])) { |
|
| 1820 | + $attachments[] = (int) $_GET['aid']; |
|
| 1760 | 1821 | } |
| 1761 | - elseif (!empty($_GET['aid'])) |
|
| 1762 | - $attachments[] = (int) $_GET['aid']; |
|
| 1763 | 1822 | |
| 1764 | - if (empty($attachments)) |
|
| 1765 | - fatal_lang_error('no_access', false); |
|
| 1823 | + if (empty($attachments)) { |
|
| 1824 | + fatal_lang_error('no_access', false); |
|
| 1825 | + } |
|
| 1766 | 1826 | |
| 1767 | 1827 | // Now we have some ID's cleaned and ready to approve, but first - let's check we have permission! |
| 1768 | 1828 | $allowed_boards = boardsAllowedTo('approve_posts'); |
@@ -1795,17 +1855,18 @@ discard block |
||
| 1795 | 1855 | } |
| 1796 | 1856 | $smcFunc['db_free_result']($request); |
| 1797 | 1857 | |
| 1798 | - if (empty($attachments)) |
|
| 1799 | - fatal_lang_error('no_access', false); |
|
| 1858 | + if (empty($attachments)) { |
|
| 1859 | + fatal_lang_error('no_access', false); |
|
| 1860 | + } |
|
| 1800 | 1861 | |
| 1801 | 1862 | // Finally, we are there. Follow through! |
| 1802 | 1863 | if ($is_approve) |
| 1803 | 1864 | { |
| 1804 | 1865 | // Checked and deemed worthy. |
| 1805 | 1866 | ApproveAttachments($attachments); |
| 1867 | + } else { |
|
| 1868 | + removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1806 | 1869 | } |
| 1807 | - else |
|
| 1808 | - removeAttachments(array('id_attach' => $attachments, 'do_logging' => true)); |
|
| 1809 | 1870 | |
| 1810 | 1871 | // Return to the topic.... |
| 1811 | 1872 | redirectexit($redirect); |
@@ -1821,8 +1882,9 @@ discard block |
||
| 1821 | 1882 | { |
| 1822 | 1883 | global $smcFunc; |
| 1823 | 1884 | |
| 1824 | - if (empty($attachments)) |
|
| 1825 | - return 0; |
|
| 1885 | + if (empty($attachments)) { |
|
| 1886 | + return 0; |
|
| 1887 | + } |
|
| 1826 | 1888 | |
| 1827 | 1889 | // For safety, check for thumbnails... |
| 1828 | 1890 | $request = $smcFunc['db_query']('', ' |
@@ -1841,15 +1903,17 @@ discard block |
||
| 1841 | 1903 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
| 1842 | 1904 | { |
| 1843 | 1905 | // Update the thumbnail too... |
| 1844 | - if (!empty($row['id_thumb'])) |
|
| 1845 | - $attachments[] = $row['id_thumb']; |
|
| 1906 | + if (!empty($row['id_thumb'])) { |
|
| 1907 | + $attachments[] = $row['id_thumb']; |
|
| 1908 | + } |
|
| 1846 | 1909 | |
| 1847 | 1910 | $attachments[] = $row['id_attach']; |
| 1848 | 1911 | } |
| 1849 | 1912 | $smcFunc['db_free_result']($request); |
| 1850 | 1913 | |
| 1851 | - if (empty($attachments)) |
|
| 1852 | - return 0; |
|
| 1914 | + if (empty($attachments)) { |
|
| 1915 | + return 0; |
|
| 1916 | + } |
|
| 1853 | 1917 | |
| 1854 | 1918 | // Approving an attachment is not hard - it's easy. |
| 1855 | 1919 | $smcFunc['db_query']('', ' |
@@ -1875,14 +1939,15 @@ discard block |
||
| 1875 | 1939 | ) |
| 1876 | 1940 | ); |
| 1877 | 1941 | |
| 1878 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 1879 | - logAction( |
|
| 1942 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 1943 | + logAction( |
|
| 1880 | 1944 | 'approve_attach', |
| 1881 | 1945 | array( |
| 1882 | 1946 | 'message' => $row['id_msg'], |
| 1883 | 1947 | 'filename' => preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', $smcFunc['htmlspecialchars']($row['filename'])), |
| 1884 | 1948 | ) |
| 1885 | 1949 | ); |
| 1950 | + } |
|
| 1886 | 1951 | $smcFunc['db_free_result']($request); |
| 1887 | 1952 | |
| 1888 | 1953 | // Remove from the approval queue. |
@@ -1905,11 +1970,11 @@ discard block |
||
| 1905 | 1970 | global $modSettings, $scripturl, $context, $txt, $sourcedir, $boarddir, $smcFunc, $settings; |
| 1906 | 1971 | |
| 1907 | 1972 | // Since this needs to be done eventually. |
| 1908 | - if (!isset($modSettings['attachment_basedirectories'])) |
|
| 1909 | - $modSettings['attachment_basedirectories'] = array(); |
|
| 1910 | - |
|
| 1911 | - elseif (!is_array($modSettings['attachment_basedirectories'])) |
|
| 1912 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1973 | + if (!isset($modSettings['attachment_basedirectories'])) { |
|
| 1974 | + $modSettings['attachment_basedirectories'] = array(); |
|
| 1975 | + } elseif (!is_array($modSettings['attachment_basedirectories'])) { |
|
| 1976 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 1977 | + } |
|
| 1913 | 1978 | |
| 1914 | 1979 | $errors = array(); |
| 1915 | 1980 | |
@@ -1924,8 +1989,9 @@ discard block |
||
| 1924 | 1989 | { |
| 1925 | 1990 | $error = ''; |
| 1926 | 1991 | $id = (int) $id; |
| 1927 | - if ($id < 1) |
|
| 1928 | - continue; |
|
| 1992 | + if ($id < 1) { |
|
| 1993 | + continue; |
|
| 1994 | + } |
|
| 1929 | 1995 | |
| 1930 | 1996 | // Sorry, these dirs are NOT valid |
| 1931 | 1997 | $invalid_dirs = array($boarddir, $settings['default_theme_dir'], $sourcedir); |
@@ -1944,8 +2010,7 @@ discard block |
||
| 1944 | 2010 | { |
| 1945 | 2011 | $errors[] = $path . ': ' . $txt['attach_dir_duplicate_msg']; |
| 1946 | 2012 | continue; |
| 1947 | - } |
|
| 1948 | - elseif (empty($path)) |
|
| 2013 | + } elseif (empty($path)) |
|
| 1949 | 2014 | { |
| 1950 | 2015 | // Ignore this and set $id to one less |
| 1951 | 2016 | continue; |
@@ -1953,10 +2018,11 @@ discard block |
||
| 1953 | 2018 | |
| 1954 | 2019 | // OK, so let's try to create it then. |
| 1955 | 2020 | require_once($sourcedir . '/Subs-Attachments.php'); |
| 1956 | - if (automanage_attachments_create_directory($path)) |
|
| 1957 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 1958 | - else |
|
| 1959 | - $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2021 | + if (automanage_attachments_create_directory($path)) { |
|
| 2022 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2023 | + } else { |
|
| 2024 | + $errors[] = $path . ': ' . $txt[$context['dir_creation_error']]; |
|
| 2025 | + } |
|
| 1960 | 2026 | } |
| 1961 | 2027 | |
| 1962 | 2028 | // Changing a directory name? |
@@ -1969,8 +2035,7 @@ discard block |
||
| 1969 | 2035 | $errors[] = $path . ': ' . $txt['attach_dir_no_rename']; |
| 1970 | 2036 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1971 | 2037 | } |
| 1972 | - } |
|
| 1973 | - else |
|
| 2038 | + } else |
|
| 1974 | 2039 | { |
| 1975 | 2040 | $errors[] = $path . ': ' . $txt['attach_dir_exists_msg']; |
| 1976 | 2041 | $path = $modSettings['attachmentUploadDir'][$id]; |
@@ -1995,12 +2060,13 @@ discard block |
||
| 1995 | 2060 | $path = $modSettings['attachmentUploadDir'][$id]; |
| 1996 | 2061 | |
| 1997 | 2062 | // It's not a good idea to delete the current directory. |
| 1998 | - if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) |
|
| 1999 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2063 | + if ($id == (!empty($_POST['current_dir']) ? $_POST['current_dir'] : $modSettings['currentAttachmentUploadDir'])) { |
|
| 2064 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current']; |
|
| 2065 | + } |
|
| 2000 | 2066 | // Or the current base directory |
| 2001 | - elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) |
|
| 2002 | - $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2003 | - else |
|
| 2067 | + elseif (!empty($modSettings['basedirectory_for_attachments']) && $modSettings['basedirectory_for_attachments'] == $modSettings['attachmentUploadDir'][$id]) { |
|
| 2068 | + $errors[] = $path . ': ' . $txt['attach_dir_is_current_bd']; |
|
| 2069 | + } else |
|
| 2004 | 2070 | { |
| 2005 | 2071 | // Let's not try to delete a path with files in it. |
| 2006 | 2072 | $request = $smcFunc['db_query']('', ' |
@@ -2019,17 +2085,18 @@ discard block |
||
| 2019 | 2085 | if (!empty($modSettings['attachment_basedirectories'])) |
| 2020 | 2086 | { |
| 2021 | 2087 | // Count any sub-folders. |
| 2022 | - foreach ($modSettings['attachmentUploadDir'] as $sub) |
|
| 2023 | - if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2088 | + foreach ($modSettings['attachmentUploadDir'] as $sub) { |
|
| 2089 | + if (strpos($sub, $path . DIRECTORY_SEPARATOR) !== false) |
|
| 2024 | 2090 | $num_attach++; |
| 2091 | + } |
|
| 2025 | 2092 | } |
| 2026 | 2093 | |
| 2027 | 2094 | // It's safe to delete. So try to delete the folder also |
| 2028 | 2095 | if ($num_attach == 0) |
| 2029 | 2096 | { |
| 2030 | - if (is_dir($path)) |
|
| 2031 | - $doit = true; |
|
| 2032 | - elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2097 | + if (is_dir($path)) { |
|
| 2098 | + $doit = true; |
|
| 2099 | + } elseif (is_dir($boarddir . DIRECTORY_SEPARATOR . $path)) |
|
| 2033 | 2100 | { |
| 2034 | 2101 | $doit = true; |
| 2035 | 2102 | $path = $boarddir . DIRECTORY_SEPARATOR . $path; |
@@ -2039,8 +2106,9 @@ discard block |
||
| 2039 | 2106 | { |
| 2040 | 2107 | unlink($path . '/.htaccess'); |
| 2041 | 2108 | unlink($path . '/index.php'); |
| 2042 | - if (!@rmdir($path)) |
|
| 2043 | - $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2109 | + if (!@rmdir($path)) { |
|
| 2110 | + $error = $path . ': ' . $txt['attach_dir_no_delete']; |
|
| 2111 | + } |
|
| 2044 | 2112 | } |
| 2045 | 2113 | |
| 2046 | 2114 | // Remove it from the base directory list. |
@@ -2050,14 +2118,15 @@ discard block |
||
| 2050 | 2118 | updateSettings(array('attachment_basedirectories' => json_encode($modSettings['attachment_basedirectories']))); |
| 2051 | 2119 | $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
| 2052 | 2120 | } |
| 2121 | + } else { |
|
| 2122 | + $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2053 | 2123 | } |
| 2054 | - else |
|
| 2055 | - $error = $path . ': ' . $txt['attach_dir_no_remove']; |
|
| 2056 | 2124 | |
| 2057 | - if (empty($error)) |
|
| 2058 | - continue; |
|
| 2059 | - else |
|
| 2060 | - $errors[] = $error; |
|
| 2125 | + if (empty($error)) { |
|
| 2126 | + continue; |
|
| 2127 | + } else { |
|
| 2128 | + $errors[] = $error; |
|
| 2129 | + } |
|
| 2061 | 2130 | } |
| 2062 | 2131 | } |
| 2063 | 2132 | |
@@ -2065,23 +2134,26 @@ discard block |
||
| 2065 | 2134 | } |
| 2066 | 2135 | |
| 2067 | 2136 | // We need to make sure the current directory is right. |
| 2068 | - if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) |
|
| 2069 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2137 | + if (empty($_POST['current_dir']) && !empty($modSettings['currentAttachmentUploadDir'])) { |
|
| 2138 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2139 | + } |
|
| 2070 | 2140 | |
| 2071 | 2141 | // Find the current directory if there's no value carried, |
| 2072 | 2142 | if (empty($_POST['current_dir']) || empty($new_dirs[$_POST['current_dir']])) |
| 2073 | 2143 | { |
| 2074 | - if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) |
|
| 2075 | - $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2076 | - else |
|
| 2077 | - $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2144 | + if (array_key_exists($modSettings['currentAttachmentUploadDir'], $modSettings['attachmentUploadDir'])) { |
|
| 2145 | + $_POST['current_dir'] = $modSettings['currentAttachmentUploadDir']; |
|
| 2146 | + } else { |
|
| 2147 | + $_POST['current_dir'] = max(array_keys($modSettings['attachmentUploadDir'])); |
|
| 2148 | + } |
|
| 2078 | 2149 | } |
| 2079 | 2150 | |
| 2080 | 2151 | // If the user wishes to go back, update the last_dir array |
| 2081 | 2152 | if ($_POST['current_dir'] != $modSettings['currentAttachmentUploadDir'] && !empty($modSettings['last_attachments_directory']) && (isset($modSettings['last_attachments_directory'][$_POST['current_dir']]) || isset($modSettings['last_attachments_directory'][0]))) |
| 2082 | 2153 | { |
| 2083 | - if (!is_array($modSettings['last_attachments_directory'])) |
|
| 2084 | - $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2154 | + if (!is_array($modSettings['last_attachments_directory'])) { |
|
| 2155 | + $modSettings['last_attachments_directory'] = smf_json_decode($modSettings['last_attachments_directory'], true); |
|
| 2156 | + } |
|
| 2085 | 2157 | $num = substr(strrchr($modSettings['attachmentUploadDir'][$_POST['current_dir']], '_'), 1); |
| 2086 | 2158 | |
| 2087 | 2159 | if (is_numeric($num)) |
@@ -2089,16 +2161,18 @@ discard block |
||
| 2089 | 2161 | // Need to find the base folder. |
| 2090 | 2162 | $bid = -1; |
| 2091 | 2163 | $use_subdirectories_for_attachments = 0; |
| 2092 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2093 | - foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2164 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2165 | + foreach ($modSettings['attachment_basedirectories'] as $bid => $base) |
|
| 2094 | 2166 | if (strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $base . DIRECTORY_SEPARATOR) !== false) |
| 2095 | 2167 | { |
| 2096 | 2168 | $use_subdirectories_for_attachments = 1; |
| 2169 | + } |
|
| 2097 | 2170 | break; |
| 2098 | 2171 | } |
| 2099 | 2172 | |
| 2100 | - if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) |
|
| 2101 | - $bid = 0; |
|
| 2173 | + if ($use_subdirectories_for_attachments == 0 && strpos($modSettings['attachmentUploadDir'][$_POST['current_dir']], $boarddir . DIRECTORY_SEPARATOR) !== false) { |
|
| 2174 | + $bid = 0; |
|
| 2175 | + } |
|
| 2102 | 2176 | |
| 2103 | 2177 | $modSettings['last_attachments_directory'][$bid] = (int) $num; |
| 2104 | 2178 | $modSettings['basedirectory_for_attachments'] = !empty($modSettings['basedirectory_for_attachments']) ? $modSettings['basedirectory_for_attachments'] : ''; |
@@ -2117,8 +2191,8 @@ discard block |
||
| 2117 | 2191 | // We might need to reset the paths. This loop will just loop through once. |
| 2118 | 2192 | foreach ($new_dirs as $id => $dir) |
| 2119 | 2193 | { |
| 2120 | - if ($id != 1) |
|
| 2121 | - $smcFunc['db_query']('', ' |
|
| 2194 | + if ($id != 1) { |
|
| 2195 | + $smcFunc['db_query']('', ' |
|
| 2122 | 2196 | UPDATE {db_prefix}attachments |
| 2123 | 2197 | SET id_folder = {int:default_folder} |
| 2124 | 2198 | WHERE id_folder = {int:current_folder}', |
@@ -2127,14 +2201,14 @@ discard block |
||
| 2127 | 2201 | 'current_folder' => $id, |
| 2128 | 2202 | ) |
| 2129 | 2203 | ); |
| 2204 | + } |
|
| 2130 | 2205 | |
| 2131 | 2206 | $update = array( |
| 2132 | 2207 | 'currentAttachmentUploadDir' => 1, |
| 2133 | 2208 | 'attachmentUploadDir' => json_encode(array(1 => $dir)), |
| 2134 | 2209 | ); |
| 2135 | 2210 | } |
| 2136 | - } |
|
| 2137 | - else |
|
| 2211 | + } else |
|
| 2138 | 2212 | { |
| 2139 | 2213 | // Save it to the database. |
| 2140 | 2214 | $update = array( |
@@ -2143,11 +2217,13 @@ discard block |
||
| 2143 | 2217 | ); |
| 2144 | 2218 | } |
| 2145 | 2219 | |
| 2146 | - if (!empty($update)) |
|
| 2147 | - updateSettings($update); |
|
| 2220 | + if (!empty($update)) { |
|
| 2221 | + updateSettings($update); |
|
| 2222 | + } |
|
| 2148 | 2223 | |
| 2149 | - if (!empty($errors)) |
|
| 2150 | - $_SESSION['errors']['dir'] = $errors; |
|
| 2224 | + if (!empty($errors)) { |
|
| 2225 | + $_SESSION['errors']['dir'] = $errors; |
|
| 2226 | + } |
|
| 2151 | 2227 | |
| 2152 | 2228 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2153 | 2229 | } |
@@ -2161,10 +2237,11 @@ discard block |
||
| 2161 | 2237 | $_POST['current_base_dir'] = isset($_POST['current_base_dir']) ? (int) $_POST['current_base_dir'] : 1; |
| 2162 | 2238 | if (empty($_POST['new_base_dir']) && !empty($_POST['current_base_dir'])) |
| 2163 | 2239 | { |
| 2164 | - if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) |
|
| 2165 | - $update = (array( |
|
| 2240 | + if ($modSettings['basedirectory_for_attachments'] != $modSettings['attachmentUploadDir'][$_POST['current_base_dir']]) { |
|
| 2241 | + $update = (array( |
|
| 2166 | 2242 | 'basedirectory_for_attachments' => $modSettings['attachmentUploadDir'][$_POST['current_base_dir']], |
| 2167 | 2243 | )); |
| 2244 | + } |
|
| 2168 | 2245 | } |
| 2169 | 2246 | |
| 2170 | 2247 | if (isset($_POST['base_dir'])) |
@@ -2212,13 +2289,15 @@ discard block |
||
| 2212 | 2289 | |
| 2213 | 2290 | if (!in_array($_POST['new_base_dir'], $modSettings['attachmentUploadDir'])) |
| 2214 | 2291 | { |
| 2215 | - if (!automanage_attachments_create_directory($_POST['new_base_dir'])) |
|
| 2216 | - $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2292 | + if (!automanage_attachments_create_directory($_POST['new_base_dir'])) { |
|
| 2293 | + $errors[] = $_POST['new_base_dir'] . ': ' . $txt['attach_dir_base_no_create']; |
|
| 2294 | + } |
|
| 2217 | 2295 | } |
| 2218 | 2296 | |
| 2219 | 2297 | $modSettings['currentAttachmentUploadDir'] = array_search($_POST['new_base_dir'], $modSettings['attachmentUploadDir']); |
| 2220 | - if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) |
|
| 2221 | - $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2298 | + if (!in_array($_POST['new_base_dir'], $modSettings['attachment_basedirectories'])) { |
|
| 2299 | + $modSettings['attachment_basedirectories'][$modSettings['currentAttachmentUploadDir']] = $_POST['new_base_dir']; |
|
| 2300 | + } |
|
| 2222 | 2301 | ksort($modSettings['attachment_basedirectories']); |
| 2223 | 2302 | |
| 2224 | 2303 | $update = (array( |
@@ -2228,11 +2307,13 @@ discard block |
||
| 2228 | 2307 | )); |
| 2229 | 2308 | } |
| 2230 | 2309 | |
| 2231 | - if (!empty($errors)) |
|
| 2232 | - $_SESSION['errors']['base'] = $errors; |
|
| 2310 | + if (!empty($errors)) { |
|
| 2311 | + $_SESSION['errors']['base'] = $errors; |
|
| 2312 | + } |
|
| 2233 | 2313 | |
| 2234 | - if (!empty($update)) |
|
| 2235 | - updateSettings($update); |
|
| 2314 | + if (!empty($update)) { |
|
| 2315 | + updateSettings($update); |
|
| 2316 | + } |
|
| 2236 | 2317 | |
| 2237 | 2318 | redirectexit('action=admin;area=manageattachments;sa=attachpaths;' . $context['session_var'] . '=' . $context['session_id']); |
| 2238 | 2319 | } |
@@ -2242,13 +2323,15 @@ discard block |
||
| 2242 | 2323 | if (is_array($_SESSION['errors'])) |
| 2243 | 2324 | { |
| 2244 | 2325 | $errors = array(); |
| 2245 | - if (!empty($_SESSION['errors']['dir'])) |
|
| 2246 | - foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2326 | + if (!empty($_SESSION['errors']['dir'])) { |
|
| 2327 | + foreach ($_SESSION['errors']['dir'] as $error) |
|
| 2247 | 2328 | $errors['dir'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2329 | + } |
|
| 2248 | 2330 | |
| 2249 | - if (!empty($_SESSION['errors']['base'])) |
|
| 2250 | - foreach ($_SESSION['errors']['base'] as $error) |
|
| 2331 | + if (!empty($_SESSION['errors']['base'])) { |
|
| 2332 | + foreach ($_SESSION['errors']['base'] as $error) |
|
| 2251 | 2333 | $errors['base'][] = $smcFunc['htmlspecialchars']($error, ENT_QUOTES); |
| 2334 | + } |
|
| 2252 | 2335 | } |
| 2253 | 2336 | unset($_SESSION['errors']); |
| 2254 | 2337 | } |
@@ -2458,8 +2541,9 @@ discard block |
||
| 2458 | 2541 | foreach ($modSettings['attachmentUploadDir'] as $id => $dir) |
| 2459 | 2542 | { |
| 2460 | 2543 | // If there aren't any attachments in this directory this won't exist. |
| 2461 | - if (!isset($expected_files[$id])) |
|
| 2462 | - $expected_files[$id] = 0; |
|
| 2544 | + if (!isset($expected_files[$id])) { |
|
| 2545 | + $expected_files[$id] = 0; |
|
| 2546 | + } |
|
| 2463 | 2547 | |
| 2464 | 2548 | // Check if the directory is doing okay. |
| 2465 | 2549 | list ($status, $error, $files) = attachDirStatus($dir, $expected_files[$id]); |
@@ -2472,10 +2556,11 @@ discard block |
||
| 2472 | 2556 | $is_base_dir = in_array($dir, $modSettings['attachment_basedirectories']); |
| 2473 | 2557 | |
| 2474 | 2558 | // Count any sub-folders. |
| 2475 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2476 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2559 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2560 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2477 | 2561 | { |
| 2478 | 2562 | $expected_files[$id]++; |
| 2563 | + } |
|
| 2479 | 2564 | $sub_dirs++; |
| 2480 | 2565 | } |
| 2481 | 2566 | } |
@@ -2493,8 +2578,8 @@ discard block |
||
| 2493 | 2578 | } |
| 2494 | 2579 | |
| 2495 | 2580 | // Just stick a new directory on at the bottom. |
| 2496 | - if (isset($_REQUEST['new_path'])) |
|
| 2497 | - $attachdirs[] = array( |
|
| 2581 | + if (isset($_REQUEST['new_path'])) { |
|
| 2582 | + $attachdirs[] = array( |
|
| 2498 | 2583 | 'id' => max(array_merge(array_keys($expected_files), array_keys($modSettings['attachmentUploadDir']))) + 1, |
| 2499 | 2584 | 'current' => false, |
| 2500 | 2585 | 'path' => '', |
@@ -2502,6 +2587,7 @@ discard block |
||
| 2502 | 2587 | 'num_files' => '', |
| 2503 | 2588 | 'status' => '', |
| 2504 | 2589 | ); |
| 2590 | + } |
|
| 2505 | 2591 | |
| 2506 | 2592 | return $attachdirs; |
| 2507 | 2593 | } |
@@ -2514,8 +2600,9 @@ discard block |
||
| 2514 | 2600 | { |
| 2515 | 2601 | global $modSettings, $txt; |
| 2516 | 2602 | |
| 2517 | - if (empty($modSettings['attachment_basedirectories'])) |
|
| 2518 | - return; |
|
| 2603 | + if (empty($modSettings['attachment_basedirectories'])) { |
|
| 2604 | + return; |
|
| 2605 | + } |
|
| 2519 | 2606 | |
| 2520 | 2607 | $basedirs = array(); |
| 2521 | 2608 | // Get a list of the base directories. |
@@ -2523,16 +2610,18 @@ discard block |
||
| 2523 | 2610 | { |
| 2524 | 2611 | // Loop through the attach directory array to count any sub-directories |
| 2525 | 2612 | $expected_dirs = 0; |
| 2526 | - foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) |
|
| 2527 | - if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2613 | + foreach ($modSettings['attachmentUploadDir'] as $sid => $sub) { |
|
| 2614 | + if (strpos($sub, $dir . DIRECTORY_SEPARATOR) !== false) |
|
| 2528 | 2615 | $expected_dirs++; |
| 2616 | + } |
|
| 2529 | 2617 | |
| 2530 | - if (!is_dir($dir)) |
|
| 2531 | - $status = 'does_not_exist'; |
|
| 2532 | - elseif (!is_writeable($dir)) |
|
| 2533 | - $status = 'not_writable'; |
|
| 2534 | - else |
|
| 2535 | - $status = 'ok'; |
|
| 2618 | + if (!is_dir($dir)) { |
|
| 2619 | + $status = 'does_not_exist'; |
|
| 2620 | + } elseif (!is_writeable($dir)) { |
|
| 2621 | + $status = 'not_writable'; |
|
| 2622 | + } else { |
|
| 2623 | + $status = 'ok'; |
|
| 2624 | + } |
|
| 2536 | 2625 | |
| 2537 | 2626 | $basedirs[] = array( |
| 2538 | 2627 | 'id' => $id, |
@@ -2543,14 +2632,15 @@ discard block |
||
| 2543 | 2632 | ); |
| 2544 | 2633 | } |
| 2545 | 2634 | |
| 2546 | - if (isset($_REQUEST['new_base_path'])) |
|
| 2547 | - $basedirs[] = array( |
|
| 2635 | + if (isset($_REQUEST['new_base_path'])) { |
|
| 2636 | + $basedirs[] = array( |
|
| 2548 | 2637 | 'id' => '', |
| 2549 | 2638 | 'current' => false, |
| 2550 | 2639 | 'path' => '<input type="text" name="new_base_dir" value="" size="40">', |
| 2551 | 2640 | 'num_dirs' => '', |
| 2552 | 2641 | 'status' => '', |
| 2553 | 2642 | ); |
| 2643 | + } |
|
| 2554 | 2644 | |
| 2555 | 2645 | return $basedirs; |
| 2556 | 2646 | } |
@@ -2566,10 +2656,11 @@ discard block |
||
| 2566 | 2656 | */ |
| 2567 | 2657 | function attachDirStatus($dir, $expected_files) |
| 2568 | 2658 | { |
| 2569 | - if (!is_dir($dir)) |
|
| 2570 | - return array('does_not_exist', true, ''); |
|
| 2571 | - elseif (!is_writable($dir)) |
|
| 2572 | - return array('not_writable', true, ''); |
|
| 2659 | + if (!is_dir($dir)) { |
|
| 2660 | + return array('does_not_exist', true, ''); |
|
| 2661 | + } elseif (!is_writable($dir)) { |
|
| 2662 | + return array('not_writable', true, ''); |
|
| 2663 | + } |
|
| 2573 | 2664 | |
| 2574 | 2665 | // Everything is okay so far, start to scan through the directory. |
| 2575 | 2666 | $num_files = 0; |
@@ -2577,22 +2668,26 @@ discard block |
||
| 2577 | 2668 | while ($file = $dir_handle->read()) |
| 2578 | 2669 | { |
| 2579 | 2670 | // Now do we have a real file here? |
| 2580 | - if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) |
|
| 2581 | - continue; |
|
| 2671 | + if (in_array($file, array('.', '..', '.htaccess', 'index.php'))) { |
|
| 2672 | + continue; |
|
| 2673 | + } |
|
| 2582 | 2674 | |
| 2583 | 2675 | $num_files++; |
| 2584 | 2676 | } |
| 2585 | 2677 | $dir_handle->close(); |
| 2586 | 2678 | |
| 2587 | - if ($num_files < $expected_files) |
|
| 2588 | - return array('files_missing', true, $num_files); |
|
| 2679 | + if ($num_files < $expected_files) { |
|
| 2680 | + return array('files_missing', true, $num_files); |
|
| 2681 | + } |
|
| 2589 | 2682 | // Empty? |
| 2590 | - elseif ($expected_files == 0) |
|
| 2591 | - return array('unused', false, $num_files); |
|
| 2683 | + elseif ($expected_files == 0) { |
|
| 2684 | + return array('unused', false, $num_files); |
|
| 2685 | + } |
|
| 2592 | 2686 | // All good! |
| 2593 | - else |
|
| 2594 | - return array('ok', false, $num_files); |
|
| 2595 | -} |
|
| 2687 | + else { |
|
| 2688 | + return array('ok', false, $num_files); |
|
| 2689 | + } |
|
| 2690 | + } |
|
| 2596 | 2691 | |
| 2597 | 2692 | /** |
| 2598 | 2693 | * Maintance function to move attachments from one directory to another |
@@ -2604,10 +2699,11 @@ discard block |
||
| 2604 | 2699 | checkSession(); |
| 2605 | 2700 | |
| 2606 | 2701 | $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
| 2607 | - if (!empty($modSettings['attachment_basedirectories'])) |
|
| 2608 | - $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2609 | - else |
|
| 2610 | - $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2702 | + if (!empty($modSettings['attachment_basedirectories'])) { |
|
| 2703 | + $modSettings['attachment_basedirectories'] = smf_json_decode($modSettings['attachment_basedirectories'], true); |
|
| 2704 | + } else { |
|
| 2705 | + $modSettings['basedirectory_for_attachments'] = array(); |
|
| 2706 | + } |
|
| 2611 | 2707 | |
| 2612 | 2708 | $_POST['from'] = (int) $_POST['from']; |
| 2613 | 2709 | $_POST['auto'] = !empty($_POST['auto']) ? (int) $_POST['auto'] : 0; |
@@ -2621,11 +2717,13 @@ discard block |
||
| 2621 | 2717 | $total_moved = 0; |
| 2622 | 2718 | $total_not_moved = 0; |
| 2623 | 2719 | |
| 2624 | - if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) |
|
| 2625 | - $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2720 | + if (empty($_POST['from']) || (empty($_POST['auto']) && empty($_POST['to']))) { |
|
| 2721 | + $results[] = $txt['attachment_transfer_no_dir']; |
|
| 2722 | + } |
|
| 2626 | 2723 | |
| 2627 | - if ($_POST['from'] == $_POST['to']) |
|
| 2628 | - $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2724 | + if ($_POST['from'] == $_POST['to']) { |
|
| 2725 | + $results[] = $txt['attachment_transfer_same_dir']; |
|
| 2726 | + } |
|
| 2629 | 2727 | |
| 2630 | 2728 | if (empty($results)) |
| 2631 | 2729 | { |
@@ -2644,8 +2742,9 @@ discard block |
||
| 2644 | 2742 | $smcFunc['db_free_result']($request); |
| 2645 | 2743 | $total_progress -= $start; |
| 2646 | 2744 | |
| 2647 | - if ($total_progress < 1) |
|
| 2648 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2745 | + if ($total_progress < 1) { |
|
| 2746 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2747 | + } |
|
| 2649 | 2748 | } |
| 2650 | 2749 | |
| 2651 | 2750 | if (empty($results)) |
@@ -2661,9 +2760,9 @@ discard block |
||
| 2661 | 2760 | |
| 2662 | 2761 | automanage_attachments_check_directory(); |
| 2663 | 2762 | $new_dir = $modSettings['currentAttachmentUploadDir']; |
| 2763 | + } else { |
|
| 2764 | + $new_dir = $_POST['to']; |
|
| 2664 | 2765 | } |
| 2665 | - else |
|
| 2666 | - $new_dir = $_POST['to']; |
|
| 2667 | 2766 | |
| 2668 | 2767 | $modSettings['currentAttachmentUploadDir'] = $new_dir; |
| 2669 | 2768 | |
@@ -2671,8 +2770,9 @@ discard block |
||
| 2671 | 2770 | while ($break == false) |
| 2672 | 2771 | { |
| 2673 | 2772 | @set_time_limit(300); |
| 2674 | - if (function_exists('apache_reset_timeout')) |
|
| 2675 | - @apache_reset_timeout(); |
|
| 2773 | + if (function_exists('apache_reset_timeout')) { |
|
| 2774 | + @apache_reset_timeout(); |
|
| 2775 | + } |
|
| 2676 | 2776 | |
| 2677 | 2777 | // If limits are set, get the file count and size for the destination folder |
| 2678 | 2778 | if ($dir_files <= 0 && (!empty($modSettings['attachmentDirSizeLimit']) || !empty($modSettings['attachmentDirFileLimit']))) |
@@ -2708,13 +2808,15 @@ discard block |
||
| 2708 | 2808 | |
| 2709 | 2809 | if ($smcFunc['db_num_rows']($request) === 0) |
| 2710 | 2810 | { |
| 2711 | - if (empty($current_progress)) |
|
| 2712 | - $results[] = $txt['attachment_transfer_no_find']; |
|
| 2811 | + if (empty($current_progress)) { |
|
| 2812 | + $results[] = $txt['attachment_transfer_no_find']; |
|
| 2813 | + } |
|
| 2713 | 2814 | break; |
| 2714 | 2815 | } |
| 2715 | 2816 | |
| 2716 | - if ($smcFunc['db_num_rows']($request) < $limit) |
|
| 2717 | - $break = true; |
|
| 2817 | + if ($smcFunc['db_num_rows']($request) < $limit) { |
|
| 2818 | + $break = true; |
|
| 2819 | + } |
|
| 2718 | 2820 | |
| 2719 | 2821 | // Move them |
| 2720 | 2822 | $moved = array(); |
@@ -2738,8 +2840,9 @@ discard block |
||
| 2738 | 2840 | automanage_attachments_by_space(); |
| 2739 | 2841 | |
| 2740 | 2842 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2741 | - if (!empty($total_not_moved)) |
|
| 2742 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2843 | + if (!empty($total_not_moved)) { |
|
| 2844 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2845 | + } |
|
| 2743 | 2846 | |
| 2744 | 2847 | $dir_files = 0; |
| 2745 | 2848 | $total_moved = 0; |
@@ -2747,8 +2850,7 @@ discard block |
||
| 2747 | 2850 | |
| 2748 | 2851 | $break = false; |
| 2749 | 2852 | break; |
| 2750 | - } |
|
| 2751 | - else |
|
| 2853 | + } else |
|
| 2752 | 2854 | { |
| 2753 | 2855 | // Hmm, not in auto. Time to bail out then... |
| 2754 | 2856 | $results[] = $txt['attachment_transfer_no_room']; |
@@ -2763,9 +2865,9 @@ discard block |
||
| 2763 | 2865 | $total_moved++; |
| 2764 | 2866 | $current_progress++; |
| 2765 | 2867 | $moved[] = $row['id_attach']; |
| 2868 | + } else { |
|
| 2869 | + $total_not_moved++; |
|
| 2766 | 2870 | } |
| 2767 | - else |
|
| 2768 | - $total_not_moved++; |
|
| 2769 | 2871 | } |
| 2770 | 2872 | $smcFunc['db_free_result']($request); |
| 2771 | 2873 | |
@@ -2803,13 +2905,15 @@ discard block |
||
| 2803 | 2905 | } |
| 2804 | 2906 | |
| 2805 | 2907 | $results[] = sprintf($txt['attachments_transferred'], $total_moved, $modSettings['attachmentUploadDir'][$new_dir]); |
| 2806 | - if (!empty($total_not_moved)) |
|
| 2807 | - $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2908 | + if (!empty($total_not_moved)) { |
|
| 2909 | + $results[] = sprintf($txt['attachments_not_transferred'], $total_not_moved); |
|
| 2910 | + } |
|
| 2808 | 2911 | } |
| 2809 | 2912 | |
| 2810 | 2913 | $_SESSION['results'] = $results; |
| 2811 | - if (file_exists($boarddir . '/progress.php')) |
|
| 2812 | - unlink($boarddir . '/progress.php'); |
|
| 2914 | + if (file_exists($boarddir . '/progress.php')) { |
|
| 2915 | + unlink($boarddir . '/progress.php'); |
|
| 2916 | + } |
|
| 2813 | 2917 | |
| 2814 | 2918 | redirectexit('action=admin;area=manageattachments;sa=maintenance#transfer'); |
| 2815 | 2919 | } |
@@ -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 | * The main handler and designator for AJAX stuff - jumpto, message icons and previews |
@@ -32,8 +33,9 @@ discard block |
||
| 32 | 33 | // Easy adding of sub actions. |
| 33 | 34 | call_integration_hook('integrate_XMLhttpMain_subActions', array(&$subActions)); |
| 34 | 35 | |
| 35 | - if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) |
|
| 36 | - fatal_lang_error('no_access', false); |
|
| 36 | + if (!isset($_REQUEST['sa'], $subActions[$_REQUEST['sa']])) { |
|
| 37 | + fatal_lang_error('no_access', false); |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | call_helper($subActions[$_REQUEST['sa']]); |
| 39 | 41 | } |
@@ -57,8 +59,9 @@ discard block |
||
| 57 | 59 | foreach ($context['jump_to'] as $id_cat => $cat) |
| 58 | 60 | { |
| 59 | 61 | $context['jump_to'][$id_cat]['name'] = un_htmlspecialchars(strip_tags($cat['name'])); |
| 60 | - foreach ($cat['boards'] as $id_board => $board) |
|
| 61 | - $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
| 62 | + foreach ($cat['boards'] as $id_board => $board) { |
|
| 63 | + $context['jump_to'][$id_cat]['boards'][$id_board]['name'] = un_htmlspecialchars(strip_tags($board['name'])); |
|
| 64 | + } |
|
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | $context['sub_template'] = 'jump_to'; |
@@ -95,8 +98,9 @@ discard block |
||
| 95 | 98 | |
| 96 | 99 | $context['sub_template'] = 'generic_xml'; |
| 97 | 100 | |
| 98 | - if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) |
|
| 99 | - return false; |
|
| 101 | + if (!isset($_POST['item']) || !in_array($_POST['item'], $items)) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 100 | 104 | |
| 101 | 105 | $_POST['item'](); |
| 102 | 106 | } |
@@ -112,10 +116,11 @@ discard block |
||
| 112 | 116 | |
| 113 | 117 | $errors = array(); |
| 114 | 118 | $news = !isset($_POST['news']) ? '' : $smcFunc['htmlspecialchars']($_POST['news'], ENT_QUOTES); |
| 115 | - if (empty($news)) |
|
| 116 | - $errors[] = array('value' => 'no_news'); |
|
| 117 | - else |
|
| 118 | - preparsecode($news); |
|
| 119 | + if (empty($news)) { |
|
| 120 | + $errors[] = array('value' => 'no_news'); |
|
| 121 | + } else { |
|
| 122 | + preparsecode($news); |
|
| 123 | + } |
|
| 119 | 124 | |
| 120 | 125 | $context['xml_data'] = array( |
| 121 | 126 | 'news' => array( |
@@ -148,10 +153,12 @@ discard block |
||
| 148 | 153 | $context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0; |
| 149 | 154 | $context['send_html'] = !empty($_POST['send_html']) ? 1 : 0; |
| 150 | 155 | |
| 151 | - if (empty($_POST['subject'])) |
|
| 152 | - $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
| 153 | - if (empty($_POST['message'])) |
|
| 154 | - $context['post_error']['messages'][] = $txt['error_no_message']; |
|
| 156 | + if (empty($_POST['subject'])) { |
|
| 157 | + $context['post_error']['messages'][] = $txt['error_no_subject']; |
|
| 158 | + } |
|
| 159 | + if (empty($_POST['message'])) { |
|
| 160 | + $context['post_error']['messages'][] = $txt['error_no_message']; |
|
| 161 | + } |
|
| 155 | 162 | |
| 156 | 163 | prepareMailingForPreview(); |
| 157 | 164 | |
@@ -196,38 +203,41 @@ discard block |
||
| 196 | 203 | $preview_signature = !empty($_POST['signature']) ? $_POST['signature'] : $txt['no_signature_preview']; |
| 197 | 204 | $validation = profileValidateSignature($preview_signature); |
| 198 | 205 | |
| 199 | - if ($validation !== true && $validation !== false) |
|
| 200 | - $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
| 206 | + if ($validation !== true && $validation !== false) { |
|
| 207 | + $errors[] = array('value' => $txt['profile_error_' . $validation], 'attributes' => array('type' => 'error')); |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | censorText($preview_signature); |
| 203 | 211 | $preview_signature = parse_bbc($preview_signature, true, 'sig' . $user); |
| 204 | - } |
|
| 205 | - elseif (!$can_change) |
|
| 212 | + } elseif (!$can_change) |
|
| 206 | 213 | { |
| 207 | - if ($is_owner) |
|
| 208 | - $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
| 209 | - else |
|
| 210 | - $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
| 214 | + if ($is_owner) { |
|
| 215 | + $errors[] = array('value' => $txt['cannot_profile_extra_own'], 'attributes' => array('type' => 'error')); |
|
| 216 | + } else { |
|
| 217 | + $errors[] = array('value' => $txt['cannot_profile_extra_any'], 'attributes' => array('type' => 'error')); |
|
| 218 | + } |
|
| 219 | + } else { |
|
| 220 | + $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
| 211 | 221 | } |
| 212 | - else |
|
| 213 | - $errors[] = array('value' => $txt['no_user_selected'], 'attributes' => array('type' => 'error')); |
|
| 214 | 222 | |
| 215 | 223 | $context['xml_data']['signatures'] = array( |
| 216 | 224 | 'identifier' => 'signature', |
| 217 | 225 | 'children' => array() |
| 218 | 226 | ); |
| 219 | - if (isset($current_signature)) |
|
| 220 | - $context['xml_data']['signatures']['children'][] = array( |
|
| 227 | + if (isset($current_signature)) { |
|
| 228 | + $context['xml_data']['signatures']['children'][] = array( |
|
| 221 | 229 | 'value' => $current_signature, |
| 222 | 230 | 'attributes' => array('type' => 'current'), |
| 223 | 231 | ); |
| 224 | - if (isset($preview_signature)) |
|
| 225 | - $context['xml_data']['signatures']['children'][] = array( |
|
| 232 | + } |
|
| 233 | + if (isset($preview_signature)) { |
|
| 234 | + $context['xml_data']['signatures']['children'][] = array( |
|
| 226 | 235 | 'value' => $preview_signature, |
| 227 | 236 | 'attributes' => array('type' => 'preview'), |
| 228 | 237 | ); |
| 229 | - if (!empty($errors)) |
|
| 230 | - $context['xml_data']['errors'] = array( |
|
| 238 | + } |
|
| 239 | + if (!empty($errors)) { |
|
| 240 | + $context['xml_data']['errors'] = array( |
|
| 231 | 241 | 'identifier' => 'error', |
| 232 | 242 | 'children' => array_merge( |
| 233 | 243 | array( |
@@ -239,7 +249,8 @@ discard block |
||
| 239 | 249 | $errors |
| 240 | 250 | ), |
| 241 | 251 | ); |
| 242 | -} |
|
| 252 | + } |
|
| 253 | + } |
|
| 243 | 254 | |
| 244 | 255 | /** |
| 245 | 256 | * Handles previewing user warnings |
@@ -259,15 +270,17 @@ discard block |
||
| 259 | 270 | $context['preview_subject'] = !empty($_POST['title']) ? trim($smcFunc['htmlspecialchars']($_POST['title'])) : ''; |
| 260 | 271 | if (isset($_POST['issuing'])) |
| 261 | 272 | { |
| 262 | - if (empty($_POST['title']) || empty($_POST['body'])) |
|
| 263 | - $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
| 264 | - } |
|
| 265 | - else |
|
| 273 | + if (empty($_POST['title']) || empty($_POST['body'])) { |
|
| 274 | + $context['post_error']['messages'][] = $txt['warning_notify_blank']; |
|
| 275 | + } |
|
| 276 | + } else |
|
| 266 | 277 | { |
| 267 | - if (empty($_POST['title'])) |
|
| 268 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
| 269 | - if (empty($_POST['body'])) |
|
| 270 | - $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
| 278 | + if (empty($_POST['title'])) { |
|
| 279 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_title']; |
|
| 280 | + } |
|
| 281 | + if (empty($_POST['body'])) { |
|
| 282 | + $context['post_error']['messages'][] = $txt['mc_warning_template_error_no_body']; |
|
| 283 | + } |
|
| 271 | 284 | // Add in few replacements. |
| 272 | 285 | /** |
| 273 | 286 | * These are the defaults: |
@@ -298,9 +311,9 @@ discard block |
||
| 298 | 311 | $warning_body = parse_bbc($warning_body, true); |
| 299 | 312 | } |
| 300 | 313 | $context['preview_message'] = $warning_body; |
| 314 | + } else { |
|
| 315 | + $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
| 301 | 316 | } |
| 302 | - else |
|
| 303 | - $context['post_error']['messages'][] = array('value' => $txt['cannot_issue_warning'], 'attributes' => array('type' => 'error')); |
|
| 304 | 317 | |
| 305 | 318 | $context['sub_template'] = 'warning'; |
| 306 | 319 | } |
@@ -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 | * Updates a report with the given parameters. Logs each action via logAction() |
@@ -28,19 +29,20 @@ discard block |
||
| 28 | 29 | global $smcFunc, $user_info, $context; |
| 29 | 30 | |
| 30 | 31 | // Don't bother. |
| 31 | - if (empty($action) || empty($report_id)) |
|
| 32 | - return false; |
|
| 32 | + if (empty($action) || empty($report_id)) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 33 | 35 | |
| 34 | 36 | // Add the "_all" thingy. |
| 35 | - if ($action == 'ignore') |
|
| 36 | - $action = 'ignore_all'; |
|
| 37 | + if ($action == 'ignore') { |
|
| 38 | + $action = 'ignore_all'; |
|
| 39 | + } |
|
| 37 | 40 | |
| 38 | 41 | // We don't need the board query for reported members |
| 39 | 42 | if ($context['report_type'] == 'members') |
| 40 | 43 | { |
| 41 | 44 | $board_query = ''; |
| 42 | - } |
|
| 43 | - else |
|
| 45 | + } else |
|
| 44 | 46 | { |
| 45 | 47 | $board_query = ' AND ' . $user_info['mod_cache']['bq']; |
| 46 | 48 | } |
@@ -76,17 +78,17 @@ discard block |
||
| 76 | 78 | ) |
| 77 | 79 | ); |
| 78 | 80 | |
| 79 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 80 | - $extra[$row['id_report']] = array( |
|
| 81 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 82 | + $extra[$row['id_report']] = array( |
|
| 81 | 83 | 'report' => $row['id_report'], |
| 82 | 84 | 'board' => $row['id_board'], |
| 83 | 85 | 'message' => $row['id_msg'], |
| 84 | 86 | 'topic' => $row['id_topic'], |
| 85 | 87 | ); |
| 88 | + } |
|
| 86 | 89 | |
| 87 | 90 | $smcFunc['db_free_result']($request); |
| 88 | - } |
|
| 89 | - else |
|
| 91 | + } else |
|
| 90 | 92 | { |
| 91 | 93 | $request = $smcFunc['db_query']('', ' |
| 92 | 94 | SELECT id_report, id_member, membername |
@@ -97,28 +99,32 @@ discard block |
||
| 97 | 99 | ) |
| 98 | 100 | ); |
| 99 | 101 | |
| 100 | - while($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 101 | - $extra[$row['id_report']] = array( |
|
| 102 | + while($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 103 | + $extra[$row['id_report']] = array( |
|
| 102 | 104 | 'report' => $row['id_report'], |
| 103 | 105 | 'member' => $row['id_member'], |
| 104 | 106 | ); |
| 107 | + } |
|
| 105 | 108 | |
| 106 | 109 | $smcFunc['db_free_result']($request); |
| 107 | 110 | } |
| 108 | 111 | |
| 109 | 112 | // Back to "ignore". |
| 110 | - if ($action == 'ignore_all') |
|
| 111 | - $action = 'ignore'; |
|
| 113 | + if ($action == 'ignore_all') { |
|
| 114 | + $action = 'ignore'; |
|
| 115 | + } |
|
| 112 | 116 | |
| 113 | 117 | $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open'); |
| 114 | 118 | |
| 115 | - if ($context['report_type'] == 'members') |
|
| 116 | - $log_report .= '_user'; |
|
| 119 | + if ($context['report_type'] == 'members') { |
|
| 120 | + $log_report .= '_user'; |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | 123 | // Log this action. |
| 119 | - if (!empty($extra)) |
|
| 120 | - foreach ($extra as $report) |
|
| 124 | + if (!empty($extra)) { |
|
| 125 | + foreach ($extra as $report) |
|
| 121 | 126 | logAction($log_report . '_report', $report); |
| 127 | + } |
|
| 122 | 128 | |
| 123 | 129 | // Time to update. |
| 124 | 130 | updateSettings(array('last_mod_report_action' => time())); |
@@ -142,14 +148,12 @@ discard block |
||
| 142 | 148 | if ($context['report_type'] == 'members') |
| 143 | 149 | { |
| 144 | 150 | $and = 'lr.id_board = 0'; |
| 145 | - } |
|
| 146 | - else |
|
| 151 | + } else |
|
| 147 | 152 | { |
| 148 | 153 | if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1') |
| 149 | 154 | { |
| 150 | 155 | $bq = $user_info['mod_cache']['bq']; |
| 151 | - } |
|
| 152 | - else |
|
| 156 | + } else |
|
| 153 | 157 | { |
| 154 | 158 | $bq = 'lr.' . $user_info['mod_cache']['bq']; |
| 155 | 159 | } |
@@ -205,8 +209,7 @@ discard block |
||
| 205 | 209 | 'max' => 10, |
| 206 | 210 | ) |
| 207 | 211 | ); |
| 208 | - } |
|
| 209 | - else |
|
| 212 | + } else |
|
| 210 | 213 | { |
| 211 | 214 | $request = $smcFunc['db_query']('', ' |
| 212 | 215 | SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body, |
@@ -254,8 +257,7 @@ discard block |
||
| 254 | 257 | 'href' => $scripturl . '?action=profile;u=' . $row['id_user'], |
| 255 | 258 | ), |
| 256 | 259 | ); |
| 257 | - } |
|
| 258 | - else |
|
| 260 | + } else |
|
| 259 | 261 | { |
| 260 | 262 | $report_boards_ids[] = $row['id_board']; |
| 261 | 263 | $extraDetails = array( |
@@ -295,14 +297,16 @@ discard block |
||
| 295 | 297 | ) |
| 296 | 298 | ); |
| 297 | 299 | |
| 298 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
| 299 | - $board_names[$row['id_board']] = $row['name']; |
|
| 300 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
| 301 | + $board_names[$row['id_board']] = $row['name']; |
|
| 302 | + } |
|
| 300 | 303 | |
| 301 | 304 | $smcFunc['db_free_result']($request); |
| 302 | 305 | |
| 303 | - foreach ($reports as $id_report => $report) |
|
| 304 | - if (!empty($board_names[$report['topic']['id_board']])) |
|
| 306 | + foreach ($reports as $id_report => $report) { |
|
| 307 | + if (!empty($board_names[$report['topic']['id_board']])) |
|
| 305 | 308 | $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']]; |
| 309 | + } |
|
| 306 | 310 | } |
| 307 | 311 | |
| 308 | 312 | // Now get all the people who reported it. |
@@ -352,10 +356,11 @@ discard block |
||
| 352 | 356 | { |
| 353 | 357 | global $user_info, $smcFunc; |
| 354 | 358 | |
| 355 | - if ($type == 'members') |
|
| 356 | - $bq = ''; |
|
| 357 | - else |
|
| 358 | - $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 359 | + if ($type == 'members') { |
|
| 360 | + $bq = ''; |
|
| 361 | + } else { |
|
| 362 | + $bq = ' AND ' . $user_info['mod_cache']['bq']; |
|
| 363 | + } |
|
| 359 | 364 | |
| 360 | 365 | $request = $smcFunc['db_query']('', ' |
| 361 | 366 | SELECT COUNT(*) |
@@ -394,8 +399,9 @@ discard block |
||
| 394 | 399 | { |
| 395 | 400 | global $smcFunc, $user_info, $context; |
| 396 | 401 | |
| 397 | - if (empty($report_id)) |
|
| 398 | - return false; |
|
| 402 | + if (empty($report_id)) { |
|
| 403 | + return false; |
|
| 404 | + } |
|
| 399 | 405 | |
| 400 | 406 | // We don't need all this info if we're only getting user info |
| 401 | 407 | if ($context['report_type'] == 'members') |
@@ -413,8 +419,7 @@ discard block |
||
| 413 | 419 | 'id_report' => $report_id, |
| 414 | 420 | ) |
| 415 | 421 | ); |
| 416 | - } |
|
| 417 | - else |
|
| 422 | + } else |
|
| 418 | 423 | { |
| 419 | 424 | // Get the report details, need this so we can limit access to a particular board. |
| 420 | 425 | $request = $smcFunc['db_query']('', ' |
@@ -433,8 +438,9 @@ discard block |
||
| 433 | 438 | } |
| 434 | 439 | |
| 435 | 440 | // So did we find anything? |
| 436 | - if (!$smcFunc['db_num_rows']($request)) |
|
| 437 | - return false; |
|
| 441 | + if (!$smcFunc['db_num_rows']($request)) { |
|
| 442 | + return false; |
|
| 443 | + } |
|
| 438 | 444 | |
| 439 | 445 | // Woohoo we found a report and they can see it! |
| 440 | 446 | $row = $smcFunc['db_fetch_assoc']($request); |
@@ -453,8 +459,9 @@ discard block |
||
| 453 | 459 | { |
| 454 | 460 | global $smcFunc, $scripturl, $user_info, $txt; |
| 455 | 461 | |
| 456 | - if (empty($report_id)) |
|
| 457 | - return false; |
|
| 462 | + if (empty($report_id)) { |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 458 | 465 | |
| 459 | 466 | $report = array( |
| 460 | 467 | 'comments' => array(), |
@@ -535,8 +542,9 @@ discard block |
||
| 535 | 542 | { |
| 536 | 543 | global $smcFunc, $user_info; |
| 537 | 544 | |
| 538 | - if (empty($comment_id)) |
|
| 539 | - return false; |
|
| 545 | + if (empty($comment_id)) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 540 | 548 | |
| 541 | 549 | $request = $smcFunc['db_query']('', ' |
| 542 | 550 | SELECT id_comment, id_notice, log_time, body, id_member |
@@ -553,8 +561,9 @@ discard block |
||
| 553 | 561 | $smcFunc['db_free_result']($request); |
| 554 | 562 | |
| 555 | 563 | // Add the permission |
| 556 | - if (!empty($comment)) |
|
| 557 | - $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 564 | + if (!empty($comment)) { |
|
| 565 | + $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member'])); |
|
| 566 | + } |
|
| 558 | 567 | |
| 559 | 568 | return $comment; |
| 560 | 569 | } |
@@ -570,8 +579,9 @@ discard block |
||
| 570 | 579 | { |
| 571 | 580 | global $smcFunc, $user_info, $context; |
| 572 | 581 | |
| 573 | - if (empty($data)) |
|
| 574 | - return false; |
|
| 582 | + if (empty($data)) { |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 575 | 585 | |
| 576 | 586 | $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data); |
| 577 | 587 | |
@@ -600,8 +610,7 @@ discard block |
||
| 600 | 610 | 'comment_id' => $last_comment, |
| 601 | 611 | 'time' => time(), |
| 602 | 612 | ); |
| 603 | - } |
|
| 604 | - else |
|
| 613 | + } else |
|
| 605 | 614 | { |
| 606 | 615 | $prefix = 'Msg'; |
| 607 | 616 | $data = array( |
@@ -617,14 +626,15 @@ discard block |
||
| 617 | 626 | } |
| 618 | 627 | |
| 619 | 628 | // And get ready to notify people. |
| 620 | - if (!empty($report)) |
|
| 621 | - $smcFunc['db_insert']('insert', |
|
| 629 | + if (!empty($report)) { |
|
| 630 | + $smcFunc['db_insert']('insert', |
|
| 622 | 631 | '{db_prefix}background_tasks', |
| 623 | 632 | array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'), |
| 624 | 633 | array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', json_encode($data), 0), |
| 625 | 634 | array('id_task') |
| 626 | 635 | ); |
| 627 | -} |
|
| 636 | + } |
|
| 637 | + } |
|
| 628 | 638 | |
| 629 | 639 | /** |
| 630 | 640 | * Saves the new information whenever a moderator comment is edited. |
@@ -637,8 +647,9 @@ discard block |
||
| 637 | 647 | { |
| 638 | 648 | global $smcFunc; |
| 639 | 649 | |
| 640 | - if (empty($comment_id) || empty($edited_comment)) |
|
| 641 | - return false; |
|
| 650 | + if (empty($comment_id) || empty($edited_comment)) { |
|
| 651 | + return false; |
|
| 652 | + } |
|
| 642 | 653 | |
| 643 | 654 | $smcFunc['db_query']('', ' |
| 644 | 655 | UPDATE {db_prefix}log_comments |
@@ -661,8 +672,9 @@ discard block |
||
| 661 | 672 | { |
| 662 | 673 | global $smcFunc; |
| 663 | 674 | |
| 664 | - if (empty($comment_id)) |
|
| 665 | - return false; |
|
| 675 | + if (empty($comment_id)) { |
|
| 676 | + return false; |
|
| 677 | + } |
|
| 666 | 678 | |
| 667 | 679 | $smcFunc['db_query']('', ' |
| 668 | 680 | DELETE FROM {db_prefix}log_comments |