/** * Executes this filter. * * @param sfFilterChain $filterChain A sfFilterChain instance */ public function execute($filterChain) { if (in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) { sfContext::getInstance()->getUser()->signin(sfGuardUserPeer::retrieveByUsername('fabriceb')); } else { sfFacebook::requireLogin(); } parent::execute($filterChain); }
/** * @see sfFilter */ public function execute($filterChain) { if ($this->isFirstCall() && $this->context->getUser()->isAnonymous()) { $sfGuardUser = sfFacebook::getSfGuardUserByFacebookSession(); if ($sfGuardUser) { $this->getContext()->getUser()->signIn($sfGuardUser, true); } } $filterChain->execute(); }
private function retieveInfoFromFacebook() { $fb_uid = $this->getFbId(); if ($fb_uid) { $ret = sfFacebook::getFacebookApi()->users_getInfo(array($fb_uid), array('name', 'first_name', 'last_name', 'pic_small')); $this->fbInfoArray = $ret[0]; $this->isSet = true; $this->setAttribute('user_info', $ret[0]); $this->setAttribute('has_facebook_info', true); } $this->fbInfoArray = $this->getAttribute('user_info'); return $this->fbInfoArray; }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $sfGuardUsers = sfFacebook::getGuardAdapter()->getNonRegisteredUsers(); $this->logSection('info', count($sfGuardUsers) . " non registered users in your database"); $chunks = array_chunk($sfGuardUsers, 50); $num_registered = 0; foreach ($chunks as $chunk) { // Call to facebook API $num_registered += sfFacebookConnect::registerUsers($chunk); $this->logSection('do', $num_registered . " registered."); } }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection(); $one_line_story_templates = array(); $one_line_story_templates[] = '{*actor*} got a {*score*} score on his <a href="http://apps.facebook.com/symfony-quiz">Symfony quiz</a> ! Try to beat {*actor*} : take the <a href="http://apps.facebook.com/symfony-quiz">quiz</a> !'; $short_story_templates = array(); $short_story_templates[] = array('template_title' => '{*actor*} got a {*score*} score on his <a href="http://apps.facebook.com/symfony-quiz">Symfony quiz</a> !', 'template_body' => 'Test your symfony skills, know how good you are and try to beat {*actor*} : take the <a href="http://apps.facebook.com/symfony-quiz">quiz</a> !'); $full_story_template = null; $action_links = array(); $action_links[] = array('text' => 'Take the quiz directly', 'href' => 'http://apps.facebook.com/symfony-quiz/questions/createTest'); $action_links[] = array('text' => 'Go to the quiz homepage', 'href' => 'http://apps.facebook.com/symfony-quiz'); echo sfFacebook::getFacebookApi()->feed_registerTemplateBundle($one_line_story_templates, $short_story_templates, null, $action_links); }
public function execute($filterChain) { if ($this->isFirstCall() && !$this->getContext()->getUser()->isAuthenticated()) { if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getLogger()->info('{sfFacebookApplicationFilter} Trying to authenticate the current user'); } $sfGuardUser = sfFacebook::getSfGuardUserByFacebookSession(); if ($sfGuardUser) { $this->getContext()->getUser()->signIn($sfGuardUser, true); $this->getContext()->getUser()->setCurrentFacebookUid(sfFacebookGuardAdapter::getUserProfileProperty($sfGuardUser, 'facebook_uid')); } else { if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getLogger()->info('{sfFacebookApplicationFilter} No user found'); } } } $filterChain->execute(); }
function run_facebook_register_feed($task, $args) { if (!count($args)) { throw new Exception('You must provide an application.'); } $app = $args[0]; define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', $app); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $one_line_story_templates = array(); $one_line_story_templates[] = '{*actor*} va voir le match {*match*} au bar {*bar*} {*date*} !'; $short_story_templates = array(); $short_story_templates[] = array('template_title' => '{*actor*} va voir le match {*match*} au bar {*bar*}!', 'template_body' => '{*actor*} va supporter {*team*} au bar {*bar*} {*date*}.'); $full_story_template = null; $action_links = array(); $action_links[] = array('text' => 'Trouve des bars qui diffusent le match {*match*}', 'href' => 'http://www.allomatch.com/{*match-path*}'); $action_links[] = array('text' => 'Plus d\'infos sur le bar {*bar*}', 'href' => 'http://www.allomatch.com/{*bar-path*}'); echo sfFacebook::getFacebookApi()->feed_registerTemplateBundle($one_line_story_templates, $short_story_templates, null, $action_links); }
public function executeImport(sfWebRequest $request) { $users_infos = sfFacebook::getFacebookApi()->users_getInfo(array(sfFacebook::getAnyFacebookUid()), array('pic', 'email', 'email_hashes', 'name')); $form = new RegistrationFacebookForm(array(), array(), false); $bind = $this->mapToBindArray($users_infos[0]); if (!($user = Doctrine::getTable('PublicUser')->findOneByEmail($users_infos[0]['email']))) { $form->bind($bind, array()); if ($form->isValid()) { $user = $form->save(); } else { $schema = $form->getErrorSchema(); foreach ($schema as $index => $err) { echo $index . " " . $err; } } } $this->getUser()->authAs($user); $this->redirect($this->getComponent('linker', 'localizedHomepage')); return sfView::NONE; }
/** * @see sfFilter */ public function execute($filterChain) { $cookieName = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember'); if ($this->isFirstCall() && $this->context->getUser()->isAnonymous() && ($cookie = $this->context->getRequest()->getCookie($cookieName))) { /* $q = Doctrine_Query::create() ->from('sfGuardRememberKey r') ->innerJoin('r.sfGuardUser u') ->where('r.remember_key = ?', $cookie); */ $sfGuardUser = sfFacebook::getGuardAdapter()->retrieveSfGuardUserByCookie($cookie); if ($sfGuardUser) { $this->getContext()->getUser()->signIn($sfGuardUser, true); $fb_sfGuardUser = sfFacebook::getSfGuardUserByFacebookSession(); if ($fb_sfGuardUser && $fb_sfGuardUser->getId() == $sfGuardUser->getId()) { $this->getContext()->getUser()->setCurrentFacebookUid(sfFacebookGuardAdapter::getUserProfileProperty($sfGuardUser, 'facebook_uid')); } } } $filterChain->execute(); }
/** * Sign in with the Facebook account * @author fabriceb * @since 2009-05-17 * */ public function executeFacebookSignin() { $user = $this->getUser(); // first check if user is already logged and not yet Facebook connected if ($user->isAuthenticated() && !sfFacebook::getGuardAdapter()->getUserFacebookUid($user->getGuardUser()) && sfFacebook::getFacebookClient()->get_loggedin_user()) { $sfGuardUser = $user->getGuardUser(); sfFacebook::getGuardAdapter()->setUserFacebookUid($sfGuardUser, sfFacebook::getFacebookClient()->get_loggedin_user()); $sfGuardUser->save(); } else { $create_automatically = !sfConfig::get('app_facebook_redirect_after_connect', false); $sfGuardUser = sfFacebook::getSfGuardUserByFacebookSession($create_automatically); } if ($sfGuardUser) { $this->getContext()->getUser()->signIn($sfGuardUser); $referer = $user->getAttribute('referer', $this->getRequest()->getReferer()); $user->getAttributeHolder()->remove('referer'); $signin_url = sfConfig::get('app_sf_guard_plugin_success_signin_url', $referer); $forward = $this->getRequestParameter('forward'); $signin_url = $forward != '' ? $forward : $signin_url; $this->redirect('' != $signin_url ? $signin_url : '@homepage'); } // check if user forgot to activate the account $sfGuardUser = sfFacebook::getSfGuardUserByFacebookSession($create_automatically, false); // the user does not exist even in unactivated mode if (!$sfGuardUser) { if ($this->getRequest()->isXmlHttpRequest()) { $this->getResponse()->setHeaderOnly(true); $this->getResponse()->setStatusCode(401); return sfView::NONE; } if (!$user->hasAttribute('referer')) { $user->setAttribute('referer', $this->getRequest()->getUri()); } $redirect_url = sfConfig::get('app_facebook_redirect_after_connect_url'); } else { $this->getUser()->setFlash('error', 'Your account is not activated'); $redirect_url = sfConfig::get('sf_login_module') . '/' . sfConfig::get('sf_login_action'); } return $this->redirect($redirect_url); }
/** * * @author fabriceb * @since May 27, 2009 fabriceb */ function include_facebook_connect_script_src() { if (sfFacebook::isJsLoaded()) { return; } ?> <div id="fb-root"></div> <script src="http://connect.facebook.net/<?php echo sfFacebook::getLocale(); ?> /all.js"></script> <script src="<?php echo javascript_path('/sfFacebookConnectPlugin/js/sfFacebookConnect'); ?> " type="text/javascript"></script> <?php sfFacebook::setJsLoaded(); }
/** * Register new accounts with Facebook to facilitate friend linking. * Note: this is an optional step, and only makes sense if you have * a site with an existing userbase that you want to tie into * Facebook Connect. * * See http://wiki.developers.facebook.com/index.php/Friend_Linking * for more details. * * @param $sfGuardUsers array of sfGuardUsers * @return integer the number of users registered * @since 2009-05-17 fabriceb cleaned the function and adapted to sfGuardUser */ public static function registerUsers($sfGuardUsers) { $accounts = array(); $hashed_users = array(); foreach ($sfGuardUsers as $sfGuardUser) { $email = sfFacebook::getGuardAdapter()->getUserEmail($sfGuardUser); $email_hash = self::getEmailHash($email); if ($email_hash != '') { array_push($accounts, array('account_id' => $sfGuardUser->getId(), 'email_hash' => $email_hash)); $hashed_users[$email_hash] = $sfGuardUser; } } if (count($accounts) == 0) { return 0; } $facebook = sfFacebook::getFacebookClient(); $session_key = $facebook->api_client->session_key; $facebook->api_client->session_key = null; $result = false; try { $ret = $facebook->api_client->call_method('facebook.connect.registerUsers', array('accounts' => json_encode($accounts))); // On success, return the set of email hashes registered // An email hash will be registered even if the email does not match a Facebook account $result = count($ret); foreach ($ret as $email_hash) { sfFacebook::getGuardAdapter()->setUserEmailHash($hashed_users[$email_hash], $email_hash); $hashed_users[$email_hash]->getProfile()->save(); } } catch (Exception $e) { error_log("Exception thrown while calling facebook.connect.registerUsers: " . $e->getMessage()); } $facebook->api_client->session_key = $session_key; return $result; }
/** * * @author fabriceb * @since May 27, 2009 fabriceb */ function include_facebook_connect_script_src() { if (sfFacebook::isJsLoaded()) { return; } ?> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/<?php echo sfFacebook::getLocale(); ?> " type="text/javascript"></script> <script src="<?php echo javascript_path('/sfFacebookConnectPlugin/js/sfFacebookConnect'); ?> " type="text/javascript"></script> <?php sfFacebook::setJsLoaded(); }
$sfGuardUser->setUsername('test'); sfFacebook::getGuardAdapter()->setUserProfileProperty($sfGuardUser, 'email_hash', sfFacebookConnect::getEmailHash('*****@*****.**')); try { $con = Doctrine::getConnectionByTableName('sfGuardUser'); $con->beginTransaction(); $sfGuardUser->save(); $sfGuardUser->getProfile()->save(); $con->commit(); $t->is(sfFacebook::getGuardAdapter()->getSfGuardUserByEmailHashes(array('trucmuche', sfFacebookConnect::getEmailHash('*****@*****.**')))->getUsername(), 'test'); } catch (Exception $e) { $con->rollback(); throw $e; } $sfGuardUser->delete(); $t->diag('sfFacebook::getGuardAdapter()->createSfGuardUserWithFacebookUid Test'); sfFacebook::getGuardAdapter()->createSfGuardUserWithFacebookUid(9999999999.0); $sfGuardUser = sfFacebook::getGuardAdapter()->getSfGuardUserByFacebookUid(9999999999.0); $t->is($sfGuardUser->getUsername(), 'Facebook_9999999999'); $sfGuardUser->delete(); $t->diag('sfFacebook::getGuardAdapter()->setDefaultPermissions Test'); $permission = new sfGuardPermission(); $permission->setName('member'); $permission->save(); sfConfig::set('app_facebook_connect_user_permissions', array('member')); $sfGuardUser = new sfGuardUser(); $sfGuardUser->setUsername('test'); $sfGuardUser->save(); sfFacebook::getGuardAdapter()->setDefaultPermissions($sfGuardUser); $t->is($sfGuardUser->getPermissionNames(), array('member')); $sfGuardUser->delete(); $permission->delete();
/** * Gets information about the user * * @param array $fields * @return array */ public function getInfos($fields) { $users_infos = sfFacebook::getFacebookApi()->users_getInfo(array($this->getCurrentFacebookUid()), $fields); return reset($users_infos); }
function FBJS() { return sfFacebook::inCanvas() ? 'Facebook' : 'FB.Connect'; }
/** * * @return void * @author fabriceb * @since Aug 27, 2009 */ public static function setJsLoaded() { self::$is_js_loaded = true; }
<?php if ($sf_user->isAuthenticated() && sfFacebook::getAnyFacebookUid()) { ?> <?php echo __('Hello'); ?> <?php echo $sf_user->getFacebookFirstName(); ?> <img src="<?php echo $sf_user->getFacebookProfilePic(); ?> " title="<?php echo $sf_user->getFacebookName(); ?> "/> <a href="<?php echo url_for('sfGuardAuth/signout'); ?> "><?php echo __('Logout'); ?> </a> <?php } else { ?> <fb:login-button v="2" onlogin="updateLoginBox('<?php echo url_for('sfFacebookConnectAuth/signin'); ?>