function broadcast_twitter($notice) { $flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE); if (is_twitter_bound($notice, $flink)) { if (TwitterOAuthClient::isPackedToken($flink->credentials)) { return broadcast_oauth($notice, $flink); } else { return broadcast_basicauth($notice, $flink); } } return true; }
function broadcast_twitter($notice) { $success = true; $flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE); // XXX: Not sure WHERE to check whether a notice should go to // Twitter. Should we even put in the queue if it shouldn't? --Zach if (!is_null($flink) && is_twitter_bound($notice, $flink)) { $fuser = $flink->getForeignUser(); $twitter_user = $fuser->nickname; $twitter_password = $flink->credentials; $uri = 'http://www.twitter.com/statuses/update.json'; // XXX: Hack to get around PHP cURL's use of @ being a a meta character $statustxt = preg_replace('/^@/', ' @', $notice->content); $options = array(CURLOPT_USERPWD => "{$twitter_user}:{$twitter_password}", CURLOPT_POST => true, CURLOPT_POSTFIELDS => array('status' => $statustxt, 'source' => common_config('integration', 'source')), CURLOPT_RETURNTRANSFER => true, CURLOPT_FAILONERROR => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => "Laconica", CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_HTTPHEADER => array('Expect:')); $ch = curl_init($uri); curl_setopt_array($ch, $options); $data = curl_exec($ch); $errmsg = curl_error($ch); if ($errmsg) { common_debug("cURL error: {$errmsg} - " . "trying to send notice for {$twitter_user}.", __FILE__); $success = false; } curl_close($ch); if (!$data) { common_debug("No data returned by Twitter's " . "API trying to send update for {$twitter_user}", __FILE__); $success = false; } // Twitter should return a status $status = json_decode($data); if (!$status->id) { common_debug("Unexpected data returned by Twitter " . " API trying to send update for {$twitter_user}", __FILE__); $success = false; } } return $success; }
/** * Check if we need to broadcast a notice over the Twitter bridge, and * do so if necessary. Will determine whether to do a straight post or * a repeat/retweet * * This function is meant to be called directly from TwitterQueueHandler. * * @param Notice $notice * @return boolean true if complete or successful, false if we should retry */ function broadcast_twitter($notice) { $flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE); // Don't bother with basic auth, since it's no longer allowed if (!empty($flink) && TwitterOAuthClient::isPackedToken($flink->credentials)) { if (is_twitter_bound($notice, $flink)) { if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) { $retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of)); if (is_object($retweet)) { Notice_to_status::saveNew($notice->id, twitter_id($retweet)); return true; } else { // Our error processing will have decided if we need to requeue // this or can discard safely. return $retweet; } } else { return broadcast_oauth($notice, $flink); } } } return true; }
function broadcast_twitter($notice) { $flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE); // Don't bother with basic auth, since it's no longer allowed if (!empty($flink) && TwitterOAuthClient::isPackedToken($flink->credentials)) { if (!empty($notice->repeat_of) && is_twitter_notice($notice->repeat_of)) { $retweet = retweet_notice($flink, Notice::staticGet('id', $notice->repeat_of)); if (!empty($retweet)) { Notice_to_status::saveNew($notice->id, $retweet->id); } } else { if (is_twitter_bound($notice, $flink)) { return broadcast_oauth($notice, $flink); } } } return true; }