XenForo_Application::set('page_start_time', $startTime);
XenForo_Application::disablePhpErrorHandler();
XenForo_Application::setDebugMode(false);
XenForo_Application::$externalDataPath = $fileDir . '/data';
XenForo_Application::$externalDataUrl = $fileDir . '/data';
XenForo_Application::$javaScriptUrl = $fileDir . '/js';
restore_error_handler();
restore_exception_handler();
$options = XenForo_Application::get('options');
$STEAM_GAMEBANNER = $options->steamDisplayBanner;
if (!empty($_GET['steamids'])) {
    /*
     * Fetch profile data
     */
    $sHelper = new Steam_Helper_Steam();
    $steamProfileAPI = $sHelper->getSteamProfileAPI($_GET['steamids']);
    $fullProfile = $_GET['fullprofile'];
    $contentJson = $sHelper->getJsonData($steamProfileAPI);
    $contentDecoded = json_decode($contentJson);
    if (isset($contentDecoded->response->players)) {
        foreach ($contentDecoded->response->players as $rows) {
            /*
             * Setup CDN on avatar URLs
             */
            $avatarPath = parse_url($rows->avatar);
            $rows->avatar = $sHelper->getSteamCDNDomain($avatarPath["path"]);
            /*
             * Apply game image to SteamProfile and use HTTPS if enabled
             */
            if ($fullProfile == 1 && isset($rows->gameid) && $STEAM_GAMEBANNER > 0) {
                $appid = $rows->gameid;
 public function actionSteamRegister()
 {
     $this->_assertPostOnly();
     $session = XenForo_Application::get('session');
     if (!$session->get('steam_id')) {
         return $this->responseError('Lost Steam ID');
     }
     // Get User Profile Data
     $id = $session->get('steam_id');
     $sHelper = new Steam_Helper_Steam();
     $steamProfileAPI = $sHelper->getSteamProfileAPI($id);
     $json_object = $sHelper->getJsonData($steamProfileAPI);
     $json_decoded = json_decode($json_object);
     if (!empty($json_decoded)) {
         $username = $json_decoded->response->players[0]->personaname;
         $avatar = $json_decoded->response->players[0]->avatarfull;
     }
     $userModel = $this->_getUserModel();
     $userExternalModel = $this->_getUserExternalModel();
     $doAssoc = $this->_input->filterSingle('associate', XenForo_Input::STRING) || $this->_input->filterSingle('force_assoc', XenForo_Input::UINT);
     if ($doAssoc) {
         $userId = $this->_associateExternalAccount();
         $userExternalModel->updateExternalAuthAssociation('steam', $id, $userId);
         $this->updateUserStats($userId, $id);
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $this->getDynamicRedirect(false, false));
     }
     $data = $this->_input->filter(array('username' => XenForo_Input::STRING, 'timezone' => XenForo_Input::STRING, 'email' => XenForo_Input::STRING, 'gender' => XenForo_Input::STRING, 'location' => XenForo_Input::STRING, 'dob_day' => XenForo_Input::UINT, 'dob_month' => XenForo_Input::UINT, 'dob_year' => XenForo_Input::UINT));
     if (XenForo_Dependencies_Public::getTosUrl() && !$this->_input->filterSingle('agree', XenForo_Input::UINT)) {
         return $this->responseError(new XenForo_Phrase('you_must_agree_to_terms_of_service'));
     }
     $options = XenForo_Application::get('options');
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     if ($options->registrationDefaults) {
         $writer->bulkSet($options->registrationDefaults, array('ignoreInvalidFields' => true));
     }
     $writer->bulkSet($data);
     $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
     $writer->set('scheme_class', $auth->getClassName());
     $writer->set('data', $auth->generate(''), 'xf_user_authenticate');
     $writer->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
     $writer->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
     $customFields = $this->_input->filterSingle('custom_fields', XenForo_Input::ARRAY_SIMPLE);
     $customFieldsShown = $this->_input->filterSingle('custom_fields_shown', XenForo_Input::STRING, array('array' => true));
     $writer->setCustomFields($customFields, $customFieldsShown);
     $writer->advanceRegistrationUserState(false);
     $writer->preSave();
     if ($options->get('registrationSetup', 'requireDob')) {
         // dob required
         if (!$data['dob_day'] || !$data['dob_month'] || !$data['dob_year']) {
             $writer->error(new XenForo_Phrase('please_enter_valid_date_of_birth'), 'dob');
         } else {
             $userAge = $this->_getUserProfileModel()->getUserAge($writer->getMergedData(), true);
             if ($userAge < 1) {
             } else {
                 if ($userAge < intval($options->get('registrationSetup', 'minimumAge'))) {
                     // TODO: set a cookie to prevent re-registration attempts
                     // But I don't care
                     $writer->error(new XenForo_Phrase('sorry_you_too_young_to_create_an_account'));
                 }
             }
         }
     }
     $writer->save();
     $user = $writer->getMergedData();
     if (!$options->steamAvatarReg) {
         unset($avatar);
     }
     if (!empty($avatar)) {
         $avatarFile = tempnam(XenForo_Helper_File::getTempDir(), 'xf');
         $httpClient = XenForo_Helper_Http::getClient(preg_replace('/\\s+/', '%20', $avatar));
         $response = $httpClient->request('GET');
         if ($response->isSuccessful()) {
             file_put_contents($avatarFile, $response->getBody());
         }
         // Apply Avatar
         try {
             $user = array_merge($user, $this->getModelFromCache('XenForo_Model_Avatar')->applyAvatar($user['user_id'], $avatarFile));
         } catch (XenForo_Exception $e) {
         }
         @unlink($avatarFile);
     }
     $userExternalModel->updateExternalAuthAssociation('steam', $id, $user['user_id']);
     XenForo_Model_Ip::log($user['user_id'], 'user', $user['user_id'], 'register');
     /* Cookies */
     $userModel->setUserRememberCookie($user['user_id']);
     $session->changeUserId($user['user_id']);
     XenForo_Visitor::setup($user['user_id']);
     $this->updateUserStats($user['user_id'], $id);
     $redirect = $this->_input->filterSingle('redirect', XenForo_Input::STRING);
     $viewParams = array('user' => $user, 'redirect' => $redirect ? XenForo_Link::convertUriToAbsoluteUri($redirect) : '', 'steam' => true);
     return $this->responseView('XenForo_ViewPublic_Register_Process', 'register_process', $viewParams, $this->_getRegistrationContainerParams());
 }