* whitespace updates.
* @link http://status.net/
* @link http://twitter.com/
*/
-
class TwitterBridgePlugin extends Plugin
{
/**
* Initializer for the plugin.
*/
-
function initialize()
{
// Allow the key and secret to be passed in
*
* @return boolean result
*/
-
static function hasKeys()
{
$ckey = common_config('twitter', 'consumer_key');
*
* @return boolean hook return
*/
-
function onRouterInitialized($m)
{
$m->connect('admin/twitter', array('action' => 'twitteradminpanel'));
*
* @return boolean hook value
*/
-
function onPluginVersion(&$versions)
{
$versions[] = array(
'author' => 'Zach Copley, Julien C',
'homepage' => 'http://status.net/wiki/Plugin:TwitterBridge',
'rawdescription' => _m(
- 'The Twitter "bridge" plugin allows you to integrate ' .
- 'your StatusNet instance with ' .
+ 'The Twitter "bridge" plugin allows integration ' .
+ 'of a StatusNet instance with ' .
'<a href="http://twitter.com/">Twitter</a>.'
)
);
*
* @return boolean hook value; true means continue processing, false means stop.
*/
-
function onCheckSchema()
{
$schema = Schema::get();
*
* @return boolean hook value
*/
-
function onStartDeleteOwnNotice(User $user, Notice $notice)
{
$n2s = Notice_to_status::staticGet('notice_id', $notice->id);
* @param Notice $notice being favored
* @return hook return value
*/
-
function onEndFavorNotice(Profile $profile, Notice $notice)
{
$flink = Foreign_link::getByUserID($profile->id,
*
* @return hook return value
*/
-
function onEndDisfavorNotice(Profile $profile, Notice $notice)
{
$flink = Foreign_link::getByUserID($profile->id,
*
* @see DB_DataObject
*/
-
class Twitter_synch_status extends Memcached_DataObject
{
public $__table = 'twitter_synch_status'; // table name
* @return Twitter_synch_status object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
throw new Exception("Use pkeyGet() for this class.");
* @return Twitter_synch_status object found, or null for no hits
*
*/
-
function pkeyGet($kv)
{
return Memcached_DataObject::pkeyGet('Twitter_synch_status', $kv);
*
* @return array array of column definitions
*/
-
function table()
{
return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
*
* @return array list of key field names
*/
-
function keys()
{
return array_keys($this->keyTypes());
* 'K' for primary key: for compound keys, add an entry for each component;
* 'U' for unique keys: compound keys are not well supported here.
*/
-
function keyTypes()
{
return array('foreign_id' => 'K',
*
* @return array magic three-false array that stops auto-incrementing.
*/
-
function sequenceKey()
{
return array(false, false, false);
'timeline' => $timeline));
if (empty($tss)) {
-
$tss = new Twitter_synch_status();
$tss->foreign_id = $foreign_id;
$tss->insert();
return true;
-
} else {
-
$orig = clone($tss);
$tss->last_id = $last_id;
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-
class SyncTwitterFriendsDaemon extends ParallelizingDaemon
{
/**
* @return void
*
**/
-
function __construct($id = null, $interval = 60,
$max_children = 2, $debug = null)
{
*
* @return string Name of the daemon.
*/
-
function name()
{
return ('synctwitterfriends.' . $this->_id);
}
function childTask($flink) {
-
// Each child ps needs its own DB connection
// Note: DataObject::getDatabaseConnection() creates
// a new connection if there isn't one already
-
$conn = &$flink->getDatabaseConnection();
$this->subscribeTwitterFriends($flink);
// XXX: Couldn't find a less brutal way to blow
// away a cached connection
-
global $_DB_DATAOBJECT;
unset($_DB_DATAOBJECT['CONNECTIONS']);
}
$syncer = new SyncTwitterFriendsDaemon($id, 60, 2, $debug);
$syncer->runOnce();
-
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-
class TwitterStatusFetcher extends ParallelizingDaemon
{
/**
*
* @return string Name of the daemon.
*/
-
function name()
{
return ('twitterstatusfetcher.'.$this->_id);
*
* @return array flinks an array of Foreign_link objects
*/
-
function getObjects()
{
global $_DB_DATAOBJECT;
}
function childTask($flink) {
-
// Each child ps needs its own DB connection
// Note: DataObject::getDatabaseConnection() creates
// a new connection if there isn't one already
-
$conn = &$flink->getDatabaseConnection();
$this->getTimeline($flink);
// XXX: Couldn't find a less brutal way to blow
// away a cached connection
-
global $_DB_DATAOBJECT;
unset($_DB_DATAOBJECT['CONNECTIONS']);
}
// Reverse to preserve order
foreach (array_reverse($timeline) as $status) {
-
// Hacktastic: filter out stuff coming from this StatusNet
-
$source = mb_strtolower(common_config('integration', 'source'));
if (preg_match("/$source/", mb_strtolower($status->source))) {
// Don't save it if the user is protected
// FIXME: save it but treat it as private
-
if ($status->user->protected) {
continue;
}
}
// Okay, record the time we synced with Twitter for posterity
-
$flink->last_noticesync = common_sql_now();
$flink->update();
}
$statusUri = $this->makeStatusURI($status->user->screen_name, $status->id);
// check to see if we've already imported the status
-
$n2s = Notice_to_status::staticGet('status_id', $status->id);
if (!empty($n2s)) {
}
// If it's a retweet, save it as a repeat!
-
if (!empty($status->retweeted_status)) {
common_log(LOG_INFO, "Status {$status->id} is a retweet of {$status->retweeted_status->id}.");
$original = $this->saveStatus($status->retweeted_status);
$author = $original->getProfile();
// TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
// TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
- $content = sprintf(_('RT @%1$s %2$s'),
+ $content = sprintf(_m('RT @%1$s %2$s'),
$author->nickname,
$original->content);
*
* @return string URI
*/
-
function makeStatusURI($username, $id)
{
return 'http://twitter.com/'
*
* @return mixed value the first Profile with that url, or null
*/
-
function getProfileByUrl($nickname, $profileurl)
{
$profile = new Profile();
*
* @return mixed value a matching Notice or null
*/
-
function checkDupe($profile, $statusUri)
{
$notice = new Notice();
function ensureProfile($user)
{
// check to see if there's already a profile for this user
-
$profileurl = 'http://twitter.com/' . $user->screen_name;
$profile = $this->getProfileByUrl($user->screen_name, $profileurl);
return $profile;
} else {
-
common_debug($this->name() . ' - Adding profile and remote profile ' .
"for Twitter user: $profileurl.");
$remote_pro = Remote_profile::staticGet('uri', $profileurl);
if (empty($remote_pro)) {
-
$remote_pro = new Remote_profile();
$remote_pro->id = $id;
$avatar = $profile->getAvatar($sizes[$size]);
// Delete the avatar, if present
-
if ($avatar) {
$avatar->delete();
}
$avatar->height = 48;
break;
default:
-
// Note: Twitter's big avatars are a different size than
// StatusNet's (StatusNet's = 96)
-
$avatar->width = 73;
$avatar->height = 73;
}
$fetcher = new TwitterStatusFetcher($id, 60, 2, $debug);
$fetcher->runOnce();
-
{
// Check to see whether the Twitter user is already in the system,
// and update its screen name and uri if so.
-
$fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
if (!empty($fuser)) {
}
} else {
-
// Kill any old, invalid records for this screen name
-
$fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
if (!empty($fuser)) {
}
function is_twitter_bound($notice, $flink) {
-
// Check to see if notice should go to Twitter
if (!empty($flink) && ($flink->noticesync & FOREIGN_NOTICE_SEND)) {
// If it's not a Twitter-style reply, or if the user WANTS to send replies,
// or if it's in reply to a twitter notice
-
if (!preg_match('/^@[a-zA-Z0-9_]{1,15}\b/u', $notice->content) ||
($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) ||
is_twitter_notice($notice->reply_to)) {
}
// Notice crossed the great divide
-
$msg = sprintf('Twitter bridge - posted notice %d to Twitter using ' .
'OAuth for User %s (user id %d).',
$notice->id,
common_switch_locale();
return mail_to_user($user, $subject, $body);
}
-
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-
class TwitteradminpanelAction extends AdminPanelAction
{
/**
*
* @return string page title
*/
-
function title()
{
return _m('Twitter');
*
* @return string instructions
*/
-
function getInstructions()
{
return _m('Twitter bridge settings');
*
* @return void
*/
-
function showForm()
{
$form = new TwitterAdminPanelForm($this);
*
* @return void
*/
-
function saveSettings()
{
static $settings = array(
*
* @return int ID of the form
*/
-
function id()
{
return 'twitteradminpanel';
*
* @return string class of the form
*/
-
function formClass()
{
return 'form_settings';
*
* @return string URL of the action
*/
-
function action()
{
return common_local_url('twitteradminpanel');
*
* @return void
*/
-
function formData()
{
$this->out->elementStart(
if (!empty($globalConsumerKey) && !empty($globalConsumerSec)) {
$this->li();
- $this->out->element('p', 'form_guide', _('Note: a global consumer key and secret are set.'));
+ $this->out->element('p', 'form_guide', _m('Note: a global consumer key and secret are set.'));
$this->unli();
}
*
* @return void
*/
-
function formActions()
{
- $this->out->submit('submit', _('Save'), 'submit', null, _('Save Twitter settings'));
+ $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save Twitter settings'));
}
}
$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;
}
if ($this->arg('create')) {
if (!$this->boolean('license')) {
- $this->showForm(_('You can\'t register if you don\'t agree to the license.'),
+ $this->showForm(_m('You can\'t register if you don\'t agree to the license.'),
$this->trimmed('newname'));
return;
}
$this->connectNewUser();
} else {
common_debug('Twitter bridge - ' . print_r($this->args, true));
- $this->showForm(_('Something weird happened.'),
+ $this->showForm(_m('Something weird happened.'),
$this->trimmed('newname'));
}
} else {
}
if (common_logged_in()) {
-
// Save the access token and Twitter user info
$user = common_current_user();
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.'));
}
return $flink_id;
$this->element('div', array('class' => 'error'), $this->error);
} else {
$this->element('div', 'instructions',
- sprintf(_('This is the first time you\'ve logged into %s so we must connect your Twitter account to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name')));
+ sprintf(_m('This is the first time you\'ve logged into %s so we must connect your Twitter account to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name')));
}
}
function title()
{
- return _('Twitter Account Setup');
+ return _m('Twitter Account Setup');
}
function showForm($error=null, $username=null)
'class' => 'form_settings',
'action' => common_local_url('twitterauthorization')));
$this->elementStart('fieldset', array('id' => 'settings_twitter_connect_options'));
- $this->element('legend', null, _('Connection options'));
+ $this->element('legend', null, _m('Connection options'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->element('input', array('type' => 'checkbox',
'name' => 'license',
'value' => 'true'));
$this->elementStart('label', array('class' => 'checkbox', 'for' => 'license'));
- $message = _('My text and files are available under %s ' .
+ $message = _m('My text and files are available under %s ' .
'except this private data: password, ' .
'email address, IM address, and phone number.');
$link = '<a href="' .
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
$this->element('legend', null,
- _('Create new account'));
+ _m('Create new account'));
$this->element('p', null,
- _('Create a new user with this nickname.'));
+ _m('Create a new user with this nickname.'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- $this->input('newname', _('New nickname'),
+ $this->input('newname', _m('New nickname'),
($this->username) ? $this->username : '',
- _('1-64 lowercase letters or numbers, no punctuation or spaces'));
+ _m('1-64 lowercase letters or numbers, no punctuation or spaces'));
$this->elementEnd('li');
$this->elementEnd('ul');
- $this->submit('create', _('Create'));
+ $this->submit('create', _m('Create'));
$this->elementEnd('fieldset');
$this->elementStart('fieldset');
$this->element('legend', null,
- _('Connect existing account'));
+ _m('Connect existing account'));
$this->element('p', null,
- _('If you already have an account, login with your username and password to connect it to your Twitter account.'));
+ _m('If you already have an account, login with your username and password to connect it to your Twitter account.'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
- $this->input('nickname', _('Existing nickname'));
+ $this->input('nickname', _m('Existing nickname'));
$this->elementEnd('li');
$this->elementStart('li');
- $this->password('password', _('Password'));
+ $this->password('password', _m('Password'));
$this->elementEnd('li');
$this->elementEnd('ul');
- $this->submit('connect', _('Connect'));
+ $this->submit('connect', _m('Connect'));
$this->elementEnd('fieldset');
$this->elementEnd('fieldset');
function createNewUser()
{
if (common_config('site', 'closed')) {
- $this->clientError(_('Registration not allowed.'));
+ $this->clientError(_m('Registration not allowed.'));
return;
}
if (common_config('site', 'inviteonly')) {
$code = $_SESSION['invitecode'];
if (empty($code)) {
- $this->clientError(_('Registration not allowed.'));
+ $this->clientError(_m('Registration not allowed.'));
return;
}
$invite = Invitation::staticGet($code);
if (empty($invite)) {
- $this->clientError(_('Not a valid invitation code.'));
+ $this->clientError(_m('Not a valid invitation code.'));
return;
}
}
if (!Validate::string($nickname, array('min_length' => 1,
'max_length' => 64,
'format' => NICKNAME_FMT))) {
- $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+ $this->showForm(_m('Nickname must have only lowercase letters and numbers and no spaces.'));
return;
}
if (!User::allowed_nickname($nickname)) {
- $this->showForm(_('Nickname not allowed.'));
+ $this->showForm(_m('Nickname not allowed.'));
return;
}
if (User::staticGet('nickname', $nickname)) {
- $this->showForm(_('Nickname already in use. Try another one.'));
+ $this->showForm(_m('Nickname already in use. Try another one.'));
return;
}
$user = User::register($args);
if (empty($user)) {
- $this->serverError(_('Error registering user.'));
+ $this->serverError(_m('Error registering user.'));
return;
}
save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
if (!$result) {
- $this->serverError(_('Error connecting user to Twitter.'));
+ $this->serverError(_m('Error connecting user to Twitter.'));
return;
}
$password = $this->trimmed('password');
if (!common_check_user($nickname, $password)) {
- $this->showForm(_('Invalid username or password.'));
+ $this->showForm(_m('Invalid username or password.'));
return;
}
save_twitter_user($this->twuid, $this->tw_fields['screen_name']);
if (!$result) {
- $this->serverError(_('Error connecting user to Twitter.'));
+ $this->serverError(_m('Error connecting user to Twitter.'));
return;
}
$result = $this->flinkUser($user->id, $this->twuid);
if (empty($result)) {
- $this->serverError(_('Error connecting user to Twitter.'));
+ $this->serverError(_m('Error connecting user to Twitter.'));
return;
}
*
* @see SettingsAction
*/
-
class TwitterloginAction extends Action
{
function handle($args)
parent::handle($args);
if (common_is_real_login()) {
- $this->clientError(_('Already logged in.'));
+ $this->clientError(_m('Already logged in.'));
}
$this->showPage();
function title()
{
- return _('Twitter Login');
+ return _m('Twitter Login');
}
function getInstructions()
{
- return _('Login with your Twitter account');
+ return _m('Login with your Twitter account');
}
function showPageNotice()
null,
array('signin' => true))));
$this->element('img', array('src' => common_path('plugins/TwitterBridge/Sign-in-with-Twitter-lighter.png'),
- 'alt' => 'Sign in with Twitter'));
+ 'alt' => _m('Sign in with Twitter')));
$this->elementEnd('a');
}
function statusesHomeTimeline($since_id = null, $max_id = null,
$cnt = null, $page = null)
{
-
$url = 'https://twitter.com/statuses/home_timeline.json';
$params = array('include_entities' => 'true');
*
* @see SettingsAction
*/
-
class TwittersettingsAction extends ConnectSettingsAction
{
/**
*
* @return void
*/
-
function showContent()
{
$this->text(_m(' first.'));
$this->elementEnd('p');
} else {
-
+ // TRANS: %1$s is the current website name.
$note = _m('Keep your %1$s account but disconnect from Twitter. ' .
'You can use your %1$s password to log in.');
*
* @return void
*/
-
function handlePost()
{
// CSRF protection
*
* @return void
*/
-
function removeTwitterAccount()
{
$user = common_current_user();
*
* @return void
*/
-
function savePreferences()
{
$noticesend = $this->boolean('noticesend');
$this->showForm(_m('Twitter preferences saved.'), true);
}
-
}