Merge branch 'testing'

This commit is contained in:
Evan Prodromou
2009-12-22 16:44:19 -08:00
234 changed files with 51807 additions and 16565 deletions

View File

@@ -86,8 +86,8 @@ class TwitterBridgePlugin extends Plugin
$action_name = $action->trimmed('action');
$action->menuItem(common_local_url('twittersettings'),
_('Twitter'),
_('Twitter integration options'),
_m('Twitter'),
_m('Twitter integration options'),
$action_name === 'twittersettings');
return true;
@@ -127,7 +127,12 @@ class TwitterBridgePlugin extends Plugin
*/
function onStartEnqueueNotice($notice, &$transports)
{
array_push($transports, 'twitter');
// Avoid a possible loop
if ($notice->source != 'twitter') {
array_push($transports, 'twitter');
}
return true;
}

View File

@@ -209,7 +209,13 @@ class TwitterStatusFetcher extends ParallelizingDaemon
continue;
}
$this->saveStatus($status, $flink);
$notice = null;
$notice = $this->saveStatus($status, $flink);
if (!empty($notice)) {
common_broadcast_notice($notice);
}
}
// Okay, record the time we synced with Twitter for posterity
@@ -235,12 +241,14 @@ class TwitterStatusFetcher extends ParallelizingDaemon
$uri = 'http://twitter.com/' . $status->user->screen_name .
'/status/' . $status->id;
$notice = Notice::staticGet('uri', $uri);
// check to see if we've already imported the status
$notice = Notice::staticGet('uri', $uri);
if (empty($notice)) {
// XXX: transaction here?
$notice = new Notice();
$notice->profile_id = $id;
@@ -257,6 +265,7 @@ class TwitterStatusFetcher extends ParallelizingDaemon
$id = $notice->insert();
Event::handle('EndNoticeSave', array($notice));
}
}
if (!Notice_inbox::pkeyGet(array('notice_id' => $notice->id,
@@ -270,7 +279,12 @@ class TwitterStatusFetcher extends ParallelizingDaemon
$inbox->source = NOTICE_INBOX_SOURCE_GATEWAY; // From a private source
$inbox->insert();
}
$notice->blowCaches();
return $notice;
}
function ensureProfile($user)

View File

@@ -0,0 +1,128 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2009-12-07 20:38-0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: twitterauthorization.php:81
msgid "Not logged in."
msgstr ""
#: twitterauthorization.php:131 twitterauthorization.php:150
#: twitterauthorization.php:170 twitterauthorization.php:217
msgid "Couldn't link your Twitter account."
msgstr ""
#: TwitterBridgePlugin.php:89
msgid "Twitter"
msgstr ""
#: TwitterBridgePlugin.php:90
msgid "Twitter integration options"
msgstr ""
#: twittersettings.php:59
msgid "Twitter settings"
msgstr ""
#: twittersettings.php:70
msgid ""
"Connect your Twitter account to share your updates with your Twitter friends "
"and vice-versa."
msgstr ""
#: twittersettings.php:118
msgid "Twitter account"
msgstr ""
#: twittersettings.php:123
msgid "Connected Twitter account"
msgstr ""
#: twittersettings.php:125
msgid "Remove"
msgstr ""
#: twittersettings.php:131
msgid "Preferences"
msgstr ""
#: twittersettings.php:135
msgid "Automatically send my notices to Twitter."
msgstr ""
#: twittersettings.php:142
msgid "Send local \"@\" replies to Twitter."
msgstr ""
#: twittersettings.php:149
msgid "Subscribe to my Twitter friends here."
msgstr ""
#: twittersettings.php:158
msgid "Import my Friends Timeline."
msgstr ""
#: twittersettings.php:174
msgid "Save"
msgstr ""
#: twittersettings.php:176
msgid "Add"
msgstr ""
#: twittersettings.php:201
msgid "There was a problem with your session token. Try again, please."
msgstr ""
#: twittersettings.php:211
msgid "Unexpected form submission."
msgstr ""
#: twittersettings.php:230
msgid "Couldn't remove Twitter user."
msgstr ""
#: twittersettings.php:234
msgid "Twitter account removed."
msgstr ""
#: twittersettings.php:255 twittersettings.php:265
msgid "Couldn't save Twitter preferences."
msgstr ""
#: twittersettings.php:269
msgid "Twitter preferences saved."
msgstr ""
#: twitter.php:333
msgid "Your Twitter bridge has been disabled."
msgstr ""
#: twitter.php:337
#, php-format
msgid ""
"Hi, %1$s. We're sorry to inform you that your link to Twitter has been "
"disabled. We no longer seem to have permission to update your Twitter "
"status. (Did you revoke %3$s's access?)\n"
"\n"
"You can re-enable your Twitter bridge by visiting your Twitter settings "
"page:\n"
"\n"
"\t%2$s\n"
"\n"
"Regards,\n"
"%3$s\n"
msgstr ""

View File

@@ -177,7 +177,7 @@ function broadcast_oauth($notice, $flink) {
try {
$status = $client->statusesUpdate($statustxt);
} catch (OAuthClientException $e) {
return process_error($e, $flink);
return process_error($e, $flink, $notice);
}
if (empty($status)) {
@@ -186,8 +186,11 @@ function broadcast_oauth($notice, $flink) {
// or the Twitter API might just be behaving flakey.
$errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' .
'trying to send update for %1$s (user id %2$s).',
$user->nickname, $user->id);
'trying to post notice %d for User %s (user id %d).',
$notice->id,
$user->nickname,
$user->id);
common_log(LOG_WARNING, $errmsg);
return false;
@@ -195,8 +198,12 @@ function broadcast_oauth($notice, $flink) {
// Notice crossed the great divide
$msg = sprintf('Twitter bridge - posted notice %s to Twitter using OAuth.',
$notice->id);
$msg = sprintf('Twitter bridge - posted notice %d to Twitter using ' .
'OAuth for User %s (user id %d).',
$notice->id,
$user->nickname,
$user->id);
common_log(LOG_INFO, $msg);
return true;
@@ -213,62 +220,69 @@ function broadcast_basicauth($notice, $flink)
try {
$status = $client->statusesUpdate($statustxt);
} catch (HTTP_Request2_Exception $e) {
return process_error($e, $flink);
} catch (BasicAuthException $e) {
return process_error($e, $flink, $notice);
}
if (empty($status)) {
$errmsg = sprintf('Twitter bridge - No data returned by Twitter API when ' .
'trying to send update for %1$s (user id %2$s).',
$user->nickname, $user->id);
'trying to post notice %d for %s (user id %d).',
$notice->id,
$user->nickname,
$user->id);
common_log(LOG_WARNING, $errmsg);
$errmsg = sprintf('No data returned by Twitter API when ' .
'trying to send update for %1$s (user id %2$s).',
$user->nickname, $user->id);
common_log(LOG_WARNING, $errmsg);
$errmsg = sprintf('No data returned by Twitter API when ' .
'trying to post notice %d for %s (user id %d).',
$notice->id,
$user->nickname,
$user->id);
common_log(LOG_WARNING, $errmsg);
return false;
}
$msg = sprintf('Twitter bridge - posted notice %s to Twitter using basic auth.',
$notice->id);
$msg = sprintf('Twitter bridge - posted notice %d to Twitter using ' .
'HTTP basic auth for User %s (user id %d).',
$notice->id,
$user->nickname,
$user->id);
common_log(LOG_INFO, $msg);
return true;
}
function process_error($e, $flink)
function process_error($e, $flink, $notice)
{
$user = $flink->getUser();
$errmsg = $e->getMessage();
$delivered = false;
$user = $flink->getUser();
$code = $e->getCode();
switch($errmsg) {
case 'The requested URL returned error: 401':
$logmsg = sprintf('Twiter bridge - User %1$s (user id: %2$s) has an invalid ' .
'Twitter screen_name/password combo or an invalid acesss token.',
$user->nickname, $user->id);
$delivered = true;
remove_twitter_link($flink);
break;
case 'The requested URL returned error: 403':
$logmsg = sprintf('Twitter bridge - User %1$s (user id: %2$s) has exceeded ' .
'his/her Twitter request limit.',
$user->nickname, $user->id);
break;
default:
$logmsg = sprintf('Twitter bridge - cURL error trying to send notice to Twitter ' .
'for user %1$s (user id: %2$s) - ' .
'code: %3$s message: %4$s.',
$user->nickname, $user->id,
$e->getCode(), $e->getMessage());
break;
}
$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);
return $delivered;
if ($code == 401) {
// Probably a revoked or otherwise bad access token - nuke!
remove_twitter_link($flink);
return true;
} else {
// For every other case, it's probably some flakiness so try
// sending the notice again later (requeue).
return false;
}
}
function format_status($notice)
@@ -333,11 +347,11 @@ function mail_twitter_bridge_removed($user)
$profile = $user->getProfile();
$subject = sprintf(_('Your Twitter bridge has been disabled.'));
$subject = sprintf(_m('Your Twitter bridge has been disabled.'));
$site_name = common_config('site', 'name');
$body = sprintf(_('Hi, %1$s. We\'re sorry to inform you that your ' .
$body = sprintf(_m('Hi, %1$s. We\'re sorry to inform you that your ' .
'link to Twitter has been disabled. We no longer seem to have ' .
'permission to update your Twitter status. (Did you revoke ' .
'%3$s\'s access?)' . "\n\n" .

View File

@@ -78,7 +78,7 @@ class TwitterauthorizationAction extends Action
parent::handle($args);
if (!common_logged_in()) {
$this->clientError(_('Not logged in.'), 403);
$this->clientError(_m('Not logged in.'), 403);
}
$user = common_current_user();
@@ -128,7 +128,7 @@ class TwitterauthorizationAction extends Action
} catch (OAuthClientException $e) {
$msg = sprintf('OAuth client cURL error - code: %1s, msg: %2s',
$e->getCode(), $e->getMessage());
$this->serverError(_('Couldn\'t link your Twitter account.'));
$this->serverError(_m('Couldn\'t link your Twitter account.'));
}
common_redirect($auth_link);
@@ -147,7 +147,7 @@ class TwitterauthorizationAction extends Action
// token we sent them
if ($_SESSION['twitter_request_token'] != $this->oauth_token) {
$this->serverError(_('Couldn\'t link your Twitter account.'));
$this->serverError(_m('Couldn\'t link your Twitter account.'));
}
try {
@@ -167,7 +167,7 @@ class TwitterauthorizationAction extends Action
} catch (OAuthClientException $e) {
$msg = sprintf('OAuth client cURL error - code: %1$s, msg: %2$s',
$e->getCode(), $e->getMessage());
$this->serverError(_('Couldn\'t link your Twitter account.'));
$this->serverError(_m('Couldn\'t link your Twitter account.'));
}
// Save the access token and Twitter user info
@@ -214,7 +214,7 @@ class TwitterauthorizationAction extends Action
if (empty($flink_id)) {
common_log_db_error($flink, 'INSERT', __FILE__);
$this->serverError(_('Couldn\'t link your Twitter account.'));
$this->serverError(_m('Couldn\'t link your Twitter account.'));
}
save_twitter_user($twitter_user->id, $twitter_user->screen_name);

View File

@@ -31,6 +31,20 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
/**
* General Exception wrapper for HTTP basic auth errors
*
* @category Integration
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*
*/
class BasicAuthException extends Exception
{
}
/**
* Class for talking to the Twitter API with HTTP Basic Auth.
*
@@ -169,12 +183,13 @@ class TwitterBasicAuthClient
}
/**
* Make a HTTP request using cURL.
* Make an HTTP request
*
* @param string $url Where to make the request
* @param array $params post parameters
*
* @return mixed the request
* @throws BasicAuthException
*/
function httpRequest($url, $params = null, $auth = true)
{
@@ -199,6 +214,12 @@ class TwitterBasicAuthClient
$response = $request->get($url);
}
$code = $response->getStatus();
if ($code < 200 || $code >= 400) {
throw new BasicAuthException($response->getBody(), $code);
}
return $response->getBody();
}

View File

@@ -56,7 +56,7 @@ class TwittersettingsAction extends ConnectSettingsAction
function title()
{
return _('Twitter settings');
return _m('Twitter settings');
}
/**
@@ -67,8 +67,8 @@ class TwittersettingsAction extends ConnectSettingsAction
function getInstructions()
{
return _('Connect your Twitter account to share your updates ' .
'with your Twitter friends and vice-versa.');
return _m('Connect your Twitter account to share your updates ' .
'with your Twitter friends and vice-versa.');
}
/**
@@ -115,38 +115,38 @@ class TwittersettingsAction extends ConnectSettingsAction
$this->elementEnd('fieldset');
} else {
$this->element('legend', null, _('Twitter account'));
$this->element('legend', null, _m('Twitter account'));
$this->elementStart('p', array('id' => 'form_confirmed'));
$this->element('a', array('href' => $fuser->uri), $fuser->nickname);
$this->elementEnd('p');
$this->element('p', 'form_note',
_('Connected Twitter account'));
_m('Connected Twitter account'));
$this->submit('remove', _('Remove'));
$this->submit('remove', _m('Remove'));
$this->elementEnd('fieldset');
$this->elementStart('fieldset', array('id' => 'settings_twitter_preferences'));
$this->element('legend', null, _('Preferences'));
$this->element('legend', null, _m('Preferences'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('noticesend',
_('Automatically send my notices to Twitter.'),
_m('Automatically send my notices to Twitter.'),
($flink) ?
($flink->noticesync & FOREIGN_NOTICE_SEND) :
true);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('replysync',
_('Send local "@" replies to Twitter.'),
_m('Send local "@" replies to Twitter.'),
($flink) ?
($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
true);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('friendsync',
_('Subscribe to my Twitter friends here.'),
_m('Subscribe to my Twitter friends here.'),
($flink) ?
($flink->friendsync & FOREIGN_FRIEND_RECV) :
false);
@@ -155,7 +155,7 @@ class TwittersettingsAction extends ConnectSettingsAction
if (common_config('twitterimport','enabled')) {
$this->elementStart('li');
$this->checkbox('noticerecv',
_('Import my Friends Timeline.'),
_m('Import my Friends Timeline.'),
($flink) ?
($flink->noticesync & FOREIGN_NOTICE_RECV) :
false);
@@ -171,9 +171,9 @@ class TwittersettingsAction extends ConnectSettingsAction
$this->elementEnd('ul');
if ($flink) {
$this->submit('save', _('Save'));
$this->submit('save', _m('Save'));
} else {
$this->submit('add', _('Add'));
$this->submit('add', _m('Add'));
}
$this->elementEnd('fieldset');
@@ -198,8 +198,8 @@ class TwittersettingsAction extends ConnectSettingsAction
// CSRF protection
$token = $this->trimmed('token');
if (!$token || $token != common_session_token()) {
$this->showForm(_('There was a problem with your session token. '.
'Try again, please.'));
$this->showForm(_m('There was a problem with your session token. '.
'Try again, please.'));
return;
}
@@ -208,7 +208,7 @@ class TwittersettingsAction extends ConnectSettingsAction
} else if ($this->arg('remove')) {
$this->removeTwitterAccount();
} else {
$this->showForm(_('Unexpected form submission.'));
$this->showForm(_m('Unexpected form submission.'));
}
}
@@ -227,11 +227,11 @@ class TwittersettingsAction extends ConnectSettingsAction
if (empty($result)) {
common_log_db_error($flink, 'DELETE', __FILE__);
$this->serverError(_('Couldn\'t remove Twitter user.'));
$this->serverError(_m('Couldn\'t remove Twitter user.'));
return;
}
$this->showForm(_('Twitter account removed.'), true);
$this->showForm(_m('Twitter account removed.'), true);
}
/**
@@ -252,7 +252,7 @@ class TwittersettingsAction extends ConnectSettingsAction
if (empty($flink)) {
common_log_db_error($flink, 'SELECT', __FILE__);
$this->showForm(_('Couldn\'t save Twitter preferences.'));
$this->showForm(_m('Couldn\'t save Twitter preferences.'));
return;
}
@@ -262,11 +262,11 @@ class TwittersettingsAction extends ConnectSettingsAction
if ($result === false) {
common_log_db_error($flink, 'UPDATE', __FILE__);
$this->showForm(_('Couldn\'t save Twitter preferences.'));
$this->showForm(_m('Couldn\'t save Twitter preferences.'));
return;
}
$this->showForm(_('Twitter preferences saved.'), true);
$this->showForm(_m('Twitter preferences saved.'), true);
}
}