]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twittersettings.php
Added configuration options to enable/disable SMS and Twitter integration.
[quix0rs-gnu-social.git] / actions / twittersettings.php
index 5492dd99581eb69e9607e0988e5ed90e0c3a4f80..3343dba95a20d240a0a42f1ab14ae97e650e6223 100644 (file)
@@ -31,7 +31,8 @@ if (!defined('LACONICA')) {
     exit(1);
 }
 
-require_once INSTALLDIR.'/lib/settingsaction.php';
+require_once INSTALLDIR.'/lib/connectsettingsaction.php';
+require_once INSTALLDIR.'/lib/twitter.php';
 
 define('SUBSCRIPTIONS', 80);
 
@@ -47,7 +48,7 @@ define('SUBSCRIPTIONS', 80);
  * @see      SettingsAction
  */
 
-class TwittersettingsAction extends SettingsAction
+class TwittersettingsAction extends ConnectSettingsAction
 {
     /**
      * Title of the page
@@ -57,7 +58,7 @@ class TwittersettingsAction extends SettingsAction
 
     function title()
     {
-        _('Twitter settings');
+        return _('Twitter settings');
     }
 
     /**
@@ -84,71 +85,109 @@ class TwittersettingsAction extends SettingsAction
 
     function showContent()
     {
+        if (!common_config('twitter', 'enabled')) {
+            $this->element('div', array('class' => 'error'),
+                           _('Twitter is not available.'));
+            return;
+        }
+
         $user = common_current_user();
 
         $profile = $user->getProfile();
 
         $fuser = null;
 
-        $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
+        $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
 
         if ($flink) {
             $fuser = $flink->getForeignUser();
         }
 
         $this->elementStart('form', array('method' => 'post',
-                                          'id' => 'twittersettings',
+                                          'id' => 'form_settings_twitter',
+                                          'class' => 'form_settings',
                                           'action' =>
                                           common_local_url('twittersettings')));
+        $this->elementStart('fieldset', array('id' => 'settings_twitter_account'));
+        $this->element('legend', null, _('Twitter Account'));
         $this->hidden('token', common_session_token());
-
-        $this->element('h2', null, _('Twitter Account'));
-
         if ($fuser) {
-            $this->elementStart('p');
-
+            $this->elementStart('ul', 'form_data');
+            $this->elementStart('li', array('id' => 'settings_twitter_remove'));
             $this->element('span', 'twitter_user', $fuser->nickname);
             $this->element('a', array('href' => $fuser->uri), $fuser->uri);
-            $this->element('span', 'input_instructions',
+            $this->element('p', 'form_note',
                            _('Current verified Twitter account.'));
             $this->hidden('flink_foreign_id', $flink->foreign_id);
-            $this->elementEnd('p');
+            $this->elementEnd('li');
+            $this->elementEnd('ul');
             $this->submit('remove', _('Remove'));
         } else {
+            $this->elementStart('ul', 'form_data');
+            $this->elementStart('li', array('id' => 'settings_twitter_login'));
             $this->input('twitter_username', _('Twitter user name'),
                          ($this->arg('twitter_username')) ?
                          $this->arg('twitter_username') :
                          $profile->nickname,
                          _('No spaces, please.')); // hey, it's what Twitter says
-
+            $this->elementEnd('li');
+            $this->elementStart('li');
             $this->password('twitter_password', _('Twitter password'));
+            $this->elementend('li');
+            $this->elementEnd('ul');
         }
+        $this->elementEnd('fieldset');
 
-        $this->element('h2', null, _('Preferences'));
+        $this->elementStart('fieldset',
+                            array('id' => 'settings_twitter_preferences'));
+        $this->element('legend', null, _('Preferences'));
 
-        $this->checkbox('noticesync',
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->checkbox('noticesend',
                         _('Automatically send my notices to Twitter.'),
                         ($flink) ?
                         ($flink->noticesync & FOREIGN_NOTICE_SEND) :
                         true);
-
+        $this->elementEnd('li');
+        $this->elementStart('li');
         $this->checkbox('replysync',
                         _('Send local "@" replies to Twitter.'),
                         ($flink) ?
                         ($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) :
                         true);
-
+        $this->elementEnd('li');
+        $this->elementStart('li');
         $this->checkbox('friendsync',
                         _('Subscribe to my Twitter friends here.'),
                         ($flink) ?
                         ($flink->friendsync & FOREIGN_FRIEND_RECV) :
                         false);
+        $this->elementEnd('li');
+
+        if (common_config('twitterbridge','enabled')) {
+            $this->elementStart('li');
+            $this->checkbox('noticerecv',
+                            _('Import my Friends Timeline.'),
+                            ($flink) ?
+                            ($flink->noticesync & FOREIGN_NOTICE_RECV) :
+                            false);
+            $this->elementEnd('li');
+        } else {
+            // preserve setting even if bidrection bridge toggled off
+            if ($flink && ($flink->noticesync & FOREIGN_NOTICE_RECV)) {
+                $this->hidden('noticerecv', true, 'noticerecv');
+            }
+        }
+
+        $this->elementEnd('ul');
 
         if ($flink) {
             $this->submit('save', _('Save'));
         } else {
             $this->submit('add', _('Add'));
         }
+        $this->elementEnd('fieldset');
 
         $this->showTwitterSubscriptions();
 
@@ -169,12 +208,12 @@ class TwittersettingsAction extends SettingsAction
 
         $current_user = common_current_user();
 
-        $qry = 'SELECT user.* ' .
+        $qry = 'SELECT "user".* ' .
           'FROM subscription ' .
-          'JOIN user ON subscription.subscribed = user.id ' .
-          'JOIN foreign_link ON foreign_link.user_id = user.id ' .
+          'JOIN "user" ON subscription.subscribed = "user".id ' .
+          'JOIN foreign_link ON foreign_link.user_id = "user".id ' .
           'WHERE subscriber = %d ' .
-          'ORDER BY user.nickname';
+          'ORDER BY "user".nickname';
 
         $user = new User();
 
@@ -210,10 +249,10 @@ class TwittersettingsAction extends SettingsAction
         $friends_count = count($friends);
 
         if ($friends_count > 0) {
-
-            $this->element('h3', null, _('Twitter Friends'));
-            $this->elementStart('div', array('id' => 'subscriptions'));
-            $this->elementStart('ul', array('id' => 'subscriptions_avatars'));
+            $this->elementStart('div', array('id' => 'entity_subscriptions',
+                                             'class' => 'section'));
+            $this->element('h2', null, _('Twitter Friends'));
+            $this->elementStart('ul', 'entities users xoxo');
 
             for ($i = 0; $i < min($friends_count, SUBSCRIPTIONS); $i++) {
 
@@ -224,27 +263,28 @@ class TwittersettingsAction extends SettingsAction
                     continue;
                 }
 
-                $this->elementStart('li');
+                $this->elementStart('li', 'vcard');
                 $this->elementStart('a', array('title' => ($other->fullname) ?
                                                $other->fullname :
                                                $other->nickname,
                                                'href' => $other->profileurl,
-                                               'rel' => 'contact',
-                                               'class' => 'subscription'));
+                                               'class' => 'url'));
 
                 $avatar = $other->getAvatar(AVATAR_MINI_SIZE);
 
                 $avatar_url = ($avatar) ?
-                  common_avatar_display_url($avatar) :
-                  common_default_avatar(AVATAR_MINI_SIZE);
+                  $avatar->displayUrl() :
+                  Avatar::defaultImage(AVATAR_MINI_SIZE);
 
                 $this->element('img', array('src' => $avatar_url,
                                             'width' => AVATAR_MINI_SIZE,
                                             'height' => AVATAR_MINI_SIZE,
-                                            'class' => 'avatar mini',
+                                            'class' => 'avatar photo',
                                             'alt' =>  ($other->fullname) ?
                                             $other->fullname :
                                             $other->nickname));
+
+                $this->element('span', 'fn nickname', $other->nickname);
                 $this->elementEnd('a');
                 $this->elementEnd('li');
 
@@ -302,7 +342,8 @@ class TwittersettingsAction extends SettingsAction
     {
         $screen_name = $this->trimmed('twitter_username');
         $password    = $this->trimmed('twitter_password');
-        $noticesync  = $this->boolean('noticesync');
+        $noticesend  = $this->boolean('noticesend');
+        $noticerecv  = $this->boolean('noticerecv');
         $replysync   = $this->boolean('replysync');
         $friendsync  = $this->boolean('friendsync');
 
@@ -341,11 +382,11 @@ class TwittersettingsAction extends SettingsAction
 
         $flink->user_id     = $user->id;
         $flink->foreign_id  = $twit_user->id;
-        $flink->service     = 1; // Twitter
+        $flink->service     = TWITTER_SERVICE;
         $flink->credentials = $password;
         $flink->created     = common_sql_now();
 
-        $flink->set_flags($noticesync, $replysync, $friendsync);
+        $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
 
         $flink_id = $flink->insert();
 
@@ -357,6 +398,8 @@ class TwittersettingsAction extends SettingsAction
 
         if ($friendsync) {
             save_twitter_friends($user, $twit_user->id, $screen_name, $password);
+            $flink->last_friendsync = common_sql_now();
+            $flink->update();
         }
 
         $this->showForm(_('Twitter settings saved.'), true);
@@ -401,7 +444,8 @@ class TwittersettingsAction extends SettingsAction
 
     function savePreferences()
     {
-        $noticesync = $this->boolean('noticesync');
+        $noticesend = $this->boolean('noticesend');
+        $noticerecv = $this->boolean('noticerecv');
         $friendsync = $this->boolean('friendsync');
         $replysync  = $this->boolean('replysync');
 
@@ -430,7 +474,7 @@ class TwittersettingsAction extends SettingsAction
 
         $original = clone($flink);
 
-        $flink->set_flags($noticesync, $replysync, $friendsync);
+        $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
 
         $result = $flink->update($original);
 
@@ -458,7 +502,7 @@ class TwittersettingsAction extends SettingsAction
 
     function verifyCredentials($screen_name, $password)
     {
-        $uri = 'http://twitter.com/account/verifyCredentials.json';
+        $uri = 'http://twitter.com/account/verify_credentials.json';
 
         $data = get_twitter_data($uri, $screen_name, $password);
 
@@ -481,4 +525,4 @@ class TwittersettingsAction extends SettingsAction
         return false;
     }
 
-}
\ No newline at end of file
+}