Exemplo n.º 1
0
 /**
  * process authenticate
  * 
  * @param mixed $signature
  * @param mixed $extra
  * @return array
  */
 public function processAuthenticate($signature, $extra = null)
 {
     \Facebook\FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
     $session = new \Facebook\FacebookSession($signature);
     $sessionInfo = $session->getSessionInfo();
     //Make sure that we received a valid token
     if ($sessionInfo->isValid()) {
         return ["SUCCESS"];
     } else {
         return ["FAILURE"];
     }
 }
Exemplo n.º 2
0
/**
 * Check if the Facebook link is available
 *
 * @return bool
 */
function socialink_facebook_available()
{
    static $result;
    if (!isset($result)) {
        $result = false;
        if (elgg_get_plugin_setting("enable_facebook", "socialink") == "yes") {
            $app_id = elgg_get_plugin_setting("facebook_app_id", "socialink");
            $app_secret = elgg_get_plugin_setting("facebook_app_secret", "socialink");
            if (!empty($app_id) && !empty($app_secret)) {
                // set defaults
                Facebook\FacebookSession::setDefaultApplication($app_id, $app_secret);
                $result = true;
            }
        }
    }
    return $result;
}
Exemplo n.º 3
0
 public function init_fb()
 {
     if (!$this->fb_loaded) {
         //Init Facebook Api
         try {
             //Exceptions
             include_once $this->root_path . 'libraries/facebook/FacebookSDKException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookRequestException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookAuthorizationException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookPermissionException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookServerException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookThrottleException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookHttpable.php';
             include_once $this->root_path . 'libraries/facebook/FacebookCanvasLoginHelper.php';
             include_once $this->root_path . 'libraries/facebook/FacebookClientException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookCurl.php';
             include_once $this->root_path . 'libraries/facebook/FacebookCurlHttpClient.php';
             include_once $this->root_path . 'libraries/facebook/FacebookJavaScriptLoginHelper.php';
             include_once $this->root_path . 'libraries/facebook/FacebookOtherException.php';
             include_once $this->root_path . 'libraries/facebook/FacebookPageTabHelper.php';
             include_once $this->root_path . 'libraries/facebook/FacebookRedirectLoginHelper.php';
             include_once $this->root_path . 'libraries/facebook/FacebookRequest.php';
             include_once $this->root_path . 'libraries/facebook/FacebookResponse.php';
             include_once $this->root_path . 'libraries/facebook/FacebookSession.php';
             include_once $this->root_path . 'libraries/facebook/GraphObject.php';
             include_once $this->root_path . 'libraries/facebook/GraphAlbum.php';
             include_once $this->root_path . 'libraries/facebook/GraphLocation.php';
             include_once $this->root_path . 'libraries/facebook/GraphSessionInfo.php';
             include_once $this->root_path . 'libraries/facebook/GraphUser.php';
             session_start();
             Facebook\FacebookSession::setDefaultApplication($this->config->get('login_fb_appid'), $this->config->get('login_fb_appsecret'));
         } catch (Exception $e) {
             $this->core->message($e->getMessage(), "Facebook Exception", 'error');
         }
         $this->init_js();
         $this->fb_loaded = true;
     }
 }
Exemplo n.º 4
0
<?php

require_once __DIR__ . '/../tournament.php';
session_start();
Facebook\FacebookSession::setDefaultApplication(C()->fbappid(), C()->fbappsecret());
function A()
{
    return Singletons::A();
}
function R($path, $queryString = [])
{
    return Singletons::R()->redirectTo($path, $queryString);
}
function S()
{
    return Singletons::S();
}
function T()
{
    return Singletons::T();
}
function U($path, $absolute = false, $querystring = [])
{
    return Singletons::U()->u($path, $absolute, $querystring);
}
function init()
{
    // Redirect to home if not signed in or signing in.
    $currentPath = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
    $exemptPaths = [U('/'), U('/signin/')];
    if (!in_array($currentPath, $exemptPaths) && S()->id() === null) {
Exemplo n.º 5
0
 /**
  * @param $path
  * @param $options
  * @return mixed|Facebook\GraphObject
  * @throws Exception
  * @throws Facebook\FacebookApiException
  * @throws Facebook\FacebookRequestException
  */
 public function postPhoto($path, $options)
 {
     //$source = '@'.realpath($source);
     try {
         $session = $this->getSession();
         /*$requestParameters = array(
               'access_token' => $session->getAccessToken(),
               //'message'      => $message,
               //'image'       => $source,
               'source'       => $source,
               //basename($source) => $source
           );
           if(count($options) > 0){
               foreach($options as $k => $v){
                   $requestParameters[$k] = $v;
               }
           }*/
         //$this->facebook->setFileUploadSupport(true);
         //$response = $this->facebook->api($path, 'POST', $requestParameters);
         $param = array('source' => 'url', 'message' => 'message');
         $data = array();
         foreach ($param as $key => $val) {
             if (isset($options[$key])) {
                 $data[$val] = $options[$key];
             }
         }
         $session = new Facebook\FacebookSession($session->getAccessToken());
         $req = new Facebook\FacebookRequest($session, 'POST', $path, $data);
         $response = $req->execute()->getGraphObject();
     } catch (Facebook\FacebookApiException $e) {
         throw $e;
     }
     return $response;
 }
<?php

// start Session
session_start();
// include composer autoloader
include_once "libs/autoload.php";
// init facebook APP
Facebook\FacebookSession::setDefaultApplication("app_id", "secret_key");
// create facebook app helper
$helper = new Facebook\FacebookRedirectLoginHelper("http://localhost/fb_login/index.php");
try {
    if ($session = $helper->getSessionFromRedirect()) {
        $_SESSION['fb_token'] = $session->getToken();
        header("Location: index.php");
    }
    // check if facebook session isset
    // if true get user information
    if (isset($_SESSION['fb_token'])) {
        $session = new Facebook\FacebookSession($_SESSION['fb_token']);
        $request = new Facebook\FacebookRequest($session, "GET", "/me");
        $request = $request->execute();
        // get User Graph
        $user = $request->getGraphObject()->asArray();
        //echo "<pre>", print_r($user), "</pre>";
    }
} catch (Facebook\FacebookRequestExeption $e) {
    // if facebook return an Error
} catch (\Exeption $e) {
    // if local issue
}
<?php

const FACEBOOK_APP_ID = '';
const FACEBOOK_APP_SECRET = '';
const USER_ACCESS_TOKEN = '';
const MAX_PAG_LOOPS = 2;
require_once './vendor/autoload.php';
Facebook\FacebookSession::setDefaultApplication(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
$fb_token = new Facebook\Entities\AccessToken(USER_ACCESS_TOKEN);
$fb_session = new Facebook\FacebookSession($fb_token);
$response = (new Facebook\FacebookRequest($fb_session, 'GET', '/me/photos/uploaded'))->execute();
$i = 0;
while ($next_request = $response->getRequestForNextPage()) {
    $response = $next_request->execute();
    $i++;
    if ($i > MAX_PAG_LOOPS) {
        break;
    }
}
Exemplo n.º 8
0
 private function getSessionFromMemcached()
 {
     $memc = F::app()->wg->memc;
     // Get the access token for this user
     $accessToken = $memc->get($this->getTokenMemcKey());
     if ($accessToken) {
         // If we have an access token, create a session from that
         $session = new \Facebook\FacebookSession($accessToken);
         try {
             $session->validate();
             $this->session = $session;
         } catch (\Exception $ex) {
             $this->logInvalidSession(__METHOD__, $ex->getMessage());
         }
     }
 }
Exemplo n.º 9
0
/**
 * Using the Event handler we add JS & CSS to the <head></head>
 */
new Core\Event(['lib_phpfox_template_getheader' => function (Phpfox_Template $Template) {
    if (!setting('m9_facebook_enabled')) {
        $Template->setHeader('<script>var Fb_Login_Disabled = true;</script>');
        $Template->setHeader('<style>.fb_login_go, #header_menu #js_block_border_user_login-block form > .table:first-of-type:before {display:none !important;} #header_menu #js_block_border_user_login-block .title { margin-bottom: 0px; }</style>');
    }
}]);
// Make sure the app is enabled
if (!setting('m9_facebook_enabled')) {
    return;
}
// Use the FB SDK to set the apps ID & Secret
Facebook\FacebookSession::setDefaultApplication(setting('m9_facebook_app_id'), setting('m9_facebook_app_secret'));
// We override the main settings page since their account is connected to FB
$Url = new Core\Url();
if (Phpfox::isUser() && $Url->uri() == '/user/setting/' && substr(Phpfox::getUserBy('email'), -3) == '@fb') {
    (new Core\Route('/user/setting'))->run(function (\Core\Controller $Controller) {
        return $Controller->render('setting.html');
    });
}
/**
 * Controller for the FB login routine
 */
(new Core\Route('/fb/login'))->run(function (\Core\Controller $Controller) {
    $helper = new Facebook\FacebookRedirectLoginHelper($Controller->url->make('/fb/auth'));
    $loginUrl = $helper->getLoginUrl();
    header('Location: ' . $loginUrl);
    exit;
Exemplo n.º 10
0
 /**
  *	Sets the session information from a signed request
  *
  *	This will "use up" the signed request by fetching the authtoken
  *
  *	@param string $sr -- the signed request token from facebook
  *	@return bool
  */
 private function setSessionFromSignedRequest($sr)
 {
     try {
         $requestObj = new Facebook\Entities\SignedRequest($sr);
         $this->fb_session = Facebook\FacebookSession::newSessionFromSignedRequest($requestObj);
         $this->fb_session->validate();
     } catch (Exception $e) {
         $this->fb_session = null;
         //$this->handleFacebookException($e);
         return false;
     }
     return true;
 }
Exemplo n.º 11
0
/**
 * Get the Facebook user_id for a given access token
 *
 * @param AccessToken|string $access_token a valid Facebook access token
 *
 * @return bool|string
 */
function socialink_facebook_get_user_id_from_access_token($access_token)
{
    if (empty($access_token)) {
        return false;
    }
    $session = new Facebook\FacebookSession($access_token);
    if (empty($session)) {
        return false;
    }
    $token = $session->getAccessToken();
    if (empty($token)) {
        return false;
    }
    $token_info = $token->getInfo();
    if (empty($token_info)) {
        return false;
    }
    return $token_info->getId();
}
Exemplo n.º 12
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    require_once 'vendor/autoload.php';
    Facebook\FacebookSession::setDefaultApplication('988836404521710', 'edab1116bb0541b7199e5a83b18ab679');
    $facebook = new Facebook\FacebookRedirectLoginHelper("http://localhost/pxami/index.php");
    try {
        if ($session = $facebook->getSessionFromRedirect()) {
            $_SESSION['user'] = $session->getToken();
            header('Location: index.php');
        }
        if (isset($_SESSION['user'])) {
            $session = new Facebook\FacebookSession($_SESSION['user']);
            $request = new Facebook\FacebookRequest($session, 'GET', '/me?fields=email, name,gender');
            $request = $request->execute();
            $user = $request->getGraphObject()->asArray();
            $id = $user['id'];
            $name = $user['name'];
            $email = $user['email'];
            $gender = $user['gender'];
            include 'scripts/db.php';
            //Check if already registered
            $query = "SELECT * FROM `user` WHERE `facebook_id` = {$id}";
            $result = mysqli_query($link, $query);
            if ($result) {
                if (mysqli_num_rows($result) > 0) {
                    $row = mysqli_fetch_array($result);
                    $_SESSION['username'] = $row['username'];
                    $_SESSION['email'] = $row['email'];
                    $_SESSION['gender'] = $row['gender'];
Exemplo n.º 13
0
#!/usr/bin/php
<?php 
$config = ['git_urls' => ['https://github.com/facebook/facebook-php-sdk-v4.git' => 'facebook-php-sdk/'], 'autoload_config' => ['facebook-php-sdk/src/Facebook/' => 'Facebook'], 'example' => function () {
    Facebook\FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET');
    // Use one of the helper classes to get a FacebookSession object.
    // FacebookRedirectLoginHelper, FacebookCanvasLoginHelper, FacebookJavaScriptLoginHelper or create a FacebookSession with a valid access token:
    $session = new Facebook\FacebookSession('access-token-here');
    // Get the GraphUser object for the current user:
    try {
        $me = (new Facebook\FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(Facebook\GraphUser::className());
        echo $me->getName();
    } catch (Facebook\FacebookRequestException $e) {
        // The Graph API returned an error
        echo $e->getMessage() . PHP_EOL;
    } catch (\Exception $e) {
        // Some other error occurred
        echo $e->getMessage() . PHP_EOL;
    }
    var_dump($session);
}];
if ($return_config) {
    return $config;
}
require_once __DIR__ . '/_yf_autoloader.php';
new yf_autoloader($config);
Exemplo n.º 14
0
<?php

session_start();
require_once 'vendor/autoload.php';
Facebook\FacebookSession::setDefaultApplication('741170789343317', 'c4124604a104523eb21820b3ee5d059a');
$facebook = new Facebook\FacebookRedirectLoginHelper('http://joe-server.site50.net/');
try {
    if ($session = $facebook->getSessionFromRedirect()) {
        $_SESSION['facebook'] = $session->getToken();
        header('Location: index.php');
    }
} catch (Facebook\FacebookRequestException $e) {
} catch (\Exception $e) {
}