Exemple #1
0
function retreive_twitter_friends($twitter_id, $screen_name, $password)
{
    $uri = "http://twitter.com/statuses/friends/{$twitter_id}.json?page=";
    $twitter_user = twitter_user_info($screen_name, $password);
    // Calculate how many pages to get...
    $pages = ceil($twitter_user->friends_count / 100);
    if ($pages == 0) {
        common_debug("Twitter bridge - Twitter user {$screen_name} has no friends! Lame.");
    }
    $friends = array();
    for ($i = 1; $i <= $pages; $i++) {
        $data = get_twitter_data($uri . $i, $screen_name, $password);
        if (!$data) {
            return null;
        }
        $more_friends = json_decode($data);
        if (!$more_friends) {
            return null;
        }
        $friends = array_merge($friends, $more_friends);
    }
    return $friends;
}
function twitter_user_page($query)
{
    $screen_name = $query[1];
    $subaction = $query[2];
    $in_reply_to_id = (string) $query[3];
    $content = '';
    if (!$screen_name) {
        theme('error', 'No username given');
    }
    // Load up user profile information and one tweet
    $user = twitter_user_info($screen_name);
    // If the user has at least one tweet
    if (isset($user->status)) {
        // Fetch the timeline early, so we can try find the tweet they're replying to
        $request = API_URL . "statuses/user_timeline.json?screen_name={$screen_name}&include_rts=true&include_entities=true&page=" . intval($_GET['page']);
        $tl = twitter_process($request);
        $tl = twitter_standard_timeline($tl, 'user');
    }
    // Build an array of people we're talking to
    $to_users = array($user->screen_name);
    // Are we replying to anyone?
    if (is_numeric($in_reply_to_id)) {
        $tweet = twitter_find_tweet_in_timeline($in_reply_to_id, $tl);
        $content .= "<p>In reply to:<br />{$tweet->text}</p>";
        if ($subaction == 'replyall') {
            $found = Twitter_Extractor::extractMentionedScreennames($tweet->text);
            $to_users = array_unique(array_merge($to_users, $found));
        }
    }
    // Build a status message to everyone we're talking to
    $status = '';
    foreach ($to_users as $username) {
        if (!user_is_current_user($username)) {
            $status .= "@{$username} ";
        }
    }
    $content .= theme('status_form', $status, $in_reply_to_id);
    $content .= theme('user_header', $user);
    $content .= theme('timeline', $tl);
    theme('page', "User {$screen_name}", $content);
}
Exemple #3
0
function twitter_date($format, $timestamp = null)
{
    static $offset;
    if (!isset($offset)) {
        if (user_is_authenticated()) {
            if (array_key_exists('utc_offset', $_COOKIE)) {
                $offset = $_COOKIE['utc_offset'];
            } else {
                $user = twitter_user_info();
                $offset = $user->utc_offset;
                setcookie('utc_offset', $offset, time() + 3000000, '/');
            }
        } else {
            $offset = 0;
        }
    }
    if (!isset($timestamp)) {
        $timestamp = time();
    }
    return gmdate($format, $timestamp + $offset);
}
Exemple #4
0
function twitter_user_page($query)
{
    $screen_name = $query[1];
    // echo "<h1>q1 = {$screen_name}</h1>";
    $subaction = $query[2];
    // echo "<h1>q2 = {$subaction}</h1>";
    $in_reply_to_id = (string) $query[3];
    // echo "<h1>q3 = {$in_reply_to_id}</h1>";
    $content = '';
    if (!$screen_name) {
        // theme('error', 'No username given');
        //	Ugly cludge because @user is a real user
        twitter_refresh('user/user');
    }
    // Load up user profile information and one tweet
    $user = twitter_user_info($screen_name);
    // If the user has at least one tweet
    if (isset($user->status)) {
        // Fetch the timeline early, so we can try find the tweet they're replying to
        $cb = get_codebird();
        $api_options = "";
        $per_page = setting_fetch('perPage', 20);
        $api_options = "&count={$per_page}";
        //	If we're paginating through
        if ($_GET['max_id']) {
            $api_options .= '&max_id=' . $_GET['max_id'];
        }
        $api_options .= "&screen_name={$screen_name}";
        $user_timeline = $cb->statuses_userTimeline($api_options);
        twitter_api_status($user_timeline);
        $tl = twitter_standard_timeline($user_timeline, 'user');
        // $content = theme('status_form');
        // $content .= theme('timeline', $tl);
        // theme('page', 'user', $content);
    }
    // Build an array of people we're talking to
    $to_users = array($user->screen_name);
    // Build an array of hashtags being used
    $hashtags = array();
    // Are we replying to anyone?
    if (is_numeric($in_reply_to_id)) {
        $tweet = twitter_find_tweet_in_timeline($in_reply_to_id, $tl);
        $out = twitter_parse_tags($tweet->text);
        $content .= "<p>In reply to:<br />{$out}</p>";
        // if ($subaction == 'replyall') {
        $found = Twitter_Extractor::create($tweet->text)->extractMentionedUsernames();
        $to_users = array_unique(array_merge($to_users, $found));
        // }
        if ($tweet->entities->hashtags) {
            $hashtags = $tweet->entities->hashtags;
        }
    }
    // Build a status message to everyone we're talking to
    $status = '';
    foreach ($to_users as $username) {
        if (!user_is_current_user($username)) {
            $status .= "@{$username} ";
        }
    }
    // Add in the hashtags they've used
    foreach ($hashtags as $hashtag) {
        $status .= "#{$hashtag->text} ";
    }
    $content .= theme('status_form', $status, $in_reply_to_id);
    $content .= theme('user_header', $user);
    $content .= theme('timeline', $tl);
    theme('page', "User {$screen_name}", $content);
}
Exemple #5
0
function twitter_user_page($query)
{
    $screen_name = $query[1];
    $subaction = $query[2];
    $in_reply_to_id = (string) $query[3];
    $content = '';
    if (!$screen_name) {
        theme('error', 'No username given');
    }
    // Load up user profile information and one tweet
    $user = twitter_user_info($screen_name);
    // If the user has at least one tweet
    if (isset($user->status)) {
        // Fetch the timeline early, so we can try find the tweet they're replying to
        $request = API_NEW . "statuses/user_timeline.json?screen_name={$screen_name}";
        if ($_GET['max_id']) {
            $request .= '&max_id=' . $_GET['max_id'];
        }
        $tl = twitter_process($request);
        $tl = twitter_standard_timeline($tl, 'user');
    }
    // Build an array of people we're talking to
    $to_users = array($user->screen_name);
    // Build an array of hashtags being used
    $hashtags = array();
    // Are we replying to anyone?
    if (is_numeric($in_reply_to_id)) {
        $tweet = twitter_find_tweet_in_timeline($in_reply_to_id, $tl);
        $out = twitter_parse_tags($tweet->text);
        $content .= "<p>In reply to:<br />{$out}</p>";
        if ($subaction == 'replyall') {
            $found = Twitter_Extractor::create($tweet->text)->extractMentionedUsernames();
            $to_users = array_unique(array_merge($to_users, $found));
        }
        if ($tweet->entities->hashtags) {
            $hashtags = $tweet->entities->hashtags;
        }
    }
    // Build a status message to everyone we're talking to
    $status = '';
    foreach ($to_users as $username) {
        if (!user_is_current_user($username)) {
            $status .= "@{$username} ";
        }
    }
    // Add in the hashtags they've used
    foreach ($hashtags as $hashtag) {
        $status .= "#{$hashtag->text} ";
    }
    $content .= theme('status_form', $status, $in_reply_to_id);
    $content .= theme('user_header', $user);
    $content .= theme('timeline', $tl);
    theme('page', "User {$screen_name}", $content);
}
Exemple #6
0
 /**
  * Associate a Twitter account with the user's account
  *
  * Validates post input; verifies it against Twitter; and if
  * successful stores in the database.
  *
  * @return void
  */
 function addTwitterAccount()
 {
     $screen_name = $this->trimmed('twitter_username');
     $password = $this->trimmed('twitter_password');
     $noticesync = $this->boolean('noticesync');
     $replysync = $this->boolean('replysync');
     $friendsync = $this->boolean('friendsync');
     if (!Validate::string($screen_name, array('min_length' => 1, 'max_length' => 15, 'format' => VALIDATE_NUM . VALIDATE_ALPHA . '_'))) {
         $this->showForm(_('Username must have only numbers, ' . 'upper- and lowercase letters, ' . 'and underscore (_). 15 chars max.'));
         return;
     }
     if (!$this->verifyCredentials($screen_name, $password)) {
         $this->showForm(_('Could not verify your Twitter credentials!'));
         return;
     }
     $twit_user = twitter_user_info($screen_name, $password);
     if (!$twit_user) {
         $this->showForm(sprintf(_('Unable to retrieve account information ' . 'For "%s" from Twitter.'), $screen_name));
         return;
     }
     if (!save_twitter_user($twit_user->id, $screen_name)) {
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     $user = common_current_user();
     $flink = new Foreign_link();
     $flink->user_id = $user->id;
     $flink->foreign_id = $twit_user->id;
     $flink->service = TWITTER_SERVICE;
     $flink->credentials = $password;
     $flink->created = common_sql_now();
     $flink->set_flags($noticesync, $replysync, $friendsync);
     $flink_id = $flink->insert();
     if (!$flink_id) {
         common_log_db_error($flink, 'INSERT', __FILE__);
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     if ($friendsync) {
         save_twitter_friends($user, $twit_user->id, $screen_name, $password);
     }
     $this->showForm(_('Twitter settings saved.'), true);
 }