]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/actions/twitterauthorization.php
Merge branch 'social-master' into nightly
[quix0rs-gnu-social.git] / plugins / TwitterBridge / actions / twitterauthorization.php
index 6a86c81cb724ea01092b9503b1e532a1dd3d08f2..30f8141a97d4051be97930d688d109018d0724c1 100644 (file)
@@ -32,7 +32,7 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
+require_once dirname(__DIR__) . '/twitter.php';
 
 /**
  * Class for doing OAuth authentication against Twitter
@@ -65,7 +65,7 @@ class TwitterauthorizationAction extends Action
      *
      * @return boolean true
      */
-    function prepare($args)
+    function prepare(array $args=array())
     {
         parent::prepare($args);
 
@@ -83,7 +83,7 @@ class TwitterauthorizationAction extends Action
      *
      * @return nothing
      */
-    function handle($args)
+    function handle(array $args=array())
     {
         parent::handle($args);
 
@@ -496,7 +496,6 @@ class TwitterauthorizationAction extends Action
         if (common_config('site', 'closed')) {
             // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed.
             $this->clientError(_m('Registration not allowed.'));
-            return;
         }
 
         $invite = null;
@@ -506,7 +505,6 @@ class TwitterauthorizationAction extends Action
             if (empty($code)) {
                 // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed.
                 $this->clientError(_m('Registration not allowed.'));
-                return;
             }
 
             $invite = Invitation::getKV($code);
@@ -514,29 +512,16 @@ class TwitterauthorizationAction extends Action
             if (empty($invite)) {
                 // TRANS: Client error displayed when trying to create a new user with an invalid invitation code.
                 $this->clientError(_m('Not a valid invitation code.'));
-                return;
             }
         }
 
         try {
-            $nickname = Nickname::normalize($this->trimmed('newname'));
+            $nickname = Nickname::normalize($this->trimmed('newname'), true);
         } catch (NicknameException $e) {
             $this->showForm($e->getMessage());
             return;
         }
 
-        if (!User::allowed_nickname($nickname)) {
-            // TRANS: Client error displayed when trying to create a new user with an invalid username.
-            $this->showForm(_m('Nickname not allowed.'));
-            return;
-        }
-
-        if (User::getKV('nickname', $nickname)) {
-            // TRANS: Client error displayed when trying to create a new user with a username that is already in use.
-            $this->showForm(_m('Nickname already in use. Try another one.'));
-            return;
-        }
-
         $fullname = trim($this->tw_fields['fullname']);
 
         $args = array('nickname' => $nickname, 'fullname' => $fullname);
@@ -555,7 +540,6 @@ class TwitterauthorizationAction extends Action
         if (empty($user)) {
             // TRANS: Server error displayed when creating a new user has failed.
             $this->serverError(_m('Error registering user.'));
-            return;
         }
 
         $result = $this->saveForeignLink($user->id,
@@ -567,7 +551,6 @@ class TwitterauthorizationAction extends Action
         if (!$result) {
             // TRANS: Server error displayed when connecting a user to a Twitter user has failed.
             $this->serverError(_m('Error connecting user to Twitter.'));
-            return;
         }
 
         common_set_user($user);
@@ -578,8 +561,7 @@ class TwitterauthorizationAction extends Action
 
         Event::handle('EndRegistrationTry', array($this));
 
-        common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)),
-                        303);
+        common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), 303);
     }
 
     function connectNewUser()
@@ -610,7 +592,6 @@ class TwitterauthorizationAction extends Action
         if (!$result) {
             // TRANS: Server error displayed connecting a user to a Twitter user has failed.
             $this->serverError(_m('Error connecting user to Twitter.'));
-            return;
         }
 
         common_debug('TwitterBridge Plugin - ' .
@@ -631,7 +612,6 @@ class TwitterauthorizationAction extends Action
         if (empty($result)) {
             // TRANS: Server error displayed connecting a user to a Twitter user has failed.
             $this->serverError(_m('Error connecting user to Twitter.'));
-            return;
         }
 
         common_debug('TwitterBridge Plugin - ' .
@@ -688,36 +668,10 @@ class TwitterauthorizationAction extends Action
 
     function bestNewNickname()
     {
-        if (!empty($this->tw_fields['fullname'])) {
-            $nickname = $this->nicknamize($this->tw_fields['fullname']);
-            if ($this->isNewNickname($nickname)) {
-                return $nickname;
-            }
-        }
-
-        return null;
-    }
-
-     // Given a string, try to make it work as a nickname
-
-     function nicknamize($str)
-     {
-         $str = preg_replace('/\W/', '', $str);
-         $str = str_replace(array('-', '_'), '', $str);
-         return strtolower($str);
-     }
-
-    function isNewNickname($str)
-    {
-        if (!Nickname::isValid($str)) {
-            return false;
-        }
-        if (!User::allowed_nickname($str)) {
-            return false;
-        }
-        if (User::getKV('nickname', $str)) {
-            return false;
+        try {
+            return Nickname::normalize($this->tw_fields['fullname'], true);
+        } catch (NicknameException $e) {
+            return null;
         }
-        return true;
     }
 }