123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- require_once dirname(__DIR__) . '/twitter.php';
- class TwittersettingsAction extends ProfileSettingsAction
- {
-
- function title()
- {
-
- return _m('Twitter settings');
- }
-
- function getInstructions()
- {
-
- return _m('Connect your Twitter account to share your updates ' .
- 'with your Twitter friends and vice-versa.');
- }
-
- 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',
- 'action' =>
- common_local_url('twittersettings')));
- $this->hidden('token', common_session_token());
- $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')),
-
- 'Connect my Twitter account');
- $this->elementEnd('li');
- $this->elementEnd('ul');
- $this->elementEnd('fieldset');
- } else {
-
- $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',
-
- _m('Connected Twitter account'));
- $this->elementEnd('fieldset');
- $this->elementStart('fieldset');
-
- $this->element('legend', null, _m('Disconnect my account from Twitter'));
- if (!$user->password) {
- $this->elementStart('p', array('class' => 'form_guide'));
-
-
- $message = sprintf(_m('Disconnecting your Twitter account ' .
- 'could make it impossible to log in! Please ' .
- '[set a password](%s) first.'),
- common_local_url('passwordsettings'));
- $message = common_markup_to_html($message);
- $this->text($message);
- $this->elementEnd('p');
- } else {
-
- $note = _m('Keep your %1$s account but disconnect from Twitter. ' .
- 'You can use your %1$s password to log in.');
- $site = common_config('site', 'name');
- $this->element('p', 'instructions',
- sprintf($note, $site));
-
- $this->submit('disconnect', _m('BUTTON','Disconnect'));
- }
- $this->elementEnd('fieldset');
- $this->elementStart('fieldset', array('id' => 'settings_twitter_preferences'));
-
- $this->element('legend', null, _m('Preferences'));
- $this->elementStart('ul', 'form_data');
- $this->elementStart('li');
- $this->checkbox('noticesend',
-
- _m('Automatically send my notices to Twitter.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_SEND) :
- true);
- $this->elementEnd('li');
- $this->elementStart('li');
- $this->checkbox('replysync',
-
- _m('Send local "@" replies to Twitter.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
- true);
- $this->elementEnd('li');
- $this->elementStart('li');
- $this->checkbox('friendsync',
-
- _m('Subscribe to my Twitter friends here.'),
- ($flink) ?
- ($flink->friendsync & FOREIGN_FRIEND_RECV) :
- false);
- $this->elementEnd('li');
- if (common_config('twitterimport','enabled')) {
- $this->elementStart('li');
- $this->checkbox('noticerecv',
-
- _m('Import my friends timeline.'),
- ($flink) ?
- ($flink->noticesync & FOREIGN_NOTICE_RECV) :
- false);
- $this->elementEnd('li');
- } else {
-
- if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) {
- $this->hidden('noticerecv', true, 'noticerecv');
- }
- }
- $this->elementEnd('ul');
- if ($flink) {
-
- $this->submit('save', _m('BUTTON','Save'));
- } else {
-
- $this->submit('add', _m('BUTTON','Add'));
- }
- $this->elementEnd('fieldset');
- }
- $this->elementEnd('form');
- }
-
- function handlePost()
- {
-
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
-
- $this->showForm(_m('There was a problem with your session token. '.
- 'Try again, please.'));
- return;
- }
- if ($this->arg('save')) {
- $this->savePreferences();
- } else if ($this->arg('disconnect')) {
- $this->removeTwitterAccount();
- } else {
-
- $this->showForm(_m('Unexpected form submission.'));
- }
- }
-
- function removeTwitterAccount()
- {
- $user = common_current_user();
- $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
- if (empty($flink)) {
-
- $this->clientError(_m('No Twitter connection to remove.'));
- }
- $result = $flink->safeDelete();
- if (empty($result)) {
- common_log_db_error($flink, 'DELETE', __FILE__);
-
- $this->serverError(_m('Could not remove Twitter user.'));
- }
-
- $this->showForm(_m('Twitter account disconnected.'), true);
- }
-
- function savePreferences()
- {
- $noticesend = $this->boolean('noticesend');
- $noticerecv = $this->boolean('noticerecv');
- $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__);
-
-
- $this->showForm(_m('Could not save Twitter preferences.'));
- return;
- }
- $original = clone($flink);
- $wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
- $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
- $result = $flink->update($original);
- if ($result === false) {
- common_log_db_error($flink, 'UPDATE', __FILE__);
-
-
- $this->showForm(_m('Could not save Twitter preferences.'));
- return;
- }
- if ($wasReceiving xor $noticerecv) {
- $this->notifyDaemon($flink->foreign_id, $noticerecv);
- }
-
- $this->showForm(_m('Twitter preferences saved.'), true);
- }
-
- function notifyDaemon($twitterUserId, $receiving)
- {
-
- }
- }
|