]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/twittersettings.php
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into...
[quix0rs-gnu-social.git] / actions / twittersettings.php
index 2d41469bba01b9c2456af282819b42d78052e96b..2b742788eee55419112a718d271f6e4285960163 100644 (file)
@@ -32,6 +32,7 @@ if (!defined('LACONICA')) {
 }
 
 require_once INSTALLDIR.'/lib/connectsettingsaction.php';
+require_once INSTALLDIR.'/lib/twitter.php';
 
 define('SUBSCRIPTIONS', 80);
 
@@ -90,7 +91,7 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         $fuser = null;
 
-        $flink = Foreign_link::getByUserID($user->id, 1); // 1 == Twitter
+        $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
 
         if ($flink) {
             $fuser = $flink->getForeignUser();
@@ -137,7 +138,7 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         $this->elementStart('ul', 'form_data');
         $this->elementStart('li');
-        $this->checkbox('noticesync',
+        $this->checkbox('noticesend',
                         _('Automatically send my notices to Twitter.'),
                         ($flink) ?
                         ($flink->noticesync & FOREIGN_NOTICE_SEND) :
@@ -157,6 +158,22 @@ class TwittersettingsAction extends ConnectSettingsAction
                         ($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) {
@@ -185,12 +202,12 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         $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();
 
@@ -260,7 +277,7 @@ class TwittersettingsAction extends ConnectSettingsAction
                                             'alt' =>  ($other->fullname) ?
                                             $other->fullname :
                                             $other->nickname));
-                
+
                 $this->element('span', 'fn nickname', $other->nickname);
                 $this->elementEnd('a');
                 $this->elementEnd('li');
@@ -319,7 +336,8 @@ class TwittersettingsAction extends ConnectSettingsAction
     {
         $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');
 
@@ -358,11 +376,11 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         $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();
 
@@ -374,6 +392,8 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         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);
@@ -418,7 +438,8 @@ class TwittersettingsAction extends ConnectSettingsAction
 
     function savePreferences()
     {
-        $noticesync = $this->boolean('noticesync');
+        $noticesend = $this->boolean('noticesend');
+        $noticerecv = $this->boolean('noticerecv');
         $friendsync = $this->boolean('friendsync');
         $replysync  = $this->boolean('replysync');
 
@@ -447,7 +468,7 @@ class TwittersettingsAction extends ConnectSettingsAction
 
         $original = clone($flink);
 
-        $flink->set_flags($noticesync, $replysync, $friendsync);
+        $flink->set_flags($noticesend, $noticerecv, $replysync, $friendsync);
 
         $result = $flink->update($original);