+function process_error($e, $flink, $notice)
+{
+ $user = $flink->getUser();
+ $code = $e->getCode();
+
+ $logmsg = sprintf('Twitter bridge - %d posting notice %d for ' .
+ 'User %s (user id: %d): %s.',
+ $code,
+ $notice->id,
+ $user->nickname,
+ $user->id,
+ $e->getMessage());
+
+ common_log(LOG_WARNING, $logmsg);
+
+ switch($code) {
+ case 401:
+ // Probably a revoked or otherwise bad access token - nuke!
+ remove_twitter_link($flink);
+ return true;
+ break;
+ case 403:
+ // User has exceeder her rate limit -- toss the notice
+ return true;
+ break;
+ default:
+
+ // For every other case, it's probably some flakiness so try
+ // sending the notice again later (requeue).
+
+ return false;
+ break;
+ }
+}
+
+function format_status($notice)
+{
+ // XXX: Hack to get around PHP cURL's use of @ being a a meta character
+ $statustxt = preg_replace('/^@/', ' @', $notice->content);
+
+ // Convert !groups to #hashes
+
+ // XXX: Make this an optional setting?
+
+ $statustxt = preg_replace('/(^|\s)!([A-Za-z0-9]{1,64})/', "\\1#\\2", $statustxt);
+
+ if (mb_strlen($statustxt) > 140) {
+ $noticeUrl = common_shorten_url($notice->uri);
+ $urlLen = mb_strlen($noticeUrl);
+ $statustxt = mb_substr($statustxt, 0, 140 - ($urlLen + 3)) . ' … ' . $noticeUrl;
+ }
+
+ return $statustxt;
+}
+