Example #1
0
/**
 * Post update to Foursquare
 */
function buddystreamFoursquarePostUpdate($content = "", $shortLink = "", $user_id = 0)
{
    global $bp;
    $lat = "";
    $long = "";
    $locName = "";
    if (isset($_COOKIE["buddystream_location"])) {
        $arrLocation = explode("#", $_COOKIE["buddystream_location"]);
        $lat = $arrLocation[0];
        $long = $arrLocation[1];
        $locName = $arrLocation[2];
    }
    //get the venue id
    $buddyStreamOAuth = new BuddyStreamOAuth();
    $buddyStreamOAuth->setParameters(array('client_id' => get_site_option("buddystream_foursquare_consumer_key"), 'client_secret' => get_site_option("buddystream_foursquare_consumer_secret"), 'v' => date('ymd'), 'll' => $lat . ',' . $long, 'limit' => 1, 'oauth_token' => get_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_token', 1)));
    $response = $buddyStreamOAuth->oAuthRequest('https://api.foursquare.com/v2/venues/search');
    $response = json_decode($response);
    $venueId = $response->response->groups[0]->items[0]->id;
    //checkin
    $buddyStreamOAuth = new BuddyStreamOAuth();
    $buddyStreamOAuth->setParameters(array('client_id' => get_site_option("buddystream_foursquare_consumer_key"), 'client_secret' => get_site_option("buddystream_foursquare_consumer_secret"), 'v' => date('ymd'), 'll' => $lat . ',' . $long, 'venueId' => $venueId, 'oauth_token' => get_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_token', 1)));
    $buddyStreamOAuth->setRequestType("POST");
    $response = $buddyStreamOAuth->oAuthRequest('https://api.foursquare.com/v2/checkins/add');
    $response = json_decode($response);
    buddyStreamAddToImportLog($bp->loggedin_user->id, $response->response->checkin->id, 'foursquare');
}
Example #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');
}
/**
 * Create a activity item
 * @param $params
 * @return string
 */
function buddystreamCreateActivity($params)
{
    global $bp, $wpdb;
    $buddyStreamExtensions = new BuddyStreamExtensions();
    $buddyStreamFilters = new BuddyStreamFilters();
    /**
     * buddystreamCreateActivity(array(
     *     'user_id'    => $user_meta->user_id,
     *     'extension'  => 'facebook',
     *     'type'       => 'photo',
     *     'content'    => $content,
     *     'item_id'    => $item['id'],
     *     'raw_date'   => $item['created_time'],
     *     'actionlink' => 'url_to_original_item')
     *  ));
     *
     */
    if (is_array($params)) {
        //load config of extension
        $originalText = $params['content'];
        foreach ($buddyStreamExtensions->getExtensionsConfigs() as $extension) {
            if (isset($extension['hashtag'])) {
                $originalText = str_replace($extension['hashtag'], "", $originalText);
                $originalText = trim($originalText);
            }
        }
        //set the content
        $content = "";
        $content = '<div class="buddystream_activity_container ' . $params['extension'] . '">' . $originalText . '</div>';
        if (!buddyStreamCheckImportLog($params['user_id'], $params['item_id'], $params['extension']) && !buddyStreamCheckExistingContent($content) && !buddyStreamCheckExistingContent($originalText)) {
            buddyStreamAddToImportLog($params['user_id'], $params['item_id'], $params['extension']);
            remove_filter('bp_activity_action_before_save', 'bp_activity_filter_kses', 1);
            $activity = new BP_Activity_Activity();
            $activity->user_id = $params['user_id'];
            $activity->component = $params['extension'];
            $activity->type = $params['extension'];
            $activity->content = $content;
            $activity->item_id = $params['item_id'];
            $activity->secondary_item_id = '';
            $activity->date_recorded = $params['raw_date'];
            $activity->hide_sitewide = 0;
            $activity->action .= '<a href="' . bp_core_get_user_domain($params['user_id']) . '" title="' . bp_core_get_username($params['user_id']) . '">' . bp_core_get_user_displayname($params['user_id']) . '</a>';
            $activity->action .= ' ' . __('posted&nbsp;a', 'buddystream_lang') . ' ';
            $activity->action .= '<a href="' . $params['actionlink'] . '" target="_blank" rel="external"> ' . __($params['type'], 'buddystream_' . $extension['name']);
            $activity->action .= '</a>: ';
            $activity->primary_link = $params['actionlink'];
            if (!preg_match("/" . $params['item_id'] . "/i", get_user_meta($params['user_id'], 'buddystream_blacklist_ids', 1))) {
                $activity->save();
                $buddyStreamFilters->updateDayLimitByOne($params['extension'], $params['user_id']);
                return true;
            }
        }
    }
    return false;
}
Example #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');
    }
}