/** * 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'); }
/** * 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'); } }
public function doImport() { global $wpdb; $buddyStreamLog = new BuddyStreamLog(); $buddyStreamFilters = new BuddyStreamFilters(); $itemCounter = 0; if (get_site_option("buddystream_tumblr_consumer_key")) { if (get_site_option('buddystream_tumblr_user_settings_syncbp') == 0) { $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='buddystream_tumblr_token'"); if ($user_metas) { foreach ($user_metas as $user_meta) { //check for daylimit $limitReached = $buddyStreamFilters->limitReached('tumblr', $user_meta->user_id); if (!$limitReached && get_user_meta($user_meta->user_id, 'buddystream_tumblr_synctoac', 1)) { //Handle the OAuth requests $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($user_meta->user_id, 'buddystream_tumblr_token', 1)); $buddystreamOAuth->setAccessTokenSecret(get_user_meta($user_meta->user_id, 'buddystream_tumblr_tokensecret', 1)); $buddystreamTumblrBlogsImport = get_user_meta($user_meta->user_id, 'buddystream_tumblr_blogs_import', 1); $buddystreamTumblrBlogsImport = explode(",", $buddystreamTumblrBlogsImport); foreach ($buddystreamTumblrBlogsImport as $blog) { $blog = urlencode('' . $blog . '.tumblr.com'); $buddystreamOAuth->setParameters(array('base-hostname' => $blog, 'api_key' => get_site_option("buddystream_tumblr_consumer_key"))); $items = $buddystreamOAuth->oAuthRequest('http://api.tumblr.com/v2/blog/' . $blog . '/posts'); $items = json_decode($items); $items = $items->response->posts; if ($items) { //go through items foreach ($items as $item) { //check for daylimit $limitReached = $buddyStreamFilters->limitReached('tumblr', $user_meta->user_id); //get the title $title = ""; if ($item->title) { $title = $item->title; $title = strip_tags($title); $title = trim($title); $title = "<strong>" . $title . "</strong> <br/>"; } //get the image $image = ""; if ($item->photos) { $caption = $item->caption; $caption = strip_tags($caption); $caption = trim($caption); $image = '<a href="' . $item->photos[0]->original_size->url . '" class="bs_lightbox"><img src="' . $item->photos[0]->alt_sizes[3]->url . '" alt="' . $caption . '"></a> '; } //get the body $body = $item->body . "" . $item->text . "" . $item->caption . ""; $body = strip_tags($body); $body = trim($body); //combine all to content $content = "" . $title . "<br>" . $image . "" . $body . ""; //check if good filter passes $goodFilters = get_site_option('buddystream_tumblr_filter'); $goodFilter = $buddyStreamFilters->searchFilter($content, $goodFilters, false, true, true); //check if bad filter passes $badFilters = get_site_option('buddystream_tumblr_filterexplicit'); $badFilter = $buddyStreamFilters->searchFilter($content, $badFilters, true); //no filters set so just import everything if (!get_site_option('buddystream_tumblr_filter')) { $goodFilter = true; } if (!get_site_option('buddystream_tumblr_filterexplicit')) { $badFilter = false; } if (!$limitReached && $goodFilter && !$badFilter) { //convert timestamp $timeStamp = strtotime($item->date); $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'tumblr', 'type' => 'tumblr blogpost', 'content' => $content, 'item_id' => $item->id, 'raw_date' => gmdate('Y-m-d H:i:s', $timeStamp), 'actionlink' => trim($item->post_url . ""))); if ($returnCreate) { $itemCounter++; } } } } } } } } } } //add record to the log $buddyStreamLog->log("Tumblr imported " . $itemCounter . " items for " . count($user_metas) . " users."); //return number of items imported return $itemCounter; }
public function doImport() { global $bp, $wpdb; $buddyStreamLog = new BuddyStreamLog(); $buddyStreamFilters = new BuddyStreamFilters(); $itemCounter = 0; if (get_site_option("buddystream_googleplus_consumer_key")) { if (get_site_option('buddystream_googleplus_user_settings_syncbp') == "on") { $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='buddystream_googleplus_token'"); if ($user_metas) { foreach ($user_metas as $user_meta) { //always start with import = true $import = true; //check for daylimit $import = $buddyStreamFilters->limitReached('googleplus', $user_meta->user_id); if (false === $import && get_user_meta($user_meta->user_id, 'buddystream_googleplus_synctoac', 1) == "1") { //Handle the OAuth requests $buddystreamOAuth = new BuddyStreamOAuth(); $buddystreamOAuth->setCallbackUrl($bp->root_domain); $buddystreamOAuth->setConsumerKey(get_site_option("buddystream_googleplus_consumer_key")); $buddystreamOAuth->setConsumerSecret(get_site_option("buddystream_googleplus_consumer_secret")); $buddystreamOAuth->setAccessToken(get_user_meta($user_meta->user_id, 'buddystream_googleplus_token', 1)); $buddystreamOAuth->setAccessTokenSecret(get_user_meta($user_meta->user_id, 'buddystream_googleplus_tokensecret', 1)); $items = $buddystreamOAuth->oAuthRequest('https://www.googleapis.com/plus/v1/people/me/activities/public'); $items = json_decode($items); if (isset($items->items)) { //go through items foreach ($items->items as $item) { //check for daylimit $limitReached = $buddyStreamFilters->limitReached('googleplus', $user_meta->user_id); if (!$limitReached) { //pre-defined $content = ""; $image = ""; //create te correct content for the activity stream //hey we have some images if (isset($item->object->attachments)) { foreach ($item->object->attachments as $media) { $media->displayName = ""; $media->url = ""; if ($media->objectType == "article") { $content .= $media->displayName . "<br>"; $content .= $media->content . "<br>"; $content .= '<a href="' . $media->url . '">' . __('visit link', 'buddystream_googleplus') . '</a>'; } elseif ($media->objectType == "video") { //transform the video url. $videoUrl = $media->url; $videoUrl = str_replace("http://www.youtube.com/v/", "", $videoUrl); $videoUrlAray = explode("&", $videoUrl); $videoId = $videoUrlAray[0]; $videoUrl = 'http://www.youtube.com/?v=' . $videoId; $content .= $media->displayName . "<br>"; $content .= $media->content . "<br>"; $image .= '<a href="' . $videoUrl . '" id="' . $videoId . '" title="' . str_replace('"', '', $media->displayName) . '" class="bs_lightbox"><img src="' . $media->image->url . '">' . $media->displayName . '</a>'; } else { $image .= '<a href="' . $media->fullImage->url . '" title="' . str_replace('"', '', $media->displayName) . '" class="bs_lightbox"><img src="' . $media->image->url . '">' . $media->displayName . '</a>'; } } } else { $content = $item->object->content; } //combine the images and content $content = $image . $content; //check if good filter passes $goodFilters = get_site_option('buddystream_googleplus_filter'); $goodFilter = $buddyStreamFilters->searchFilter($content, $goodFilters, false, true, true); //check if bad filter passes $badFilters = get_site_option('buddystream_googleplus_filterexplicit'); $badFilter = $buddyStreamFilters->searchFilter($content, $badFilters, true); //no filters set so just import everything if (!get_site_option('buddystream_googleplus_filter')) { $goodFilter = true; } if (!get_site_option('buddystream_googleplus_filterexplicit')) { $badFilter = false; } if ($goodFilter && !$badFilter) { $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'googleplus', 'type' => 'google+ ' . $item->object->objectType, 'content' => $content, 'item_id' => 'googleplus_' . $item->id, 'raw_date' => gmdate('Y-m-d H:i:s', strtotime($item->published)), 'actionlink' => $item->url)); if ($returnCreate) { $itemCounter++; } } unset($videoId, $content, $videoUrl, $image); } } } } } } } } //add record to the log $buddyStreamLog->log("Google+ imported " . $itemCounter . " items."); //return number of items imported return $itemCounter; }
?> <?php if (!get_site_option('buddystream_tumblr_import')) { _e('There are no settings available.</br></br>', 'buddystream_tumblr'); } else { //get the blogs for the settings //Handle the OAuth requests $buddystreamOAuth = new BuddyStreamOAuth(); $buddystreamOAuth->setRequestTokenUrl('http://www.tumblr.com/oauth/request_token'); $buddystreamOAuth->setAccessTokenUrl('http://www.tumblr.com/oauth/access_token'); $buddystreamOAuth->setAuthorizeUrl('http://www.tumblr.com/oauth/authorize'); $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)); $blogs = $buddystreamOAuth->oAuthRequest('http://api.tumblr.com/v2/user/info'); $blogs = json_decode($blogs); ?> <table class="table table-striped" cellspacing="0"> <thead> <tr> <th><?php echo __('Synchronize Tumblr updates to my activity stream?', 'buddystream_tumblr'); ?> </th> </tr> </thead> <tbody>
public function doImport() { global $bp, $wpdb; $buddyStreamLog = new BuddyStreamLog(); $buddyStreamFilters = new BuddyStreamFilters(); //item counter for in the logs $itemCounter = 0; if (get_site_option("tweetstream_consumer_key")) { if (get_site_option('tweetstream_user_settings_syncbp') == 0) { $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='tweetstream_token'"); if ($user_metas) { foreach ($user_metas as $user_meta) { //check for $limitReached = $buddyStreamFilters->limitReached('twitter', $user_meta->user_id); if (!$limitReached && get_user_meta($user_meta->user_id, 'tweetstream_synctoac', 1) && !get_user_meta($user_meta->user_id, 'buddystream_linkedin_reauth', 1)) { //Handle the OAuth requests $buddyStreamOAuth = new BuddyStreamOAuth(); $buddyStreamOAuth->setCallbackUrl($bp->root_domain); $buddyStreamOAuth->setConsumerKey(get_site_option("tweetstream_consumer_key")); $buddyStreamOAuth->setConsumerSecret(get_site_option("tweetstream_consumer_secret")); $buddyStreamOAuth->setAccessToken(get_user_meta($user_meta->user_id, 'tweetstream_token', 1)); $buddyStreamOAuth->setAccessTokenSecret(get_user_meta($user_meta->user_id, 'tweetstream_tokensecret', 1)); //update the user Info $twitter_settings = $buddyStreamOAuth->oAuthRequest('https://api.twitter.com/1.1/account/settings.json'); $twitter_settings = json_decode($twitter_settings); $screenName = $twitter_settings->screen_name; update_user_meta($user_meta->user_id, 'tweetstream_screenname', $screenName); $twitter_account = $buddyStreamOAuth->oAuthRequest('https://api.twitter.com/1.1/users/show.json?screen_name=' . $screenName); $twitter_account = json_decode($twitter_account); update_user_meta($user_meta->user_id, 'gl_twitter_followers', $twitter_account->followers_count); update_user_meta($user_meta->user_id, 'gl_twitter_following', $twitter_account->friends_count); //update_user_meta($user_meta->user_id, 'description', $twitter_account->description); //Hook to do something on user during import process do_action('buddystream_import_twitter_user', $user_meta->user_id); //get timeline $items = $buddyStreamOAuth->oAuthRequest('https://api.twitter.com/1.1/statuses/user_timeline.json'); $items = json_decode($items); if ($items->error) { update_user_meta($user_meta->user_id, "buddystream_twitter_reauth", true); } if ($items && !$items->error) { //go through tweets foreach ($items as $tweet) { //check daylimit $limitReached = $buddyStreamFilters->limitReached('twitter', $user_meta->user_id); //check if good filter passes $goodFilters = get_site_option('tweetstream_filter'); $goodFilter = $buddyStreamFilters->searchFilter($tweet->text, $goodFilters, false, true, true); //check if bad filter passes $badFilters = get_site_option('tweetstream_filterexplicit'); $badFilter = $buddyStreamFilters->searchFilter($tweet->text, $badFilters, true); //no filters set so just import everything if (!get_site_option('tweetstream_filter')) { $goodFilter = true; } if (!get_site_option('tweetstream_filterexplicit')) { $badFilter = false; } //check if source filter passes $sourceFilter = $buddyStreamFilters->searchFilter($bp->root_domain, $tweet->source, true); if (!$limitReached && $goodFilter && !$badFilter && !$sourceFilter) { $content = ''; if (isset($tweet->entities->media)) { foreach ($tweet->entities->media as $media) { $content .= '<a href="' . urldecode($media->media_url) . '" rel="lightbox" class="thickbox"><img src="' . $media->media_url . '"></a>'; } } $content .= $tweet->text; $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'twitter', 'type' => 'tweet', 'content' => $content, 'item_id' => buddystreamGetTweetId($tweet->id), 'raw_date' => gmdate('Y-m-d H:i:s', strtotime($tweet->created_at)), 'actionlink' => 'https://www.twitter.com/' . $screenName . '/status/' . buddystreamGetTweetId($tweet->id))); if ($returnCreate) { $itemCounter++; } } } } } } } } } //add record to the log $buddyStreamLog->log("Twitter imported " . $itemCounter . " tweets for " . count($user_metas) . " users."); //return number of items imported return $itemCounter; }