* @link http://status.net/
*/
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
require_once dirname(__DIR__) . '/twitter.php';
*/
class TwittersettingsAction extends ProfileSettingsAction
{
+ protected $flink = null;
+ protected $fuser = null;
+
+ protected function doPreparation()
+ {
+ $this->flink = Foreign_link::getByUserID($this->scoped->getID(), TWITTER_SERVICE);
+ if ($this->flink instanceof Foreign_link) {
+ $this->fuser = $this->flink->getForeignUser();
+ }
+ }
/**
* Title of the page
*
*/
function showContent()
{
-
- $user = common_current_user();
-
- $profile = $user->getProfile();
-
- $fuser = null;
-
- $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
-
- if (!empty($flink)) {
- $fuser = $flink->getForeignUser();
- }
-
$this->elementStart('form', array('method' => 'post',
'id' => 'form_settings_twitter',
'class' => 'form_settings',
$this->elementStart('fieldset', array('id' => 'settings_twitter_account'));
- if (empty($fuser)) {
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li', array('id' => 'settings_twitter_login_button'));
- $this->element('a', array('href' => common_local_url('twitterauthorization')),
- // TRANS: Link description to connect to a Twitter account.
- 'Connect my Twitter account');
- $this->elementEnd('li');
- $this->elementEnd('ul');
-
- $this->elementEnd('fieldset');
- } else {
+ if ($this->fuser instanceof Foreign_user) {
// TRANS: Fieldset legend.
$this->element('legend', null, _m('Twitter account'));
$this->elementStart('p', array('id' => 'form_confirmed'));
- $this->element('a', array('href' => $fuser->uri), $fuser->nickname);
+ $this->element('a', array('href' => $this->fuser->uri), $this->fuser->nickname);
$this->elementEnd('p');
$this->element('p', 'form_note',
// TRANS: Form note when a Twitter account has been connected.
// TRANS: Fieldset legend.
$this->element('legend', null, _m('Disconnect my account from Twitter'));
- if (!$user->password) {
+ if (!$this->scoped->hasPassword()) {
$this->elementStart('p', array('class' => 'form_guide'));
// TRANS: Form guide. %s is a URL to the password settings.
// TRANS: This message contains a Markdown link in the form [description](link).
$this->checkbox('noticesend',
// TRANS: Checkbox label.
_m('Automatically send my notices to Twitter.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_SEND) :
- true);
+ $this->flink->noticesync & FOREIGN_NOTICE_SEND);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('replysync',
// TRANS: Checkbox label.
_m('Send local "@" replies to Twitter.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
- true);
+ $this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('friendsync',
// TRANS: Checkbox label.
_m('Subscribe to my Twitter friends here.'),
- ($flink) ?
- ($flink->friendsync & FOREIGN_FRIEND_RECV) :
- false);
+ $this->flink->friendsync & FOREIGN_FRIEND_RECV);
$this->elementEnd('li');
if (common_config('twitterimport','enabled')) {
$this->checkbox('noticerecv',
// TRANS: Checkbox label.
_m('Import my friends timeline.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_RECV) :
- false);
+ $this->flink->noticesync & FOREIGN_NOTICE_RECV);
$this->elementEnd('li');
} else {
// preserve setting even if bidrection bridge toggled off
- if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) {
+ if ($this->flink->noticesync & FOREIGN_NOTICE_RECV) {
$this->hidden('noticerecv', true, 'noticerecv');
}
}
$this->elementEnd('ul');
- if ($flink) {
+ if ($this->flink) {
// TRANS: Button text for saving Twitter integration settings.
$this->submit('save', _m('BUTTON','Save'));
} else {
// TRANS: Button text for adding Twitter integration.
$this->submit('add', _m('BUTTON','Add'));
}
-
- $this->elementEnd('fieldset');
+ } else {
+ $this->elementStart('ul', 'form_data');
+ $this->elementStart('li', array('id' => 'settings_twitter_login_button'));
+ $this->element('a', array('href' => common_local_url('twitterauthorization')),
+ // TRANS: Link description to connect to a Twitter account.
+ 'Connect my Twitter account');
+ $this->elementEnd('li');
+ $this->elementEnd('ul');
}
+ $this->elementEnd('fieldset');
+
$this->elementEnd('form');
}
$friendsync = $this->boolean('friendsync');
$replysync = $this->boolean('replysync');
- $user = common_current_user();
- $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
-
- if (empty($flink)) {
- common_log_db_error($flink, 'SELECT', __FILE__);
- // @todo FIXME: Shouldn't this be a serverError()?
+ if (!$this->flink instanceof Foreign_link) {
+ common_log_db_error($this->flink, 'SELECT', __FILE__);
// TRANS: Server error displayed when saving Twitter integration preferences fails.
- $this->showForm(_m('Could not save Twitter preferences.'));
- return;
+ throw new ServerException(_m('Your account is not linked to Twitter.'));
}
- $original = clone($flink);
+ $original = clone($this->flink);
$wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
- $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
- $result = $flink->update($original);
+ $this->flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
+ $result = $this->flink->update($original);
if ($result === false) {
- common_log_db_error($flink, 'UPDATE', __FILE__);
- // @todo FIXME: Shouldn't this be a serverError()?
+ common_log_db_error($this->flink, 'UPDATE', __FILE__);
// TRANS: Server error displayed when saving Twitter integration preferences fails.
- $this->showForm(_m('Could not save Twitter preferences.'));
- return;
+ throw new ServerException(_m('Could not save Twitter preferences.'));
}
if ($wasReceiving xor $noticerecv) {
- $this->notifyDaemon($flink->foreign_id, $noticerecv);
+ $this->notifyDaemon($this->flink->foreign_id, $noticerecv);
}
// TRANS: Success message after saving Twitter integration preferences.