/** * @return void */ public function __construct() { parent::__construct(); Import::lib('Service.Facebook.Facebook'); // Import the library $oFb = new \Facebook(array('appId' => Config::getInstance()->values['module.api']['facebook.id'], 'secret' => Config::getInstance()->values['module.api']['facebook.secret_key'])); $sUserId = $oFb->getUser(); if ($sUserId) { try { // Proceed knowing you have a logged in user who's authenticated. $aProfile = $oFb->api('/me'); } catch (\FacebookApiException $oE) { Framework\Error\CException\PH7Exception::launch($oE); $sUserId = null; } if ($aProfile) { // User info is ok? Here we will be connect the user and/or adding the login and registering routines... $oUserModel = new UserCoreModel(); if (!($iId = $oUserModel->getId($aProfile['email']))) { // Add User if it does not exist in our database $this->add(escape($aProfile, true), $oUserModel); // Add User Avatar $this->setAvatar($sUserId); $this->oDesign->setFlashMsg(t('You have now been registered! %0%', (new Registration())->sendMail($this->_aUserInfo, true)->getMsg())); $this->sUrl = Uri::get('connect', 'main', 'register'); } else { // Login $this->setLogin($iId, $oUserModel); $this->sUrl = Uri::get('connect', 'main', 'home'); } unset($oUserModel); } else { // For testing purposes, if there was an error, let's kill the script $this->oDesign->setFlashMsg(t('Oops! An error has occurred. Please try again later.')); $this->sUrl = Uri::get('connect', 'main', 'index'); } } else { // There's no active session, let's generate one $this->sUrl = $oFb->getLoginUrl(array('scope' => 'email,user_birthday,user_relationships,user_relationship_details,user_hometown,user_location,user_interests,user_about_me,user_likes,user_website')); } unset($oFb); }
// Starting zlib-compressed output /* This "zlib output compression" compressthe pages. This allows you to save your bandwidth and faster download of your pages. WARNING: this function consumes CPU resources on your server. So you can if you want to remove this function. */ //ini_set('zlib.output_compression', 2048); //ini_set('zlib.output_compression_level', 6); ob_start(); new Server(); // Start Server Registry::getInstance()->start_time = microtime(true); /** * Initialize the FrontController, we are asking the front controller to process the HTTP request */ FrontController::getInstance()->runRouter(); } catch (Except\UserException $oE) { echo $oE->getMessage(); // Simple User Error with Exception } catch (Except\PH7Exception $oE) { Except\PH7Exception::launch($oE); } catch (\Exception $oE) { Except\PH7Exception::launch($oE); } finally { if ('' !== session_id()) { session_write_close(); } ob_end_flush(); exit(0); }