diff options
author | Zach Copley <zach@controlyourself.ca> | 2008-09-23 22:36:15 -0400 |
---|---|---|
committer | Zach Copley <zach@controlyourself.ca> | 2008-09-23 22:36:15 -0400 |
commit | 06859cc14e5d68c83e4ecb38a0a32f354bc6ed80 (patch) | |
tree | f95877e2d693b2ec54d26ad483b1e8a776a0ab71 /lib | |
parent | 285f062197e7ffe18e2a1cf001f0f6eb8e8821fc (diff) |
Twitter bridge - pref setting to turn off sending @-replies to Twitter
darcs-hash:20080924023615-7b5ce-c747e8236b3967824ed93f18285e1b6e0b46c3f0.gz
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.php | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/lib/util.php b/lib/util.php index b0edb8ef0..a45f4a214 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1107,16 +1107,28 @@ function common_save_replies($notice) { } function common_broadcast_notice($notice, $remote=false) { - + // Check to see if notice should go to Twitter $flink = Foreign_link::getForeignLink($notice->profile_id, 1); // 1 == Twitter - - if ($flink->noticesync == 1) { - if (!common_twitter_broadcast($notice, $flink)) { - common_debug('Unable to send notice: ' . $notice->id . ' to Twitter.', __FILE__); + if ($flink->noticesync >= 1) { + $ok_to_send = true; + + // Check to see whether user wants to filter @-replies + if ($flink->noticesync == 3) { + if (preg_match('/(?:^|\s)@([A-Za-z0-9_\-\.]{1,64})/', $notice->content)) { + $ok_to_send = false; + } + } + + if ($ok_to_send) { + $result = common_twitter_broadcast($notice, $flink); + + if (!$result) { + common_debug('Unable to send notice: ' . $notice->id . ' to Twitter.', __FILE__); + } } } - + if (common_config('queue', 'enabled')) { # Do it later! return common_enqueue_notice($notice); @@ -1125,17 +1137,17 @@ function common_broadcast_notice($notice, $remote=false) { } } -function common_twitter_broadcast($notice, $flink) { +function common_twitter_broadcast($notice, $flink) { global $config; $success = true; $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, @@ -1151,27 +1163,27 @@ function common_twitter_broadcast($notice, $flink) { CURLOPT_CONNECTTIMEOUT => 120, // XXX: Scary!!!! How long should this be? CURLOPT_TIMEOUT => 120 ); - + $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.", + 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 + // Twitter should return a status $status = json_decode($data); if (!$status->id) { @@ -1179,8 +1191,8 @@ function common_twitter_broadcast($notice, $flink) { __FILE__); $success = false; } - - return $status; + + return $success; } # Stick the notice on the queue |