@@ -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'], |
@@ -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 | * Main entry point for the admin search settings screen. |
@@ -107,11 +108,13 @@ discard block |
||
107 | 108 | // Perhaps the search method wants to add some settings? |
108 | 109 | require_once($sourcedir . '/Search.php'); |
109 | 110 | $searchAPI = findSearchAPI(); |
110 | - if (is_callable(array($searchAPI, 'searchSettings'))) |
|
111 | - call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
111 | + if (is_callable(array($searchAPI, 'searchSettings'))) { |
|
112 | + call_user_func_array(array($searchAPI, 'searchSettings'), array(&$config_vars)); |
|
113 | + } |
|
112 | 114 | |
113 | - if ($return_config) |
|
114 | - return $config_vars; |
|
115 | + if ($return_config) { |
|
116 | + return $config_vars; |
|
117 | + } |
|
115 | 118 | |
116 | 119 | $context['page_title'] = $txt['search_settings_title']; |
117 | 120 | $context['sub_template'] = 'show_settings'; |
@@ -126,8 +129,9 @@ discard block |
||
126 | 129 | |
127 | 130 | call_integration_hook('integrate_save_search_settings'); |
128 | 131 | |
129 | - if (empty($_POST['search_results_per_page'])) |
|
130 | - $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
132 | + if (empty($_POST['search_results_per_page'])) { |
|
133 | + $_POST['search_results_per_page'] = !empty($modSettings['search_results_per_page']) ? $modSettings['search_results_per_page'] : $modSettings['defaultMaxMessages']; |
|
134 | + } |
|
131 | 135 | saveDBSettings($config_vars); |
132 | 136 | $_SESSION['adm-save'] = true; |
133 | 137 | redirectexit('action=admin;area=managesearch;sa=settings;' . $context['session_var'] . '=' . $context['session_id']); |
@@ -177,17 +181,20 @@ discard block |
||
177 | 181 | call_integration_hook('integrate_save_search_weights'); |
178 | 182 | |
179 | 183 | $changes = array(); |
180 | - foreach ($factors as $factor) |
|
181 | - $changes[$factor] = (int) $_POST[$factor]; |
|
184 | + foreach ($factors as $factor) { |
|
185 | + $changes[$factor] = (int) $_POST[$factor]; |
|
186 | + } |
|
182 | 187 | updateSettings($changes); |
183 | 188 | } |
184 | 189 | |
185 | 190 | $context['relative_weights'] = array('total' => 0); |
186 | - foreach ($factors as $factor) |
|
187 | - $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
191 | + foreach ($factors as $factor) { |
|
192 | + $context['relative_weights']['total'] += isset($modSettings[$factor]) ? $modSettings[$factor] : 0; |
|
193 | + } |
|
188 | 194 | |
189 | - foreach ($factors as $factor) |
|
190 | - $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
195 | + foreach ($factors as $factor) { |
|
196 | + $context['relative_weights'][$factor] = round(100 * (isset($modSettings[$factor]) ? $modSettings[$factor] : 0) / $context['relative_weights']['total'], 1); |
|
197 | + } |
|
191 | 198 | |
192 | 199 | createToken('admin-msw'); |
193 | 200 | } |
@@ -215,8 +222,9 @@ discard block |
||
215 | 222 | $context['search_apis'] = loadSearchAPIs(); |
216 | 223 | |
217 | 224 | // Detect whether a fulltext index is set. |
218 | - if ($context['supports_fulltext']) |
|
219 | - detectFulltextIndex(); |
|
225 | + if ($context['supports_fulltext']) { |
|
226 | + detectFulltextIndex(); |
|
227 | + } |
|
220 | 228 | |
221 | 229 | if (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'createfulltext') |
222 | 230 | { |
@@ -252,8 +260,7 @@ discard block |
||
252 | 260 | 'language' => $language_ftx |
253 | 261 | ) |
254 | 262 | ); |
255 | - } |
|
256 | - else |
|
263 | + } else |
|
257 | 264 | { |
258 | 265 | // Make sure it's gone before creating it. |
259 | 266 | $smcFunc['db_query']('', ' |
@@ -273,8 +280,7 @@ discard block |
||
273 | 280 | } |
274 | 281 | |
275 | 282 | $context['fulltext_index'] = 'body'; |
276 | - } |
|
277 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
283 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removefulltext' && !empty($context['fulltext_index'])) |
|
278 | 284 | { |
279 | 285 | checkSession('get'); |
280 | 286 | validateToken('admin-msm', 'get'); |
@@ -291,12 +297,12 @@ discard block |
||
291 | 297 | $context['fulltext_index'] = ''; |
292 | 298 | |
293 | 299 | // Go back to the default search method. |
294 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') |
|
295 | - updateSettings(array( |
|
300 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'fulltext') { |
|
301 | + updateSettings(array( |
|
296 | 302 | 'search_index' => '', |
297 | 303 | )); |
298 | - } |
|
299 | - elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
304 | + } |
|
305 | + } elseif (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'removecustom') |
|
300 | 306 | { |
301 | 307 | checkSession('get'); |
302 | 308 | validateToken('admin-msm', 'get'); |
@@ -318,12 +324,12 @@ discard block |
||
318 | 324 | )); |
319 | 325 | |
320 | 326 | // Go back to the default search method. |
321 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
322 | - updateSettings(array( |
|
327 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
328 | + updateSettings(array( |
|
323 | 329 | 'search_index' => '', |
324 | 330 | )); |
325 | - } |
|
326 | - elseif (isset($_POST['save'])) |
|
331 | + } |
|
332 | + } elseif (isset($_POST['save'])) |
|
327 | 333 | { |
328 | 334 | checkSession(); |
329 | 335 | validateToken('admin-msmpost'); |
@@ -345,8 +351,8 @@ discard block |
||
345 | 351 | // Get some info about the messages table, to show its size and index size. |
346 | 352 | if ($db_type == 'mysql') |
347 | 353 | { |
348 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
349 | - $request = $smcFunc['db_query']('', ' |
|
354 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
355 | + $request = $smcFunc['db_query']('', ' |
|
350 | 356 | SHOW TABLE STATUS |
351 | 357 | FROM {string:database_name} |
352 | 358 | LIKE {string:table_name}', |
@@ -355,14 +361,15 @@ discard block |
||
355 | 361 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
356 | 362 | ) |
357 | 363 | ); |
358 | - else |
|
359 | - $request = $smcFunc['db_query']('', ' |
|
364 | + } else { |
|
365 | + $request = $smcFunc['db_query']('', ' |
|
360 | 366 | SHOW TABLE STATUS |
361 | 367 | LIKE {string:table_name}', |
362 | 368 | array( |
363 | 369 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
364 | 370 | ) |
365 | 371 | ); |
372 | + } |
|
366 | 373 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
367 | 374 | { |
368 | 375 | // Only do this if the user has permission to execute this query. |
@@ -374,8 +381,8 @@ discard block |
||
374 | 381 | } |
375 | 382 | |
376 | 383 | // Now check the custom index table, if it exists at all. |
377 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
378 | - $request = $smcFunc['db_query']('', ' |
|
384 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
385 | + $request = $smcFunc['db_query']('', ' |
|
379 | 386 | SHOW TABLE STATUS |
380 | 387 | FROM {string:database_name} |
381 | 388 | LIKE {string:table_name}', |
@@ -384,14 +391,15 @@ discard block |
||
384 | 391 | 'table_name' => str_replace('_', '\_', $match[2]) . 'log_search_words', |
385 | 392 | ) |
386 | 393 | ); |
387 | - else |
|
388 | - $request = $smcFunc['db_query']('', ' |
|
394 | + } else { |
|
395 | + $request = $smcFunc['db_query']('', ' |
|
389 | 396 | SHOW TABLE STATUS |
390 | 397 | LIKE {string:table_name}', |
391 | 398 | array( |
392 | 399 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'log_search_words', |
393 | 400 | ) |
394 | 401 | ); |
402 | + } |
|
395 | 403 | if ($request !== false && $smcFunc['db_num_rows']($request) == 1) |
396 | 404 | { |
397 | 405 | // Only do this if the user has permission to execute this query. |
@@ -400,8 +408,7 @@ discard block |
||
400 | 408 | $context['table_info']['custom_index_length'] = $row['Data_length'] + $row['Index_length']; |
401 | 409 | $smcFunc['db_free_result']($request); |
402 | 410 | } |
403 | - } |
|
404 | - elseif ($db_type == 'postgresql') |
|
411 | + } elseif ($db_type == 'postgresql') |
|
405 | 412 | { |
406 | 413 | // In order to report the sizes correctly we need to perform vacuum (optimize) on the tables we will be using. |
407 | 414 | //db_extend(); |
@@ -443,38 +450,38 @@ discard block |
||
443 | 450 | $context['table_info']['data_length'] = (int) $row['table_size']; |
444 | 451 | $context['table_info']['index_length'] = (int) $row['index_size']; |
445 | 452 | $context['table_info']['fulltext_length'] = (int) $row['index_size']; |
446 | - } |
|
447 | - elseif ($row['indexname'] == $db_prefix . 'log_search_words') |
|
453 | + } elseif ($row['indexname'] == $db_prefix . 'log_search_words') |
|
448 | 454 | { |
449 | 455 | $context['table_info']['index_length'] = (int) $row['index_size']; |
450 | 456 | $context['table_info']['custom_index_length'] = (int) $row['index_size']; |
451 | 457 | } |
452 | 458 | } |
453 | 459 | $smcFunc['db_free_result']($request); |
454 | - } |
|
455 | - else |
|
456 | - // Didn't work for some reason... |
|
460 | + } else { |
|
461 | + // Didn't work for some reason... |
|
457 | 462 | $context['table_info'] = array( |
458 | 463 | 'data_length' => $txt['not_applicable'], |
459 | 464 | 'index_length' => $txt['not_applicable'], |
460 | 465 | 'fulltext_length' => $txt['not_applicable'], |
461 | 466 | 'custom_index_length' => $txt['not_applicable'], |
462 | 467 | ); |
463 | - } |
|
464 | - else |
|
465 | - $context['table_info'] = array( |
|
468 | + } |
|
469 | + } else { |
|
470 | + $context['table_info'] = array( |
|
466 | 471 | 'data_length' => $txt['not_applicable'], |
467 | 472 | 'index_length' => $txt['not_applicable'], |
468 | 473 | 'fulltext_length' => $txt['not_applicable'], |
469 | 474 | 'custom_index_length' => $txt['not_applicable'], |
470 | 475 | ); |
476 | + } |
|
471 | 477 | |
472 | 478 | // Format the data and index length in kilobytes. |
473 | 479 | foreach ($context['table_info'] as $type => $size) |
474 | 480 | { |
475 | 481 | // If it's not numeric then just break. This database engine doesn't support size. |
476 | - if (!is_numeric($size)) |
|
477 | - break; |
|
482 | + if (!is_numeric($size)) { |
|
483 | + break; |
|
484 | + } |
|
478 | 485 | |
479 | 486 | $context['table_info'][$type] = comma_format($context['table_info'][$type] / 1024) . ' ' . $txt['search_method_kilobytes']; |
480 | 487 | } |
@@ -503,8 +510,9 @@ discard block |
||
503 | 510 | |
504 | 511 | // Scotty, we need more time... |
505 | 512 | @set_time_limit(600); |
506 | - if (function_exists('apache_reset_timeout')) |
|
507 | - @apache_reset_timeout(); |
|
513 | + if (function_exists('apache_reset_timeout')) { |
|
514 | + @apache_reset_timeout(); |
|
515 | + } |
|
508 | 516 | |
509 | 517 | $context[$context['admin_menu_name']]['current_subsection'] = 'method'; |
510 | 518 | $context['page_title'] = $txt['search_index_custom']; |
@@ -534,8 +542,7 @@ discard block |
||
534 | 542 | $context['start'] = (int) $context['index_settings']['resume_at']; |
535 | 543 | unset($context['index_settings']['resume_at']); |
536 | 544 | $context['step'] = 1; |
537 | - } |
|
538 | - else |
|
545 | + } else |
|
539 | 546 | { |
540 | 547 | $context['index_settings'] = array( |
541 | 548 | 'bytes_per_word' => isset($_REQUEST['bytes_per_word']) && isset($index_properties[$_REQUEST['bytes_per_word']]) ? (int) $_REQUEST['bytes_per_word'] : 2, |
@@ -544,12 +551,14 @@ discard block |
||
544 | 551 | $context['step'] = isset($_REQUEST['step']) ? (int) $_REQUEST['step'] : 0; |
545 | 552 | |
546 | 553 | // admin timeouts are painful when building these long indexes - but only if we actually have such things enabled |
547 | - if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) |
|
548 | - $_SESSION['admin_time'] = time(); |
|
554 | + if (empty($modSettings['securityDisable']) && $_SESSION['admin_time'] + 3300 < time() && $context['step'] >= 1) { |
|
555 | + $_SESSION['admin_time'] = time(); |
|
556 | + } |
|
549 | 557 | } |
550 | 558 | |
551 | - if ($context['step'] !== 0) |
|
552 | - checkSession('request'); |
|
559 | + if ($context['step'] !== 0) { |
|
560 | + checkSession('request'); |
|
561 | + } |
|
553 | 562 | |
554 | 563 | // Step 0: let the user determine how they like their index. |
555 | 564 | if ($context['step'] === 0) |
@@ -578,12 +587,14 @@ discard block |
||
578 | 587 | $smcFunc['db_create_word_search']($index_properties[$context['index_settings']['bytes_per_word']]['column_definition']); |
579 | 588 | |
580 | 589 | // Temporarily switch back to not using a search index. |
581 | - if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') |
|
582 | - updateSettings(array('search_index' => '')); |
|
590 | + if (!empty($modSettings['search_index']) && $modSettings['search_index'] == 'custom') { |
|
591 | + updateSettings(array('search_index' => '')); |
|
592 | + } |
|
583 | 593 | |
584 | 594 | // Don't let simultanious processes be updating the search index. |
585 | - if (!empty($modSettings['search_custom_index_config'])) |
|
586 | - updateSettings(array('search_custom_index_config' => '')); |
|
595 | + if (!empty($modSettings['search_custom_index_config'])) { |
|
596 | + updateSettings(array('search_custom_index_config' => '')); |
|
597 | + } |
|
587 | 598 | } |
588 | 599 | |
589 | 600 | $num_messages = array( |
@@ -599,16 +610,16 @@ discard block |
||
599 | 610 | 'starting_id' => $context['start'], |
600 | 611 | ) |
601 | 612 | ); |
602 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
603 | - $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
613 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
614 | + $num_messages[empty($row['todo']) ? 'done' : 'todo'] = $row['num_messages']; |
|
615 | + } |
|
604 | 616 | |
605 | 617 | if (empty($num_messages['todo'])) |
606 | 618 | { |
607 | 619 | $context['step'] = 2; |
608 | 620 | $context['percentage'] = 80; |
609 | 621 | $context['start'] = 0; |
610 | - } |
|
611 | - else |
|
622 | + } else |
|
612 | 623 | { |
613 | 624 | // Number of seconds before the next step. |
614 | 625 | $stop = time() + 3; |
@@ -649,21 +660,22 @@ discard block |
||
649 | 660 | |
650 | 661 | $context['start'] += $forced_break ? $number_processed : $messages_per_batch; |
651 | 662 | |
652 | - if (!empty($inserts)) |
|
653 | - $smcFunc['db_insert']('ignore', |
|
663 | + if (!empty($inserts)) { |
|
664 | + $smcFunc['db_insert']('ignore', |
|
654 | 665 | '{db_prefix}log_search_words', |
655 | 666 | array('id_word' => 'int', 'id_msg' => 'int'), |
656 | 667 | $inserts, |
657 | 668 | array('id_word', 'id_msg') |
658 | 669 | ); |
670 | + } |
|
659 | 671 | if ($num_messages['todo'] === 0) |
660 | 672 | { |
661 | 673 | $context['step'] = 2; |
662 | 674 | $context['start'] = 0; |
663 | 675 | break; |
676 | + } else { |
|
677 | + updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
664 | 678 | } |
665 | - else |
|
666 | - updateSettings(array('search_custom_index_resume' => json_encode(array_merge($context['index_settings'], array('resume_at' => $context['start']))))); |
|
667 | 679 | } |
668 | 680 | |
669 | 681 | // Since there are still two steps to go, 80% is the maximum here. |
@@ -674,9 +686,9 @@ discard block |
||
674 | 686 | // Step 2: removing the words that occur too often and are of no use. |
675 | 687 | elseif ($context['step'] === 2) |
676 | 688 | { |
677 | - if ($context['index_settings']['bytes_per_word'] < 4) |
|
678 | - $context['step'] = 3; |
|
679 | - else |
|
689 | + if ($context['index_settings']['bytes_per_word'] < 4) { |
|
690 | + $context['step'] = 3; |
|
691 | + } else |
|
680 | 692 | { |
681 | 693 | $stop_words = $context['start'] === 0 || empty($modSettings['search_stopwords']) ? array() : explode(',', $modSettings['search_stopwords']); |
682 | 694 | $stop = time() + 3; |
@@ -697,20 +709,22 @@ discard block |
||
697 | 709 | 'minimum_messages' => $max_messages, |
698 | 710 | ) |
699 | 711 | ); |
700 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
701 | - $stop_words[] = $row['id_word']; |
|
712 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
713 | + $stop_words[] = $row['id_word']; |
|
714 | + } |
|
702 | 715 | $smcFunc['db_free_result']($request); |
703 | 716 | |
704 | 717 | updateSettings(array('search_stopwords' => implode(',', $stop_words))); |
705 | 718 | |
706 | - if (!empty($stop_words)) |
|
707 | - $smcFunc['db_query']('', ' |
|
719 | + if (!empty($stop_words)) { |
|
720 | + $smcFunc['db_query']('', ' |
|
708 | 721 | DELETE FROM {db_prefix}log_search_words |
709 | 722 | WHERE id_word in ({array_int:stop_words})', |
710 | 723 | array( |
711 | 724 | 'stop_words' => $stop_words, |
712 | 725 | ) |
713 | 726 | ); |
727 | + } |
|
714 | 728 | |
715 | 729 | $context['start'] += $index_properties[$context['index_settings']['bytes_per_word']]['step_size']; |
716 | 730 | if ($context['start'] > $index_properties[$context['index_settings']['bytes_per_word']]['max_size']) |
@@ -771,8 +785,9 @@ discard block |
||
771 | 785 | $searchAPI = new $search_class_name(); |
772 | 786 | |
773 | 787 | // No Support? NEXT! |
774 | - if (!$searchAPI->is_supported) |
|
775 | - continue; |
|
788 | + if (!$searchAPI->is_supported) { |
|
789 | + continue; |
|
790 | + } |
|
776 | 791 | |
777 | 792 | $apis[$index_name] = array( |
778 | 793 | 'filename' => $file, |
@@ -819,10 +834,10 @@ discard block |
||
819 | 834 | 'messages_ftx' => $db_prefix . 'messages_ftx', |
820 | 835 | ) |
821 | 836 | ); |
822 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
823 | - $context['fulltext_index'][] = $row['indexname']; |
|
824 | - } |
|
825 | - else |
|
837 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
838 | + $context['fulltext_index'][] = $row['indexname']; |
|
839 | + } |
|
840 | + } else |
|
826 | 841 | { |
827 | 842 | $request = $smcFunc['db_query']('', ' |
828 | 843 | SHOW INDEX |
@@ -833,17 +848,19 @@ discard block |
||
833 | 848 | $context['fulltext_index'] = ''; |
834 | 849 | if ($request !== false || $smcFunc['db_num_rows']($request) != 0) |
835 | 850 | { |
836 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
837 | - if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
851 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
852 | + if ($row['Column_name'] == 'body' && (isset($row['Index_type']) && $row['Index_type'] == 'FULLTEXT' || isset($row['Comment']) && $row['Comment'] == 'FULLTEXT')) |
|
838 | 853 | $context['fulltext_index'][] = $row['Key_name']; |
854 | + } |
|
839 | 855 | $smcFunc['db_free_result']($request); |
840 | 856 | |
841 | - if (is_array($context['fulltext_index'])) |
|
842 | - $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
857 | + if (is_array($context['fulltext_index'])) { |
|
858 | + $context['fulltext_index'] = array_unique($context['fulltext_index']); |
|
859 | + } |
|
843 | 860 | } |
844 | 861 | |
845 | - if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) |
|
846 | - $request = $smcFunc['db_query']('', ' |
|
862 | + if (preg_match('~^`(.+?)`\.(.+?)$~', $db_prefix, $match) !== 0) { |
|
863 | + $request = $smcFunc['db_query']('', ' |
|
847 | 864 | SHOW TABLE STATUS |
848 | 865 | FROM {string:database_name} |
849 | 866 | LIKE {string:table_name}', |
@@ -852,20 +869,22 @@ discard block |
||
852 | 869 | 'table_name' => str_replace('_', '\_', $match[2]) . 'messages', |
853 | 870 | ) |
854 | 871 | ); |
855 | - else |
|
856 | - $request = $smcFunc['db_query']('', ' |
|
872 | + } else { |
|
873 | + $request = $smcFunc['db_query']('', ' |
|
857 | 874 | SHOW TABLE STATUS |
858 | 875 | LIKE {string:table_name}', |
859 | 876 | array( |
860 | 877 | 'table_name' => str_replace('_', '\_', $db_prefix) . 'messages', |
861 | 878 | ) |
862 | 879 | ); |
880 | + } |
|
863 | 881 | |
864 | 882 | if ($request !== false) |
865 | 883 | { |
866 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
867 | - if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
884 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
885 | + if (isset($row['Engine']) && strtolower($row['Engine']) != 'myisam' && !(strtolower($row['Engine']) == 'innodb' && version_compare($smcFunc['db_get_version'], '5.6.4', '>='))) |
|
868 | 886 | $context['cannot_create_fulltext'] = true; |
887 | + } |
|
869 | 888 | $smcFunc['db_free_result']($request); |
870 | 889 | } |
871 | 890 | } |
@@ -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 | * Shows a listing of registered members. |
@@ -110,8 +111,9 @@ discard block |
||
110 | 111 | |
111 | 112 | $context['custom_profile_fields'] = getCustFieldsMList(); |
112 | 113 | |
113 | - if (!empty($context['custom_profile_fields']['columns'])) |
|
114 | - $context['columns'] += $context['custom_profile_fields']['columns']; |
|
114 | + if (!empty($context['custom_profile_fields']['columns'])) { |
|
115 | + $context['columns'] += $context['custom_profile_fields']['columns']; |
|
116 | + } |
|
115 | 117 | |
116 | 118 | $context['colspan'] = 0; |
117 | 119 | $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array(); |
@@ -147,12 +149,12 @@ discard block |
||
147 | 149 | call_integration_hook('integrate_memberlist_buttons'); |
148 | 150 | |
149 | 151 | // Jump to the sub action. |
150 | - if (isset($subActions[$context['listing_by']])) |
|
151 | - call_helper($subActions[$context['listing_by']][1]); |
|
152 | - |
|
153 | - else |
|
154 | - call_helper($subActions['all'][1]); |
|
155 | -} |
|
152 | + if (isset($subActions[$context['listing_by']])) { |
|
153 | + call_helper($subActions[$context['listing_by']][1]); |
|
154 | + } else { |
|
155 | + call_helper($subActions['all'][1]); |
|
156 | + } |
|
157 | + } |
|
156 | 158 | |
157 | 159 | /** |
158 | 160 | * List all members, page by page, with sorting. |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | if ($use_cache) |
178 | 180 | { |
179 | 181 | // Maybe there's something cached already. |
180 | - if (!empty($modSettings['memberlist_cache'])) |
|
181 | - $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
182 | + if (!empty($modSettings['memberlist_cache'])) { |
|
183 | + $memberlist_cache = smf_json_decode($modSettings['memberlist_cache'], true); |
|
184 | + } |
|
182 | 185 | |
183 | 186 | // The chunk size for the cached index. |
184 | 187 | $cache_step_size = 500; |
@@ -234,13 +237,15 @@ discard block |
||
234 | 237 | } |
235 | 238 | |
236 | 239 | // Set defaults for sort (real_name) and start. (0) |
237 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
238 | - $_REQUEST['sort'] = 'real_name'; |
|
240 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
241 | + $_REQUEST['sort'] = 'real_name'; |
|
242 | + } |
|
239 | 243 | |
240 | 244 | if (!is_numeric($_REQUEST['start'])) |
241 | 245 | { |
242 | - if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) |
|
243 | - fatal_error('Hacker?', false); |
|
246 | + if (preg_match('~^[^\'\\\\/]~' . ($context['utf8'] ? 'u' : ''), $smcFunc['strtolower']($_REQUEST['start']), $match) === 0) { |
|
247 | + fatal_error('Hacker?', false); |
|
248 | + } |
|
244 | 249 | |
245 | 250 | $_REQUEST['start'] = $match[0]; |
246 | 251 | |
@@ -259,16 +264,18 @@ discard block |
||
259 | 264 | } |
260 | 265 | |
261 | 266 | $context['letter_links'] = ''; |
262 | - for ($i = 97; $i < 123; $i++) |
|
263 | - $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
267 | + for ($i = 97; $i < 123; $i++) { |
|
268 | + $context['letter_links'] .= '<a href="' . $scripturl . '?action=mlist;sa=all;start=' . chr($i) . '#letter' . chr($i) . '">' . strtoupper(chr($i)) . '</a> '; |
|
269 | + } |
|
264 | 270 | |
265 | 271 | // Sort out the column information. |
266 | 272 | foreach ($context['columns'] as $col => $column_details) |
267 | 273 | { |
268 | 274 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sort=' . $col . ';start=0'; |
269 | 275 | |
270 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
271 | - $context['columns'][$col]['href'] .= ';desc'; |
|
276 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
277 | + $context['columns'][$col]['href'] .= ';desc'; |
|
278 | + } |
|
272 | 279 | |
273 | 280 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
274 | 281 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -317,8 +324,9 @@ discard block |
||
317 | 324 | elseif ($use_cache && $_REQUEST['sort'] === 'real_name') |
318 | 325 | { |
319 | 326 | $first_offset = floor(($memberlist_cache['num_members'] - $modSettings['defaultMaxMembers'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
320 | - if ($first_offset < 0) |
|
321 | - $first_offset = 0; |
|
327 | + if ($first_offset < 0) { |
|
328 | + $first_offset = 0; |
|
329 | + } |
|
322 | 330 | $second_offset = ceil(($memberlist_cache['num_members'] - $_REQUEST['start']) / $cache_step_size) * $cache_step_size; |
323 | 331 | |
324 | 332 | $where = 'mem.real_name BETWEEN {string:real_name_low} AND {string:real_name_high}'; |
@@ -395,12 +403,13 @@ discard block |
||
395 | 403 | ) |
396 | 404 | ); |
397 | 405 | $context['custom_search_fields'] = array(); |
398 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
399 | - $context['custom_search_fields'][$row['col_name']] = array( |
|
406 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
407 | + $context['custom_search_fields'][$row['col_name']] = array( |
|
400 | 408 | 'colname' => $row['col_name'], |
401 | 409 | 'name' => $row['field_name'], |
402 | 410 | 'desc' => $row['field_desc'], |
403 | 411 | ); |
412 | + } |
|
404 | 413 | $smcFunc['db_free_result']($request); |
405 | 414 | |
406 | 415 | // They're searching.. |
@@ -413,23 +422,27 @@ discard block |
||
413 | 422 | $context['old_search_value'] = urlencode($_REQUEST['search']); |
414 | 423 | |
415 | 424 | // No fields? Use default... |
416 | - if (empty($_POST['fields'])) |
|
417 | - $_POST['fields'] = array('name'); |
|
425 | + if (empty($_POST['fields'])) { |
|
426 | + $_POST['fields'] = array('name'); |
|
427 | + } |
|
418 | 428 | |
419 | 429 | // Set defaults for how the results are sorted |
420 | - if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) |
|
421 | - $_REQUEST['sort'] = 'real_name'; |
|
430 | + if (!isset($_REQUEST['sort']) || !isset($context['columns'][$_REQUEST['sort']])) { |
|
431 | + $_REQUEST['sort'] = 'real_name'; |
|
432 | + } |
|
422 | 433 | |
423 | 434 | // Build the column link / sort information. |
424 | 435 | foreach ($context['columns'] as $col => $column_details) |
425 | 436 | { |
426 | 437 | $context['columns'][$col]['href'] = $scripturl . '?action=mlist;sa=search;start=0;sort=' . $col; |
427 | 438 | |
428 | - if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) |
|
429 | - $context['columns'][$col]['href'] .= ';desc'; |
|
439 | + if ((!isset($_REQUEST['desc']) && $col == $_REQUEST['sort']) || ($col != $_REQUEST['sort'] && !empty($column_details['default_sort_rev']))) { |
|
440 | + $context['columns'][$col]['href'] .= ';desc'; |
|
441 | + } |
|
430 | 442 | |
431 | - if (isset($_POST['search']) && isset($_POST['fields'])) |
|
432 | - $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
443 | + if (isset($_POST['search']) && isset($_POST['fields'])) { |
|
444 | + $context['columns'][$col]['href'] .= ';search=' . $_POST['search'] . ';fields=' . implode(',', $_POST['fields']); |
|
445 | + } |
|
433 | 446 | |
434 | 447 | $context['columns'][$col]['link'] = '<a href="' . $context['columns'][$col]['href'] . '" rel="nofollow">' . $context['columns'][$col]['label'] . '</a>'; |
435 | 448 | $context['columns'][$col]['selected'] = $_REQUEST['sort'] == $col; |
@@ -452,8 +465,7 @@ discard block |
||
452 | 465 | { |
453 | 466 | $fields = allowedTo('moderate_forum') ? array('member_name', 'real_name') : array('real_name'); |
454 | 467 | $search_fields[] = 'name'; |
455 | - } |
|
456 | - else |
|
468 | + } else |
|
457 | 469 | { |
458 | 470 | $fields = array(); |
459 | 471 | $search_fields = array(); |
@@ -478,9 +490,10 @@ discard block |
||
478 | 490 | $search_fields[] = 'email'; |
479 | 491 | } |
480 | 492 | |
481 | - if ($smcFunc['db_case_sensitive']) |
|
482 | - foreach ($fields as $key => $field) |
|
493 | + if ($smcFunc['db_case_sensitive']) { |
|
494 | + foreach ($fields as $key => $field) |
|
483 | 495 | $fields[$key] = 'LOWER(' . $field . ')'; |
496 | + } |
|
484 | 497 | |
485 | 498 | $customJoin = array(); |
486 | 499 | $customCount = 10; |
@@ -499,8 +512,9 @@ discard block |
||
499 | 512 | } |
500 | 513 | |
501 | 514 | // No search fields? That means you're trying to hack things |
502 | - if (empty($search_fields)) |
|
503 | - fatal_lang_error('invalid_search_string', false); |
|
515 | + if (empty($search_fields)) { |
|
516 | + fatal_lang_error('invalid_search_string', false); |
|
517 | + } |
|
504 | 518 | |
505 | 519 | $query = $_POST['search'] == '' ? '= {string:blank_string}' : ($smcFunc['db_case_sensitive'] ? 'LIKE LOWER({string:search})' : 'LIKE {string:search}'); |
506 | 520 | |
@@ -538,8 +552,7 @@ discard block |
||
538 | 552 | ); |
539 | 553 | printMemberListRows($request); |
540 | 554 | $smcFunc['db_free_result']($request); |
541 | - } |
|
542 | - else |
|
555 | + } else |
|
543 | 556 | { |
544 | 557 | // These are all the possible fields. |
545 | 558 | $context['search_fields'] = array( |
@@ -554,14 +567,14 @@ discard block |
||
554 | 567 | { |
555 | 568 | unset($context['search_fields']['email']); |
556 | 569 | $context['search_defaults'] = array('name'); |
557 | - } |
|
558 | - else |
|
570 | + } else |
|
559 | 571 | { |
560 | 572 | $context['search_defaults'] = array('name', 'email'); |
561 | 573 | } |
562 | 574 | |
563 | - foreach ($context['custom_search_fields'] as $field) |
|
564 | - $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
575 | + foreach ($context['custom_search_fields'] as $field) { |
|
576 | + $context['search_fields']['cust_' . $field['colname']] = sprintf($txt['mlist_search_by'], $field['name']); |
|
577 | + } |
|
565 | 578 | |
566 | 579 | $context['sub_template'] = 'search'; |
567 | 580 | $context['old_search'] = isset($_GET['search']) ? $_GET['search'] : (isset($_POST['search']) ? $smcFunc['htmlspecialchars']($_POST['search']) : ''); |
@@ -603,12 +616,14 @@ discard block |
||
603 | 616 | $smcFunc['db_free_result']($result); |
604 | 617 | |
605 | 618 | // Avoid division by zero... |
606 | - if ($most_posts == 0) |
|
607 | - $most_posts = 1; |
|
619 | + if ($most_posts == 0) { |
|
620 | + $most_posts = 1; |
|
621 | + } |
|
608 | 622 | |
609 | 623 | $members = array(); |
610 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
611 | - $members[] = $row['id_member']; |
|
624 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
625 | + $members[] = $row['id_member']; |
|
626 | + } |
|
612 | 627 | |
613 | 628 | // Load all the members for display. |
614 | 629 | loadMemberData($members); |
@@ -616,8 +631,9 @@ discard block |
||
616 | 631 | $context['members'] = array(); |
617 | 632 | foreach ($members as $member) |
618 | 633 | { |
619 | - if (!loadMemberContext($member)) |
|
620 | - continue; |
|
634 | + if (!loadMemberContext($member)) { |
|
635 | + continue; |
|
636 | + } |
|
621 | 637 | |
622 | 638 | $context['members'][$member] = $memberContext[$member]; |
623 | 639 | $context['members'][$member]['post_percent'] = round(($context['members'][$member]['real_posts'] * 100) / $most_posts); |
@@ -634,20 +650,21 @@ discard block |
||
634 | 650 | continue; |
635 | 651 | } |
636 | 652 | |
637 | - if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) |
|
638 | - $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
639 | - |
|
640 | - elseif ($column['type'] == 'check') |
|
641 | - $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
653 | + if ($column['bbc'] && !empty($context['members'][$member]['options'][$key])) { |
|
654 | + $context['members'][$member]['options'][$key] = strip_tags(parse_bbc($context['members'][$member]['options'][$key])); |
|
655 | + } elseif ($column['type'] == 'check') { |
|
656 | + $context['members'][$member]['options'][$key] = $context['members'][$member]['options'][$key] == 0 ? $txt['no'] : $txt['yes']; |
|
657 | + } |
|
642 | 658 | |
643 | 659 | // Enclosing the user input within some other text? |
644 | - if (!empty($column['enclose'])) |
|
645 | - $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
660 | + if (!empty($column['enclose'])) { |
|
661 | + $context['members'][$member]['options'][$key] = strtr($column['enclose'], array( |
|
646 | 662 | '{SCRIPTURL}' => $scripturl, |
647 | 663 | '{IMAGES_URL}' => $settings['images_url'], |
648 | 664 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
649 | 665 | '{INPUT}' => $context['members'][$member]['options'][$key], |
650 | 666 | )); |
667 | + } |
|
651 | 668 | } |
652 | 669 | } |
653 | 670 | } |
@@ -688,17 +705,17 @@ discard block |
||
688 | 705 | ); |
689 | 706 | |
690 | 707 | // Get the right sort method depending on the cust field type. |
691 | - if ($row['field_type'] != 'check') |
|
692 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
708 | + if ($row['field_type'] != 'check') { |
|
709 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
693 | 710 | 'down' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 ASC, COALESCE(t' . $row['col_name'] . '.value, "") DESC', |
694 | 711 | 'up' => 'LENGTH(t' . $row['col_name'] . '.value) > 0 DESC, COALESCE(t' . $row['col_name'] . '.value, "") ASC' |
695 | 712 | ); |
696 | - |
|
697 | - else |
|
698 | - $cpf['columns'][$row['col_name']]['sort'] = array( |
|
713 | + } else { |
|
714 | + $cpf['columns'][$row['col_name']]['sort'] = array( |
|
699 | 715 | 'down' => 't' . $row['col_name'] . '.value DESC', |
700 | 716 | 'up' => 't' . $row['col_name'] . '.value ASC' |
701 | 717 | ); |
718 | + } |
|
702 | 719 | |
703 | 720 | $cpf['join'][$row['col_name']] = 'LEFT JOIN {db_prefix}themes AS t' . $row['col_name'] . ' ON (t' . $row['col_name'] . '.variable = {literal:' . $row['col_name'] . '} AND t' . $row['col_name'] . '.id_theme = 1 AND t' . $row['col_name'] . '.id_member = mem.id_member)'; |
704 | 721 | } |
@@ -12,8 +12,9 @@ discard block |
||
12 | 12 | * @version 2.1 Beta 3 |
13 | 13 | */ |
14 | 14 | |
15 | -if (!defined('SMF')) |
|
15 | +if (!defined('SMF')) { |
|
16 | 16 | die('No direct access...'); |
17 | +} |
|
17 | 18 | |
18 | 19 | /** |
19 | 20 | * Report a post or profile to the moderator... ask for a comment. |
@@ -35,10 +36,11 @@ discard block |
||
35 | 36 | |
36 | 37 | // You can't use this if it's off or you are not allowed to do it. |
37 | 38 | // If we don't have the ID of something to report, we'll die with a no_access error below |
38 | - if (isset($_REQUEST['msg'])) |
|
39 | - isAllowedTo('report_any'); |
|
40 | - elseif (isset($_REQUEST['u'])) |
|
41 | - isAllowedTo('report_user'); |
|
39 | + if (isset($_REQUEST['msg'])) { |
|
40 | + isAllowedTo('report_any'); |
|
41 | + } elseif (isset($_REQUEST['u'])) { |
|
42 | + isAllowedTo('report_user'); |
|
43 | + } |
|
42 | 44 | |
43 | 45 | // Previewing or modifying? |
44 | 46 | if (isset($_POST['preview']) && !isset($_POST['save'])) |
@@ -56,19 +58,23 @@ discard block |
||
56 | 58 | } |
57 | 59 | |
58 | 60 | // If they're posting, it should be processed by ReportToModerator2. |
59 | - if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) |
|
60 | - ReportToModerator2(); |
|
61 | + if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']) && !isset($_POST['preview'])) { |
|
62 | + ReportToModerator2(); |
|
63 | + } |
|
61 | 64 | |
62 | 65 | // We need a message ID or user ID to check! |
63 | - if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) |
|
64 | - fatal_lang_error('no_access', false); |
|
66 | + if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']) && empty($_REQUEST['u'])) { |
|
67 | + fatal_lang_error('no_access', false); |
|
68 | + } |
|
65 | 69 | |
66 | 70 | // For compatibility, accept mid, but we should be using msg. (not the flavor kind!) |
67 | - if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) |
|
68 | - $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
71 | + if (!empty($_REQUEST['msg']) || !empty($_REQUEST['mid'])) { |
|
72 | + $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg']; |
|
73 | + } |
|
69 | 74 | // msg and mid empty - assume we're reporting a user |
70 | - elseif (!empty($_REQUEST['u'])) |
|
71 | - $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
75 | + elseif (!empty($_REQUEST['u'])) { |
|
76 | + $_REQUEST['u'] = (int) $_REQUEST['u']; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | // Set up some form values |
74 | 80 | $context['report_type'] = isset($_REQUEST['msg']) ? 'msg' : 'u'; |
@@ -89,8 +95,9 @@ discard block |
||
89 | 95 | 'id_msg' => $_REQUEST['msg'], |
90 | 96 | ) |
91 | 97 | ); |
92 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
93 | - fatal_lang_error('no_board', false); |
|
98 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
99 | + fatal_lang_error('no_board', false); |
|
100 | + } |
|
94 | 101 | list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result); |
95 | 102 | $smcFunc['db_free_result']($result); |
96 | 103 | |
@@ -101,8 +108,7 @@ discard block |
||
101 | 108 | |
102 | 109 | // The submit URL is different for users than it is for posts |
103 | 110 | $context['submit_url'] = $scripturl . '?action=reporttm;msg=' . $_REQUEST['msg'] . ';topic=' . $topic; |
104 | - } |
|
105 | - else |
|
111 | + } else |
|
106 | 112 | { |
107 | 113 | // Check the user's ID |
108 | 114 | $result = $smcFunc['db_query']('', ' |
@@ -114,8 +120,9 @@ discard block |
||
114 | 120 | ) |
115 | 121 | ); |
116 | 122 | |
117 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
118 | - fatal_lang_error('no_user', false); |
|
123 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
124 | + fatal_lang_error('no_user', false); |
|
125 | + } |
|
119 | 126 | list($_REQUEST['u'], $display_name, $username) = $smcFunc['db_fetch_row']($result); |
120 | 127 | |
121 | 128 | $context['current_user'] = $_REQUEST['u']; |
@@ -170,10 +177,11 @@ discard block |
||
170 | 177 | is_not_guest(); |
171 | 178 | |
172 | 179 | // You must have the proper permissions! |
173 | - if (isset($_REQUEST['msg'])) |
|
174 | - isAllowedTo('report_any'); |
|
175 | - else |
|
176 | - isAllowedTo('report_user'); |
|
180 | + if (isset($_REQUEST['msg'])) { |
|
181 | + isAllowedTo('report_any'); |
|
182 | + } else { |
|
183 | + isAllowedTo('report_user'); |
|
184 | + } |
|
177 | 185 | |
178 | 186 | // Make sure they aren't spamming. |
179 | 187 | spamProtection('reporttm'); |
@@ -187,17 +195,20 @@ discard block |
||
187 | 195 | $post_errors = array(); |
188 | 196 | |
189 | 197 | // Check their session. |
190 | - if (checkSession('post', '', false) != '') |
|
191 | - $post_errors[] = 'session_timeout'; |
|
198 | + if (checkSession('post', '', false) != '') { |
|
199 | + $post_errors[] = 'session_timeout'; |
|
200 | + } |
|
192 | 201 | |
193 | 202 | // Make sure we have a comment and it's clean. |
194 | - if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') |
|
195 | - $post_errors[] = 'no_comment'; |
|
203 | + if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '') { |
|
204 | + $post_errors[] = 'no_comment'; |
|
205 | + } |
|
196 | 206 | |
197 | 207 | $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => '')); |
198 | 208 | |
199 | - if ($smcFunc['strlen']($poster_comment) > 254) |
|
200 | - $post_errors[] = 'post_too_long'; |
|
209 | + if ($smcFunc['strlen']($poster_comment) > 254) { |
|
210 | + $post_errors[] = 'post_too_long'; |
|
211 | + } |
|
201 | 212 | |
202 | 213 | // Any errors? |
203 | 214 | if (!empty($post_errors)) |
@@ -205,8 +216,9 @@ discard block |
||
205 | 216 | loadLanguage('Errors'); |
206 | 217 | |
207 | 218 | $context['post_errors'] = array(); |
208 | - foreach ($post_errors as $post_error) |
|
209 | - $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
219 | + foreach ($post_errors as $post_error) { |
|
220 | + $context['post_errors'][$post_error] = $txt['error_' . $post_error]; |
|
221 | + } |
|
210 | 222 | |
211 | 223 | return ReportToModerator(); |
212 | 224 | } |
@@ -215,8 +227,7 @@ discard block |
||
215 | 227 | { |
216 | 228 | // Handle this elsewhere to keep things from getting too long |
217 | 229 | reportPost($_POST['msg'], $poster_comment); |
218 | - } |
|
219 | - else |
|
230 | + } else |
|
220 | 231 | { |
221 | 232 | reportUser($_POST['u'], $poster_comment); |
222 | 233 | } |
@@ -247,8 +258,9 @@ discard block |
||
247 | 258 | 'id_msg' => $_POST['msg'], |
248 | 259 | ) |
249 | 260 | ); |
250 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
251 | - fatal_lang_error('no_board', false); |
|
261 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
262 | + fatal_lang_error('no_board', false); |
|
263 | + } |
|
252 | 264 | $message = $smcFunc['db_fetch_assoc']($request); |
253 | 265 | $smcFunc['db_free_result']($request); |
254 | 266 | |
@@ -264,18 +276,20 @@ discard block |
||
264 | 276 | 'ignored' => 1, |
265 | 277 | ) |
266 | 278 | ); |
267 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
268 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
279 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
280 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
281 | + } |
|
269 | 282 | |
270 | 283 | $smcFunc['db_free_result']($request); |
271 | 284 | |
272 | 285 | // If we're just going to ignore these, then who gives a monkeys... |
273 | - if (!empty($ignore)) |
|
274 | - redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
286 | + if (!empty($ignore)) { |
|
287 | + redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']); |
|
288 | + } |
|
275 | 289 | |
276 | 290 | // Already reported? My god, we could be dealing with a real rogue here... |
277 | - if (!empty($id_report)) |
|
278 | - $smcFunc['db_query']('', ' |
|
291 | + if (!empty($id_report)) { |
|
292 | + $smcFunc['db_query']('', ' |
|
279 | 293 | UPDATE {db_prefix}log_reported |
280 | 294 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
281 | 295 | WHERE id_report = {int:id_report}', |
@@ -284,11 +298,13 @@ discard block |
||
284 | 298 | 'id_report' => $id_report, |
285 | 299 | ) |
286 | 300 | ); |
301 | + } |
|
287 | 302 | // Otherwise, we shall make one! |
288 | 303 | else |
289 | 304 | { |
290 | - if (empty($message['real_name'])) |
|
291 | - $message['real_name'] = $message['poster_name']; |
|
305 | + if (empty($message['real_name'])) { |
|
306 | + $message['real_name'] = $message['poster_name']; |
|
307 | + } |
|
292 | 308 | |
293 | 309 | $id_report = $smcFunc['db_insert']('', |
294 | 310 | '{db_prefix}log_reported', |
@@ -367,8 +383,9 @@ discard block |
||
367 | 383 | 'id_member' => $_POST['u'] |
368 | 384 | ) |
369 | 385 | ); |
370 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
371 | - fatal_lang_error('no_user', false); |
|
386 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
387 | + fatal_lang_error('no_user', false); |
|
388 | + } |
|
372 | 389 | $user = $smcFunc['db_fetch_assoc']($request); |
373 | 390 | $smcFunc['db_free_result']($request); |
374 | 391 | |
@@ -388,18 +405,20 @@ discard block |
||
388 | 405 | 'ignored' => 1, |
389 | 406 | ) |
390 | 407 | ); |
391 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
392 | - list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
408 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
409 | + list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request); |
|
410 | + } |
|
393 | 411 | |
394 | 412 | $smcFunc['db_free_result']($request); |
395 | 413 | |
396 | 414 | // If we're just going to ignore these, then who gives a monkeys... |
397 | - if (!empty($ignore)) |
|
398 | - redirectexit('action=profile;u=' . $_POST['u']); |
|
415 | + if (!empty($ignore)) { |
|
416 | + redirectexit('action=profile;u=' . $_POST['u']); |
|
417 | + } |
|
399 | 418 | |
400 | 419 | // Already reported? My god, we could be dealing with a real rogue here... |
401 | - if (!empty($id_report)) |
|
402 | - $smcFunc['db_query']('', ' |
|
420 | + if (!empty($id_report)) { |
|
421 | + $smcFunc['db_query']('', ' |
|
403 | 422 | UPDATE {db_prefix}log_reported |
404 | 423 | SET num_reports = num_reports + 1, time_updated = {int:current_time} |
405 | 424 | WHERE id_report = {int:id_report}', |
@@ -408,6 +427,7 @@ discard block |
||
408 | 427 | 'id_report' => $id_report, |
409 | 428 | ) |
410 | 429 | ); |
430 | + } |
|
411 | 431 | // Otherwise, we shall make one! |
412 | 432 | else |
413 | 433 | { |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -1,9 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Try to handle it with the upper level index.php. (it should know what to do.) |
4 | -if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) |
|
4 | +if (file_exists(dirname(dirname(__FILE__)) . '/index.php')) { |
|
5 | 5 | include (dirname(dirname(__FILE__)) . '/index.php'); |
6 | -else |
|
6 | +} else { |
|
7 | 7 | exit; |
8 | +} |
|
8 | 9 | |
9 | 10 | ?> |
10 | 11 | \ No newline at end of file |
@@ -15,8 +15,9 @@ discard block |
||
15 | 15 | * Original module by Mach8 - We'll never forget you. |
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 | * splits a topic into two topics. |
@@ -30,15 +31,17 @@ discard block |
||
30 | 31 | global $topic, $sourcedir; |
31 | 32 | |
32 | 33 | // And... which topic were you splitting, again? |
33 | - if (empty($topic)) |
|
34 | - fatal_lang_error('numbers_one_to_nine', false); |
|
34 | + if (empty($topic)) { |
|
35 | + fatal_lang_error('numbers_one_to_nine', false); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // Are you allowed to split topics? |
37 | 39 | isAllowedTo('split_any'); |
38 | 40 | |
39 | 41 | // Load up the "dependencies" - the template, getMsgMemberID(), and sendNotifications(). |
40 | - if (!isset($_REQUEST['xml'])) |
|
41 | - loadTemplate('SplitTopics'); |
|
42 | + if (!isset($_REQUEST['xml'])) { |
|
43 | + loadTemplate('SplitTopics'); |
|
44 | + } |
|
42 | 45 | require_once($sourcedir . '/Subs-Boards.php'); |
43 | 46 | require_once($sourcedir . '/Subs-Post.php'); |
44 | 47 | |
@@ -50,12 +53,12 @@ discard block |
||
50 | 53 | ); |
51 | 54 | |
52 | 55 | // ?action=splittopics;sa=LETSBREAKIT won't work, sorry. |
53 | - if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) |
|
54 | - SplitIndex(); |
|
55 | - |
|
56 | - else |
|
57 | - call_helper($subActions[$_REQUEST['sa']]); |
|
58 | -} |
|
56 | + if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) { |
|
57 | + SplitIndex(); |
|
58 | + } else { |
|
59 | + call_helper($subActions[$_REQUEST['sa']]); |
|
60 | + } |
|
61 | + } |
|
59 | 62 | |
60 | 63 | /** |
61 | 64 | * screen shown before the actual split. |
@@ -71,8 +74,9 @@ discard block |
||
71 | 74 | global $txt, $topic, $context, $smcFunc, $modSettings; |
72 | 75 | |
73 | 76 | // Validate "at". |
74 | - if (empty($_GET['at'])) |
|
75 | - fatal_lang_error('numbers_one_to_nine', false); |
|
77 | + if (empty($_GET['at'])) { |
|
78 | + fatal_lang_error('numbers_one_to_nine', false); |
|
79 | + } |
|
76 | 80 | $_GET['at'] = (int) $_GET['at']; |
77 | 81 | |
78 | 82 | // Retrieve the subject and stuff of the specific topic/message. |
@@ -89,26 +93,31 @@ discard block |
||
89 | 93 | 'split_at' => $_GET['at'], |
90 | 94 | ) |
91 | 95 | ); |
92 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
93 | - fatal_lang_error('cant_find_messages'); |
|
96 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
97 | + fatal_lang_error('cant_find_messages'); |
|
98 | + } |
|
94 | 99 | list ($_REQUEST['subname'], $num_replies, $unapproved_posts, $id_first_msg, $approved) = $smcFunc['db_fetch_row']($request); |
95 | 100 | $smcFunc['db_free_result']($request); |
96 | 101 | |
97 | 102 | // If not approved validate they can see it. |
98 | - if ($modSettings['postmod_active'] && !$approved) |
|
99 | - isAllowedTo('approve_posts'); |
|
103 | + if ($modSettings['postmod_active'] && !$approved) { |
|
104 | + isAllowedTo('approve_posts'); |
|
105 | + } |
|
100 | 106 | |
101 | 107 | // If this topic has unapproved posts, we need to count them too... |
102 | - if ($modSettings['postmod_active'] && allowedTo('approve_posts')) |
|
103 | - $num_replies += $unapproved_posts - ($approved ? 0 : 1); |
|
108 | + if ($modSettings['postmod_active'] && allowedTo('approve_posts')) { |
|
109 | + $num_replies += $unapproved_posts - ($approved ? 0 : 1); |
|
110 | + } |
|
104 | 111 | |
105 | 112 | // Check if there is more than one message in the topic. (there should be.) |
106 | - if ($num_replies < 1) |
|
107 | - fatal_lang_error('topic_one_post', false); |
|
113 | + if ($num_replies < 1) { |
|
114 | + fatal_lang_error('topic_one_post', false); |
|
115 | + } |
|
108 | 116 | |
109 | 117 | // Check if this is the first message in the topic (if so, the first and second option won't be available) |
110 | - if ($id_first_msg == $_GET['at']) |
|
111 | - return SplitSelectTopics(); |
|
118 | + if ($id_first_msg == $_GET['at']) { |
|
119 | + return SplitSelectTopics(); |
|
120 | + } |
|
112 | 121 | |
113 | 122 | // Basic template information.... |
114 | 123 | $context['message'] = array( |
@@ -137,8 +146,9 @@ discard block |
||
137 | 146 | checkSession(); |
138 | 147 | |
139 | 148 | // Clean up the subject. |
140 | - if (!isset($_POST['subname']) || $_POST['subname'] == '') |
|
141 | - $_POST['subname'] = $txt['new_topic']; |
|
149 | + if (!isset($_POST['subname']) || $_POST['subname'] == '') { |
|
150 | + $_POST['subname'] = $txt['new_topic']; |
|
151 | + } |
|
142 | 152 | |
143 | 153 | // Redirect to the selector if they chose selective. |
144 | 154 | if ($_POST['step2'] == 'selective') |
@@ -163,16 +173,19 @@ discard block |
||
163 | 173 | 'split_at' => $_POST['at'], |
164 | 174 | ) |
165 | 175 | ); |
166 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
167 | - $messagesToBeSplit[] = $row['id_msg']; |
|
176 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
177 | + $messagesToBeSplit[] = $row['id_msg']; |
|
178 | + } |
|
168 | 179 | $smcFunc['db_free_result']($request); |
169 | 180 | } |
170 | 181 | // Only the selected message has to be split. That should be easy. |
171 | - elseif ($_POST['step2'] == 'onlythis') |
|
172 | - $messagesToBeSplit[] = $_POST['at']; |
|
182 | + elseif ($_POST['step2'] == 'onlythis') { |
|
183 | + $messagesToBeSplit[] = $_POST['at']; |
|
184 | + } |
|
173 | 185 | // There's another action?! |
174 | - else |
|
175 | - fatal_lang_error('no_access', false); |
|
186 | + else { |
|
187 | + fatal_lang_error('no_access', false); |
|
188 | + } |
|
176 | 189 | |
177 | 190 | $context['old_topic'] = $topic; |
178 | 191 | $context['new_topic'] = splitTopic($topic, $messagesToBeSplit, $_POST['subname']); |
@@ -199,8 +212,9 @@ discard block |
||
199 | 212 | $_SESSION['split_selection'][$topic] = empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic]; |
200 | 213 | |
201 | 214 | // This is a special case for split topics from quick-moderation checkboxes |
202 | - if (isset($_REQUEST['subname_enc'])) |
|
203 | - $_REQUEST['subname'] = urldecode($_REQUEST['subname_enc']); |
|
215 | + if (isset($_REQUEST['subname_enc'])) { |
|
216 | + $_REQUEST['subname'] = urldecode($_REQUEST['subname_enc']); |
|
217 | + } |
|
204 | 218 | |
205 | 219 | $context['not_selected'] = array( |
206 | 220 | 'num_messages' => 0, |
@@ -252,10 +266,12 @@ discard block |
||
252 | 266 | ) |
253 | 267 | ); |
254 | 268 | // You can't split the last message off. |
255 | - if (empty($context['not_selected']['start']) && $smcFunc['db_num_rows']($request) <= 1 && $_REQUEST['move'] == 'down') |
|
256 | - $_REQUEST['move'] = ''; |
|
257 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
258 | - $original_msgs['not_selected'][] = $row['id_msg']; |
|
269 | + if (empty($context['not_selected']['start']) && $smcFunc['db_num_rows']($request) <= 1 && $_REQUEST['move'] == 'down') { |
|
270 | + $_REQUEST['move'] = ''; |
|
271 | + } |
|
272 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
273 | + $original_msgs['not_selected'][] = $row['id_msg']; |
|
274 | + } |
|
259 | 275 | $smcFunc['db_free_result']($request); |
260 | 276 | if (!empty($_SESSION['split_selection'][$topic])) |
261 | 277 | { |
@@ -275,8 +291,9 @@ discard block |
||
275 | 291 | 'messages_per_page' => $context['messages_per_page'], |
276 | 292 | ) |
277 | 293 | ); |
278 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
279 | - $original_msgs['selected'][] = $row['id_msg']; |
|
294 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
295 | + $original_msgs['selected'][] = $row['id_msg']; |
|
296 | + } |
|
280 | 297 | $smcFunc['db_free_result']($request); |
281 | 298 | } |
282 | 299 | } |
@@ -286,12 +303,13 @@ discard block |
||
286 | 303 | { |
287 | 304 | $_REQUEST['msg'] = (int) $_REQUEST['msg']; |
288 | 305 | |
289 | - if ($_REQUEST['move'] == 'reset') |
|
290 | - $_SESSION['split_selection'][$topic] = array(); |
|
291 | - elseif ($_REQUEST['move'] == 'up') |
|
292 | - $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg'])); |
|
293 | - else |
|
294 | - $_SESSION['split_selection'][$topic][] = $_REQUEST['msg']; |
|
306 | + if ($_REQUEST['move'] == 'reset') { |
|
307 | + $_SESSION['split_selection'][$topic] = array(); |
|
308 | + } elseif ($_REQUEST['move'] == 'up') { |
|
309 | + $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg'])); |
|
310 | + } else { |
|
311 | + $_SESSION['split_selection'][$topic][] = $_REQUEST['msg']; |
|
312 | + } |
|
295 | 313 | } |
296 | 314 | |
297 | 315 | // Make sure the selection is still accurate. |
@@ -310,8 +328,9 @@ discard block |
||
310 | 328 | ) |
311 | 329 | ); |
312 | 330 | $_SESSION['split_selection'][$topic] = array(); |
313 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
314 | - $_SESSION['split_selection'][$topic][] = $row['id_msg']; |
|
331 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
332 | + $_SESSION['split_selection'][$topic][] = $row['id_msg']; |
|
333 | + } |
|
315 | 334 | $smcFunc['db_free_result']($request); |
316 | 335 | } |
317 | 336 | |
@@ -328,13 +347,15 @@ discard block |
||
328 | 347 | 'is_approved' => 1, |
329 | 348 | ) |
330 | 349 | ); |
331 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
332 | - $context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = $row['num_messages']; |
|
350 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
351 | + $context[empty($row['is_selected']) || $row['is_selected'] == 'f' ? 'not_selected' : 'selected']['num_messages'] = $row['num_messages']; |
|
352 | + } |
|
333 | 353 | $smcFunc['db_free_result']($request); |
334 | 354 | |
335 | 355 | // Fix an oversized starting page (to make sure both pageindexes are properly set). |
336 | - if ($context['selected']['start'] >= $context['selected']['num_messages']) |
|
337 | - $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : ($context['selected']['num_messages'] - (($context['selected']['num_messages'] % $context['messages_per_page']) == 0 ? $context['messages_per_page'] : ($context['selected']['num_messages'] % $context['messages_per_page']))); |
|
356 | + if ($context['selected']['start'] >= $context['selected']['num_messages']) { |
|
357 | + $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : ($context['selected']['num_messages'] - (($context['selected']['num_messages'] % $context['messages_per_page']) == 0 ? $context['messages_per_page'] : ($context['selected']['num_messages'] % $context['messages_per_page']))); |
|
358 | + } |
|
338 | 359 | |
339 | 360 | // Build a page list of the not-selected topics... |
340 | 361 | $context['not_selected']['page_index'] = constructPageIndex($scripturl . '?action=splittopics;sa=selectTopics;subname=' . strtr(urlencode($_REQUEST['subname']), array('%' => '%%')) . ';topic=' . $topic . '.%1$d;start2=' . $context['selected']['start'], $context['not_selected']['start'], $context['not_selected']['num_messages'], $context['messages_per_page'], true); |
@@ -434,11 +455,12 @@ discard block |
||
434 | 455 | ); |
435 | 456 | |
436 | 457 | $context['changes'] = array(); |
437 | - foreach ($changes as $change_type => $change_array) |
|
438 | - foreach ($change_array as $section => $msg_array) |
|
458 | + foreach ($changes as $change_type => $change_array) { |
|
459 | + foreach ($change_array as $section => $msg_array) |
|
439 | 460 | { |
440 | 461 | if (empty($msg_array)) |
441 | 462 | continue; |
463 | + } |
|
442 | 464 | |
443 | 465 | foreach ($msg_array as $id_msg) |
444 | 466 | { |
@@ -447,8 +469,9 @@ discard block |
||
447 | 469 | 'type' => $change_type, |
448 | 470 | 'section' => $section, |
449 | 471 | ); |
450 | - if ($change_type == 'insert') |
|
451 | - $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg]; |
|
472 | + if ($change_type == 'insert') { |
|
473 | + $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg]; |
|
474 | + } |
|
452 | 475 | } |
453 | 476 | } |
454 | 477 | } |
@@ -468,12 +491,14 @@ discard block |
||
468 | 491 | checkSession(); |
469 | 492 | |
470 | 493 | // Default the subject in case it's blank. |
471 | - if (!isset($_POST['subname']) || $_POST['subname'] == '') |
|
472 | - $_POST['subname'] = $txt['new_topic']; |
|
494 | + if (!isset($_POST['subname']) || $_POST['subname'] == '') { |
|
495 | + $_POST['subname'] = $txt['new_topic']; |
|
496 | + } |
|
473 | 497 | |
474 | 498 | // You must've selected some messages! Can't split out none! |
475 | - if (empty($_SESSION['split_selection'][$topic])) |
|
476 | - fatal_lang_error('no_posts_selected', false); |
|
499 | + if (empty($_SESSION['split_selection'][$topic])) { |
|
500 | + fatal_lang_error('no_posts_selected', false); |
|
501 | + } |
|
477 | 502 | |
478 | 503 | $context['old_topic'] = $topic; |
479 | 504 | $context['new_topic'] = splitTopic($topic, $_SESSION['split_selection'][$topic], $_POST['subname']); |
@@ -499,8 +524,9 @@ discard block |
||
499 | 524 | global $smcFunc, $txt, $sourcedir; |
500 | 525 | |
501 | 526 | // Nothing to split? |
502 | - if (empty($splitMessages)) |
|
503 | - fatal_lang_error('no_posts_selected', false); |
|
527 | + if (empty($splitMessages)) { |
|
528 | + fatal_lang_error('no_posts_selected', false); |
|
529 | + } |
|
504 | 530 | |
505 | 531 | // Get some board info. |
506 | 532 | $request = $smcFunc['db_query']('', ' |
@@ -532,8 +558,9 @@ discard block |
||
532 | 558 | ) |
533 | 559 | ); |
534 | 560 | // You can't select ALL the messages! |
535 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
536 | - fatal_lang_error('selected_all_posts', false); |
|
561 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
562 | + fatal_lang_error('selected_all_posts', false); |
|
563 | + } |
|
537 | 564 | |
538 | 565 | $split1_first_msg = null; |
539 | 566 | $split1_last_msg = null; |
@@ -541,24 +568,27 @@ discard block |
||
541 | 568 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
542 | 569 | { |
543 | 570 | // Get the right first and last message dependant on approved state... |
544 | - if (empty($split1_first_msg) || $row['myid_first_msg'] < $split1_first_msg) |
|
545 | - $split1_first_msg = $row['myid_first_msg']; |
|
546 | - if (empty($split1_last_msg) || $row['approved']) |
|
547 | - $split1_last_msg = $row['myid_last_msg']; |
|
571 | + if (empty($split1_first_msg) || $row['myid_first_msg'] < $split1_first_msg) { |
|
572 | + $split1_first_msg = $row['myid_first_msg']; |
|
573 | + } |
|
574 | + if (empty($split1_last_msg) || $row['approved']) { |
|
575 | + $split1_last_msg = $row['myid_last_msg']; |
|
576 | + } |
|
548 | 577 | |
549 | 578 | // Get the counts correct... |
550 | 579 | if ($row['approved']) |
551 | 580 | { |
552 | 581 | $split1_replies = $row['message_count'] - 1; |
553 | 582 | $split1_unapprovedposts = 0; |
554 | - } |
|
555 | - else |
|
583 | + } else |
|
556 | 584 | { |
557 | - if (!isset($split1_replies)) |
|
558 | - $split1_replies = 0; |
|
585 | + if (!isset($split1_replies)) { |
|
586 | + $split1_replies = 0; |
|
587 | + } |
|
559 | 588 | // If the topic isn't approved then num replies must go up by one... as first post wouldn't be counted. |
560 | - elseif (!$split1_approved) |
|
561 | - $split1_replies++; |
|
589 | + elseif (!$split1_approved) { |
|
590 | + $split1_replies++; |
|
591 | + } |
|
562 | 592 | |
563 | 593 | $split1_unapprovedposts = $row['message_count']; |
564 | 594 | } |
@@ -584,10 +614,12 @@ discard block |
||
584 | 614 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
585 | 615 | { |
586 | 616 | // As before get the right first and last message dependant on approved state... |
587 | - if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) |
|
588 | - $split2_first_msg = $row['myid_first_msg']; |
|
589 | - if (empty($split2_last_msg) || $row['approved']) |
|
590 | - $split2_last_msg = $row['myid_last_msg']; |
|
617 | + if (empty($split2_first_msg) || $row['myid_first_msg'] < $split2_first_msg) { |
|
618 | + $split2_first_msg = $row['myid_first_msg']; |
|
619 | + } |
|
620 | + if (empty($split2_last_msg) || $row['approved']) { |
|
621 | + $split2_last_msg = $row['myid_last_msg']; |
|
622 | + } |
|
591 | 623 | |
592 | 624 | // Then do the counts again... |
593 | 625 | if ($row['approved']) |
@@ -595,18 +627,20 @@ discard block |
||
595 | 627 | $split2_approved = true; |
596 | 628 | $split2_replies = $row['message_count'] - 1; |
597 | 629 | $split2_unapprovedposts = 0; |
598 | - } |
|
599 | - else |
|
630 | + } else |
|
600 | 631 | { |
601 | 632 | // Should this one be approved?? |
602 | - if ($split2_first_msg == $row['myid_first_msg']) |
|
603 | - $split2_approved = false; |
|
633 | + if ($split2_first_msg == $row['myid_first_msg']) { |
|
634 | + $split2_approved = false; |
|
635 | + } |
|
604 | 636 | |
605 | - if (!isset($split2_replies)) |
|
606 | - $split2_replies = 0; |
|
637 | + if (!isset($split2_replies)) { |
|
638 | + $split2_replies = 0; |
|
639 | + } |
|
607 | 640 | // As before, fix number of replies. |
608 | - elseif (!$split2_approved) |
|
609 | - $split2_replies++; |
|
641 | + elseif (!$split2_approved) { |
|
642 | + $split2_replies++; |
|
643 | + } |
|
610 | 644 | |
611 | 645 | $split2_unapprovedposts = $row['message_count']; |
612 | 646 | } |
@@ -616,12 +650,14 @@ discard block |
||
616 | 650 | $split2_lastMem = getMsgMemberID($split2_last_msg); |
617 | 651 | |
618 | 652 | // No database changes yet, so let's double check to see if everything makes at least a little sense. |
619 | - if ($split1_first_msg <= 0 || $split1_last_msg <= 0 || $split2_first_msg <= 0 || $split2_last_msg <= 0 || $split1_replies < 0 || $split2_replies < 0 || $split1_unapprovedposts < 0 || $split2_unapprovedposts < 0 || !isset($split1_approved) || !isset($split2_approved)) |
|
620 | - fatal_lang_error('cant_find_messages'); |
|
653 | + if ($split1_first_msg <= 0 || $split1_last_msg <= 0 || $split2_first_msg <= 0 || $split2_last_msg <= 0 || $split1_replies < 0 || $split2_replies < 0 || $split1_unapprovedposts < 0 || $split2_unapprovedposts < 0 || !isset($split1_approved) || !isset($split2_approved)) { |
|
654 | + fatal_lang_error('cant_find_messages'); |
|
655 | + } |
|
621 | 656 | |
622 | 657 | // You cannot split off the first message of a topic. |
623 | - if ($split1_first_msg > $split2_first_msg) |
|
624 | - fatal_lang_error('split_first_post', false); |
|
658 | + if ($split1_first_msg > $split2_first_msg) { |
|
659 | + fatal_lang_error('split_first_post', false); |
|
660 | + } |
|
625 | 661 | |
626 | 662 | // We're off to insert the new topic! Use 0 for now to avoid UNIQUE errors. |
627 | 663 | $split2_ID_TOPIC = $smcFunc['db_insert']('', |
@@ -644,14 +680,16 @@ discard block |
||
644 | 680 | array('id_topic'), |
645 | 681 | 1 |
646 | 682 | ); |
647 | - if ($split2_ID_TOPIC <= 0) |
|
648 | - fatal_lang_error('cant_insert_topic'); |
|
683 | + if ($split2_ID_TOPIC <= 0) { |
|
684 | + fatal_lang_error('cant_insert_topic'); |
|
685 | + } |
|
649 | 686 | |
650 | 687 | // Move the messages over to the other topic. |
651 | 688 | $new_subject = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($new_subject)), array("\r" => '', "\n" => '', "\t" => '')); |
652 | 689 | // Check the subject length. |
653 | - if ($smcFunc['strlen']($new_subject) > 100) |
|
654 | - $new_subject = $smcFunc['substr']($new_subject, 0, 100); |
|
690 | + if ($smcFunc['strlen']($new_subject) > 100) { |
|
691 | + $new_subject = $smcFunc['substr']($new_subject, 0, 100); |
|
692 | + } |
|
655 | 693 | // Valid subject? |
656 | 694 | if ($new_subject != '') |
657 | 695 | { |
@@ -722,8 +760,8 @@ discard block |
||
722 | 760 | ); |
723 | 761 | |
724 | 762 | // If the new topic isn't approved ensure the first message flags this just in case. |
725 | - if (!$split2_approved) |
|
726 | - $smcFunc['db_query']('', ' |
|
763 | + if (!$split2_approved) { |
|
764 | + $smcFunc['db_query']('', ' |
|
727 | 765 | UPDATE {db_prefix}messages |
728 | 766 | SET approved = {int:approved} |
729 | 767 | WHERE id_msg = {int:id_msg} |
@@ -734,6 +772,7 @@ discard block |
||
734 | 772 | 'id_topic' => $split2_ID_TOPIC, |
735 | 773 | ) |
736 | 774 | ); |
775 | + } |
|
737 | 776 | |
738 | 777 | // The board has more topics now (Or more unapproved ones!). |
739 | 778 | $smcFunc['db_query']('', ' |
@@ -760,8 +799,9 @@ discard block |
||
760 | 799 | if ($smcFunc['db_num_rows']($request) > 0) |
761 | 800 | { |
762 | 801 | $replaceEntries = array(); |
763 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
764 | - $replaceEntries[] = array($row['id_member'], $split2_ID_TOPIC, $row['id_msg'], $row['unwatched']); |
|
802 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
803 | + $replaceEntries[] = array($row['id_member'], $split2_ID_TOPIC, $row['id_msg'], $row['unwatched']); |
|
804 | + } |
|
765 | 805 | |
766 | 806 | $smcFunc['db_insert']('ignore', |
767 | 807 | '{db_prefix}log_topics', |
@@ -785,8 +825,9 @@ discard block |
||
785 | 825 | // If there's a search index that needs updating, update it... |
786 | 826 | require_once($sourcedir . '/Search.php'); |
787 | 827 | $searchAPI = findSearchAPI(); |
788 | - if (is_callable(array($searchAPI, 'topicSplit'))) |
|
789 | - $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages); |
|
828 | + if (is_callable(array($searchAPI, 'topicSplit'))) { |
|
829 | + $searchAPI->topicSplit($split2_ID_TOPIC, $splitMessages); |
|
830 | + } |
|
790 | 831 | |
791 | 832 | // Maybe we want to let an external CMS know about this split |
792 | 833 | $split1 = array( |
@@ -833,12 +874,12 @@ discard block |
||
833 | 874 | ); |
834 | 875 | |
835 | 876 | // ?action=mergetopics;sa=LETSBREAKIT won't work, sorry. |
836 | - if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) |
|
837 | - MergeIndex(); |
|
838 | - |
|
839 | - else |
|
840 | - call_helper($subActions[$_REQUEST['sa']]); |
|
841 | -} |
|
877 | + if (empty($_REQUEST['sa']) || !isset($subActions[$_REQUEST['sa']])) { |
|
878 | + MergeIndex(); |
|
879 | + } else { |
|
880 | + call_helper($subActions[$_REQUEST['sa']]); |
|
881 | + } |
|
882 | + } |
|
842 | 883 | |
843 | 884 | /** |
844 | 885 | * allows to pick a topic to merge the current topic with. |
@@ -852,8 +893,9 @@ discard block |
||
852 | 893 | global $txt, $board, $context, $smcFunc, $sourcedir; |
853 | 894 | global $scripturl, $modSettings; |
854 | 895 | |
855 | - if (!isset($_GET['from'])) |
|
856 | - fatal_lang_error('no_access', false); |
|
896 | + if (!isset($_GET['from'])) { |
|
897 | + fatal_lang_error('no_access', false); |
|
898 | + } |
|
857 | 899 | $_GET['from'] = (int) $_GET['from']; |
858 | 900 | |
859 | 901 | $_REQUEST['targetboard'] = isset($_REQUEST['targetboard']) ? (int) $_REQUEST['targetboard'] : $board; |
@@ -864,9 +906,9 @@ discard block |
||
864 | 906 | { |
865 | 907 | $can_approve_boards = boardsAllowedTo('approve_posts'); |
866 | 908 | $onlyApproved = $can_approve_boards !== array(0) && !in_array($_REQUEST['targetboard'], $can_approve_boards); |
909 | + } else { |
|
910 | + $onlyApproved = false; |
|
867 | 911 | } |
868 | - else |
|
869 | - $onlyApproved = false; |
|
870 | 912 | |
871 | 913 | // How many topics are on this board? (used for paging.) |
872 | 914 | $request = $smcFunc['db_query']('', ' |
@@ -900,8 +942,9 @@ discard block |
||
900 | 942 | 'is_approved' => 1, |
901 | 943 | ) |
902 | 944 | ); |
903 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
904 | - fatal_lang_error('no_board'); |
|
945 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
946 | + fatal_lang_error('no_board'); |
|
947 | + } |
|
905 | 948 | list ($subject) = $smcFunc['db_fetch_row']($request); |
906 | 949 | $smcFunc['db_free_result']($request); |
907 | 950 | |
@@ -914,8 +957,9 @@ discard block |
||
914 | 957 | // Check which boards you have merge permissions on. |
915 | 958 | $merge_boards = boardsAllowedTo('merge_any'); |
916 | 959 | |
917 | - if (empty($merge_boards)) |
|
918 | - fatal_lang_error('cannot_merge_any', 'user'); |
|
960 | + if (empty($merge_boards)) { |
|
961 | + fatal_lang_error('cannot_merge_any', 'user'); |
|
962 | + } |
|
919 | 963 | |
920 | 964 | // No sense in loading this if you can only merge on this board |
921 | 965 | if (count($merge_boards) > 1 || in_array(0, $merge_boards)) |
@@ -929,8 +973,9 @@ discard block |
||
929 | 973 | ); |
930 | 974 | |
931 | 975 | // Only include these boards in the list (0 means you're an admin') |
932 | - if (!in_array(0, $merge_boards)) |
|
933 | - $options['included_boards'] = $merge_boards; |
|
976 | + if (!in_array(0, $merge_boards)) { |
|
977 | + $options['included_boards'] = $merge_boards; |
|
978 | + } |
|
934 | 979 | |
935 | 980 | $context['merge_categories'] = getBoardList($options); |
936 | 981 | } |
@@ -976,8 +1021,9 @@ discard block |
||
976 | 1021 | } |
977 | 1022 | $smcFunc['db_free_result']($request); |
978 | 1023 | |
979 | - if (empty($context['topics']) && count($merge_boards) <= 1 && !in_array(0, $merge_boards)) |
|
980 | - fatal_lang_error('merge_need_more_topics'); |
|
1024 | + if (empty($context['topics']) && count($merge_boards) <= 1 && !in_array(0, $merge_boards)) { |
|
1025 | + fatal_lang_error('merge_need_more_topics'); |
|
1026 | + } |
|
981 | 1027 | |
982 | 1028 | $context['sub_template'] = 'merge'; |
983 | 1029 | } |
@@ -1007,24 +1053,29 @@ discard block |
||
1007 | 1053 | checkSession('request'); |
1008 | 1054 | |
1009 | 1055 | // Handle URLs from MergeIndex. |
1010 | - if (!empty($_GET['from']) && !empty($_GET['to'])) |
|
1011 | - $topics = array((int) $_GET['from'], (int) $_GET['to']); |
|
1056 | + if (!empty($_GET['from']) && !empty($_GET['to'])) { |
|
1057 | + $topics = array((int) $_GET['from'], (int) $_GET['to']); |
|
1058 | + } |
|
1012 | 1059 | |
1013 | 1060 | // If we came from a form, the topic IDs came by post. |
1014 | - if (!empty($_POST['topics']) && is_array($_POST['topics'])) |
|
1015 | - $topics = $_POST['topics']; |
|
1061 | + if (!empty($_POST['topics']) && is_array($_POST['topics'])) { |
|
1062 | + $topics = $_POST['topics']; |
|
1063 | + } |
|
1016 | 1064 | |
1017 | 1065 | // There's nothing to merge with just one topic... |
1018 | - if (empty($topics) || !is_array($topics) || count($topics) == 1) |
|
1019 | - fatal_lang_error('merge_need_more_topics'); |
|
1066 | + if (empty($topics) || !is_array($topics) || count($topics) == 1) { |
|
1067 | + fatal_lang_error('merge_need_more_topics'); |
|
1068 | + } |
|
1020 | 1069 | |
1021 | 1070 | // Make sure every topic is numeric, or some nasty things could be done with the DB. |
1022 | - foreach ($topics as $id => $topic) |
|
1023 | - $topics[$id] = (int) $topic; |
|
1071 | + foreach ($topics as $id => $topic) { |
|
1072 | + $topics[$id] = (int) $topic; |
|
1073 | + } |
|
1024 | 1074 | |
1025 | 1075 | // Joy of all joys, make sure they're not messing about with unapproved topics they can't see :P |
1026 | - if ($modSettings['postmod_active']) |
|
1027 | - $can_approve_boards = boardsAllowedTo('approve_posts'); |
|
1076 | + if ($modSettings['postmod_active']) { |
|
1077 | + $can_approve_boards = boardsAllowedTo('approve_posts'); |
|
1078 | + } |
|
1028 | 1079 | |
1029 | 1080 | // Get info about the topics and polls that will be merged. |
1030 | 1081 | $request = $smcFunc['db_query']('', ' |
@@ -1045,8 +1096,9 @@ discard block |
||
1045 | 1096 | 'limit' => count($topics), |
1046 | 1097 | ) |
1047 | 1098 | ); |
1048 | - if ($smcFunc['db_num_rows']($request) < 2) |
|
1049 | - fatal_lang_error('no_topic_id'); |
|
1099 | + if ($smcFunc['db_num_rows']($request) < 2) { |
|
1100 | + fatal_lang_error('no_topic_id'); |
|
1101 | + } |
|
1050 | 1102 | $num_views = 0; |
1051 | 1103 | $is_sticky = 0; |
1052 | 1104 | $boardTotals = array(); |
@@ -1059,34 +1111,38 @@ discard block |
||
1059 | 1111 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1060 | 1112 | { |
1061 | 1113 | // Sorry, redirection topics can't be merged |
1062 | - if (!empty($row['id_redirect_topic'])) |
|
1063 | - fatal_lang_error('cannot_merge_redirect', false); |
|
1114 | + if (!empty($row['id_redirect_topic'])) { |
|
1115 | + fatal_lang_error('cannot_merge_redirect', false); |
|
1116 | + } |
|
1064 | 1117 | |
1065 | 1118 | // Make a note for the board counts... |
1066 | - if (!isset($boardTotals[$row['id_board']])) |
|
1067 | - $boardTotals[$row['id_board']] = array( |
|
1119 | + if (!isset($boardTotals[$row['id_board']])) { |
|
1120 | + $boardTotals[$row['id_board']] = array( |
|
1068 | 1121 | 'posts' => 0, |
1069 | 1122 | 'topics' => 0, |
1070 | 1123 | 'unapproved_posts' => 0, |
1071 | 1124 | 'unapproved_topics' => 0 |
1072 | 1125 | ); |
1126 | + } |
|
1073 | 1127 | |
1074 | 1128 | // We can't see unapproved topics here? |
1075 | 1129 | if ($modSettings['postmod_active'] && !$row['approved'] && $can_approve_boards != array(0) && in_array($row['id_board'], $can_approve_boards)) |
1076 | 1130 | { |
1077 | 1131 | unset($topics[$row['id_topic']]); // If we can't see it, we should not merge it and not adjust counts! Instead skip it. |
1078 | 1132 | continue; |
1079 | - }elseif (!$row['approved']) |
|
1080 | - $boardTotals[$row['id_board']]['unapproved_topics']++; |
|
1081 | - else |
|
1082 | - $boardTotals[$row['id_board']]['topics']++; |
|
1133 | + } elseif (!$row['approved']) { |
|
1134 | + $boardTotals[$row['id_board']]['unapproved_topics']++; |
|
1135 | + } else { |
|
1136 | + $boardTotals[$row['id_board']]['topics']++; |
|
1137 | + } |
|
1083 | 1138 | |
1084 | 1139 | $boardTotals[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
1085 | 1140 | $boardTotals[$row['id_board']]['posts'] += $row['num_replies'] + ($row['approved'] ? 1 : 0); |
1086 | 1141 | |
1087 | 1142 | // In the case of making a redirect, the topic count goes up by one due to the redirect topic. |
1088 | - if (isset($_POST['postRedirect'])) |
|
1089 | - $boardTotals[$row['id_board']]['topics']--; |
|
1143 | + if (isset($_POST['postRedirect'])) { |
|
1144 | + $boardTotals[$row['id_board']]['topics']--; |
|
1145 | + } |
|
1090 | 1146 | |
1091 | 1147 | $topic_data[$row['id_topic']] = array( |
1092 | 1148 | 'id' => $row['id_topic'], |
@@ -1112,11 +1168,13 @@ discard block |
||
1112 | 1168 | $boards[] = $row['id_board']; |
1113 | 1169 | |
1114 | 1170 | // If there's no poll, id_poll == 0... |
1115 | - if ($row['id_poll'] > 0) |
|
1116 | - $polls[] = $row['id_poll']; |
|
1171 | + if ($row['id_poll'] > 0) { |
|
1172 | + $polls[] = $row['id_poll']; |
|
1173 | + } |
|
1117 | 1174 | // Store the id_topic with the lowest id_first_msg. |
1118 | - if (empty($firstTopic)) |
|
1119 | - $firstTopic = $row['id_topic']; |
|
1175 | + if (empty($firstTopic)) { |
|
1176 | + $firstTopic = $row['id_topic']; |
|
1177 | + } |
|
1120 | 1178 | |
1121 | 1179 | // Lowest topic id gets selected as surviving topic id. We need to store this board so we can adjust the topic count (This one will not have a redirect topic) |
1122 | 1180 | if ($row['id_topic'] < $lowestTopicId || empty($lowestTopicId)) |
@@ -1130,11 +1188,13 @@ discard block |
||
1130 | 1188 | $smcFunc['db_free_result']($request); |
1131 | 1189 | |
1132 | 1190 | // If we didn't get any topics then they've been messing with unapproved stuff. |
1133 | - if (empty($topic_data)) |
|
1134 | - fatal_lang_error('no_topic_id'); |
|
1191 | + if (empty($topic_data)) { |
|
1192 | + fatal_lang_error('no_topic_id'); |
|
1193 | + } |
|
1135 | 1194 | |
1136 | - if (isset($_POST['postRedirect']) && !empty($lowestTopicBoard)) |
|
1137 | - $boardTotals[$lowestTopicBoard]['topics']++; |
|
1195 | + if (isset($_POST['postRedirect']) && !empty($lowestTopicBoard)) { |
|
1196 | + $boardTotals[$lowestTopicBoard]['topics']++; |
|
1197 | + } |
|
1138 | 1198 | |
1139 | 1199 | // Will this be approved? |
1140 | 1200 | $context['is_approved'] = $topic_data[$firstTopic]['approved']; |
@@ -1150,8 +1210,9 @@ discard block |
||
1150 | 1210 | |
1151 | 1211 | // Get the boards a user is allowed to merge in. |
1152 | 1212 | $merge_boards = boardsAllowedTo('merge_any'); |
1153 | - if (empty($merge_boards)) |
|
1154 | - fatal_lang_error('cannot_merge_any', 'user'); |
|
1213 | + if (empty($merge_boards)) { |
|
1214 | + fatal_lang_error('cannot_merge_any', 'user'); |
|
1215 | + } |
|
1155 | 1216 | |
1156 | 1217 | // Make sure they can see all boards.... |
1157 | 1218 | $request = $smcFunc['db_query']('', ' |
@@ -1168,8 +1229,9 @@ discard block |
||
1168 | 1229 | ) |
1169 | 1230 | ); |
1170 | 1231 | // If the number of boards that's in the output isn't exactly the same as we've put in there, you're in trouble. |
1171 | - if ($smcFunc['db_num_rows']($request) != count($boards)) |
|
1172 | - fatal_lang_error('no_board'); |
|
1232 | + if ($smcFunc['db_num_rows']($request) != count($boards)) { |
|
1233 | + fatal_lang_error('no_board'); |
|
1234 | + } |
|
1173 | 1235 | $smcFunc['db_free_result']($request); |
1174 | 1236 | |
1175 | 1237 | if (empty($_REQUEST['sa']) || $_REQUEST['sa'] == 'options') |
@@ -1188,8 +1250,8 @@ discard block |
||
1188 | 1250 | 'limit' => count($polls), |
1189 | 1251 | ) |
1190 | 1252 | ); |
1191 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1192 | - $context['polls'][] = array( |
|
1253 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1254 | + $context['polls'][] = array( |
|
1193 | 1255 | 'id' => $row['id_poll'], |
1194 | 1256 | 'topic' => array( |
1195 | 1257 | 'id' => $row['id_topic'], |
@@ -1198,6 +1260,7 @@ discard block |
||
1198 | 1260 | 'question' => $row['question'], |
1199 | 1261 | 'selected' => $row['id_topic'] == $firstTopic |
1200 | 1262 | ); |
1263 | + } |
|
1201 | 1264 | $smcFunc['db_free_result']($request); |
1202 | 1265 | } |
1203 | 1266 | if (count($boards) > 1) |
@@ -1213,18 +1276,20 @@ discard block |
||
1213 | 1276 | 'limit' => count($boards), |
1214 | 1277 | ) |
1215 | 1278 | ); |
1216 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1217 | - $context['boards'][] = array( |
|
1279 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1280 | + $context['boards'][] = array( |
|
1218 | 1281 | 'id' => $row['id_board'], |
1219 | 1282 | 'name' => $row['name'], |
1220 | 1283 | 'selected' => $row['id_board'] == $topic_data[$firstTopic]['board'] |
1221 | 1284 | ); |
1285 | + } |
|
1222 | 1286 | $smcFunc['db_free_result']($request); |
1223 | 1287 | } |
1224 | 1288 | |
1225 | 1289 | $context['topics'] = $topic_data; |
1226 | - foreach ($topic_data as $id => $topic) |
|
1227 | - $context['topics'][$id]['selected'] = $topic['id'] == $firstTopic; |
|
1290 | + foreach ($topic_data as $id => $topic) { |
|
1291 | + $context['topics'][$id]['selected'] = $topic['id'] == $firstTopic; |
|
1292 | + } |
|
1228 | 1293 | |
1229 | 1294 | $context['page_title'] = $txt['merge']; |
1230 | 1295 | $context['sub_template'] = 'merge_extra_options'; |
@@ -1233,13 +1298,15 @@ discard block |
||
1233 | 1298 | |
1234 | 1299 | // Determine target board. |
1235 | 1300 | $target_board = count($boards) > 1 ? (int) $_REQUEST['board'] : $boards[0]; |
1236 | - if (!in_array($target_board, $boards)) |
|
1237 | - fatal_lang_error('no_board'); |
|
1301 | + if (!in_array($target_board, $boards)) { |
|
1302 | + fatal_lang_error('no_board'); |
|
1303 | + } |
|
1238 | 1304 | |
1239 | 1305 | // Determine which poll will survive and which polls won't. |
1240 | 1306 | $target_poll = count($polls) > 1 ? (int) $_POST['poll'] : (count($polls) == 1 ? $polls[0] : 0); |
1241 | - if ($target_poll > 0 && !in_array($target_poll, $polls)) |
|
1242 | - fatal_lang_error('no_access', false); |
|
1307 | + if ($target_poll > 0 && !in_array($target_poll, $polls)) { |
|
1308 | + fatal_lang_error('no_access', false); |
|
1309 | + } |
|
1243 | 1310 | $deleted_polls = empty($target_poll) ? $polls : array_diff($polls, array($target_poll)); |
1244 | 1311 | |
1245 | 1312 | // Determine the subject of the newly merged topic - was a custom subject specified? |
@@ -1247,19 +1314,23 @@ discard block |
||
1247 | 1314 | { |
1248 | 1315 | $target_subject = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
1249 | 1316 | // Keep checking the length. |
1250 | - if ($smcFunc['strlen']($target_subject) > 100) |
|
1251 | - $target_subject = $smcFunc['substr']($target_subject, 0, 100); |
|
1317 | + if ($smcFunc['strlen']($target_subject) > 100) { |
|
1318 | + $target_subject = $smcFunc['substr']($target_subject, 0, 100); |
|
1319 | + } |
|
1252 | 1320 | |
1253 | 1321 | // Nothing left - odd but pick the first topics subject. |
1254 | - if ($target_subject == '') |
|
1255 | - $target_subject = $topic_data[$firstTopic]['subject']; |
|
1322 | + if ($target_subject == '') { |
|
1323 | + $target_subject = $topic_data[$firstTopic]['subject']; |
|
1324 | + } |
|
1256 | 1325 | } |
1257 | 1326 | // A subject was selected from the list. |
1258 | - elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) |
|
1259 | - $target_subject = $topic_data[(int) $_POST['subject']]['subject']; |
|
1327 | + elseif (!empty($topic_data[(int) $_POST['subject']]['subject'])) { |
|
1328 | + $target_subject = $topic_data[(int) $_POST['subject']]['subject']; |
|
1329 | + } |
|
1260 | 1330 | // Nothing worked? Just take the subject of the first message. |
1261 | - else |
|
1262 | - $target_subject = $topic_data[$firstTopic]['subject']; |
|
1331 | + else { |
|
1332 | + $target_subject = $topic_data[$firstTopic]['subject']; |
|
1333 | + } |
|
1263 | 1334 | |
1264 | 1335 | // Get the first and last message and the number of messages.... |
1265 | 1336 | $request = $smcFunc['db_query']('', ' |
@@ -1285,15 +1356,13 @@ discard block |
||
1285 | 1356 | { |
1286 | 1357 | $num_replies = $row['message_count'] - 1; |
1287 | 1358 | $num_unapproved = 0; |
1288 | - } |
|
1289 | - else |
|
1359 | + } else |
|
1290 | 1360 | { |
1291 | 1361 | $topic_approved = 0; |
1292 | 1362 | $num_replies = 0; |
1293 | 1363 | $num_unapproved = $row['message_count']; |
1294 | 1364 | } |
1295 | - } |
|
1296 | - else |
|
1365 | + } else |
|
1297 | 1366 | { |
1298 | 1367 | // If this has a lower first_msg then the first post is not approved and hence the number of replies was wrong! |
1299 | 1368 | if ($first_msg > $row['first_msg']) |
@@ -1339,8 +1408,9 @@ discard block |
||
1339 | 1408 | list ($member_started) = $smcFunc['db_fetch_row']($request); |
1340 | 1409 | list ($member_updated) = $smcFunc['db_fetch_row']($request); |
1341 | 1410 | // First and last message are the same, so only row was returned. |
1342 | - if ($member_updated === NULL) |
|
1343 | - $member_updated = $member_started; |
|
1411 | + if ($member_updated === NULL) { |
|
1412 | + $member_updated = $member_started; |
|
1413 | + } |
|
1344 | 1414 | |
1345 | 1415 | $smcFunc['db_free_result']($request); |
1346 | 1416 | |
@@ -1353,8 +1423,9 @@ discard block |
||
1353 | 1423 | array( |
1354 | 1424 | 'topic_list' => $topics, |
1355 | 1425 | )); |
1356 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1357 | - $affected_msgs[] = $row[0]; |
|
1426 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1427 | + $affected_msgs[] = $row[0]; |
|
1428 | + } |
|
1358 | 1429 | $smcFunc['db_free_result']($request); |
1359 | 1430 | |
1360 | 1431 | // Assign the first topic ID to be the merged topic. |
@@ -1432,9 +1503,9 @@ discard block |
||
1432 | 1503 | // Grab the response prefix (like 'Re: ') in the default forum language. |
1433 | 1504 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
1434 | 1505 | { |
1435 | - if ($language === $user_info['language']) |
|
1436 | - $context['response_prefix'] = $txt['response_prefix']; |
|
1437 | - else |
|
1506 | + if ($language === $user_info['language']) { |
|
1507 | + $context['response_prefix'] = $txt['response_prefix']; |
|
1508 | + } else |
|
1438 | 1509 | { |
1439 | 1510 | loadLanguage('index', $language, false); |
1440 | 1511 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -1514,8 +1585,9 @@ discard block |
||
1514 | 1585 | if ($smcFunc['db_num_rows']($request) > 0) |
1515 | 1586 | { |
1516 | 1587 | $replaceEntries = array(); |
1517 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1518 | - $replaceEntries[] = array($row['id_member'], $id_topic, $row['new_id_msg'], $row['unwatched']); |
|
1588 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1589 | + $replaceEntries[] = array($row['id_member'], $id_topic, $row['new_id_msg'], $row['unwatched']); |
|
1590 | + } |
|
1519 | 1591 | |
1520 | 1592 | $smcFunc['db_insert']('replace', |
1521 | 1593 | '{db_prefix}log_topics', |
@@ -1552,8 +1624,9 @@ discard block |
||
1552 | 1624 | if ($smcFunc['db_num_rows']($request) > 0) |
1553 | 1625 | { |
1554 | 1626 | $replaceEntries = array(); |
1555 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1556 | - $replaceEntries[] = array($row['id_member'], $id_topic, 0, $row['sent']); |
|
1627 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1628 | + $replaceEntries[] = array($row['id_member'], $id_topic, 0, $row['sent']); |
|
1629 | + } |
|
1557 | 1630 | |
1558 | 1631 | $smcFunc['db_insert']('replace', |
1559 | 1632 | '{db_prefix}log_notify', |
@@ -1728,8 +1801,9 @@ discard block |
||
1728 | 1801 | // If there's a search index that needs updating, update it... |
1729 | 1802 | require_once($sourcedir . '/Search.php'); |
1730 | 1803 | $searchAPI = findSearchAPI(); |
1731 | - if (is_callable(array($searchAPI, 'topicMerge'))) |
|
1732 | - $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : array($context['response_prefix'], $target_subject)); |
|
1804 | + if (is_callable(array($searchAPI, 'topicMerge'))) { |
|
1805 | + $searchAPI->topicMerge($id_topic, $topics, $affected_msgs, empty($_POST['enforce_subject']) ? null : array($context['response_prefix'], $target_subject)); |
|
1806 | + } |
|
1733 | 1807 | |
1734 | 1808 | // Merging is the sort of thing an external CMS might want to know about |
1735 | 1809 | $merged_topic = array( |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('Location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
12 | 12 | header('Location: ' . $boardurl); |
13 | 13 | } |
14 | 14 | // Can't find it... just forget it. |
15 | -else |
|
15 | +else { |
|
16 | 16 | exit; |
17 | +} |
|
17 | 18 | |
18 | 19 | ?> |
19 | 20 | \ No newline at end of file |