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);
    }
}
Example #2
0
 private function _get_shortlink($permalink, $post_id, $options)
 {
     $shortlink = $permalink;
     if ($options['shorten']) {
         if ($options['tinyurl'][0]) {
             $shortlink = $this->_get_TinyURL($permalink, self::TWEET_TINYURL_URL);
         } elseif ($options['bitly'][0]) {
             $shortlink = $this->_get_bitly($permalink, self::TWEET_BITLY_URL, $options['bitly'][1], $options['bitly'][2]);
         } elseif ($options['jmp'][0]) {
             $shortlink = $this->_get_bitly($permalink, self::TWEET_JMP_URL, $options['jmp'][1], $options['jmp'][2]);
         } elseif ($options['isgd'][0]) {
             $shortlink = $this->_get_TinyURL(rawurlencode($permalink), self::TWEET_ISGD_URL);
         } elseif ($options['other_tinyurl'][0]) {
             $shortlink = $this->_get_TinyURL($permalink, $options['other_tinyurl'][1]);
         } elseif (function_exists('get_shortlink')) {
             $shortlink = get_shortlink($post_id);
         } elseif (function_exists('wpme_get_shortlink')) {
             $shortlink = wpme_get_shortlink($post_id);
         } else {
             $shortlink = $this->_get_TinyURL($permalink);
         }
     }
     return $this->_chk_url($shortlink) ? $shortlink : $permalink;
 }