Beispiel #1
0
/**
 * Post update to Facebook
 */
function buddystreamFacebookPostUpdate($content = "", $shortLink = "", $user_id = 0)
{
    global $bp;
    $buddyStreamFilters = new BuddyStreamFilters();
    //strip out location tag
    $content = str_replace("#location", "", $content);
    //handle oauth calls
    $buddyStreamOAuth = new BuddyStreamOAuth();
    //figure out if where to post to (wall/page or both)
    $arrayContent = explode(" ", $content);
    if (in_array("#facebook", $arrayContent)) {
        $buddyStreamOAuth->setRequestType('POST');
        $buddyStreamOAuth->setParameters(array('client_id' => get_site_option("facestream_application_id"), 'client_secret' => get_site_option("facestream_application_secret"), 'access_token' => str_replace("&expires", "", get_user_meta($user_id, 'facestream_session_key', 1)), 'message' => $buddyStreamFilters->filterPostContent($content, $shortLink)));
        $buddyStreamOAuth->oAuthRequest('https://graph.facebook.com/me/feed');
    }
    $arrayContent = explode(" ", $content);
    if (in_array("#facebookpage", $arrayContent)) {
        //get the pages for this user
        $facebookPages = get_user_meta($user_id, 'buddystream_facebook_pages', 1);
        //explode the pages
        $facebookPagesArray = explode(',', $facebookPages);
        foreach ($facebookPagesArray as $page) {
            //explode page details
            $pageArray = explode(':', $page);
            $buddyStreamOAuth->setRequestType('POST');
            $buddyStreamOAuth->setParameters(array('client_id' => get_site_option("facestream_application_id"), 'client_secret' => get_site_option("facestream_application_secret"), 'access_token' => $pageArray[1], 'message' => $buddyStreamFilters->filterPostContent($content, $shortLink)));
            $buddyStreamOAuth->oAuthRequest('https://graph.facebook.com/' . $pageArray[0] . '/feed');
        }
    }
}
Beispiel #2
0
/**
 * Post update to Twitter
 */
function buddystreamTwitterPostUpdate($content = "", $shortLink = "", $user_id = 0)
{
    global $bp;
    $buddyStreamFilters = new BuddyStreamFilters();
    //check for location
    $lat = null;
    $long = null;
    if (preg_match("/#location/i", $content)) {
        if (isset($_COOKIE["buddystream_location"])) {
            $arrLocation = explode("#", $_COOKIE["buddystream_location"]);
            $lat = $arrLocation[0];
            $long = $arrLocation[1];
        }
    }
    //strip out location tag
    $content = str_replace("#location", "", $content);
    $buddyStreamOAuth = new BuddyStreamOAuth();
    $buddyStreamOAuth->setRequestTokenUrl('https://api.twitter.com/oauth/request_token');
    $buddyStreamOAuth->setAccessTokenUrl('https://api.twitter.com/oauth/access_token');
    $buddyStreamOAuth->setAuthorizeUrl('https://api.twitter.com/oauth/authorize');
    $buddyStreamOAuth->setConsumerKey(get_site_option("tweetstream_consumer_key"));
    $buddyStreamOAuth->setConsumerSecret(get_site_option("tweetstream_consumer_secret"));
    $buddyStreamOAuth->setAccessToken(get_user_meta($bp->loggedin_user->id, 'tweetstream_token', 1));
    $buddyStreamOAuth->setAccessTokenSecret(get_user_meta($bp->loggedin_user->id, 'tweetstream_tokensecret', 1));
    $buddyStreamOAuth->setParameters(array('status' => $buddyStreamFilters->filterPostContent($content, $shortLink, 140), 'lat' => $lat, 'long' => $long));
    $buddyStreamOAuth->setRequestType("POST");
    $response = $buddyStreamOAuth->oAuthRequest('https://api.twitter.com/1.1/statuses/update.json');
    $response = json_decode($response);
    buddyStreamAddToImportLog($bp->loggedin_user->id, $response->id_str, 'twitter');
}
Beispiel #3
0
/**
 * Post update to Linkedin
 */
function buddystreamLinkedinPostUpdate($content = "", $shortLink = "", $user_id = 0)
{
    global $bp;
    $buddyStreamFilters = new BuddyStreamFilters();
    //strip out location tag
    $content = str_replace("#location", "", $content);
    $content = $buddyStreamFilters->filterPostContent($content, $shortLink);
    $content = '<?xml version="1.0" encoding="UTF-8"?><share><comment>' . $content . '</comment><visibility><code>anyone</code></visibility></share>';
    //Handle the oAuth requests
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setPostData($content);
    $buddystreamOAuth->oAuthRequestPostXml('https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=' . get_user_meta($user_id, 'buddystream_linkedin_token', 1));
}
Beispiel #4
0
/**
 * Post update to Tumblr
 */
function buddystreamTumblrPostUpdate($content = "", $shortLink = "", $user_id = 0)
{
    //no location so remove tag
    $content = str_replace("#location", "", $content);
    global $bp;
    $buddyStreamFilters = new BuddyStreamFilters();
    //handle oauth calls
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setConsumerKey(get_site_option("buddystream_tumblr_consumer_key"));
    $buddystreamOAuth->setConsumerSecret(get_site_option("buddystream_tumblr_consumer_secret"));
    $buddystreamOAuth->setAccessToken(get_user_meta($bp->loggedin_user->id, 'buddystream_tumblr_token', 1));
    $buddystreamOAuth->setAccessTokenSecret(get_user_meta($bp->loggedin_user->id, 'buddystream_tumblr_tokensecret', 1));
    $buddystreamOAuth->setRequestType('POST');
    $buddystreamOAuth->setParameters(array('type' => 'text', 'body' => $buddyStreamFilters->filterPostContent($content, $shortLink)));
    $buddystreamTumblrBlogsOut = get_user_meta($bp->loggedin_user->id, 'buddystream_tumblr_blogs_out', 1);
    $buddystreamTumblrBlogsOut = explode(",", $buddystreamTumblrBlogsOut);
    foreach ($buddystreamTumblrBlogsOut as $blog) {
        $blog = urlencode('' . $blog . '.tumblr.com');
        $result = $buddystreamOAuth->oAuthRequest('http://api.tumblr.com/v2/blog/' . $blog . '/post');
        $result = json_decode($result);
        buddyStreamAddToImportLog($bp->loggedin_user->id, $result->response->id, 'tumblr');
    }
}