function get_fb_friends($uid, $sex = false)
{
    $fql_query = array('user_friends' => "SELECT uid2 FROM friend WHERE uid1 = {$uid}", 'friend_info' => 'SELECT uid, first_name, last_name, name, pic_small, pic_big, pic_square, pic, sex ' . ' FROM user WHERE uid IN ( SELECT uid2 FROM #user_friends )');
    try {
        $query_result = facebook_client()->api_client->fql_multiQuery($fql_query);
        $friends = array();
        if (!empty($query_result[1]) && !empty($query_result[1]['fql_result_set'])) {
            foreach ($query_result[1]['fql_result_set'] as $friend) {
                if ($sex && $friend['sex'] == $sex || false == $sex) {
                    $friends[$friend['uid']] = $friend;
                }
            }
        } else {
            $friends = false;
        }
    } catch (Exception $e) {
        $friends = false;
    }
    return $friends;
}
Example #2
0
function get_connected_friends($user)
{
    $results = array();
    $query = 'SELECT uid, email_hashes, has_added_app FROM user WHERE uid IN ' . '(SELECT uid2 FROM friend WHERE uid1 = ' . $user->fb_uid . ')';
    try {
        $rows = facebook_client()->api_client->fql_query($query);
        // Do filtering in PHP because the FQL doesn't allow it (yet)
        if (!empty($rows)) {
            foreach ($rows as $row) {
                if (is_array($row['email_hashes']) && count($row['email_hashes']) > 0 || $row['has_added_app'] == 1) {
                    unset($row['has_added_app']);
                    $results[] = $row;
                }
            }
        }
    } catch (Exception $e) {
        error_log("Failure in the api: " . $e->getMessage());
    }
    return $results;
}
function verify_facebook_callback()
{
    $app_properties = facebook_client()->api_client->admin_getAppProperties(array('callback_url'));
    $facebook_callback_url = idx($app_properties, 'callback_url');
    $local_callback_url = get_callback_url();
    if (!$facebook_callback_url) {
        throw new Exception('You need to configure your callback URL in the ' . '<a href="http://www.facebook.com/developers/">Facebook Developers App</a>');
    }
    if (!$local_callback_url) {
        throw new Exception('Copy your Facebook callback URL into lib/config.php. ' . 'Your Callback is ' . $facebook_callback_url);
    }
    if (strpos($local_callback_url, 'http://') === null) {
        throw new Exception('Your configured callback url must begin with http://. ' . 'It is currently set to "' . $local_callback_url . '"');
    }
    if (get_domain($facebook_callback_url) != get_domain($local_callback_url)) {
        throw new Exception('Your config file says the callback URL is "' . $local_callback_url . '", but Facebook says "' . $facebook_callback_url . '"');
    }
    if (get_domain($local_callback_url) != get_domain($_SERVER['SCRIPT_URI'])) {
        throw new Exception('Your config file says the callback URL is "' . $local_callback_url . '", but you are on "' . $_SERVER['SCRIPT_URI'] . '"');
    }
}
Example #4
0
<?php

include_once 'lib/core.php';
include_once 'lib/fbconnect.php';
/*
 * This is called after the Facebook Connect button is pressed on the front page
 * or anywhere on the site. This is the code that links accounts.
 */
// Gets any credentials for The Run Around
$user = User::getLoggedIn();
if (idx($_POST, 'save')) {
    // Facebook client library will validate the signature against the secret
    // key, and produce a user id if it all checks out
    $fb_uid = facebook_client()->get_loggedin_user();
    if ($fb_uid) {
        // The user is connecting an existing account
        // with their Facebook account.
        if ($user && $_POST['link_to_current_user']) {
            $user->connectWithFacebookUID($fb_uid);
        } else {
            if (!$user) {
                $user = User::createFromFacebookUID($fb_uid);
            }
        }
    }
}
if ($user) {
    $user->logIn();
    echo 1;
} else {
    echo 0;
 function fbc_get_unconnected_friends_xfbml($all_rows = TRUE, $row_start = 0, $num_rows = 10)
 {
     // RETURNS ALL UNCONNECTED FRIENDS ASSOCIATED WITH FBUID FOR USE WITH XFBML RENDER
     $fql_query = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=' . $this->fbc_uid . ') AND has_added_app=0 ';
     if (!$all_rows) {
         $fql_query .= 'LIMIT ' . $row_start . ', ' . $num_rows;
     }
     try {
         $fql_result = facebook_client()->api_client->fql_query($fql_query);
     } catch (Exception $e) {
         // probably an expired session
         return null;
     }
     return $fql_result;
 }
Example #6
0
<?php

require_once 'lib/twitter_init.php';
require_once 'lib/init.php';
if ($_REQUEST['message'] != "" && isset($_REQUEST['message'])) {
    $request = stripslashes($_REQUEST['message']);
    if ($_REQUEST['service'] == 'both' || $_REQUEST['service'] == 'twitter') {
        $to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
        $content = $to->OAuthRequest('http://twitter.com/statuses/update.json', array('status' => $request), 'POST');
    }
    if ($_REQUEST['service'] == 'both' || $_REQUEST['service'] == 'facebook') {
        $facebook_content = facebook_client()->api_client->stream_publish($request);
    }
    echo json_encode(array('twitter' => $content, 'facebook' => $facebook_content));
}
Example #7
0
function facebook_get_fields($fb_uid, $fields)
{
    try {
        $infos = facebook_client()->api_client->users_getInfo($fb_uid, $fields);
        if (empty($infos)) {
            return null;
        }
        return reset($infos);
    } catch (Exception $e) {
        error_log("Failure in the api when requesting " . join(",", $fields) . " on uid " . $fb_uid . " : " . $e->getMessage());
        return null;
    }
}
Example #8
0
 function logOut()
 {
     setcookie(USER_COOKIE_NAME, 'unknown');
     if ($this->is_facebook_user()) {
         try {
             // it's important to expire the session, or else the user
             // may find themselves logged back in when they come back
             // This is NOT the same as disconnecting from the app - you
             // can get a new session at any time with auth.getSession.
             facebook_client()->expire_session();
         } catch (Exception $e) {
             // nothing, probably an expired session
         }
     }
 }
Example #9
0
<?php

$message = stripslashes($_REQUEST['message']);
if ($_REQUEST['service'] == 'facebook') {
    require_once 'lib/init.php';
    $result = facebook_client()->api_client->stream_addComment($_REQUEST['reply_to'], $message);
} else {
    if ($_REQUEST['service'] == 'twitter') {
        require_once 'lib/twitter_init.php';
        $to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
        $result = $to->OAuthRequest('http://twitter.com/statuses/update.json', array('status' => $message, 'in_reply_to_status_id' => $_REQUEST['reply_to']), 'POST');
    }
}
echo $result;
Example #10
0
<?php

require_once 'lib/init.php';
$start_time = '';
if (isset($_REQUEST['newest_id']) && $_REQUEST['newest_id'] != "") {
    $start_time = $_REQUEST['newest_id'];
}
$content = facebook_client()->api_client->stream_get('', '', $start_time, '', '', '', '');
if ($content['profiles'] == null) {
    $content['profiles'] = array();
}
if ($content['posts'] == null) {
    $content['posts'] = array();
}
$profiles = array();
$posts = array();
foreach ($content['profiles'] as $profile) {
    $profiles[$profile['id']] = $profile;
}
$i = 0;
foreach ($content['posts'] as $post) {
    $posts[$i] = array();
    $posts[$i]['id'] = $post['post_id'];
    $posts[$i]['author'] = $post['actor_id'];
    $posts[$i]['author_name'] = $profiles[$post['actor_id']]['name'];
    $posts[$i]['pic'] = $profiles[$post['actor_id']]['pic_square'];
    if ($post['target_id'] != "") {
        $posts[$i]['target'] = $post['target_id'];
        $posts[$i]['target_name'] = $profiles[$post['target_id']]['name'];
    }
    $posts[$i]['message'] = $post['message'];
Example #11
0
<?php

require_once 'lib/init.php';
if (isset($_REQUEST['permission']) && $_REQUEST['permission'] != "") {
    $permission = $_REQUEST['permission'];
} else {
    $permission = 'read_stream';
}
$gained = facebook_client()->api_client->call_method('Users.hasAppPermission', array('ext_perm' => $permission));
echo $gained == true ? true : false;
<?php

/*
 * When you register a user on Facebook using an email hash, you also register an "account id".
 * If that user responds to the request and connects their accounts, then you can be notified at
 * the "post-authorize-url" as configured in your developer account settings.
 *
 * This is that post-authorize-url.
 */
define(MAIN_PATH, realpath('.'));
include_once MAIN_PATH . '/init.php';
$fb = facebook_client();
$fb_uid = $fb->get_loggedin_user();
$account_ids = idx($fb->fb_params, 'linked_account_ids');
if (!($account_ids && $fb_uid)) {
    exit;
}
// Theoretically possible for a single facebook user to have multiple accounts on this system,
// Since they could have multiple email addresses. so account for that
foreach ($account_ids as $account_id) {
    $user = User::getByUsername($account_id);
    $user->connectWithFacebookUID($fb_uid);
    $user->save();
}
Example #13
0
<?php

$array = array();
require_once 'lib/init.php';
// require twitterOAuth lib
require_once 'lib/twitter_init.php';
function deleteIfFound($name)
{
    if ($_COOKIE[$name]) {
        setcookie($name, '', time() - 3600);
    }
}
try {
    $fb_user_id = facebook_client()->api_client->call_method('Users.getLoggedInUser', array());
} catch (FacebookRestClientException $e) {
    $fb_user_id = false;
}
/*
 * Switch based on where in the process you are
 *
 * 'default': Get a request token from twitter for new user
 * 'returned': The user has authorize the app on twitter
 */
switch ($state) {
    /*{{{*/
    default:
        /* Create TwitterOAuth object with app key/secret */
        $to = new TwitterOAuth($consumer_key, $consumer_secret);
        /* Request tokens from twitter */
        $tok = $to->getRequestToken();
        /* Save tokens for later */