Example #1
0
    function get_facebook_cookie($app_id, $application_secret)
    {
        $args = array();
        parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
        ksort($args);
        $payload = '';
        foreach ($args as $key => $value) {
            if ($key != 'sig') {
                $payload .= $key . '=' . $value;
            }
        }
        if (md5($payload . $application_secret) != $args['sig']) {
            return null;
        }
        return $args;
    }
    $cookie = get_facebook_cookie($setting['facebook_appid'], $setting['facebook_secret']);
    // Facebook's connection failed? Maybe we can still do it ourselves...
    if (!isset($fb_user['id'])) {
        $open = @file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']);
        if ($open != FALSE) {
            $fbdata = json_decode($open);
            $fb_user = array();
            foreach ($fbdata as $key => $fbdata2) {
                $fb_user[$key] = $fbdata2;
            }
        }
    }
} else {
    $facebook_session = 0;
}
Example #2
0
/**
 * fb_login()
 *
 * @package fb-connect
 * @since 1.0
 *
 * shortcode for FB connect button. this is used in widget so keep that in mind if you change anything here
 *
 */
function fb_login($atts)
{
    global $wpdb;
    extract(shortcode_atts(array('size' => 'medium', 'login_text' => __('Login', 'wp-facebook-connect'), 'logout_text' => __('Logout', 'wp-facebook-connect'), 'connect_text' => __('Connect', 'wp-facebook-connect')), $atts));
    $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
    $perms = apply_filters('fb_connect_perms', array('email'));
    //only show facebook connect when user is not logged in
    if (is_user_logged_in()) {
        if ($cookie) {
            do_action('fb_connect_button_fb_wp');
            ?>
			<a class="fb_button fb_button_<?php 
            echo $size;
            ?>
" href="<?php 
            echo wp_logout_url(get_bloginfo('url'));
            ?>
">
				<span class="fb_button_text">
					<?php 
            echo $logout_text;
            ?>
		    	</span>
		    </a>
		    <?php 
        } else {
            do_action('fb_connect_button_nofb_wp');
            ?>
			<fb:login-button perms="<?php 
            echo implode(',', $perms);
            ?>
" size="<?php 
            echo $size;
            ?>
" >
				<?php 
            echo $connect_text;
            ?>
			</fb:login-button>
			<?php 
        }
    } else {
        if ($cookie) {
            //this should never happen, because there is login process on
            //INIT and by this time you should either be loged in or have new user created and loged in
            do_action('fb_connect_button_fb_nowp');
            _e('Facebook Connect error: login process failed!', 'wp-facebook-connect');
        } else {
            do_action('fb_connect_button_nofb_nowp');
            ?>
			<fb:login-button perms="<?php 
            echo implode(',', $perms);
            ?>
" size="<?php 
            echo $size;
            ?>
" >
				<?php 
            echo $login_text;
            ?>
			</fb:login-button>
			<?php 
        }
    }
}
Example #3
0
function fb_wallpost_wosdk_api($title, $caption, $description = "Astra Vires est un jeu gratuit jouable par navigateur de stratégie et de conquête spatiale. Démarrez avec un vaisseau, explorez la galaxie et devenez un chef militaire redoutable !", $cookie = '')
{
    if (empty($cookie)) {
        //post for logged in user
        $cookie = get_facebook_cookie();
        $cookie = $cookie['access_token'];
    }
    $attachment = '
	{
		"name": "' . utf8_encode($title) . '",
		"href": "http://www.astravires.fr",
		"caption": "' . utf8_encode($caption) . '",
		"description": "' . utf8_encode($description) . '",
		"media": [
	    {
	        "type": "image",
	        "src": "http://www.astravires.fr/images/logofb.jpg",
	        "href": "http://www.astravires.fr"
	    }]
	}';
    $action_links = array(array('text' => utf8_encode('Jouer à Astra Vires !'), 'href' => 'http://www.astravires.fr'));
    $action_links = json_encode($action_links);
    $action_links = urlencode($action_links);
    $attachment = urlencode($attachment);
    if ($cookie != "" && $title != "" && $caption != "") {
        $result = json_decode(file_get_contents("https://api.facebook.com/method/stream.publish?access_token=" . $cookie . "&attachment={$attachment}&action_links={$action_links}"));
        return $result;
    } else {
        return 0;
    }
}
    // check sig
    $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
    if ($sig !== $expected_sig) {
        error_log('Bad Signed JSON signature!');
        return null;
    }
    return $data;
}
function base64_url_decode($input)
{
    return base64_decode(strtr($input, '-_', '+/'));
}
$user = "";
$cookie = "";
if (isset($_COOKIE['fbsr_' . YOUR_APP_ID])) {
    $cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
    $user = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
    print_r($user);
    //echo "<strong style=\"font-size:0;\">".$user->id."</strong>";
    /*Uncomment this to show all available variables
    echo "<pre>";
     - print_r function expose all the values available to get from facebook login connect.
    print_r($user);
     1. Save nessary values from $user Object to your Database
     2. Register a Sesion Variable based on your user account code
     3. Redirect to Account Dashboard
    echo "</pre>";*/
    //print_r($user);
    //count($user);
    //echo '<br />'.$user->id;
}
Example #5
0
    $data = dbr();
    login_to_server($data['login_name'], '', $data['bp_user_id']);
} elseif (empty($_COOKIE['session_id']) || empty($_COOKIE['login_id']) || isset($_POST['submit'])) {
    login_to_server();
    //user already logged in. but check session details.
} else {
    check_auth();
    if ($login_id == 1) {
        //admin trying to continue old session.
        echo $st[793];
        exit;
    }
}
if ($fbuser && empty($p_user['fb_token'])) {
    // verify if the user has fb_token and set it
    $tmp_fb_token = get_facebook_cookie();
    dbn("update user_accounts set fb_token='" . $tmp_fb_token['access_token'] . "' WHERE login_id = '{$p_user['login_id']}'");
}
$rs = "<br /><br />" . $st[794];
//print_header("Game Listings");
$nomPage = 'game_listing';
require 'includes/haut_index.inc.php';
//user has selected a game.
if (isset($_REQUEST['game_selected'])) {
    db("select db_name from se_games where game_id = '" . (int) $_REQUEST['game_selected'] . "'");
    $game_db = dbr(1);
    $db_name = $game_db['db_name'];
    //see if the user is already in the game
    db("select game_login_count, banned_time, banned_reason from {$db_name}_users where login_id = '{$login_id}'");
    $in_game = dbr(1);
    //user logging into selected game. update the db, and redirect to location.php
Example #6
0
{
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
        if ($key != 'sig') {
            $payload .= $key . '=' . $value;
        }
    }
    if (md5($payload . $application_secret) != $args['sig']) {
        return null;
    }
    return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?>
	<!DOCTYPE html>
	<html xmlns="http://www.w3.org/1999/xhtml"
	      xmlns:fb="http://www.facebook.com/2008/fbml">
	<body>
	<?php 
if ($cookie) {
    //###cookie is set, user is logged in
    $user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
    //###display the user profile photo
    echo '<img src="http://graph.facebook.com/' . $user->{'id'} . '/picture" alt="' . $user->{'name'} . '"/>';
    echo '<br />';
    //###display the user Facebook ID
    echo '<b>Your Facebook ID:</b> ' . $user->{'id'};
    echo '<br />';
Example #7
0
{
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
        if ($key != 'sig') {
            $payload .= $key . '=' . $value;
        }
    }
    if (md5($payload . $app_secret) != $args['sig']) {
        return null;
    }
    return $args;
}
$cookie = get_facebook_cookie(APP_ID, APP_SECRET);
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
session_start();
$_SESSION['fb_id'] = $user->id;
$_SESSION['fb_name'] = $user->name;
$_SESSION['fb_fname'] = $user->first_name;
$_SESSION['fb_lname'] = $user->last_name;
$_SESSION['fb_username'] = $user->username;
$_SESSION['fb_gender'] = $user->gender;
$_SESSION['fb_hometown'] = $user->hometown->name;
$_SESSION['fb_locale'] = $user->locale;
$_SESSION['fb_current_location'] = $user->location->name;
$_SESSION['fb_profile'] = $user->link;
$_SESSION['fb_relationship_status'] = $user->relationship_status;
$_SESSION['fb_img_big'] = "https://graph.facebook.com/" . $user->id . "/picture?type=large";
$_SESSION['fb_img_small'] = "https://graph.facebook.com/" . $user->id . "/picture";
Example #8
0
  $args = array();
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
  ksort($args);
  $payload = '';
  foreach ($args as $key => $value) {
    if ($key != 'sig') {
      $payload .= $key . '=' . $value; 
    }
  }
  if (md5($payload . $application_secret) != $args['sig']) {
    return array();
  }
  return $args;
}

$cookie = get_facebook_cookie(cfg('facebook/app_id'), cfg('facebook/app_secret'));

?>

<span id="fb-root"></span>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>

  FB.init({appId: '<?php 
echo cfg('facebook/app_id');
?>
', status: true, cookie: true, xfbml: true});
  FB.Event.subscribe('auth.login', function(response) {
        window.location.reload();
      });
  
Example #9
0
/**
 * fb_login_user()
 *
 * @package fb-connect
 * @since 1.0
 *
 * this is the main function that performs the login or user creation process
 *
 * @return true
 */
function fb_login_user()
{
    global $wpdb;
    //@todo: investigate: does this gets included doing regular request?
    require_once ABSPATH . 'wp-includes/registration.php';
    //mmmm, cookie
    $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
    //if we have cookie, then try to get user data
    if ($cookie) {
        //get user data
        $user = json_decode(@file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
        //if user data is empty, then nothing will happen
        if (!empty($user)) {
            //this should never happen, since email address is required to register in FB
            //I put it here just in case of API changes or some other disaster, like wrong API key or secret
            if (!isset($user->email) || empty($user->email)) {
                do_action('fb_connect_get_email_error');
            }
            //if user is logged in, then we just need to associate FB account with WordPress account
            if (is_user_logged_in()) {
                global $current_user;
                get_currentuserinfo();
                $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);
                if ($fb_uid == $user->id) {
                    return true;
                }
                if ($user->email == $current_user->user_email) {
                    //if FB email is the same as WP email we don't need to do anything.
                    do_action('fb_connect_wp_fb_same_email');
                    $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);
                    if (!$fb_uid) {
                        update_user_meta($current_user->ID, 'fb_uid', $user->id);
                    }
                    return true;
                } else {
                    //else we need to set fb_uid in user meta, this will be used to identify this user
                    do_action('fb_connect_wp_fb_different_email');
                    $fb_uid = get_user_meta($current_user->ID, 'fb_uid', true);
                    if (!$fb_uid) {
                        update_user_meta($current_user->ID, 'fb_uid', $user->id);
                    }
                    $fb_email = get_user_meta($current_user->ID, 'fb_email', true);
                    if (!$fb_uid) {
                        update_user_meta($current_user->ID, 'fb_email', $user->email);
                    }
                    //that's it, we don't need to do anything else, because the user is already logged in.
                    return true;
                }
            } else {
                //check if user has account in the website. get id
                $existing_user = $wpdb->get_var('SELECT DISTINCT `u`.`ID` FROM `' . $wpdb->users . '` `u` JOIN `' . $wpdb->usermeta . '` `m` ON `u`.`ID` = `m`.`user_id`  WHERE (`m`.`meta_key` = "fb_uid" AND `m`.`meta_value` = "' . $user->id . '" ) OR user_email = "' . $user->email . '" OR (`m`.`meta_key` = "fb_email" AND `m`.`meta_value` = "' . $user->email . '" )  LIMIT 1 ');
                //if the user exists - set cookie, do wp_login, redirect and exit
                if ($existing_user > 0) {
                    $fb_uid = get_user_meta($existing_user, 'fb_uid', true);
                    if (!$fb_uid) {
                        update_user_meta($new_user, 'fb_uid', $user->id);
                    }
                    $user_info = get_userdata($existing_user);
                    do_action('fb_connect_fb_same_email');
                    wp_set_auth_cookie($existing_user, true, false);
                    do_action('wp_login', $user_info->user_login);
                    if (wp_get_referer()) {
                        wp_redirect(wp_get_referer());
                    } else {
                        wp_redirect($_SERVER['REQUEST_URI']);
                    }
                    exit;
                    //if user don't exist - create one and do all the same stuff: cookie, wp_login, redirect, exit
                } else {
                    do_action('fb_connect_fb_new_email');
                    //sanitize username
                    $username = sanitize_user($user->first_name, true);
                    //check if username is taken
                    //if so - add something in the end and check again
                    $i = '';
                    while (username_exists($username . $i)) {
                        $i = absint($i);
                        $i++;
                    }
                    //this will be new user login name
                    $username = $username . $i;
                    //put everything in nice array
                    $userdata = array('user_pass' => wp_generate_password(), 'user_login' => $username, 'user_nicename' => $username, 'user_email' => $user->email, 'display_name' => $user->name, 'nickname' => $username, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'role' => 'subscriber');
                    $userdata = apply_filters('fb_connect_new_userdata', $userdata, $user);
                    //create new user
                    $new_user = absint(wp_insert_user($userdata));
                    do_action('fb_connect_new_user', $new_user);
                    //if user created succesfully - log in and reload
                    if ($new_user > 0) {
                        update_user_meta($new_user, 'fb_uid', $user->id);
                        $user_info = get_userdata($new_user);
                        wp_set_auth_cookie($new_user, true, false);
                        do_action('wp_login', $user_info->user_login);
                        wp_redirect(wp_get_referer());
                        exit;
                    } else {
                        echo 'Facebook Connect: Error creating new user!';
                    }
                }
            }
        }
    }
}
Example #10
0
function getCookie()
{
    return get_facebook_cookie('102871766442464', '981fef3ce9d8e664b9277072210dd88b');
}