} else {
             $settingsToAdd[$setting] = 0;
         }
     }
     // Register him
     $user = $FacebookConnect->register($newuser);
     // Insert options and extra data and login
     if (!$user['error']) {
         $db->update_query('users', $settingsToAdd, 'uid = ' . (int) $user['uid']);
         // Sync
         $newUser = array_merge($user, $settingsToAdd);
         $FacebookConnect->sync($newUser);
         // Login
         $FacebookConnect->login($user);
         // Redirect
         $FacebookConnect->redirect($mybb->input['redUrl'], $lang->sprintf($lang->myfbconnect_redirect_title, $user['username']), $lang->myfbconnect_redirect_registered);
     } else {
         $errors = inline_error($user['error']);
     }
 }
 $options = '';
 $settingsToBuild = '';
 // Checking if we want to sync that stuff (admin)
 $settingsToCheck = array('fbavatar', 'fbbday', 'fbsex', 'fbdetails', 'fbbio', 'fblocation');
 foreach ($settingsToCheck as $setting) {
     $tempKey = 'myfbconnect_' . $setting;
     if ($mybb->settings[$tempKey]) {
         $settingsToBuild[] = $setting;
     }
 }
 foreach ($settingsToBuild as $setting) {
function myfbconnect_usercp()
{
    global $mybb, $lang, $inlinesuccess;
    // Load API in certain areas
    if (in_array($mybb->input['action'], array('fblink', 'do_fblink')) or $_SESSION['fblogin'] or $mybb->input['action'] == 'myfbconnect' and $mybb->request_method == 'post') {
        require_once MYBB_ROOT . "inc/plugins/MyFacebookConnect/class_facebook.php";
        $FacebookConnect = new MyFacebook();
    }
    $settingsToCheck = array('fbavatar', 'fbbday', 'fbsex', 'fbdetails', 'fbbio', 'fblocation');
    if (!$lang->myfbconnect) {
        $lang->load('myfbconnect');
    }
    // Authenticate
    if ($mybb->input['action'] == 'fblink') {
        $FacebookConnect->set_fallback('usercp.php?action=do_fblink');
        $FacebookConnect->authenticate();
    }
    // Link account to his Facebook's one
    if ($mybb->input['action'] == 'do_fblink') {
        if (!$FacebookConnect->check_user()) {
            error($lang->myfbconnect_error_noauth);
        }
        $user = $FacebookConnect->get_user('id,verified');
        if ($user) {
            $FacebookConnect->link_user('', $user['id']);
        }
        $FacebookConnect->redirect('usercp.php?action=myfbconnect', '', $lang->myfbconnect_success_linked);
    }
    // Settings page
    if ($mybb->input['action'] == 'myfbconnect') {
        global $db, $theme, $templates, $headerinclude, $header, $footer, $plugins, $usercpnav;
        add_breadcrumb($lang->nav_usercp, 'usercp.php');
        add_breadcrumb($lang->myfbconnect_page_title, 'usercp.php?action=myfbconnect');
        // The user is changing his settings
        if ($mybb->request_method == 'post' or $_SESSION['fblogin']) {
            if ($mybb->request_method == 'post') {
                verify_post_check($mybb->input['my_post_key']);
            }
            // He's unlinking his account
            if ($mybb->input['unlink']) {
                $FacebookConnect->unlink_user();
                redirect('usercp.php?action=myfbconnect', $lang->myfbconnect_success_accunlinked, $lang->myfbconnect_success_accunlinked_title);
            } else {
                $settings = array();
                foreach ($settingsToCheck as $setting) {
                    $settings[$setting] = 0;
                    if ($mybb->input[$setting] == 1) {
                        $settings[$setting] = 1;
                    }
                    // Build a list of parameters to include in the fallback URL
                    $loginUrlExtra .= "&{$setting}=" . $settings[$setting];
                }
                // This user is not logged in with Facebook
                if (!$FacebookConnect->check_user()) {
                    // Store a token in the session, we will check for it in the next call
                    $_SESSION['fblogin'] = 1;
                    $FacebookConnect->set_fallback("usercp.php?action=myfbconnect" . $loginUrlExtra);
                    $FacebookConnect->authenticate();
                    return;
                }
                if ($db->update_query('users', $settings, 'uid = ' . (int) $mybb->user['uid'])) {
                    unset($_SESSION['fblogin']);
                    $newUser = array_merge($mybb->user, $settings);
                    $FacebookConnect->sync($newUser);
                    redirect('usercp.php?action=myfbconnect', $lang->myfbconnect_success_settingsupdated, $lang->myfbconnect_success_settingsupdated_title);
                }
            }
        }
        $options = '';
        if ($mybb->user['myfb_uid']) {
            $userSettings = array();
            // Checking if admins and users want to sync that stuff
            foreach ($settingsToCheck as $setting) {
                $tempKey = 'myfbconnect_' . $setting;
                if (!$mybb->settings[$tempKey]) {
                    continue;
                }
                $userSettings[$setting] = 0;
                if ($mybb->user[$setting]) {
                    $userSettings[$setting] = 1;
                }
            }
            $text = $lang->myfbconnect_settings_whattosync;
            $unlink = "<input type=\"submit\" class=\"button\" name=\"unlink\" value=\"{$lang->myfbconnect_settings_unlink}\" />";
            if ($userSettings) {
                foreach ($userSettings as $setting => $value) {
                    $tempKey = 'myfbconnect_settings_' . $setting;
                    $checked = '';
                    if ($value) {
                        $checked = " checked=\"checked\"";
                    }
                    $label = $lang->{$tempKey};
                    $altbg = alt_trow();
                    eval("\$options .= \"" . $templates->get('myfbconnect_usercp_settings_setting') . "\";");
                }
            } else {
                $text = $lang->myfbconnect_settings_connected;
            }
        } else {
            $text = $lang->myfbconnect_settings_linkaccount;
            eval("\$options = \"" . $templates->get('myfbconnect_usercp_settings_linkprofile') . "\";");
        }
        eval("\$content = \"" . $templates->get('myfbconnect_usercp_settings') . "\";");
        output_page($content);
    }
}