示例#1
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');
}
</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();
    if ($redirectUrl) {
        echo '<a href="' . $redirectUrl . '" class="buddystream_authorize_button">' . __('Click here to start authorization', 'buddystream_googleplus') . '</a><br/><br/>';
</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";
    $redirectUrl = "https://www.linkedin.com/uas/oauth2/authorization?scope=w_share&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";
    if ($redirectUrl) {
           class="buddystream_reset_button"><?php 
        echo __('Remove Twitter synchronization', 'buddystream_twitter');
        ?>
</a>
    <?php 
    }
    ?>
    </form>

<?php 
} else {
    echo __('<h3>Twitter setup</h3>You may setup you twitter intergration over here.<br/>Before you can begin using Twitter with this site you must authorize on Twitter by clicking the link below.', 'buddystream_twitter') . '<br/><br/>';
    //oauth
    $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->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=twitter');
    $buddystreamOAuth->setConsumerKey(get_site_option("tweetstream_consumer_key"));
    $buddystreamOAuth->setConsumerSecret(get_site_option("tweetstream_consumer_secret"));
    //get request token 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, 'tweetstream_token_temp', '' . $requestToken['oauth_token'] . '');
    update_user_meta($bp->loggedin_user->id, 'tweetstream_token_secret_temp', '' . $requestToken['oauth_token_secret'] . '');
    //get the redirect url for the user
    $redirectUrl = $buddystreamOAuth->getRedirectUrl();
    if ($redirectUrl) {
        echo '<a href="' . $redirectUrl . '" class="buddystream_authorize_button">' . __('Click here to start authorization', 'buddystream_twitter') . '</a><br/><br/>';
    } else {
<?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);
</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) {
        echo '<a href="' . $redirectUrl . '" class="buddystream_authorize_button">' . __('Click here to start authorization', 'buddystream_tumblr') . '</a><br/><br/>';
    } else {
if ($_GET['reset'] == 'true') {
    delete_user_meta($bp->loggedin_user->id, 'facestream_session_key');
    delete_user_meta($bp->loggedin_user->id, 'facestream_synctoac');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_facebook_syncpage');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_facebook_syncalbum');
    delete_user_meta($bp->loggedin_user->id, 'facestream_synctoac');
    delete_user_meta($bp->loggedin_user->id, 'facestream_filtermentions');
    delete_user_meta($bp->loggedin_user->id, 'facestream_user_id');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_facebook_privacy_friends');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_facebook_pages');
    delete_user_meta($bp->loggedin_user->id, 'buddystream_facebook_albums');
}
//back from facebook with code
if (isset($_GET['code'])) {
    $buddystreamOAuth = new BuddyStreamOAuth();
    $buddystreamOAuth->setAccessTokenUrl('https://graph.facebook.com/oauth/access_token');
    $buddystreamOAuth->setCallbackUrl($bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-facebook');
    $buddystreamOAuth->setParameters(array('redirect_uri' => $bp->loggedin_user->domain . BP_SETTINGS_SLUG . '/buddystream-networks/?network=facebook', 'client_id' => get_site_option("facestream_application_id"), 'client_secret' => get_site_option("facestream_application_secret"), 'code' => $_GET['code']));
    //get accesstoken and save it
    $accessToken = $buddystreamOAuth->accessToken(true);
    //create tokenarray from output
    $tokenArray = explode("=", $accessToken);
    update_user_meta($bp->loggedin_user->id, 'facestream_session_key', str_replace("&expires", "", $tokenArray[1]));
    update_user_meta($bp->loggedin_user->id, 'facestream_synctoac', 1);
    update_user_meta($bp->loggedin_user->id, 'buddystream_facebook_syncpage', 1);
    update_user_meta($bp->loggedin_user->id, 'buddystream_facebook_syncalbum', 1);
    delete_user_meta($bp->loggedin_user->id, "buddystream_facebook_reauth", true);
    //for other plugins
    do_action('buddystream_facebook_activated');
}
//save user settings