Exemple #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) {
        ?>
</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";
        <a href="?network=twitter&reset=true"
           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/>';
        ?>
</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/>';