forked from GNUsocial/gnu-social
Twittersettings now works better as Profilesettings extension
This commit is contained in:
parent
d6d06c8cbb
commit
5933056a5b
@ -27,9 +27,7 @@
|
|||||||
* @link http://status.net/
|
* @link http://status.net/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
require_once dirname(__DIR__) . '/twitter.php';
|
require_once dirname(__DIR__) . '/twitter.php';
|
||||||
|
|
||||||
@ -46,6 +44,16 @@ require_once dirname(__DIR__) . '/twitter.php';
|
|||||||
*/
|
*/
|
||||||
class TwittersettingsAction extends ProfileSettingsAction
|
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
|
* Title of the page
|
||||||
*
|
*
|
||||||
@ -81,19 +89,6 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
*/
|
*/
|
||||||
function showContent()
|
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',
|
$this->elementStart('form', array('method' => 'post',
|
||||||
'id' => 'form_settings_twitter',
|
'id' => 'form_settings_twitter',
|
||||||
'class' => 'form_settings',
|
'class' => 'form_settings',
|
||||||
@ -104,21 +99,11 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
|
|
||||||
$this->elementStart('fieldset', array('id' => 'settings_twitter_account'));
|
$this->elementStart('fieldset', array('id' => 'settings_twitter_account'));
|
||||||
|
|
||||||
if (empty($fuser)) {
|
if ($this->fuser instanceof Foreign_user) {
|
||||||
$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 {
|
|
||||||
// TRANS: Fieldset legend.
|
// TRANS: Fieldset legend.
|
||||||
$this->element('legend', null, _m('Twitter account'));
|
$this->element('legend', null, _m('Twitter account'));
|
||||||
$this->elementStart('p', array('id' => 'form_confirmed'));
|
$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->elementEnd('p');
|
||||||
$this->element('p', 'form_note',
|
$this->element('p', 'form_note',
|
||||||
// TRANS: Form note when a Twitter account has been connected.
|
// TRANS: Form note when a Twitter account has been connected.
|
||||||
@ -130,7 +115,7 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
// TRANS: Fieldset legend.
|
// TRANS: Fieldset legend.
|
||||||
$this->element('legend', null, _m('Disconnect my account from Twitter'));
|
$this->element('legend', null, _m('Disconnect my account from Twitter'));
|
||||||
|
|
||||||
if (!$user->password) {
|
if (!$this->scoped->hasPassword()) {
|
||||||
$this->elementStart('p', array('class' => 'form_guide'));
|
$this->elementStart('p', array('class' => 'form_guide'));
|
||||||
// TRANS: Form guide. %s is a URL to the password settings.
|
// TRANS: Form guide. %s is a URL to the password settings.
|
||||||
// TRANS: This message contains a Markdown link in the form [description](link).
|
// TRANS: This message contains a Markdown link in the form [description](link).
|
||||||
@ -165,25 +150,19 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
$this->checkbox('noticesend',
|
$this->checkbox('noticesend',
|
||||||
// TRANS: Checkbox label.
|
// TRANS: Checkbox label.
|
||||||
_m('Automatically send my notices to Twitter.'),
|
_m('Automatically send my notices to Twitter.'),
|
||||||
($flink) ?
|
$this->flink->noticesync & FOREIGN_NOTICE_SEND);
|
||||||
($flink->noticesync & FOREIGN_NOTICE_SEND) :
|
|
||||||
true);
|
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementStart('li');
|
$this->elementStart('li');
|
||||||
$this->checkbox('replysync',
|
$this->checkbox('replysync',
|
||||||
// TRANS: Checkbox label.
|
// TRANS: Checkbox label.
|
||||||
_m('Send local "@" replies to Twitter.'),
|
_m('Send local "@" replies to Twitter.'),
|
||||||
($flink) ?
|
$this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY);
|
||||||
($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
|
|
||||||
true);
|
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
$this->elementStart('li');
|
$this->elementStart('li');
|
||||||
$this->checkbox('friendsync',
|
$this->checkbox('friendsync',
|
||||||
// TRANS: Checkbox label.
|
// TRANS: Checkbox label.
|
||||||
_m('Subscribe to my Twitter friends here.'),
|
_m('Subscribe to my Twitter friends here.'),
|
||||||
($flink) ?
|
$this->flink->friendsync & FOREIGN_FRIEND_RECV);
|
||||||
($flink->friendsync & FOREIGN_FRIEND_RECV) :
|
|
||||||
false);
|
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
|
|
||||||
if (common_config('twitterimport','enabled')) {
|
if (common_config('twitterimport','enabled')) {
|
||||||
@ -191,31 +170,37 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
$this->checkbox('noticerecv',
|
$this->checkbox('noticerecv',
|
||||||
// TRANS: Checkbox label.
|
// TRANS: Checkbox label.
|
||||||
_m('Import my friends timeline.'),
|
_m('Import my friends timeline.'),
|
||||||
($flink) ?
|
$this->flink->noticesync & FOREIGN_NOTICE_RECV);
|
||||||
($flink->noticesync & FOREIGN_NOTICE_RECV) :
|
|
||||||
false);
|
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
} else {
|
} else {
|
||||||
// preserve setting even if bidrection bridge toggled off
|
// 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->hidden('noticerecv', true, 'noticerecv');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->elementEnd('ul');
|
$this->elementEnd('ul');
|
||||||
|
|
||||||
if ($flink) {
|
if ($this->flink) {
|
||||||
// TRANS: Button text for saving Twitter integration settings.
|
// TRANS: Button text for saving Twitter integration settings.
|
||||||
$this->submit('save', _m('BUTTON','Save'));
|
$this->submit('save', _m('BUTTON','Save'));
|
||||||
} else {
|
} else {
|
||||||
// TRANS: Button text for adding Twitter integration.
|
// TRANS: Button text for adding Twitter integration.
|
||||||
$this->submit('add', _m('BUTTON','Add'));
|
$this->submit('add', _m('BUTTON','Add'));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
$this->elementEnd('fieldset');
|
$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');
|
$this->elementEnd('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,32 +274,25 @@ class TwittersettingsAction extends ProfileSettingsAction
|
|||||||
$friendsync = $this->boolean('friendsync');
|
$friendsync = $this->boolean('friendsync');
|
||||||
$replysync = $this->boolean('replysync');
|
$replysync = $this->boolean('replysync');
|
||||||
|
|
||||||
$user = common_current_user();
|
if (!$this->flink instanceof Foreign_link) {
|
||||||
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
|
common_log_db_error($this->flink, 'SELECT', __FILE__);
|
||||||
|
|
||||||
if (empty($flink)) {
|
|
||||||
common_log_db_error($flink, 'SELECT', __FILE__);
|
|
||||||
// @todo FIXME: Shouldn't this be a serverError()?
|
|
||||||
// TRANS: Server error displayed when saving Twitter integration preferences fails.
|
// TRANS: Server error displayed when saving Twitter integration preferences fails.
|
||||||
$this->showForm(_m('Could not save Twitter preferences.'));
|
throw new ServerException(_m('Your account is not linked to Twitter.'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$original = clone($flink);
|
$original = clone($this->flink);
|
||||||
$wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
|
$wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
|
||||||
$flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
|
$this->flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
|
||||||
$result = $flink->update($original);
|
$result = $this->flink->update($original);
|
||||||
|
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
common_log_db_error($flink, 'UPDATE', __FILE__);
|
common_log_db_error($this->flink, 'UPDATE', __FILE__);
|
||||||
// @todo FIXME: Shouldn't this be a serverError()?
|
|
||||||
// TRANS: Server error displayed when saving Twitter integration preferences fails.
|
// TRANS: Server error displayed when saving Twitter integration preferences fails.
|
||||||
$this->showForm(_m('Could not save Twitter preferences.'));
|
throw new ServerException(_m('Could not save Twitter preferences.'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($wasReceiving xor $noticerecv) {
|
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.
|
// TRANS: Success message after saving Twitter integration preferences.
|
||||||
|
Loading…
Reference in New Issue
Block a user