Пример #1
0
/**
 * Activates the plugin.
 *
 */
function accountswitcher_activate()
{
    global $mybb, $db, $cache, $templates, $lang, $eas;
    $lang->load("accountswitcher");
    // Template edits
    accountswitcher_revert_template_edits();
    accountswitcher_apply_template_edits();
    // Integrate MyAlerts
    $alertsetting = 0;
    if ($db->table_exists('alert_types')) {
        $alertsetting = 1;
        if (!accountswitcher_alerts_status()) {
            accountswitcher_alerts_integrate();
        }
    }
    // If we are upgrading...add the new settings
    $query = $db->simple_select("settings", "*", "name='aj_postjump'");
    $result = $db->num_rows($query);
    if (!$result) {
        $query2 = $db->simple_select("settinggroups", "COUNT(*) as rows");
        $rows = $db->fetch_field($query2, "rows");
        // Add settinggroup for the settings
        $account_jumper_group = array("name" => "Enhanced Account Switcher", "title" => $db->escape_string($lang->as_name), "description" => $db->escape_string($lang->aj_group_descr), "disporder" => $rows + 1, "isdefault" => 0);
        $db->insert_query("settinggroups", $account_jumper_group);
        $gid = $db->insert_id();
        // Add settings for the settinggroup
        $account_jumper_1 = array("name" => "aj_postjump", "title" => $db->escape_string($lang->aj_postjump_title), "description" => $db->escape_string($lang->aj_postjump_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 1, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_1);
        $account_jumper_2 = array("name" => "aj_changeauthor", "title" => $db->escape_string($lang->aj_changeauthor_title), "description" => $db->escape_string($lang->aj_changeauthor_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 2, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_2);
        $account_jumper_3 = array("name" => "aj_pmnotice", "title" => $db->escape_string($lang->aj_pmnotice_title), "description" => $db->escape_string($lang->aj_pmnotice_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 3, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_3);
        $account_jumper_4 = array("name" => "aj_profile", "title" => $db->escape_string($lang->aj_profile_title), "description" => $db->escape_string($lang->aj_profile_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 4, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_4);
        $account_jumper_5 = array("name" => "aj_away", "title" => $db->escape_string($lang->aj_away_title), "description" => $db->escape_string($lang->aj_away_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 5, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_5);
    }
    // Upgrade to v1.5
    $query_gr = $db->simple_select("settinggroups", "gid", "name='Enhanced Account Switcher'");
    $eacgid = $db->fetch_array($query_gr);
    if ($eacgid) {
        $gid = $eacgid['gid'];
    }
    $query_reload = $db->simple_select("settings", "*", "name='aj_reload'");
    $result_reload = $db->num_rows($query_reload);
    if (!$result_reload) {
        $account_jumper_6 = array("name" => "aj_reload", "title" => $db->escape_string($lang->aj_reload_title), "description" => $db->escape_string($lang->aj_reload_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 6, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_6);
    }
    $query_list = $db->simple_select("settings", "*", "name='aj_list'");
    $result_list = $db->num_rows($query_list);
    if (!$result_list) {
        $account_jumper_7 = array("name" => "aj_list", "title" => $db->escape_string($lang->aj_list_title), "description" => $db->escape_string($lang->aj_list_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 7, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_7);
        $account_jumper_8 = array("name" => "aj_postuser", "title" => $db->escape_string($lang->aj_postuser_title), "description" => $db->escape_string($lang->aj_postuser_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 8, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_8);
    }
    $query_share = $db->simple_select("settings", "*", "name='aj_shareuser'");
    $result_share = $db->num_rows($query_share);
    if (!$result_share) {
        $account_jumper_9 = array("name" => "aj_shareuser", "title" => $db->escape_string($lang->aj_shareuser_title), "description" => $db->escape_string($lang->aj_shareuser_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 9, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_9);
    }
    $query_sort = $db->simple_select("settings", "*", "name='aj_sortuser'");
    $result_sort = $db->num_rows($query_sort);
    if (!$result_sort) {
        $account_jumper_11 = array("name" => "aj_sortuser", "title" => $db->escape_string($lang->aj_sortuser_title), "description" => $db->escape_string($lang->aj_sortuser_descr), "optionscode" => "select\nuid=User-ID\nuname=Username", "value" => "uid", "disporder" => 11, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_11);
    }
    $query_dropdown = $db->simple_select("settings", "*", "name='aj_headerdropdown'");
    $result_dropdown = $db->num_rows($query_dropdown);
    // Upgrade to v1.6
    if (!$result_dropdown) {
        $account_jumper_12 = array("name" => "aj_headerdropdown", "title" => $db->escape_string($lang->aj_headerdropdown_title), "description" => $db->escape_string($lang->aj_headerdropdown_descr), "optionscode" => "yesno", "value" => 0, "disporder" => 12, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_12);
    }
    $query_admin_changeauthor = $db->simple_select("settings", "*", "name='aj_admin_changeauthor'");
    $result_admin_changeauthor = $db->num_rows($query_admin_changeauthor);
    // Upgrade to v1.7
    if (!$result_admin_changeauthor) {
        $account_jumper_13 = array("name" => "aj_admin_changeauthor", "title" => $db->escape_string($lang->aj_admin_changeauthor_title), "description" => $db->escape_string($lang->aj_admin_changeauthor_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 13, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_13);
        $account_jumper_14 = array("name" => "aj_admin_changegroup", "title" => $db->escape_string($lang->aj_admin_changegroup_title), "description" => $db->escape_string($lang->aj_admin_changegroup_descr), "optionscode" => "radio\nadmin=" . $db->escape_string($lang->aj_admin_changegroup_admins) . "\nsupermods=" . $db->escape_string($lang->aj_admin_changegroup_supermods) . "\nmods=" . $db->escape_string($lang->aj_admin_changegroup_mods) . "", "value" => "admin", "disporder" => 14, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_14);
    }
    // Upgrade to v2.0
    $query_authorpm = $db->simple_select("settings", "*", "name='aj_authorpm'");
    $result_authorpm = $db->num_rows($query_authorpm);
    if (!$result_authorpm) {
        $account_jumper_15 = array("name" => "aj_authorpm", "title" => $db->escape_string($lang->aj_authorpm_title), "description" => $db->escape_string($lang->aj_authorpm_descr), "optionscode" => "yesno", "value" => 0, "disporder" => 15, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_15);
    }
    $query_memberlist = $db->simple_select("settings", "*", "name='aj_memberlist'");
    $result_memberlist = $db->num_rows($query_memberlist);
    if (!$result_memberlist) {
        $account_jumper_16 = array("name" => "aj_memberlist", "title" => $db->escape_string($lang->aj_memberlist_title), "description" => $db->escape_string($lang->aj_memberlist_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 16, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_16);
    }
    $query_sidebar = $db->simple_select("settings", "*", "name='aj_sidebar'");
    $result_sidebar = $db->num_rows($query_sidebar);
    if (!$result_sidebar) {
        $account_jumper_17 = array("name" => "aj_sidebar", "title" => $db->escape_string($lang->aj_sidebar_title), "description" => $db->escape_string($lang->aj_sidebar_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 17, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_17);
    }
    $query_sharestyle = $db->simple_select("settings", "*", "name='aj_sharestyle'");
    $result_sharestyle = $db->num_rows($query_sharestyle);
    if (!$result_sharestyle) {
        $account_jumper_10 = array("name" => "aj_sharestyle", "title" => $db->escape_string($lang->aj_sharestyle_title), "description" => $db->escape_string($lang->aj_sharestyle_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 10, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_10);
        $account_jumper_18 = array("name" => "aj_secstyle", "title" => $db->escape_string($lang->aj_secstyle_title), "description" => $db->escape_string($lang->aj_secstyle_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 18, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_18);
    }
    $query_profilefield = $db->simple_select("settings", "*", "name='aj_profilefield'");
    $result_profilefield = $db->num_rows($query_profilefield);
    if (!$result_profilefield) {
        $account_jumper_19 = array("name" => "aj_profilefield", "title" => $db->escape_string($lang->aj_profilefield_title), "description" => $db->escape_string($lang->aj_profilefield_descr), "optionscode" => "yesno", "value" => 0, "disporder" => 19, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_19);
        $account_jumper_20 = array("name" => "aj_profilefield_id", "title" => $db->escape_string($lang->aj_profilefield_id_title), "description" => $db->escape_string($lang->aj_profilefield_id_descr), "optionscode" => "numeric", "value" => "0", "disporder" => 20, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_20);
    }
    $query_postcount = $db->simple_select("settings", "*", "name='aj_postcount'");
    $result_postcount = $db->num_rows($query_postcount);
    if (!$result_postcount) {
        $account_jumper_21 = array("name" => "aj_postcount", "title" => $db->escape_string($lang->aj_postcount_title), "description" => $db->escape_string($lang->aj_postcount_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 21, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_21);
    }
    $query_myalerts = $db->simple_select("settings", "*", "name='aj_myalerts'");
    $result_myalerts = $db->num_rows($query_myalerts);
    if (!$result_myalerts) {
        $account_jumper_22 = array("name" => "aj_myalerts", "title" => $db->escape_string($lang->aj_myalerts_title), "description" => $db->escape_string($lang->aj_myalerts_descr), "optionscode" => "yesno", "value" => $alertsetting, "disporder" => 22, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_22);
    }
    $query_privacy = $db->simple_select("settings", "*", "name='aj_privacy'");
    $result_privacy = $db->num_rows($query_privacy);
    if (!$result_privacy) {
        $account_jumper_23 = array("name" => "aj_privacy", "title" => $db->escape_string($lang->aj_privacy_title), "description" => $db->escape_string($lang->aj_privacy_descr), "optionscode" => "yesno", "value" => 1, "disporder" => 23, "gid" => (int) $gid);
        $db->insert_query("settings", $account_jumper_23);
    }
    // Refresh settings.php
    rebuild_settings();
    // If we are upgrading...add the new templates
    $query_tpl = $db->simple_select('templategroups', '*', 'prefix="accountswitcher"');
    $result_template = $db->num_rows($query_tpl);
    if (!$result_template) {
        accountswitcher_templates_add();
    }
    // If we are upgrading... add the new table columns
    if (!$db->field_exists("as_share", "users")) {
        $db->add_column('users', 'as_share', 'INT(1) NOT NULL DEFAULT "0"');
    }
    if (!$db->field_exists("as_shareuid", "users")) {
        $db->add_column('users', 'as_shareuid', 'INT(11) NOT NULL DEFAULT "0"');
    }
    // Add new columns for 2.0
    if (!$db->field_exists("as_sec", "users")) {
        $db->add_column('users', 'as_sec', 'INT(1) NOT NULL DEFAULT "0"');
    }
    if (!$db->field_exists("as_secreason", "users")) {
        $db->add_column('users', 'as_secreason', 'TEXT NOT NULL');
    }
    if (!$db->field_exists("as_privacy", "users")) {
        $db->add_column('users', 'as_privacy', 'INT(1) NOT NULL DEFAULT "0"');
    }
    if (!$db->field_exists("as_buddyshare", "users")) {
        $db->add_column('users', 'as_buddyshare', 'INT(1) NOT NULL DEFAULT "0"');
    }
    // Update settings language phrases
    accountswitcher_settings_lang();
    // Build accounts and userfield cache
    require_once MYBB_ROOT . "/inc/plugins/accountswitcher/class_accountswitcher.php";
    $eas = new AccountSwitcher($mybb, $db, $cache, $templates);
    $eas->update_accountswitcher_cache();
    $eas->update_userfields_cache();
}
Пример #2
0
/**
 * The switch function deletes the mybbuser cookie, sets a new cookie for the selected account and starts a new session.
 * Function is called by ajax request and sends the new users post key.
 *
 */
function accountswitcher_switch()
{
    global $db, $mybb, $lang, $charset, $cache, $templates;
    if ($mybb->user['uid'] != 0 && isset($mybb->input['switchuser']) && $mybb->input['switchuser'] == 1 && $mybb->request_method == "post") {
        require_once MYBB_ROOT . "/inc/plugins/accountswitcher/class_accountswitcher.php";
        $eas = new AccountSwitcher($mybb, $db, $cache, $templates);
        // Get permissions for this user
        $userPermission = user_permissions($mybb->user['uid']);
        // Get permissions for the master. First get the master
        $master = get_user((int) $mybb->user['as_uid']);
        // Get his permissions
        $masterPermission = user_permissions($master['uid']);
        // If one of both has the permission allow to switch
        if ($userPermission['as_canswitch'] == 1 || $masterPermission['as_canswitch'] == 1) {
            if (!isset($lang->as_invaliduser)) {
                $lang->load("accountswitcher");
            }
            verify_post_check($mybb->get_input('my_post_key'));
            // Get user info
            $user = get_user($mybb->get_input('uid', MyBB::INPUT_INT));
            // Check if user exists
            if (!$user) {
                error($lang->as_invaliduser);
            }
            // Can the new account be shared?
            if ($user['as_share'] != 0 && $mybb->settings['aj_shareuser'] == 1) {
                // Account already used by another user?
                if ($user['as_shareuid'] != 0) {
                    log_moderator_action(array('uid' => $user['uid'], 'username' => $user['username']), $lang->aj_switch_invalid_log);
                    return;
                }
                // Account only shared by buddies?
                if ($user['as_buddyshare'] != 0) {
                    // No buddy - no switch
                    if ($user['buddylist'] != '') {
                        $buddylist = explode(",", $user['buddylist']);
                    }
                    if (empty($buddylist) || !empty($buddylist) && !in_array($mybb->user['uid'], $buddylist)) {
                        log_moderator_action(array('uid' => $user['uid'], 'username' => $user['username']), $lang->aj_switch_invalid_log);
                        return;
                    }
                }
                // Shared account is free - set share uid
                if ($user['as_shareuid'] == 0) {
                    $updated_shareuid = array("as_shareuid" => (int) $mybb->user['uid']);
                    $db->update_query("users", $updated_shareuid, "uid='" . (int) $user['uid'] . "'");
                    $eas->update_accountswitcher_cache();
                    $user['as_shareuid'] = (int) $mybb->user['uid'];
                }
            }
            // Make sure you can switch to an attached account only
            if ($user['as_uid'] == $mybb->user['uid'] || $user['as_uid'] != 0 && $user['as_uid'] == $mybb->user['as_uid'] || $user['uid'] == $mybb->user['as_uid'] || $user['as_shareuid'] == $mybb->user['uid'] || $user['uid'] == $mybb->user['as_shareuid']) {
                // Is the current account shared?
                if ($mybb->user['as_share'] != 0) {
                    // Account used by another user?
                    if ($mybb->user['as_shareuid'] == 0) {
                        log_moderator_action(array('uid' => $user['uid'], 'username' => $user['username']), $lang->aj_switch_invalid_log);
                        return;
                    }
                    // Reset share uid
                    if ($mybb->user['as_shareuid'] != 0) {
                        $updated_shareuid = array("as_shareuid" => 0);
                        $db->update_query("users", $updated_shareuid, "uid='" . (int) $mybb->user['uid'] . "'");
                        $eas->update_accountswitcher_cache();
                    }
                }
                // Log the old user out
                my_unsetcookie("mybbuser");
                my_unsetcookie("sid");
                if ($mybb->user['uid']) {
                    $time = TIME_NOW;
                    // Run this after the shutdown query from session system
                    $db->shutdown_query("UPDATE " . TABLE_PREFIX . "users SET lastvisit='{$time}', lastactive='{$time}' WHERE uid='{$mybb->user['uid']}'");
                    $db->delete_query("sessions", "sid = '{$session->sid}'");
                }
                // Now let the login datahandler do the work
                require_once MYBB_ROOT . "inc/datahandlers/login.php";
                $loginhandler = new LoginDataHandler("get");
                $mybb->input['remember'] = "yes";
                $loginhandler->set_data($user);
                $validated = $loginhandler->validate_login();
                $loginhandler->complete_login();
                // Create session for this user
                require_once MYBB_ROOT . "inc/class_session.php";
                $session = new session();
                $session->init();
                $mybb->session =& $session;
                $mybb->post_code = generate_post_check();
                // Send new users post code
                header("Content-type: text/plain; charset={$charset}");
                echo $mybb->post_code;
                exit;
            } else {
                log_moderator_action(array('uid' => $user['uid'], 'username' => $user['username']), $lang->aj_switch_invalid_log);
                error($lang->as_notattacheduser);
            }
        }
    }
}