]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apichecknickname.php
Separating classes into files and stronger typing
[quix0rs-gnu-social.git] / actions / apichecknickname.php
1 <?php
2                 
3 /**
4  * StatusNet, the distributed open-source microblogging tool
5  *
6  * Check nickname
7  *
8  * Returns 1 if nickname is available on this instance, 0 if not. Error if site is private.
9  *
10  * PHP version 5
11  *
12  * LICENCE: This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public License
23  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24  *
25  * @category  API
26  * @package   GNUsocial
27  * @author    Hannes Mannerheim <h@nnesmannerhe.im>
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29  * @link      http://www.gnu.org/software/social/
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 class ApiCheckNicknameAction extends ApiAction
35 {
36
37     protected function prepare(array $args=array())
38     {
39         parent::prepare($args);
40
41         if (common_config('site', 'private')) {
42             $this->clientError(_('This site is private.'), 403);
43         }
44
45         if ($this->format !== 'json') {
46             $this->clientError('This method currently only serves JSON.', 415);
47         }
48
49         return true;
50     }
51
52     protected function handle()
53     {
54         parent::handle();
55
56         $nickname = $this->trimmed('nickname');
57
58         try {
59             Nickname::normalize($nickname, true);
60             $nickname_ok = 1;
61         } catch (NicknameException $e) {
62             $nickname_ok = 0;
63         }
64
65         $this->initDocument('json');
66         $this->showJsonObjects($nickname_ok);
67         $this->endDocument('json');
68     }
69 }