]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/twittersettings.php
Merge branch 'atompub' into 0.9.x
[quix0rs-gnu-social.git] / plugins / TwitterBridge / twittersettings.php
index bc9a636a1586d4bc289d768371a2fb78bea53b42..c169172b0000f980c80137fabf130ad0975473c5 100644 (file)
@@ -45,7 +45,6 @@ require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
  *
  * @see      SettingsAction
  */
-
 class TwittersettingsAction extends ConnectSettingsAction
 {
     /**
@@ -79,7 +78,6 @@ class TwittersettingsAction extends ConnectSettingsAction
      *
      * @return void
      */
-
     function showContent()
     {
 
@@ -121,8 +119,36 @@ class TwittersettingsAction extends ConnectSettingsAction
             $this->elementEnd('p');
             $this->element('p', 'form_note',
                            _m('Connected Twitter account'));
+            $this->elementEnd('fieldset');
+
+            $this->elementStart('fieldset');
 
-            $this->submit('remove', _m('Remove'));
+            $this->element('legend', null, _m('Disconnect my account from Twitter'));
+
+            if (!$user->password) {
+
+                $this->elementStart('p', array('class' => 'form_guide'));
+                // @todo FIXME: Bad i18n (patchwork in three parts).
+                $this->text(_m('Disconnecting your Twitter ' .
+                               'could make it impossible to log in! Please '));
+                $this->element('a',
+                    array('href' => common_local_url('passwordsettings')),
+                        _m('set a password'));
+
+                $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.');
+
+                $site = common_config('site', 'name');
+
+                $this->element('p', 'instructions',
+                    sprintf($note, $site));
+
+                $this->submit('disconnect', _m('Disconnect'));
+            }
 
             $this->elementEnd('fieldset');
 
@@ -155,7 +181,7 @@ class TwittersettingsAction extends ConnectSettingsAction
             if (common_config('twitterimport','enabled')) {
                 $this->elementStart('li');
                 $this->checkbox('noticerecv',
-                                _m('Import my Friends Timeline.'),
+                                _m('Import my friends timeline.'),
                                 ($flink) ?
                                 ($flink->noticesync & FOREIGN_NOTICE_RECV) :
                                 false);
@@ -192,7 +218,6 @@ class TwittersettingsAction extends ConnectSettingsAction
      *
      * @return void
      */
-
     function handlePost()
     {
         // CSRF protection
@@ -205,7 +230,7 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         if ($this->arg('save')) {
             $this->savePreferences();
-        } else if ($this->arg('remove')) {
+        } else if ($this->arg('disconnect')) {
             $this->removeTwitterAccount();
         } else {
             $this->showForm(_m('Unexpected form submission.'));
@@ -217,13 +242,17 @@ class TwittersettingsAction extends ConnectSettingsAction
      *
      * @return void
      */
-
     function removeTwitterAccount()
     {
         $user = common_current_user();
         $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
 
-        $result = $flink->delete();
+        if (empty($flink)) {
+            $this->clientError(_m('No Twitter connection to remove.'));
+            return;
+        }
+
+        $result = $flink->safeDelete();
 
         if (empty($result)) {
             common_log_db_error($flink, 'DELETE', __FILE__);
@@ -231,7 +260,7 @@ class TwittersettingsAction extends ConnectSettingsAction
             return;
         }
 
-        $this->showForm(_m('Twitter account removed.'), true);
+        $this->showForm(_m('Twitter account disconnected.'), true);
     }
 
     /**
@@ -239,7 +268,6 @@ class TwittersettingsAction extends ConnectSettingsAction
      *
      * @return void
      */
-
     function savePreferences()
     {
         $noticesend = $this->boolean('noticesend');
@@ -257,6 +285,7 @@ class TwittersettingsAction extends ConnectSettingsAction
         }
 
         $original = clone($flink);
+        $wasReceiving = (bool)($original->noticesync & FOREIGN_NOTICE_RECV);
         $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
         $result = $flink->update($original);
 
@@ -266,7 +295,19 @@ class TwittersettingsAction extends ConnectSettingsAction
             return;
         }
 
+        if ($wasReceiving xor $noticerecv) {
+            $this->notifyDaemon($flink->foreign_id, $noticerecv);
+        }
+
         $this->showForm(_m('Twitter preferences saved.'), true);
     }
 
+    /**
+     * Tell the import daemon that we've updated a user's receive status.
+     */
+    function notifyDaemon($twitterUserId, $receiving)
+    {
+        // todo... should use control signals rather than queues
+    }
+
 }