exit(1);
}
-require_once INSTALLDIR . '/plugins/TwitterBridge/twitter.php';
+require_once dirname(__DIR__) . '/twitter.php';
/**
* Class for doing OAuth authentication against Twitter
*
* @return boolean true
*/
- function prepare($args)
+ function prepare(array $args=array())
{
parent::prepare($args);
*
* @return nothing
*/
- function handle($args)
+ function handle(array $args=array())
{
parent::handle($args);
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;
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);
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);
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,
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);
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()
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 - ' .
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 - ' .
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;
}
}