Esempio n. 1
0
function upgrade15_usernameupdate()
{
    global $db, $output, $mybb;
    $output->print_header("Performing Queries");
    echo "<p>Performing username updates..</p>";
    flush();
    require_once MYBB_ROOT . "inc/datahandler.php";
    require_once MYBB_ROOT . "inc/datahandlers/user.php";
    $not_renameable = array();
    // Because commas can cause some problems with private message sending in usernames we have to remove them
    $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
    while ($user = $db->fetch_array($query)) {
        $userhandler = new UserDataHandler('update');
        $updated_user = array("uid" => $user['uid'], "username" => str_replace(',', '', $user['username']));
        $userhandler->set_data($updated_user);
        if (!$userhandler->validate_user()) {
            $not_renameable[] = htmlspecialchars_uni($user['username']);
        } else {
            $userhandler->update_user();
        }
    }
    if (!empty($not_renameable)) {
        echo "<span style=\"color: red;\">NOTICE:</span> The following users could not be renamed automatically. Please rename these users in the Admin CP manually after the upgrade process has finished completing:<br />\n\t\t<ul>\n\t\t<li>";
        echo implode('</li>\\n<li>', $not_renameable);
        echo "</li>\n\t\t</ul>";
    }
    $contents .= "Click next to continue with the upgrade process.</p>";
    $output->print_contents($contents);
    $output->print_footer("15_done");
}
Esempio n. 2
0
function upgrade15_usernameupdate()
{
    global $db, $output, $mybb, $plugins;
    $output->print_header("Performing Queries");
    echo "<p>Performing username updates..</p>";
    flush();
    require_once MYBB_ROOT . "inc/datahandler.php";
    require_once MYBB_ROOT . "inc/datahandlers/user.php";
    // Load plugin system for datahandler
    require_once MYBB_ROOT . "inc/class_plugins.php";
    $plugins = new pluginSystem();
    $not_renameable = array();
    // Because commas can cause some problems with private message sending in usernames we have to remove them
    $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
    while ($user = $db->fetch_array($query)) {
        $prefix = '';
        $userhandler = new UserDataHandler('update');
        do {
            $username = str_replace(',', '', $user['username']) . '_' . $prefix;
            $updated_user = array("uid" => $user['uid'], "username" => $username);
            $userhandler->set_data($updated_user);
            ++$prefix;
        } while (!$userhandler->verify_username() || $userhandler->verify_username_exists());
        if (!$userhandler->validate_user()) {
            $not_renameable[] = htmlspecialchars_uni($user['username']);
        } else {
            $db->update_query("users", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("posts", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("threads", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("threads", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
            $db->update_query("forums", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
            update_stats(array("numusers" => "+0"));
        }
    }
    if (!empty($not_renameable)) {
        echo "<span style=\"color: red;\">NOTICE:</span> The following users could not be renamed automatically. Please rename these users in the Admin CP manually after the upgrade process has finished completing:<br />\n\t\t<ul>\n\t\t<li>";
        echo implode('</li>\\n<li>', $not_renameable);
        echo "</li>\n\t\t</ul>";
    }
    $contents .= "Click next to continue with the upgrade process.</p>";
    $output->print_contents($contents);
    $output->print_footer("15_done");
}
Esempio n. 3
0
function upgrade15_usernameupdate()
{
    global $db, $output, $mybb, $plugins;
    $output->print_header("Wykonywanie zapytań");
    echo "<p>Trwa wykonywanie wymaganych zapytań do bazy danych...</p>";
    flush();
    require_once MYBB_ROOT . "inc/datahandler.php";
    require_once MYBB_ROOT . "inc/datahandlers/user.php";
    // Load plugin system for datahandler
    require_once MYBB_ROOT . "inc/class_plugins.php";
    $plugins = new pluginSystem();
    $not_renameable = array();
    // Because commas can cause some problems with private message sending in usernames we have to remove them
    $query = $db->simple_select("users", "uid, username", "username LIKE '%,%'");
    while ($user = $db->fetch_array($query)) {
        $prefix = '';
        $userhandler = new UserDataHandler('update');
        do {
            $username = str_replace(',', '', $user['username']) . '_' . $prefix;
            $updated_user = array("uid" => $user['uid'], "username" => $username);
            $userhandler->set_data($updated_user);
            ++$prefix;
        } while (!$userhandler->verify_username() || $userhandler->verify_username_exists());
        if (!$userhandler->validate_user()) {
            $not_renameable[] = htmlspecialchars_uni($user['username']);
        } else {
            $db->update_query("users", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("posts", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("threads", array('username' => $db->escape_string($username)), "uid='{$user['uid']}'");
            $db->update_query("threads", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
            $db->update_query("forums", array('lastposter' => $db->escape_string($username)), "lastposteruid='{$user['uid']}'");
            update_stats(array("numusers" => "+0"));
        }
    }
    if (!empty($not_renameable)) {
        echo "<span style=\"color: red;\">OSTRZEŻENIE:</span> Poniższe loginy nie mogły zostać zmienione automatycznie. Zmień je ręcznie po zakończeniu procesu aktualizacji.<br />\n\t\t<ul>\n\t\t<li>";
        echo implode('</li>\\n<li>', $not_renameable);
        echo "</li>\n\t\t</ul>";
    }
    $contents .= "Naciśnij przycisk Dalej, aby kontynuować proces aktualizacji.</p>";
    $output->print_contents($contents);
    $output->print_footer("15_done");
}
Esempio n. 4
0
 if ($mybb->input['new_password']) {
     $updated_user['password'] = $mybb->input['new_password'];
     $updated_user['password2'] = $mybb->input['confirm_new_password'];
 }
 $updated_user['options'] = array("allownotices" => $mybb->input['allownotices'], "hideemail" => $mybb->input['hideemail'], "subscriptionmethod" => $mybb->input['subscriptionmethod'], "invisible" => $mybb->input['invisible'], "dstcorrection" => $mybb->input['dstcorrection'], "threadmode" => $mybb->input['threadmode'], "showsigs" => $mybb->input['showsigs'], "showavatars" => $mybb->input['showavatars'], "showquickreply" => $mybb->input['showquickreply'], "receivepms" => $mybb->input['receivepms'], "receivefrombuddy" => $mybb->input['receivefrombuddy'], "pmnotice" => $mybb->input['pmnotice'], "daysprune" => $mybb->input['daysprune'], "showcodebuttons" => intval($mybb->input['showcodebuttons']), "pmnotify" => $mybb->input['pmnotify'], "showredirect" => $mybb->input['showredirect']);
 if ($mybb->settings['usertppoptions']) {
     $updated_user['options']['tpp'] = intval($mybb->input['tpp']);
 }
 if ($mybb->settings['userpppoptions']) {
     $updated_user['options']['ppp'] = intval($mybb->input['ppp']);
 }
 // Set the data of the user in the datahandler.
 $userhandler->set_data($updated_user);
 $errors = '';
 // Validate the user and get any errors that might have occurred.
 if (!$userhandler->validate_user()) {
     $errors = $userhandler->get_friendly_errors();
 } else {
     // Are we removing an avatar from this user?
     if ($mybb->input['remove_avatar']) {
         $extra_user_updates = array("avatar" => "", "avatardimensions" => "", "avatartype" => "");
         remove_avatars($user['uid']);
     }
     // Are we uploading a new avatar?
     if ($_FILES['avatar_upload']['name']) {
         $avatar = upload_avatar($_FILES['avatar_upload'], $user['uid']);
         if ($avatar['error']) {
             $errors = array($avatar['error']);
         } else {
             if ($avatar['width'] > 0 && $avatar['height'] > 0) {
                 $avatar_dimensions = $avatar['width'] . "|" . $avatar['height'];
Esempio n. 5
0
 /**
  * Updates userdata
  *
  * @param array $userdata Data of the User (uid is required as index)
  * @param boolean Return errors as MyBB array or nicely formated?
  * @return boolean|array
  */
 function updateUser($userdata = array(), $inline_error = true)
 {
     // Userdata Array needs to contain the UserID
     if (!isset($userdata['uid'])) {
         $this->_errorAndDie('A UserID (Array-Key: <i>uid</i>) is required to update a user');
     }
     require_once MYBB_ROOT . 'inc/functions_user.php';
     require_once MYBB_ROOT . 'inc/datahandlers/user.php';
     $userhandler = new UserDataHandler('update');
     $userhandler->set_data($userdata);
     if (!$userhandler->validate_user()) {
         $errors = $userhandler->get_friendly_errors();
         return $inline_error === true ? inline_error($errors) : $errors;
     }
     $userhandler->update_user();
     return true;
 }
 /**
  * Registers an user with Facebook data
  */
 public function register($user)
 {
     if (!$user) {
         return false;
     }
     global $mybb, $session, $plugins, $lang;
     require_once MYBB_ROOT . "inc/datahandlers/user.php";
     $userhandler = new UserDataHandler("insert");
     $plength = 8;
     if ($mybb->settings['minpasswordlength']) {
         $plength = (int) $mybb->settings['minpasswordlength'];
     }
     $password = random_str($plength);
     $new_user = array("username" => $user['name'], "password" => $password, "password2" => $password, "email" => $user['email'], "email2" => $user['email'], "usergroup" => (int) $mybb->settings['myfbconnect_usergroup'], "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "options" => array("hideemail" => 1));
     /* Registration might fail for custom profile fields required at registration... workaround = IN_ADMINCP defined.
     		Placed straight before the registration process to avoid conflicts with third party plugins messying around with
     		templates (I'm looking at you, PHPTPL) */
     define("IN_ADMINCP", 1);
     $userhandler->set_data($new_user);
     if ($userhandler->validate_user()) {
         $user_info = $userhandler->insert_user();
         $plugins->run_hooks("member_do_register_end");
         // Deliver a welcome PM
         if ($mybb->settings['myfbconnect_passwordpm']) {
             require_once MYBB_ROOT . "inc/datahandlers/pm.php";
             $pmhandler = new PMDataHandler();
             $pmhandler->admin_override = true;
             // Make sure admins haven't done something bad
             $fromid = (int) $mybb->settings['myfbconnect_passwordpm_fromid'];
             if (!$mybb->settings['myfbconnect_passwordpm_fromid'] or !user_exists($mybb->settings['myfbconnect_passwordpm_fromid'])) {
                 $fromid = 0;
             }
             $message = $mybb->settings['myfbconnect_passwordpm_message'];
             $subject = $mybb->settings['myfbconnect_passwordpm_subject'];
             $thingsToReplace = array("{user}" => $user_info['username'], "{password}" => $password);
             // Replace what needs to be replaced
             foreach ($thingsToReplace as $find => $replace) {
                 $message = str_replace($find, $replace, $message);
             }
             $pm = array("subject" => $subject, "message" => $message, "fromid" => $fromid, "toid" => array($user_info['uid']));
             // Some defaults :)
             $pm['options'] = array("signature" => 1);
             $pmhandler->set_data($pm);
             // Now let the PM handler do all the hard work
             if ($pmhandler->validate_pm()) {
                 $pmhandler->insert_pm();
             } else {
                 error($lang->sprintf($lang->myfbconnect_error_report, $pmhandler->get_friendly_errors()));
             }
         }
         // Post a message on the user's wall
         if ($mybb->settings['myfbconnect_postonwall']) {
             $this->post_on_wall($mybb->settings['myfbconnect_postonwall_message']);
         }
         // Finally return our new user data
         return $user_info;
     } else {
         return array('error' => $userhandler->get_friendly_errors());
     }
     return true;
 }
/**
 *
 * Redirect Output - steam_output_to_misc
 * - - - - - - - - - - - - - - -
 * @desc This function is holds the actions issued by the Steam Login plugin.
 * @since 1.0
 * @version 1.6
 *
 */
function steam_output_to_misc()
{
    global $mybb, $db, $session;
    // The standard action to redirect the user to Steam community.
    if ($mybb->input['action'] == 'steam_login') {
        steam_redirect();
    }
    // close if($mybb->input['action'] == 'steam_login')
    if ($mybb->input['action'] == 'steam_return') {
        $get_key = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_api_key'"));
        $check_update_username = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_update_username'"));
        $check_update_avatar = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_update_avatar'"));
        $check_avatar_size = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_avatar_size'"));
        $check_required_field = $db->fetch_array($db->simple_select("settings", "name, value", "name = 'steamlogin_required_field'"));
        if ($get_key['value'] == null) {
            die("<strong>Not Configured</strong> The Steam Login plugin hasn't been configured correctly. Please ensure an API key is set in the Configuration settings.");
        } else {
            require_once MYBB_ROOT . 'inc/class_steam.php';
            require_once MYBB_ROOT . 'inc/class_lightopenid.php';
            require_once MYBB_ROOT . 'inc/functions.php';
            require_once MYBB_ROOT . 'inc/class_session.php';
            $steam = new steam();
            $steam_open_id = new LightOpenID();
            $steam_open_id->validate();
            $return_explode = explode('/', $steam_open_id->identity);
            $steamid = end($return_explode);
            $steam_info = $steam->get_user_info($steamid);
            // Check the status.
            if ($steam_info['status'] == 'success') {
                $steamid = $steam_info['steamid'];
                $personaname = $steam_info['personaname'];
                $profileurl = $steam_info['profileurl'];
                $avatar = $steam_info['avatars']['medium'];
                // Check the avatar size set in the database.
                if ($check_avatar_size['value'] == '0') {
                    $avatar = $steam_info['avatars']['small'];
                }
                if ($check_avatar_size['value'] == '2') {
                    $avatar = $steam_info['avatars']['large'];
                }
                $personaname = strip_tags($personaname);
                //This is so people can not use tags that display.
                $personaname = $db->escape_string($personaname);
                // Perform a check to see if the user already exists in the database.
                $user_check = $db->num_rows($db->simple_select("users", "*", "loginname = '{$steamid}'"));
                if ($user_check == 0) {
                    $password = random_str(8);
                    $email = $steamid . '@steamcommunity.com';
                    $default_usergroup = 2;
                    // On a standard MyBB installation this is the group: Registered
                    require_once MYBB_ROOT . "inc/datahandlers/user.php";
                    $userhandler = new UserDataHandler("insert");
                    $new_user_data = array("username" => $personaname, "password" => $password, "password2" => $password, "email" => $email, "email2" => $email, "avatar" => $avatar, "usergroup" => $default_usergroup, "displaygroup" => $default_usergroup, "website" => $profileurl, "regip" => $session->ipaddress, "longregip" => my_ip2long($session->ipaddress), "loginname" => $steamid);
                    if ($check_required_field['value'] != "" and is_numeric($check_required_field['value'])) {
                        // Check the field exists.
                        $field_exists = $db->num_rows($db->simple_select("profilefields", "*", "fid = '" . $check_required_field['value'] . "'"));
                        if ($field_exists > 0) {
                            $new_user_data['profile_fields']['fid' . $check_required_field['value']] = $steamid;
                        }
                    }
                    $userhandler->set_data($new_user_data);
                    if ($userhandler->validate_user()) {
                        $user_info = $userhandler->insert_user();
                    }
                    // close if ($userhandler->validate_user())
                } else {
                    // close if($user_check == 0)
                    $update = array();
                    // Init our update array.
                    // Do our checks for both username and avatar.
                    if ($check_update_username['value'] == 1) {
                        $update['username'] = $personaname;
                    }
                    if ($check_update_avatar['value'] == 1) {
                        $update['avatar'] = $avatar;
                    }
                    // Run our update query if the array isn't empty.
                    if (!empty($update)) {
                        $db->update_query('users', $update, "loginname = '{$steamid}'");
                    }
                }
                // close else
                $user = $db->fetch_array($db->simple_select("users", "*", "loginname = '{$steamid}'"));
                // Login the user.
                my_setcookie("mybbuser", $user['uid'] . "_" . $user['loginkey'], true, true);
                my_setcookie("sid", $session->sid, -1, true);
                redirect("index.php", 'Your account has been authenticated and you have been logged in.<br/> Powered By <a href="http://www.steampowered.com" target="_blank">Steam</a>', 'Login via Steam');
            }
            // close if($steam_info['status'] == 'success')
        }
        // close else
    }
    // close if($mybb->input['action'] == 'steam_login')
}