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 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));
}
Example #3
0
 public function doImport()
 {
     global $bp, $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     //item counter for in the logs
     $itemCounter = 0;
     if (get_site_option("buddystream_instagram_consumer_key")) {
         $user_metas = $wpdb->get_results("SELECT user_id FROM " . $wpdb->usermeta . " WHERE meta_key='buddystream_instagram_token'");
         if ($user_metas) {
             foreach ($user_metas as $user_meta) {
                 //check for
                 $limitReached = $buddyStreamFilters->limitReached('instagram', $user_meta->user_id);
                 if (!$limitReached && get_user_meta($user_meta->user_id, 'buddystream_instagram_synctoac', 1)) {
                     //Handle the OAuth requests
                     $buddyStreamOAuth = new BuddyStreamOAuth();
                     $items = $buddyStreamOAuth->executeRequest('https://api.instagram.com/v1/users/' . get_user_meta($user_meta->user_id, 'buddystream_instagram_id', 1) . '/media/recent/?&access_token=' . get_user_meta($user_meta->user_id, 'buddystream_instagram_token', 1));
                     $items = json_decode($items);
                     $items = $items->data;
                     //Info about user
                     $instagram_account = $buddyStreamOAuth->executeRequest('https://api.instagram.com/v1/users/' . get_user_meta($user_meta->user_id, 'buddystream_instagram_id', 1) . '/?&access_token=' . get_user_meta($user_meta->user_id, 'buddystream_instagram_token', 1));
                     $instagram_account = json_decode($instagram_account);
                     update_user_meta($user_meta->user_id, 'gl_instagram_followers', $instagram_account->data->counts->followed_by);
                     update_user_meta($user_meta->user_id, 'gl_instagram_following', $instagram_account->data->counts->follows);
                     //Hook to do something on user during import process
                     do_action('buddystream_import_instagram_user', $user_meta->user_id);
                     if ($items) {
                         //go through tweets
                         foreach ($items as $item) {
                             //check daylimit
                             $limitReached = $buddyStreamFilters->limitReached('instagram', $user_meta->user_id);
                             //check if source filter passes
                             if (!$limitReached) {
                                 $returnCreate = false;
                                 $content = '<a href="' . $item->images->standard_resolution->url . '" rel="lightbox" class="bs_lightbox" id="' . $item->id . '"><img src="' . $item->images->low_resolution->url . '"></a> ' . $item->caption->text;
                                 $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'instagram', 'type' => 'Instagram', 'content' => $content, 'item_id' => $item->id, 'raw_date' => gmdate('Y-m-d H:i:s', (int) $item->created_time), 'actionlink' => $item->link));
                                 if ($returnCreate) {
                                     $itemCounter++;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Instagram imported " . $itemCounter . " images for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Example #4
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');
        }
    }
}
Example #5
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');
    }
}
Example #6
0
 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;
 }
Example #7
0
 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;
 }
        echo __('Remove LinkedIn synchronization.', 'buddystream_facebook');
        ?>
</a>
    <?php 
    }
    ?>

    </form>

<?php 
} else {
    echo '<h3>' . __('LinkedIn setup</h3>
                 You may setup you linkedIn intergration over here.<br/>
                 Before you can begin using LinkedIn with this site you must authorize on LinkedIn by clicking the link below.', 'buddystream_linkedin') . '<br/><br/>';
    //oauth
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setRequestTokenUrl('https://api.linkedin.com/uas/oauth/requestToken');
    $buddystreamOAuth->setAccessTokenUrl('https://api.linkedin.com/uas/oauth/accessToken');
    $buddystreamOAuth->setAuthorizeUrl('https://api.linkedin.com/uas/oauth/authorize');
    $buddystreamOAuth->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=linkedin');
    $buddystreamOAuth->setConsumerKey(get_site_option("buddystream_linkedin_consumer_key"));
    $buddystreamOAuth->setConsumerSecret(get_site_option("buddystream_linkedin_consumer_secret"));
    //get requesttoken and save it for later use.
    $requestToken = $buddystreamOAuth->requestToken();
    $buddystreamOAuth->setRequestToken($requestToken['oauth_token']);
    $buddystreamOAuth->setRequestTokenSecret($requestToken['oauth_token_secret']);
    update_user_meta($bp->loggedin_user->id, 'buddystream_linkedin_token_temp', '' . $requestToken['oauth_token'] . '');
    update_user_meta($bp->loggedin_user->id, 'buddystream_linkedin_tokensecret_temp', '' . $requestToken['oauth_token_secret'] . '');
    //get the redirect url for the user
    //$redirectUrl = $buddystreamOAuth->getRedirectUrl();
    // $redirectUrl =  "https://www.linkedin.com/uas/oauth2/authorization?scope=rw_nus&response_type=code&client_id=".get_site_option("buddystream_linkedin_consumer_key")."&state=".uniqid()."&redirect_uri=" . $bp->loggedin_user->domain . BP_SETTINGS_SLUG . "/buddystream-networks/?network=linkedin";
<?php

global $bp;
if ($_GET['reset'] == 'true') {
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_token');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_tokensecret');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_tokensecret_temp');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_token_temp');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_mention');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_synctoac');
}
if (isset($_GET['code'])) {
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setAccessTokenUrl('https://foursquare.com/oauth2/access_token');
    $buddystreamOAuth->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-foursquare');
    $buddystreamOAuth->setParameters(array('redirect_uri' => $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=foursquare', 'client_id' => get_site_option("buddystream_foursquare_consumer_key"), 'client_secret' => get_site_option("buddystream_foursquare_consumer_secret"), 'grant_type' => 'authorization_code', 'code' => $_GET['code']));
    //get accesstoken and save it
    $accessToken = json_decode($buddystreamOAuth->accessToken(true));
    update_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_token', $accessToken->access_token);
    update_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_synctoac', 1);
    //for other plugins
    do_action('buddystream_foursquare_activated');
}
if ($_POST) {
    update_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_synctoac', $_POST['buddystream_foursquare_synctoac']);
    //achievements plugins
    update_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_achievements', $_POST['buddystream_foursquare_achievements']);
    $message = __('Settings saved', 'buddystream_foursquare');
}
//put some options into variables
$buddystream_foursquare_synctoac = get_user_meta($bp->loggedin_user->id, 'buddystream_foursquare_synctoac', 1);
                        </td>
                    </tr>
                    </tbody>
                </table>

            <?php 
                _e('facebook albums description', 'buddystream_facebook');
                ?>
<br/><br/>

                <table class="table table-striped" cellspacing="0">
                    <tbody>

                        <?php 
                //Handle the OAuth requests
                $buddystreamOAuth = new BuddyStreamOAuth();
                $buddystreamOAuth->setParameters(array('client_id' => get_site_option("facestream_application_id"), 'client_secret' => get_site_option("facestream_application_secret"), 'access_token' => get_user_meta($bp->loggedin_user->id, 'facestream_session_key', 1)));
                $photoAlbums = $buddystreamOAuth->oAuthRequest('https://graph.facebook.com/me/albums');
                $photoAlbums = json_decode($photoAlbums);
                //get saved pages
                $savedFacebookAlbums = get_user_meta($bp->loggedin_user->id, 'buddystream_facebook_albums', 1);
                $savedFacebookAlbums = explode(',', $savedFacebookAlbums);
                if ($photoAlbums->data) {
                    foreach ($photoAlbums->data as $album) {
                        $checked = "";
                        if (in_array($album->id, $savedFacebookAlbums)) {
                            $checked = "checked";
                        }
                        echo '<tr><td><input type="checkbox" name="buddystream_facebook_albums[]" value="' . $album->id . '" ' . $checked . '/> ' . $album->name . '</td></tr>';
                    }
                }
Example #11
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');
}
        echo __('Remove Tumblr synchronization.', 'buddystream_facebook');
        ?>
</a>
    <?php 
    }
    ?>

    </form>

<?php 
} else {
    echo '<h3>' . __('Tumblr setup', 'buddystream_tumblr') . '</h3>';
    echo __('You may setup you Tumblr intergration over here.<br/>
                 Before you can begin using Tumblr with this site you must authorize on Tumblr by clicking the link below.', 'buddystream_tumblr') . '<br/><br/>';
    //oauth
    $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->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=tumblr');
    $buddystreamOAuth->setConsumerKey(get_site_option("buddystream_tumblr_consumer_key"));
    $buddystreamOAuth->setConsumerSecret(get_site_option("buddystream_tumblr_consumer_secret"));
    //get requesttoken and save it for later use.
    $requestToken = $buddystreamOAuth->requestToken();
    $buddystreamOAuth->setRequestToken($requestToken['oauth_token']);
    $buddystreamOAuth->setRequestTokenSecret($requestToken['oauth_token_secret']);
    update_user_meta($bp->loggedin_user->id, 'buddystream_tumblr_token_temp', '' . $requestToken['oauth_token'] . '');
    update_user_meta($bp->loggedin_user->id, 'buddystream_tumblr_tokensecret_temp', '' . $requestToken['oauth_token_secret'] . '');
    //get the redirect url for the user
    $redirectUrl = $buddystreamOAuth->getRedirectUrl();
    if ($redirectUrl) {
Example #13
0
 public function doImport()
 {
     global $bp, $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     //item counter for in the logs
     $itemCounter = 0;
     if (get_site_option("buddystream_foursquare_consumer_key")) {
         if (get_site_option('buddystream_foursquare_user_settings_syncbp') == 0) {
             $user_metas = $wpdb->get_results("SELECT user_id FROM " . $wpdb->usermeta . " WHERE meta_key='buddystream_foursquare_token'");
             if ($user_metas) {
                 foreach ($user_metas as $user_meta) {
                     //check for
                     $limitReached = $buddyStreamFilters->limitReached('foursquare', $user_meta->user_id);
                     if (!$limitReached && get_user_meta($user_meta->user_id, 'buddystream_foursquare_synctoac', 1)) {
                         //Handle the OAuth requests
                         $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'), 'oauth_token' => get_user_meta($user_meta->user_id, 'buddystream_foursquare_token', 1)));
                         $items = $buddyStreamOAuth->oAuthRequest('https://api.foursquare.com/v2/users/self/checkins');
                         $items = json_decode($items);
                         $items = $items->response->checkins->items;
                         if ($items) {
                             //go through tweets
                             foreach ($items as $item) {
                                 //check daylimit
                                 $limitReached = $buddyStreamFilters->limitReached('foursquare', $user_meta->user_id);
                                 //check if source filter passes
                                 if (!$limitReached) {
                                     $returnCreate = false;
                                     //icon
                                     $icon = "";
                                     $icon = $item->venue->categories[0]->icon;
                                     $icon = str_replace("https", "http", $icon);
                                     //map settings
                                     if (get_site_option("buddystream_foursquare_map_height")) {
                                         $height = get_site_option("buddystream_foursquare_map_height");
                                     } else {
                                         $height = 150;
                                     }
                                     if (get_site_option("buddystream_foursquare_map_width")) {
                                         $width = get_site_option("buddystream_foursquare_map_width");
                                     } else {
                                         $width = 520;
                                     }
                                     if (get_site_option("buddystream_foursquare_map_zoom")) {
                                         $zoom = get_site_option("buddystream_foursquare_map_zoom");
                                     } else {
                                         $zoom = 13;
                                     }
                                     $content = '';
                                     $content .= 'Checked in <a href="' . $item->venue->canonicalUrl . '" target="_blank">' . $item->venue->name . '</a><br>';
                                     $content .= '<a href="' . $item->venue->canonicalUrl . '" target="_blank"><img src="http://maps.googleapis.com/maps/api/staticmap?center=' . $item->location->lat . ',' . $item->venue->location->lng . '&zoom=' . $zoom . '&size=' . $width . 'x' . $height . '&sensor=false&markers=icon%3A' . $icon . '%7C' . $item->venue->location->lat . ',' . $item->venue->location->lng . '&format=png32">';
                                     $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'foursquare', 'type' => 'checkin', 'content' => $content, 'item_id' => $item->id, 'raw_date' => gmdate('Y-m-d H:i:s', $item->createdAt), 'actionlink' => $item->venue->canonicalUrl));
                                     if ($returnCreate) {
                                         $itemCounter++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Foursquare imported " . $itemCounter . " checkins for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Example #14
0
 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;
 }
Example #15
0
 public function doImport()
 {
     global $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='facestream_session_key';");
     if ($user_metas) {
         foreach ($user_metas as $user_meta) {
             //get the privacy level of importing
             $privacyLevelAlbums = "everyone";
             //admin setting for default privacy setting (by default on ALL_FRIENDS).
             if (get_site_option("buddystream_facebook_privacy_setting")) {
                 $privacyLevelAlbums = "friends";
             }
             //user setting for privacy settings
             if (get_user_meta($user_meta->user_id, 'buddystream_facebook_privacy_friends', 1)) {
                 $privacyLevelAlbums = "friends";
             }
             //check for daylimit
             $limitReached = $buddyStreamFilters->limitReached('facebook', $user_meta->user_id);
             if (!$limitReached && get_site_option('facestream_user_settings_syncalbumsbp') && get_user_meta($user_meta->user_id, 'buddystream_facebook_syncalbum', 1) && get_user_meta($user_meta->user_id, 'buddystream_facebook_albums', 1) && !get_user_meta($user_meta->user_id, 'buddystream_facebook_reauth', 1)) {
                 //get the pages for this user
                 $facebookAlbums = get_user_meta($user_meta->user_id, 'buddystream_facebook_albums', 1);
                 //explode the pages
                 $facebookAlbumsArray = explode(',', $facebookAlbums);
                 foreach ($facebookAlbumsArray as $album) {
                     //get all photos in this album.
                     $buddyStreamOAuth = new BuddyStreamOAuth();
                     $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_meta->user_id, 'facestream_session_key', 1))));
                     $fbAlbum = $buddyStreamOAuth->oAuthRequest('https://graph.facebook.com/' . $album);
                     $fbAlbum = json_decode($fbAlbum);
                     $photos = $buddyStreamOAuth->oAuthRequest('https://graph.facebook.com/' . $album . '/photos');
                     $photos = json_decode($photos);
                     //we have a error, set re-authenticate to true
                     if (strpos(" " . $photos->error->message, "Error")) {
                         //update_user_meta($user_meta->user_id,"buddystream_facebook_reauth", true);
                     }
                     if ($photos->data) {
                         foreach ($photos->data as $photo) {
                             //check daylimit
                             $limitReached = $buddyStreamFilters->limitReached('facebook', $user_meta->user_id);
                             if (!$limitReached && ($fbAlbum->privacy == "everyone" or $fbAlbum->privacy == $privacyLevelAlbums)) {
                                 //set the content
                                 $content = '';
                                 $content = '<a href="' . $photo->source . '" class="bs_lightbox"><img src="' . $photo->picture . '"></a>' . $photo->name;
                                 //check if good filter passes
                                 $goodFilters = get_site_option('facestream_filter');
                                 $goodFilter = $buddyStreamFilters->searchFilter($content, $goodFilters, false, true, true);
                                 //check if bad filter passes
                                 $badFilters = get_site_option('facestream_filterexplicit');
                                 $badFilter = $buddyStreamFilters->searchFilter($content, $badFilters, true);
                                 //no filters set so just import everything
                                 if (!get_site_option('facestream_filter')) {
                                     $goodFilter = true;
                                 }
                                 if (!get_site_option('facestream_filterexplicit')) {
                                     $badFilter = false;
                                 }
                                 //check of item does not exist.
                                 if ($goodFilter && !$badFilter) {
                                     $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'facebook', 'type' => 'Facebook photo', 'content' => $content, 'item_id' => $photo->id, 'raw_date' => gmdate('Y-m-d H:i:s', strtotime($photo->created_time)), 'actionlink' => $photo->link));
                                     if ($returnCreate) {
                                         $itemCounter++;
                                     }
                                 }
                             }
                         }
                     }
                     unset($buddyStreamOAuth, $photos);
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("Facebook Albums imported " . $itemCounter . "  items for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
Example #16
0
 public function doImport()
 {
     global $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='facestream_session_key';");
     if ($user_metas) {
         foreach ($user_metas as $user_meta) {
             //get the privacy level of importing
             $privacyLevel = "EVERYONE";
             //admin setting for default privacy setting (by default on ALL_FRIENDS).
             if (get_site_option("buddystream_facebook_privacy_setting")) {
                 $privacyLevel = "ALL_FRIENDS";
             }
             //user setting for privacy settings
             if (get_user_meta($user_meta->user_id, 'buddystream_facebook_privacy_friends', 1)) {
                 $privacyLevel = "ALL_FRIENDS";
             }
             //check for daylimit
             $limitReached = $buddyStreamFilters->limitReached('facebook', $user_meta->user_id);
             if (!$limitReached && get_site_option('facestream_user_settings_syncpagesbp') && get_user_meta($user_meta->user_id, 'buddystream_facebook_syncpage', 1) && get_user_meta($user_meta->user_id, 'buddystream_facebook_pages', 1) && !get_user_meta($user_meta->user_id, 'buddystream_facebook_reauth', 1)) {
                 //get the pages for this user
                 $facebookPages = get_user_meta($user_meta->user_id, 'buddystream_facebook_pages', 1);
                 //explode the pages
                 $facebookPagesArray = explode(',', $facebookPages);
                 foreach ($facebookPagesArray as $page) {
                     //explode page details
                     $pageArray = explode(':', $page);
                     //Handle the OAuth requests
                     $buddyStreamOAuth = new BuddyStreamOAuth();
                     $buddyStreamOAuth->setParameters(array('client_id' => get_site_option("facestream_application_id"), 'client_secret' => get_site_option("facestream_application_secret"), 'access_token' => $pageArray[1]));
                     $items = $buddyStreamOAuth->oAuthRequest('https://graph.facebook.com/' . $pageArray[0] . '/feed');
                     $items = json_decode($items);
                     //we have a error, set re-authenticate to true
                     if (strpos(" " . $items->error->message, "Error")) {
                         //update_user_meta($user_meta->user_id,"buddystream_facebook_reauth", true);
                     }
                     if (isset($items->data)) {
                         foreach ($items->data as $item) {
                             //from me
                             $fromMe = false;
                             if ($item->from->id == $pageArray[0]) {
                                 $fromMe = true;
                             }
                             //check day limit
                             $limitReached = $buddyStreamFilters->limitReached('facebook', $user_meta->user_id);
                             if (!$limitReached && $fromMe && ($item->privacy->value == "EVERYONE" or $item->privacy->value == $privacyLevel)) {
                                 if (!isset($item->message)) {
                                     $item->message = "";
                                 }
                                 if (!isset($item->description)) {
                                     $item->description = "";
                                 }
                                 if (!isset($item->picture)) {
                                     $item->picture = "";
                                 }
                                 if (!isset($item->name)) {
                                     $item->name = "";
                                 }
                                 //shorten the message/description
                                 $message = "";
                                 $message = $item->message;
                                 if (strlen($message) > 400) {
                                     $message = substr($message, 0, 400) . "...";
                                 }
                                 if (empty($message)) {
                                     $message = $item->description;
                                     if (strlen($message) > 400) {
                                         $message = substr($message, 0, 400) . "...";
                                     }
                                 }
                                 //reset the content
                                 $content = "";
                                 //are we allowed to import this type
                                 if ($item->type == "status" && get_site_option("facestream_user_settings_syncupdatesbp") == "on") {
                                     $content = $message;
                                 }
                                 if ($item->type == "photo" && get_site_option("facestream_user_settings_syncphotosbp") == "on") {
                                     $fullSize = $item->picture;
                                     $fullSize = str_replace("_s", "_n", $fullSize);
                                     $fullSize = str_replace("_z", "_n", $fullSize);
                                     $content = '<a href="' . $fullSize . '" class="bs_lightbox"><img src="' . $item->picture . '"></a>' . $message;
                                 }
                                 if ($item->type == "link" && get_site_option("facestream_user_settings_synclinksbp") == "on") {
                                     if ($item->picture) {
                                         $imgArray = explode("=", $item->picture);
                                         $imgArray = array_reverse($imgArray);
                                     }
                                     $content = '<a href="' . urldecode($imgArray[0]) . '" class="bs_lightbox"><img src="' . $item->picture . '"></a><strong><a href="' . $item->link . '" target="_new" rel="external">' . $item->name . '</a></strong><br/>' . $message;
                                 }
                                 if ($item->type == "video" && get_site_option("facestream_user_settings_syncvideosbp") == "on") {
                                     if ($item->attribution != "YouTube") {
                                         $content = '<a href="' . $item->link . '" class="bs_lightbox"><img src="' . $item->picture . '"></a>' . $message;
                                     }
                                 }
                                 //check if good filter passes
                                 $goodFilters = get_site_option('facestream_filter');
                                 $goodFilter = $buddyStreamFilters->searchFilter($content, $goodFilters, false, true, true);
                                 //check if bad filter passes
                                 $badFilters = get_site_option('facestream_filterexplicit');
                                 $badFilter = $buddyStreamFilters->searchFilter($content, $badFilters, true);
                                 //check if source filter passes
                                 $sourceFilter = false;
                                 if (isset($item->application->id)) {
                                     $sourceFilter = $buddyStreamFilters->searchFilter(get_site_option("facestream_application_id"), $item->application->id, true);
                                 }
                                 //no filters set so just import everything
                                 if (!get_site_option('facestream_filter')) {
                                     $goodFilter = true;
                                 }
                                 if (!get_site_option('facestream_filterexplicit')) {
                                     $badFilter = false;
                                 }
                                 //check of item does not exist.
                                 if ($goodFilter && !$badFilter && !$sourceFilter) {
                                     $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'facebook', 'type' => 'Facebook page ' . $item->type, 'content' => $content, 'item_id' => $item->id, 'raw_date' => gmdate('Y-m-d H:i:s', strtotime($item->created_time)), 'actionlink' => 'http://www.facebook.com/' . $pageArray[0] . '/'));
                                     if ($returnCreate) {
                                         $itemCounter++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             unset($buddyStreamOAuth, $items);
         }
     }
     //add record to the log
     $buddyStreamLog->log("Facebook Pages imported " . $itemCounter . " items for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }
        echo __('Remove Google+ synchronization.', 'buddystream_facebook');
        ?>
</a>
    <?php 
    }
    ?>

    </form>

<?php 
} else {
    echo '<h3>' . __('Google+ setup</h3>
                 You may setup you Google+ intergration over here.<br/>
                 Before you can begin using Google+ with this site you must authorize on Google+ by clicking the link below.', 'buddystream_googleplus') . '<br/><br/>';
    //oauth
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setRequestTokenUrl('https://www.google.com/accounts/OAuthGetRequestToken');
    $buddystreamOAuth->setAccessTokenUrl('https://www.google.com/accounts/OAuthGetAccessToken');
    $buddystreamOAuth->setAuthorizeUrl('https://www.google.com/accounts/OAuthAuthorizeToken');
    $buddystreamOAuth->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=googleplus');
    $buddystreamOAuth->setParameters(array('scope' => 'https://www.googleapis.com/auth/plus.me'));
    $buddystreamOAuth->setConsumerKey(get_site_option("buddystream_googleplus_consumer_key"));
    $buddystreamOAuth->setConsumerSecret(get_site_option("buddystream_googleplus_consumer_secret"));
    //get requesttoken and save it for later use.
    $requestToken = $buddystreamOAuth->requestToken();
    $buddystreamOAuth->setRequestToken($requestToken['oauth_token']);
    $buddystreamOAuth->setRequestTokenSecret($requestToken['oauth_token_secret']);
    update_user_meta($bp->loggedin_user->id, 'buddystream_googleplus_token_temp', '' . urldecode($requestToken['oauth_token'] . ''));
    update_user_meta($bp->loggedin_user->id, 'buddystream_googleplus_tokensecret_temp', '' . $requestToken['oauth_token_secret'] . '');
    //get the redirect url for the user
    $redirectUrl = $buddystreamOAuth->getRedirectUrl();
Example #18
0
 public function doImport()
 {
     global $wpdb;
     $buddyStreamLog = new BuddyStreamLog();
     $buddyStreamFilters = new BuddyStreamFilters();
     $itemCounter = 0;
     if (get_site_option("buddystream_linkedin_consumer_key")) {
         if (get_site_option('buddystream_linkedin_user_settings_syncbp') == 0) {
             $user_metas = $wpdb->get_results("SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='buddystream_linkedin_token'");
             if ($user_metas) {
                 foreach ($user_metas as $user_meta) {
                     //check for daylimit
                     $limitReached = $buddyStreamFilters->limitReached('linkedin', $user_meta->user_id);
                     if (!$limitReached && get_user_meta($user_meta->user_id, 'buddystream_linkedin_synctoac', 1) && !get_user_meta($user_meta->user_id, 'buddystream_linkedin_reauth', 1)) {
                         //Handle the OAuth requests
                         $buddystreamOAuth = new BuddyStreamOAuth();
                         $buddystreamOAuth->setParameters(array('client_id' => get_site_option("buddystream_linkedin_consumer_key"), 'client_secret' => get_site_option("buddystream_linkedin_consumer_secret"), 'oauth2_access_token' => get_user_meta($user_meta->user_id, 'buddystream_linkedin_token', 1)));
                         $items = $buddystreamOAuth->executeRequest('https://api.linkedin.com/v1/people/~/network/updates?type=SHAR&scope=self&oauth2_access_token=' . get_user_meta($user_meta->user_id, 'buddystream_linkedin_token', 1));
                         $items = simplexml_load_string($items);
                         if (strpos(" " . $items->message, "Invalid")) {
                             update_user_meta($user_meta->user_id, "buddystream_linkedin_reauth", true);
                         }
                         if ($items->status == "401") {
                             update_user_meta($user_meta->user_id, "buddystream_linkedin_reauth", true);
                         }
                         if ($items) {
                             //go through items
                             foreach ($items as $item) {
                                 //check for daylimit
                                 $limitReached = $buddyStreamFilters->limitReached('linkedin', $user_meta->user_id);
                                 //get the content
                                 if ($item->{'update-type'} == 'SHAR') {
                                     $content = $item->{'update-content'}->{'person'}->{'current-share'}->{'comment'};
                                 }
                                 //check if good filter passes
                                 $goodFilters = get_site_option('buddystream_linkedin_filter');
                                 $goodFilter = $buddyStreamFilters->searchFilter($content, $goodFilters, false, true, true);
                                 //check if bad filter passes
                                 $badFilters = get_site_option('buddystream_linkedin_filterexplicit');
                                 $badFilter = $buddyStreamFilters->searchFilter($content, $badFilters, true);
                                 //no filters set so just import everything
                                 if (!get_site_option('buddystream_linkedin_filter')) {
                                     $goodFilter = true;
                                 }
                                 if (!get_site_option('buddystream_linkedin_filterexplicit')) {
                                     $badFilter = false;
                                 }
                                 if (!$limitReached && $goodFilter && !$badFilter) {
                                     //convert timestamp
                                     $timeStamp = $item->timestamp;
                                     $timeStamp = substr($timeStamp, 0, 10);
                                     $returnCreate = buddystreamCreateActivity(array('user_id' => $user_meta->user_id, 'extension' => 'linkedin', 'type' => 'status', 'content' => $content, 'item_id' => "linkedin_" . $item->{'update-key'}, 'raw_date' => gmdate('Y-m-d H:i:s', $timeStamp), 'actionlink' => trim($item->{'update-content'}->{'person'}->{'site-standard-profile-request'}->{'url'} . "")));
                                     if ($returnCreate) {
                                         $itemCounter++;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     //add record to the log
     $buddyStreamLog->log("LinkedIn imported " . $itemCounter . " items for " . count($user_metas) . " users.");
     //return number of items imported
     return $itemCounter;
 }