Пример #1
0
function stc_comm_send_to_twitter()
{
    $options = get_option('stc_options');
    if (!$options['comment_text']) {
        return;
    }
    $postid = (int) $_POST['comment_post_ID'];
    if (!$postid) {
        return;
    }
    // send the comment to twitter
    if ($_POST['stc_comm_send'] == 'send') {
        // args to send to twitter
        $args = array();
        // check for coords from the post
        $lat = (double) $_POST['stc_lat'];
        $long = (double) $_POST['stc_long'];
        if ($lat != 0 && $long != 0) {
            // we got coords, include them
            $args['lat'] = $lat;
            $args['long'] = $long;
        }
        if (function_exists('wp_get_shortlink')) {
            // use the shortlink if it's available
            $link = wp_get_shortlink($postid);
        } else {
            if (function_exists('get_shortlink')) {
                // use the shortlink if it's available
                $link = get_shortlink($postid);
            } else {
                // use the full permalink (twitter will shorten for you)
                $link = get_permalink($postid);
            }
        }
        $args['status'] = str_replace('%', $link, $options['comment_text']);
        $resp = stc_do_request('http://api.twitter.com/1/statuses/update', $args);
    }
}
Пример #2
0
function stc_get_credentials($force_check = false)
{
    // cache the results in the session so we don't do this over and over
    if (!$force_check && $_SESSION['stc_credentials']) {
        return $_SESSION['stc_credentials'];
    }
    $_SESSION['stc_credentials'] = stc_do_request('http://twitter.com/account/verify_credentials');
    return $_SESSION['stc_credentials'];
}
Пример #3
0
function stc_followers_get($username)
{
    // check the cache first
    $resp = get_transient("stc_followers_{$username}");
    if ($resp != false) {
        return $resp;
    }
    $options = get_option('stc_options');
    if (!$username || !$options['autotweet_token'] || !$options['autotweet_secret']) {
        return;
    }
    $args = array();
    $args['acc_token'] = $options['autotweet_token'];
    $args['acc_secret'] = $options['autotweet_secret'];
    $args['screen_name'] = $username;
    $args['cursor'] = -1;
    $resp = stc_do_request('http://api.twitter.com/1/followers/ids', $args, 'GET');
    if (!$resp) {
        return array();
    }
    // save the count for later
    set_transient("stc_followers_{$username}_count", count($resp->ids), STC_FOLLOWER_CACHE);
    // $resp is an array of up to 5000 of our followers. Grab 100 of them at random.
    $fols = $resp->ids;
    $fols = array_rand(array_flip($fols), 100);
    // we now have 100 integer IDs. So let's go look up their names and such:
    $args = array();
    $args['acc_token'] = $options['autotweet_token'];
    $args['acc_secret'] = $options['autotweet_secret'];
    $args['user_id'] = implode($fols, ',');
    $resp = stc_do_request('http://api.twitter.com/1/users/lookup', $args, 'GET');
    // $resp should now be an array of up to 100 twitter user objects.
    set_transient("stc_followers_{$username}", $resp, STC_FOLLOWER_CACHE);
    // cache the result
    return $resp;
}
Пример #4
0
function stc_publish_automatic($id, $post)
{
    // check to make sure post is published
    if ($post->post_status !== 'publish') {
        return;
    }
    // check options to see if we need to send to FB at all
    $options = get_option('stc_options');
    if (!$options['autotweet_flag'] || !$options['autotweet_token'] || !$options['autotweet_secret'] || !$options['publish_text']) {
        return;
    }
    // args to send to twitter
    $args = array();
    $args['status'] = stc_get_default_tweet($id);
    $args['acc_token'] = $options['autotweet_token'];
    $args['acc_secret'] = $options['autotweet_secret'];
    $resp = stc_do_request('http://api.twitter.com/1/statuses/update', $args);
}