예제 #1
2
파일: connect.php 프로젝트: anantgarg/kudos
function facebook()
{
    global $template;
    $facebook = new Facebook(array('appId' => FB_APPID, 'secret' => FB_APPSECRET));
    $user = $facebook->getUser();
    if ($user) {
        try {
            $pages = $facebook->api('/me/accounts');
            $template->set('pages', $pages);
            $permissions = $facebook->api("/me/permissions");
            $publish_actions = 0;
            $manage_pages = 0;
            foreach ($permissions['data'] as $permission) {
                if ($permission['permission'] == 'publish_actions') {
                    $publish_actions = 1;
                }
                if ($permission['permission'] == 'manage_pages') {
                    $manage_pages = 1;
                }
            }
            if ($publish_actions == 0 || $manage_pages == 0) {
                throw new Exception("Oops");
            }
        } catch (Exception $e) {
            $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
            header("Location: " . $url);
            exit;
        }
    } else {
        $url = $facebook->getLoginUrl(array("scope" => "publish_actions,manage_pages"));
        header("Location: " . $url);
        exit;
    }
}
예제 #2
0
 /**
  * Redirect user to facebook to obtain params
  * @return string - user id
  */
 public function runAuth()
 {
     $user = $this->facebook->getUser();
     if (!$user) {
         if (!$this->isAjax()) {
             redirect($this->getLoginUrl());
         } else {
             // output json
             $this->renderJson(array('loginUrl' => $this->getLoginUrl()));
         }
     }
     return $user;
 }
예제 #3
0
 /**
  * Log a user in
  * @return Array Userdata
  * @throws FacebookApiException
  */
 public function login($grabUserImage = false)
 {
     $uid = $this->_client->getUser();
     $accessToken = $this->_client->getAccessToken();
     // If a user is authenticated, $userData will be filled with user data
     $userData = $this->_client->api('/me');
     if ($grabUserImage) {
         $apiUrl = '/' . $this->_client->getUser() . '/picture?redirect=0&type=large';
         $picture = $this->_client->api($apiUrl);
         $userData['imageUrl'] = $picture['data']['url'];
     }
     $userData['access_token'] = $accessToken;
     return $userData;
 }
 public function getInput()
 {
     if ($this->fb->getUser()) {
         $user = $this->fb->getUser();
         $profile = $this->fb->api("/me?fields=id,name,picture");
         $label = "<img src='" . $profile['picture']['data']['url'] . "' />" . $profile['name'];
         $logout = $this->fb->getLogoutUrl(array('next' => JURI::base()));
         return $label . "<br /><a href='" . $logout . "'>Log out of Facebook</a>";
     } else {
         // Not logged in - display a login link
         $uri = JURI::current();
         $loginUrl = $this->fb->getLoginUrl(array('redirect_uri' => "http://aquinas.dphin.co.uk/login/profile?layout=edit"));
         return "<a href='" . $loginUrl . "'>Connect your Facebook account</a>";
     }
 }
예제 #5
0
 public function call()
 {
     //echo $this->_fbLoginRedirectUrl;exit;
     // Create our Application instance (replace this with your appId and secret).
     $facebook = new Facebook(array('appId' => $this->_fbAppId, 'secret' => $this->_fbAppSecret, 'cookie' => false));
     // Get User ID
     $this->_fbUser = $facebook->getUser();
     // We may or may not have this data based on whether the user is logged in.
     // If we have a $user id here, it means we know the user is logged into
     // Facebook, but we don't know if the access token is valid. An access
     // token is invalid if the user logged out of Facebook.
     if ($this->_fbUser) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $this->_fbUserProfile = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             error_log($e);
             $this->_fbUser = null;
         }
     }
     // Login or logout url will be needed depending on current user state.
     if ($this->_fbUser) {
         $this->_fbLogoutUrl = $facebook->getLogoutUrl(array("next" => $this->_fbLogoutRedirectUrl));
     } else {
         $this->_fbLoginUrl = $facebook->getLoginUrl(array('redirect_uri' => $this->_fbLoginRedirectUrl));
         //echo $this->_fbLoginUrl;exit;
     }
 }
 private function face($access_token, $dataConfig)
 {
     require_once 'php-sdk/src/facebook.php';
     $facebook = new Facebook($dataConfig);
     $facebook->setAccessToken($access_token);
     Zend_Debug::dump($user = $facebook->getUser());
     if ($user) {
         $this->view->faceUrl = $facebook->getLogoutUrl();
     } else {
         $this->view->faceUrl = $facebook->getLoginUrl();
     }
     Zend_Debug::dump($_REQUEST);
     Zend_Debug::dump($naitik = $facebook->api('/100000874886897'));
     if ($user) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $user_profile = $facebook->api('/me');
             print_r($user_profile);
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     $this->view->user = $naitik;
 }
 public function doLogin()
 {
     $code = Input::get('code');
     if (strlen($code) == 0) {
         return Redirect::to('/')->with('message', 'There was an error communicating with Facebook');
     }
     $facebook = new Facebook(Config::get('facebook'));
     $uid = $facebook->getUser();
     if ($uid == 0) {
         return Redirect::to('/')->with('message', 'There was an error');
     }
     $me = $facebook->api('/me', ['fields' => ['id', 'first_name', 'last_name', 'picture', 'email', 'gender']]);
     $profile = Profile::whereUid($uid)->first();
     if (empty($profile)) {
         $user = new User();
         $user->name = $me['first_name'] . ' ' . $me['last_name'];
         $user->email = $me['email'];
         $user->photo = 'https://graph.facebook.com/' . $me['id'] . '/picture?type=large';
         $user->save();
         $profile = new Profile();
         $profile->uid = $uid;
         $profile->username = $me['id'];
         $profile->gender = $me['gender'];
         $profile = $user->profiles()->save($profile);
     }
     $profile->access_token = $facebook->getAccessToken();
     $profile->save();
     $user = $profile->user;
     Auth::login($user);
     return Redirect::to('/')->with('message', 'Logged in with Facebook');
 }
예제 #8
0
 function connectFacebook()
 {
     $this->autoRender = false;
     $facebook = new Facebook(array('appId' => $this->facebookAppId, 'secret' => $this->facebookSecret));
     $user = $facebook->getUser();
     if ($user) {
         try {
             $user_profile = $facebook->api('/me');
             $userinfo = $this->User->find('first', array('conditions' => array('User.username' => isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'], 'User.social_connect' => 'facebook')));
             if (empty($userinfo)) {
                 $data['User']['username'] = isset($user_profile['id']) ? $user_profile['id'] : $user_profile['email'];
                 $data['User']['password'] = $user_profile['id'];
                 $data['User']['group_id'] = $this->socialLoginGroupId;
                 $data['User']['social_connect'] = 'facebook';
                 $data['User']['social_info'] = json_encode($user_profile);
                 $this->User->create();
                 $this->User->save($data);
                 $userinfo = $this->User->find('first', array('conditions' => array('User.id' => $this->User->id)));
                 $this->makeUserLogin($userinfo);
             } else {
                 $this->makeUserLogin($userinfo);
             }
         } catch (Exception $e) {
             error_log($e->getMessage());
             $this->Session->setFlash($e->getMessage());
             $user = NULL;
         }
     } else {
         $this->Session->setFlash('Sorry.Please try again');
     }
     $this->render('Social/close_window');
 }
예제 #9
0
파일: Welcome.php 프로젝트: binhhv/job
 public function acceptLogin()
 {
     $facebook = new Facebook(array('appId' => '1494342414191651', 'secret' => '775288a56787896f92da0f2096c6de7c'));
     if (!is_null($this->session->userdata('fb'))) {
         //redirect('/');
         redirect('/home');
     } else {
         $user = $facebook->getUser();
         if ($user) {
             $user_profile = null;
             try {
                 //Proceed knowing you have a logged in user who's authenticated.
                 $user_profile = $facebook->api('/me');
                 var_dump($user_profile);
             } catch (FacebookApiException $e) {
                 error_log($e);
                 //$user = null;
                 $this->loadview('404');
             }
             $logoutUrl = $facebook->getLogoutUrl();
             $data = array('fb' => array('user_id' => $user, 'name' => $user_profile['name'], 'logout' => $logoutUrl));
             $this->session->set_userdata($data);
             redirect('/');
         } else {
             header('Location:' . $facebook->getLoginUrl());
             //$this->load->view('404');
             //$this->loadview('404');
         }
     }
 }
예제 #10
0
function fbpromo_clientarea($vars)
{
    global $_LANG;
    require dirname(__FILE__) . "/src/facebook.php";
    $app_id = fbpromo_get_addon('appid');
    $application_secret = fbpromo_get_addon('appsecret');
    $facebook = new Facebook(array('appId' => $app_id, 'secret' => $application_secret));
    // Get User ID
    $user = $facebook->getUser();
    // We may or may not have this data based on whether the user is logged in.
    //
    // If we have a $user id here, it means we know the user is logged into
    // Facebook, but we don't know if the access token is valid. An access
    // token is invalid if the user logged out of Facebook.
    if ($user) {
        try {
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');
        } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }
    }
    require dirname(__FILE__) . '/clientarea.php';
    die;
}
예제 #11
0
function getFacebookUserDetails($params)
{
    //$graph_url = "https://graph.facebook.com/me?access_token=$access_token";
    //
    // 	$ch = curl_init();
    // 	curl_setopt($ch, CURLOPT_URL, $graph_url);
    // 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // 	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // 	$user = @json_decode(curl_exec($ch));
    //	curl_close($ch);
    //    return $user;
    //die(print_r(realpath(dirname(__FILE__))));
    //echo '8888';
    //$CI =& get_instance();
    //echo '7777';
    //$CI->load->library('facebook');
    //die( base_url() );
    //echo 'base...'.$params->base_dir;
    require_once $params->base_dir . '/server/facebook.php';
    $facebook = new Facebook(array('appId' => $params->app_id, 'secret' => $params->app_secret));
    $user = $facebook->getUser();
    if ($user) {
        try {
            // Proceed knowing you have a logged in user who's authenticated.
            $user_profile = $facebook->api('/me');
        } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }
        return $user_profile;
    }
}
예제 #12
0
 function try_connect($pubit = 0, $stUrl = '', $PublishMessage = '')
 {
     $myparams =& JComponentHelper::getParams('com_fbjconnect');
     $getappid = $myparams->get('appid');
     $getappsec = $myparams->get('appsecret');
     $access_token = "";
     $uid = "";
     $postresult = false;
     $facebook = new Facebook(array('appId' => $getappid, 'secret' => $getappsec, 'cookie' => true));
     $session = $facebook->getSession();
     $me = null;
     $uid = "";
     if ($session) {
         try {
             $access_token = $facebook->getAccessToken();
             $me = $facebook->api('/me');
             $uid = $facebook->getUser();
             if ($pubit == 1) {
                 $fbpic = JURI::base() . 'modules/mod_jfbgconnect/fgimage.jpg';
                 $postresult = $facebook->api('/me/feed/', 'post', array('access_token' => $access_token, 'picture' => $fbpic, 'link' => $stUrl, 'message' => $PublishMessage));
             }
         } catch (FacebookApiException $e) {
             error_log($e);
         }
     }
     return array($uid, $me, $session, $access_token, $postresult);
 }
 /**
  * Function for check login
  *
  */
 public function login()
 {
     // Setting the page title
     $this->set("title_for_layout", "User Login");
     if ($this->Auth->login()) {
         $this->redirect($this->Auth->redirect());
     } else {
         if ($this->request->is('post')) {
             $this->Session->setFlash(__('Invalid username or password, try again'));
         }
     }
     $facebooksecretkey = '4753a9042404a78aaff1069f73aa8994';
     $facebookapikey = '203755806382341';
     App::import('Vendor', 'facebook', array('file' => 'facebook/src/facebook.php'));
     $facebook = new Facebook(array('appId' => "{$facebookapikey}", 'secret' => "{$facebooksecretkey}"));
     $user = $facebook->getUser();
     $facebookLoginUrl = $facebook->getLoginUrl();
     $this->set('facebookLoginUrl', $facebookLoginUrl);
     if ($user) {
         $faceBookUserProfile = $facebook->api('/me');
         if (isset($faceBookUserProfile) && !empty($faceBookUserProfile)) {
             $this->facebook($faceBookUserProfile);
         }
     }
     //ends here
 }
예제 #14
0
 public function get_user_data_fb()
 {
     parse_str($_SERVER['QUERY_STRING'], $_REQUEST);
     $facebook = new Facebook(array('appId' => '876274572459160', 'secret' => 'c44768470ff9f9d7a52784f6f5fbfd9a', 'cookie' => true, 'redirect_uri' => 'kepoabis.com'));
     Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
     Facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
     $user = $facebook->getUser();
     $user_data = array();
     if ($user) {
         try {
             $user_data = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     $url = "";
     $img = "";
     if ($user) {
         $url = "<strong><em>You are connected with Facebook.<br></em></strong>";
         //$facebook->getLogoutUrl();
         $img = "https://graph.facebook.com/" . $user . "/picture";
     } else {
         $url = "<a class='btn btn-default btn-social btn-facebook' href=" . $facebook->getLoginUrl() . "><i class='fa fa-facebook'></i>Sign in with Facebook</a>";
     }
     return array("url" => $url, "img" => $img, "is_login" => $user, "user_data" => $user_data);
 }
 /**
  * Try to login with Facebook and return true on success
  * @return boolean
  */
 protected function loginWithFacebook()
 {
     $objFacebook = new Facebook(array('appId' => $this->fblogin_appId, 'secret' => $this->fblogin_appKey));
     $arrProfile = false;
     if ($objFacebook->getUser() > 0) {
         try {
             $arrProfile = $objFacebook->api('/me?fields=id,name,first_name,last_name,email,gender');
         } catch (FacebookApiException $e) {
             $arrProfile = false;
             $this->log('Could not fetch the Facebook data: ' . $e->getMessage(), 'ModuleFacebookLogin loginWithFacebook()', TL_ERROR);
         }
     }
     // Log the error message
     if (!$arrProfile) {
         $this->log('Could not fetch the Facebook user.', 'ModuleFacebookLogin loginWithFacebook()', TL_ERROR);
         return false;
     }
     $time = time();
     $objUser = $this->Database->prepare("SELECT id FROM tl_member WHERE fblogin=? AND login=1 AND (start='' OR start<{$time}) AND (stop='' OR stop>{$time}) AND disable=''")->limit(1)->execute($arrProfile['id']);
     // Create a new user if none found
     if (!$objUser->numRows) {
         $objUser = $this->createNewUser($arrProfile);
         if ($objUser === false) {
             return false;
         }
     }
     $this->import('FrontendUser', 'User');
     return $this->User->login($arrProfile);
 }
	public function authenticateFacebook() {
		$fbconfig = Yum::module()->facebookConfig;
		if (!$fbconfig || $fbconfig && !is_array($fbconfig))
			throw new Exception('actionLogout for Facebook was called, but is not activated in application configuration');

		Yii::import('application.modules.user.vendors.facebook.*');
		require_once('Facebook.php');
		$facebook = new Facebook($fbconfig);

		$fb_uid = $facebook->getUser();
		$profile = YumProfile::model()->findByAttributes(array('facebook_id'=>$fb_uid));
		$user = ($profile) ? YumUser::model()->findByPk($profile->user_id) : null;
		if ($user === null)
			$this->errorCode = self::ERROR_USERNAME_INVALID;
		else if($user->status == YumUser::STATUS_INACTIVE)
			$this->errorCode = self::ERROR_STATUS_INACTIVE;
		else if($user->status == YumUser::STATUS_BANNED)
			$this->errorCode = self::ERROR_STATUS_BANNED;
		else
		{
			$this->id = $user->id;
			$this->username = '******';
			$this->facebook_id = $fb_uid;
			//$this->facebook_user = $facebook->api('/me');
			$this->errorCode = self::ERROR_NONE;
		}
	}
예제 #17
0
 public function actionFacebook()
 {
     require_once 'facebook/facebook.php';
     $facebook = new Facebook(array('appId' => Yii::app()->params['facebookAppId'], 'secret' => Yii::app()->params['facebookSecretCode'], 'cookie' => true));
     $user = $facebook->getUser();
     if (isset($_POST['Member']['memberid'])) {
         $memberdata = Member::model()->getMemberById($_POST['Member']['memberid']);
         $this->actMemberinfo($memberdata, '', '', '', 'facebook', '');
     } else {
         if (!empty($user)) {
             //Active session, let's try getting the user id (getUser()) and user info (api->('/me'))
             try {
                 //$facebookuserid = $facebook->getUser();
                 $facebookuser = $facebook->api('/me');
                 //print_r($facebookuser);
             } catch (FacebookApiException $e) {
                 error_log($e);
             }
             if (!empty($facebookuser)) {
                 $memberdata = Member::model()->getMemberByOauth($facebookuser['id']);
                 $this->actMemberinfo($memberdata, '', '', $facebookuser, 'facebook', '');
             } else {
                 //For testing purposes, if there was an error, let's kill the script
                 die("There was an error.");
             }
         } else {
             //There's no active session, let's generate one
             $login_url = $facebook->getLoginUrl(array('scope' => 'email'));
             // echo $login_url;
             header("Location: " . $login_url);
         }
     }
 }
예제 #18
0
 /**
  * Render method
  * @return void
  */
 public function render()
 {
     $config = array('appId' => $this->arguments['id'], 'secret' => $this->arguments['secret'], 'allowSignedRequest' => false);
     $facebook = new Facebook($config);
     $user_id = $facebook->getUser();
     $this->renderChildren();
 }
 public function process_request($request)
 {
     if ($request == 'facebook-login') {
         $app_id = qa_opt('facebook_app_id');
         $app_secret = qa_opt('facebook_app_secret');
         $tourl = qa_get('to');
         if (!strlen($tourl)) {
             $tourl = qa_path_absolute('');
         }
         if (strlen($app_id) && strlen($app_secret)) {
             require_once $this->directory . 'facebook.php';
             $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
             $fb_userid = $facebook->getUser();
             if ($fb_userid) {
                 try {
                     $user = $facebook->api('/me?fields=email,name,verified,location,website,about,picture.width(250)');
                     if (is_array($user)) {
                         qa_log_in_external_user('facebook', $fb_userid, array('email' => @$user['email'], 'handle' => @$user['name'], 'confirmed' => @$user['verified'], 'name' => @$user['name'], 'location' => @$user['location']['name'], 'website' => @$user['website'], 'about' => @$user['bio'], 'avatar' => strlen(@$user['picture']['data']['url']) ? qa_retrieve_url($user['picture']['data']['url']) : null));
                     }
                 } catch (FacebookApiException $e) {
                 }
             } else {
                 qa_redirect_raw($facebook->getLoginUrl(array('redirect_uri' => $tourl)));
             }
         }
         qa_redirect_raw($tourl);
     }
 }
예제 #20
0
 public function postar($dados, $usuario)
 {
     require 'complements/facebook/Facebook.php';
     $facebook = new Facebook(array('appId' => '1651517385125370', 'secret' => '84b4334e3cfe153b5a4348407709cbf0'));
     // Get User ID
     $user = $facebook->getUser();
     if ($user) {
         try {
             echo "teste";
             exit;
             $page_id = $usuario;
             $page_info = $facebook->api("/{$page_id}?fields=access_token");
             if (!empty($page_info['access_token'])) {
                 $args = array('access_token' => $page_info['access_token'], 'message' => $dados[texto]);
                 $post_id = $facebook->api("/{$page_id}/feed", "post", $args);
             } else {
                 $permissions = $facebook->api("/me/permissions");
                 if (!array_key_exists('publish_stream', $permissions['data'][0]) || !array_key_exists('manage_pages', $permissions['data'][0])) {
                     // We don't have one of the permissions
                     // Alert the admin or ask for the permission!
                     header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")));
                 }
             }
         } catch (FacebookApiException $e) {
             error_log($e);
             $user = null;
         }
     }
     // Login or logout url will be needed depending on current user state.
     if ($user) {
         $logoutUrl = $facebook->getLogoutUrl();
     } else {
         $loginUrl = $facebook->getLoginUrl(array('scope' => 'manage_pages,publish_stream'));
     }
 }
예제 #21
0
 public function authenticate()
 {
     $session = Yii::app()->session;
     $facebook = new Facebook(array('appId' => $this->key, 'secret' => $this->secret));
     $here = Yii::app()->request->hostInfo . Yii::app()->request->url;
     // Get User ID
     $user = $facebook->getUser();
     // already logged in
     if (isset($user)) {
         try {
             // Proceed knowing you have a logged in user who's authenticated.
             $user_profile = $facebook->api('/me');
             $session['facebook_user'] = $user_profile;
             $this->_authenticated = true;
         } catch (FacebookApiException $e) {
             $user = null;
             $params = array("scope" => "user_birthday,email,read_stream");
             $loginUrl = $facebook->getLoginUrl($params);
             Yii::app()->request->redirect($loginUrl);
         }
         // Log in!
     } else {
         $params = array("scope" => "user_birthday,email,read_stream");
         $loginUrl = $facebook->getLoginUrl($params);
         Yii::app()->request->redirect($loginUrl);
     }
     return $this->_authenticated;
 }
예제 #22
0
 function loginByOpenID()
 {
     $post = $_POST;
     $get = $_GET;
     $request = $_REQUEST;
     $site = $this->siteUrl();
     $callBackUrl = $this->callBackUrl();
     $response = new stdClass();
     $a = explode('_', $this->get_var(parent::$loginKey));
     $action = $a[1];
     $options = $this->getOptions();
     $config = array('appId' => $options['facebook_key'], 'secret' => $options['facebook_secret']);
     $facebook = new Facebook($config);
     if ($action == 'login') {
         $loginUrl = $facebook->getLoginUrl(array('redirect_uri' => $callBackUrl . parent::$loginKey . '=' . self::$loginBy . '_check', 'scope' => 'email'));
         $this->redirect($loginUrl);
         exit;
     } else {
         echo "jay";
         die;
         $user = $facebook->getUser();
         if ($user) {
             try {
                 // Proceed knowing you have a logged in user who's authenticated.
                 $user_profile = $facebook->api('/me');
             } catch (FacebookApiException $e) {
                 error_log($e);
                 $user = null;
             }
         }
         if ($user != null) {
             $response->status = 'SUCCESS';
             $response->deuid = $user_profile['id'];
             $response->deutype = 'facebook';
             $response->first_name = $user_profile['first_name'];
             $response->last_name = $user_profile['last_name'];
             $response->email = $user_profile['email'];
             $response->username = $user_profile['email'];
             ////['id'].'@facebook';
             $headers = get_headers('https://graph.facebook.com/' . $user_profile['id'] . '/picture', 1);
             // just a precaution, check whether the header isset...
             if (isset($headers['Location'])) {
                 $response->deuimage = $headers['Location'];
                 // string
             } else {
                 $response->deuimage = false;
                 // nothing there? .. weird, but okay!
             }
             $response->error_message = '';
         } else {
             $response->status = 'ERROR';
             $response->error_code = 2;
             $response->error_message = 'INVALID AUTHORIZATION';
         }
     }
     return $response;
 }
예제 #23
0
 /**
  * Facebook login 
  */
 public function actionlogin()
 {
     require_once Yii::app()->basePath . '/vendor/facebook-php-sdk/src/facebook.php';
     $facebook = new Facebook(array('appId' => '894567207287021', 'secret' => 'cf43d6c081acaed16c908cac9d49bc07'));
     $fbUser = $facebook->getUser();
     $loginUrl = $facebook->getLoginUrl(array('redirect_uri' => "http://localhost/olx/index.php?r=/social/listing", 'cancel_uri' => '', 'scope' => 'email,user_likes'));
     $this->redirect($loginUrl);
     die;
     $this->render('login', array('data' => array('facebook' => $facebook)));
 }
예제 #24
0
 public static function userID()
 {
     $config = array();
     $config['appId'] = '314321845272806';
     $config['secret'] = '41092253be637c17fe70cddc2d481375';
     $config['fileUpload'] = true;
     // optional
     $facebook = new Facebook($config);
     return $facebook->getUser();
 }
예제 #25
0
 protected function _connectCallback()
 {
     $helper = Mage::helper('social/facebook');
     $storeId = Mage::app()->getStore()->getStoreId();
     $websiteId = Mage::app()->getStore()->getWebsiteId();
     $facebook = new Facebook(array('appId' => $helper->getFacebookConfig('client_id', $storeId), 'secret' => $helper->getFacebookConfig('client_secret', $storeId)));
     $fid = $facebook->getUser();
     $ftoken = $facebook->getAccessToken();
     if ($fid) {
         try {
             $data = $facebook->api('/me');
             $customersByFacebookId = Mage::helper('social/facebook')->getCustomersByFacebookId($fid, $websiteId);
             if (Mage::getSingleton('customer/session')->isLoggedIn()) {
                 if ($customersByFacebookId->getSize()) {
                     Mage::getSingleton('core/session')->addNotice($this->__('Your facebook account is already connected to one of our store accounts.'));
                     return $this;
                 }
                 $customer = Mage::getSingleton('customer/session')->getCustomer();
                 Mage::helper('social/facebook')->connectByFacebookId($customer, $fid, $ftoken);
                 Mage::getSingleton('core/session')->addSuccess($this->__('Your facebook account is now connected to your store account. You can now login using our facebook login button or using store account credentials you will receive to your email address.'));
                 return $this;
             }
             if ($customersByFacebookId->getSize()) {
                 $customer = $customersByFacebookId->getFirstItem();
                 Mage::helper('social/facebook')->loginByCustomer($customer);
                 Mage::getSingleton('core/session')->addSuccess($this->__('You have successfully logged in using your facebook account.'));
                 return $this;
             }
             $customersByEmail = Mage::helper('social/facebook')->getCustomersByEmail($data['email'], $websiteId);
             if ($customersByEmail->getSize()) {
                 $customer = $customersByEmail->getFirstItem();
                 Mage::helper('social/facebook')->connectByFacebookId($customer, $fid, $ftoken);
                 Mage::getSingleton('core/session')->addSuccess($this->__('We have discovered you already have an account at our store. Your facebook account is now connected to your store account.'));
                 return $this;
             }
             $firstName = $data['first_name'];
             if (empty($firstName)) {
                 throw new Exception($this->__('Sorry, could not retrieve your facebook first name. Please try again.'));
             }
             $lastName = $data['last_name'];
             if (empty($lastName)) {
                 throw new Exception($this->__('Sorry, could not retrieve your facebook last name. Please try again.'));
             }
             Mage::helper('social/facebook')->connectByCreatingAccount($data['email'], $data['first_name'], $data['last_name'], $fid, $ftoken);
             Mage::getSingleton('core/session')->addSuccess($this->__('Your facebook account is now connected to your new user account at our store. Now you can login using our facebook login button or using store account credentials you will receive to your email address.'));
             return $this;
         } catch (Exception $e) {
             Mage::getSingleton('core/session')->addError($this->__($e->getMessage()));
             return $this;
         }
     } else {
         Mage::getSingleton('core/session')->addError($this->__('Sorry, could not login. Please try again.'));
         return $this;
     }
 }
예제 #26
0
 /**
  * Render the facebook user viewhelper
  *
  * @param string $id
  * @param string $secret
  * @param string $string 
  * @return var $output
  * 
  */
 public function render($id, $secret, $string)
 {
     $config = array('appId' => $id, 'secret' => $secret, 'allowSignedRequest' => false);
     $facebook = new Facebook($config);
     $user_id = $facebook->getUser();
     if ($user_id) {
         $user_profile = $facebook->api('/me', 'GET');
         $output = "Name: " . $user_profile[$string];
     }
     return $output;
 }
예제 #27
0
/**
 * Gets the basic data from facebook if is there a facebook session active
 * @return array[uid,username,email,first_name,last_name,pic_big] | null
 */
function getBasicDataFromFB()
{
    $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true));
    $userId = $facebook->getUser();
    $fbme = null;
    if (!empty($userId)) {
        $fql = 'SELECT uid, username, email, name, first_name, last_name, pic_big FROM user WHERE uid = me()';
        $fbme1 = $facebook->api(array('method' => 'fql.query', 'query' => $fql));
        $fbme = $fbme1[0];
    }
    return $fbme;
}
function update_facebook_wall($text)
{
    $appId = '101183239949229';
    $appSecret = 'fd040afd3af84cc13b6a70ea602b4ca6';
    $srcPageId = '116587918401126';
    //Use Evan Hsu's access token because he is one of the Page Admins
    //**** The access Token will need to be updated whenever Evan changes his Facebook password
    $accessToken = 'AAABcBo8TC60BAOJGsdKapdUYfvbBOJm9jc9EHZBZBpD45mAN2poo9t7nfxtII3I7XZAxH9RMuI1AOD2BjWUEyso17nTkNVR2aEGaZC287Vqe8932fjQ9';
    $config = array('appId' => $appId, 'secret' => $appSecret);
    $facebook = new Facebook($config);
    $args = array('access_token' => $accessToken, 'message' => $text);
    try {
        $post_id = $facebook->api("/{$srcPageId}/feed", "post", $args);
    } catch (FacebookApiException $e) {
        //If post failed, do nothing. Permission check happens below.
    }
    if (!$post_id) {
        // If the accessToken is no longer valid (Evan changed his password or revoked permissions),
        // then someone with admin access to the Siskiyou facebook page will need to be logged in.
        $user = $facebook->getUser();
        if ($user) {
            try {
                $page_info = $facebook->api("/{$srcPageId}?fields=access_token");
                if (!empty($page_info['access_token'])) {
                    $args = array('access_token' => $page_info['access_token'], 'message' => $text);
                    $post_id = $facebook->api("/{$srcPageId}/feed", "post", $args);
                    //echo "Access Token: ".$page_info['access_token'];
                } else {
                    $permissions = $facebook->api("/me/permissions");
                    if (!array_key_exists('publish_stream', $permissions['data'][0]) || !array_key_exists('manage_pages', $permissions['data'][0])) {
                        // We don't have one of the permissions
                        // Alert the admin or ask for the permission!
                        header("Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages, offline_access")));
                    }
                }
            } catch (FacebookApiException $e) {
                //error_log($e);
                $user = null;
            }
        }
        // Login or logout url will be needed depending on current user state.
        if ($user) {
            $logoutUrl = $facebook->getLogoutUrl();
        } else {
            $loginUrl = $facebook->getLoginUrl(array('scope' => 'manage_pages,publish_stream,offline_access'));
            header("Location: " . $loginUrl);
        }
    }
    // END if(!$post_id)
    if ($post_id != "") {
        header('location: http://www.siskiyourappellers.com/current.php');
    }
}
 protected function setUpFacebookInteractions($options)
 {
     // Create our Facebook Application instance
     $facebook = new Facebook(array('appId' => $options['facebook_app_id']->option_value, 'secret' => $options['facebook_api_secret']->option_value));
     $fb_user = $facebook->getUser();
     if ($fb_user) {
         try {
             $fb_user_profile = $facebook->api('/me');
         } catch (FacebookApiException $e) {
             error_log($e);
             $fb_user = null;
             $fb_user_profile = null;
         }
     }
     //Plant unique token for CSRF protection during auth per https://developers.facebook.com/docs/authentication/
     if (SessionCache::get('facebook_auth_csrf') == null) {
         SessionCache::put('facebook_auth_csrf', md5(uniqid(rand(), true)));
     }
     $params = array('scope' => 'offline_access,read_stream,user_likes,user_location,user_website,read_friendlists,friends_location', 'state' => SessionCache::get('facebook_auth_csrf'));
     $fbconnect_link = $facebook->getLoginUrl($params);
     $this->addToView('fbconnect_link', $fbconnect_link);
     $status = self::processPageActions($options, $facebook);
     $this->addInfoMessage($status["info"]);
     $this->addErrorMessage($status["error"]);
     $this->addSuccessMessage($status["success"]);
     $logger = Logger::getInstance();
     $user_pages = array();
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook');
     $ownerinstance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
     foreach ($owner_instances as $instance) {
         $tokens = $ownerinstance_dao->getOAuthTokens($instance->id);
         $access_token = $tokens['oauth_access_token'];
         if ($instance->network == 'facebook') {
             //not a page
             $pages = FacebookGraphAPIAccessor::apiRequest('/' . $instance->network_user_id . '/likes', $access_token);
             if (@$pages->data) {
                 $user_pages[$instance->network_user_id] = $pages->data;
             }
         }
     }
     $this->addToView('user_pages', $user_pages);
     $owner_instance_pages = $instance_dao->getByOwnerAndNetwork($this->owner, 'facebook page');
     if (count($owner_instance_pages) > 0) {
         $this->addToView('owner_instance_pages', $owner_instance_pages);
     }
     $this->addToView('owner_instances', $owner_instances);
     if (isset($options['facebook_api_key'])) {
         $this->addToView('fb_api_key', $options['facebook_api_key']->option_value);
     }
 }
예제 #30
-1
 /**
  * Fetch the HTML for the button
  *
  * @param   string   $type  Unused string.
  * @param   string   $name  The name of the button icon class.
  * @param   string   $text  Button text.
  * @param   string   $task  Task associated with the button.
  * @param   boolean  $list  True to allow lists
  *
  * @return  string  HTML string for the button
  *
  * @since   3.0
  */
 public function fetchButton($type = 'J2FBPost', $name = '', $text = '', $task = '', $list = false)
 {
     $class = $this->fetchIconClass($name);
     if ($name == "apply" || $name == "new") {
         $btnClass = "btn btn-small btn-success";
         $iconWhite = "icon-white";
     } else {
         $btnClass = "btn btn-small";
         $iconWhite = "";
     }
     JFactory::getDocument()->addStyleDeclaration('div#toolbar div#toolbar-' . $name . ' button.btn i.icon-' . $name . '-login::before {color: #2F96B4;content: "\\"";}');
     JFactory::getDocument()->addStyleDeclaration('div#toolbar div#toolbar-' . $name . ' button.btn i.icon-' . $name . '::before {color: #2F96B4;content: "&";}');
     JFactory::getDocument()->addStyleDeclaration('div#toolbar div#toolbar-' . $name . ' button.btn i.icon-' . $name . '-waiting::before {color: #2F96B4;content: "j";}');
     // Create our Application instance
     $facebook = new Facebook(array('appId' => self::$appid, 'secret' => self::$secret, 'cookie' => true));
     if ($fbuser = $facebook->getUser()) {
         try {
             $user_profile = $facebook->api('/me');
             //Get user pages details using Facebook Query Language (FQL)
             $fql_query = 'SELECT page_id, name, page_url FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid=' . $fbuser . ')';
             $postResults = $facebook->api(array('method' => 'fql.query', 'query' => $fql_query));
         } catch (FacebookApiException $e) {
             JError::raiseWarning(1, $e->getMessage());
             return null;
         }
     } else {
         //Show login button for guest users
         $i18n_text = JText::_('Login');
         $doTask = $facebook->getLoginUrl(array('redirect_uri' => JURI::current(), 'scope' => 'publish_stream,read_stream,offline_access,manage_pages'));
         /* 
          * publish_stream – allows the application to publish updates to Facebook on the user’s behalf
          * read_stream – allows the application to read from the user’s News Feed
          * offline_access – converts the access_token to one that doesn’t expire, thus letting the application make API calls anytime. Without this, the application’s access_token will expire after a few minutes, which isn’t ideal in this case
          * manage_pages – lets the application access the user’s Facebook Pages. Since the application we’re building deals with Facebook Pages, we’ll need this as well.
          */
         $html = "<button class=\"btn btn-small\" onclick=\"location.href='{$doTask}';\">\n";
         $html .= "<i class=\"{$class}-login\">\n";
         $html .= "</i>\n";
         $html .= "{$i18n_text}\n";
         $html .= "</button>\n";
     }
     if ($fbuser && $postResults) {
         $i18n_text = JText::_($text);
         $doTask = $this->_getCommand($name, $task, $list);
         $doc = JFactory::getDocument();
         $doc->addScript("../media/lib_eshiol_core/js/encryption.js");
         $doc->addScript("../media/lib_eshiol_core/js/core.js");
         foreach ($postResults as $item) {
             $options[] = array('text' => $item['name'], 'value' => $item['page_id']);
         }
         array_unshift($options, JHTML::_('select.option', 0, '- Select a page -'));
         $html = "<button data-toggle=\"modal\" data-target=\"#collapseModal{$name}\" class=\"" . $btnClass . "\">\n";
         $html .= "<i class=\"{$class} {$iconWhite}\">\n";
         $html .= "</i>\n";
         $html .= "{$i18n_text}\n";
         $html .= "</button>\n";
         $html .= "\r\n<div class=\"modal hide fade\" id=\"collapseModal{$name}\">\r\n\t<div class=\"modal-header\">\r\n\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\">x</button>\r\n\t\t<h3>Post to Facebook</h3>\r\n\t</div>\r\n\t<div class=\"modal-body\" style=\"min-height:250px\">\r\n\t\t<p>Post to facebook using www.eshiol.it app</p>\r\n\t\t<div class=\"control-group\">\r\n\t\t\t<div class=\"controls\">" . JHtml::_('select.genericlist', $options, 'fbpage', array('list.attr' => 'class="inputbox" size="1"', 'list.select' => 0)) . "\r\n\t\t\t</div>\r\n\t\t</div>\r\n\t</div>\r\n\t<div class=\"modal-footer\">\r\n\t\t<button class=\"btn\" type=\"button\" onclick=\"document.id('fbpage').value=''\" data-dismiss=\"modal\">\r\n\t\t\t" . JText::_('JCANCEL') . "\r\n\t\t</button>\r\n\t\t<button class=\"btn btn-primary\" type=\"button\" onclick=\"{$doTask}\">\r\n\t\t\t{$i18n_text}\r\n\t\t</button>\r\n\t</div>\r\n</div>\r\n\t\t\t";
     }
     return $html;
 }