Exemplo n.º 1
0
 /**
  *	Reintialize the facebook application
  *
  *	If for some reason the FB status changes during a script run (for example you enable it in the vb option)
  *	this will force an attempt to recheck its status.  Otherwise we will store the status based on the first
  *	attempt.
  *
  *	If the intiailization fails, the reason can be determeined via vB_Library_Facebook::getInitializeFailureMessage();
  *
  *	@return boolean false if it failed, true if not
  */
 public function reinitialize()
 {
     //if we tried before and couldn't load the SDK, don't try again.  We won't actually
     //load the SDK file the second time and this will cause a problem.
     if (self::$sdk_failed) {
         return false;
     }
     //reset our state
     $this->facebookInitialized = false;
     $this->failureReason = "";
     $options = vB::getDatastore()->getValue('options');
     if (!$options['facebookactive']) {
         $this->failureReason = "Facebook is not active";
         return false;
     }
     if (empty($options['facebookappid']) or empty($options['facebooksecret'])) {
         $this->failureReason = "Facebook is not configured";
         return false;
     }
     if (defined('SKIP_SESSIONCREATE')) {
         $this->failureReason = "Facebook is not available when session creation is skipped";
         return false;
     }
     try {
         require_once DIR . '/libraries/facebook/autoload.php';
     } catch (Exception $e) {
         $this->failureReason = "Facebook SDK failed to initialize";
         $this->handleFacebookException($e);
         self::$sdk_failed = true;
         return false;
     }
     Facebook\FacebookSession::setDefaultApplication($options['facebookappid'], $options['facebooksecret']);
     $this->facebookInitialized = true;
     return true;
 }
Exemplo n.º 2
0
 /**
  * Only called internally
  *
  * @param FacebookClientConfig $config
  *
  * @throws Exception
  */
 private function __construct(FacebookClientConfig $config)
 {
     $this->facebookUserId = null;
     if ($config->hasFacebookAPI()) {
         // Use client passed to our constructor
         $this->facebookAPI = $config->getFacebookAPI();
     } else {
         // Construct our own client
         // Make sure we have the ID and secret
         if (!$config->hasAppID() || !$config->hasAppSecret()) {
             throw new Exception(wfMessage('fbconnect-graphapi-not-configured')->text());
         }
         Facebook\FacebookSession::setDefaultApplication($config->getAppID(), $config->getAppSecret());
         $this->facebookAPI = new Facebook\FacebookJavaScriptLoginHelper();
     }
 }
Exemplo n.º 3
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.º 4
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.º 5
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.º 6
0
 /**
  * 初期化
  *
  * @param $appid
  * @param $seckey
  * @param bool $cookie
  * @return bool
  */
 public function init($appid, $seckey)
 {
     $this->apiId = $appid;
     $this->secret_key = $seckey;
     //$this->cookie_use = $cookie;
     // Facebookクラス生成
     Facebook\FacebookSession::setDefaultApplication($this->apiId, $this->secret_key);
     /*
             $this->facebook = new Facebook(array(
                 'appId'  => $this->apiId,
                 'secret' => $this->secret_key,
                 'cookie' => $this->cookie_use,
             ));*/
     return true;
 }
<?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.º 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
<?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.º 11
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.º 12
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) {
}