]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/apibareauth.php
0ae477f468b63d6a0e7e38a0c81e0b0d18bc346b
[quix0rs-gnu-social.git] / lib / apibareauth.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Base class for API actions that require "bare auth". Bare auth means
6  * authentication is required only if the action is called without an argument
7  * or query param specifying user id.
8  *
9  * PHP version 5
10  *
11  * LICENCE: This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Affero General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Affero General Public License for more details.
20  *
21  * You should have received a copy of the GNU Affero General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  *
24  * @category  API
25  * @package   StatusNet
26  * @author    Zach Copley <zach@status.net>
27  * @copyright 2009 StatusNet, Inc.
28  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29  * @link      http://status.net/
30  */
31
32 if (!defined('STATUSNET')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/apiauth.php';
37
38 /**
39  * Actions extending this class will require auth unless a target
40  * user ID has been specified
41  *
42  * @category API
43  * @package  StatusNet
44  * @author   Zach Copley <zach@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46  * @link     http://status.net/
47  */
48
49 class ApiBareAuthAction extends ApiAuthAction
50 {
51
52     /**
53      * Take arguments for running
54      *
55      * @param array $args $_REQUEST args
56      *
57      * @return boolean success flag
58      *
59      */
60
61     function prepare($args)
62     {
63         parent::prepare($args);
64         return true;
65     }
66
67     /**
68      * Does this API resource require authentication?
69      *
70      * @return boolean true or false
71      */
72
73     function requiresAuth()
74     {
75         // If the site is "private", all API methods except statusnet/config
76         // need authentication
77
78         if (common_config('site', 'private')) {
79             return true;
80         }
81
82         // check whether a user has been specified somehow
83
84         $id           = $this->arg('id');
85         $user_id      = $this->arg('user_id');
86         $screen_name  = $this->arg('screen_name');
87
88         if (empty($id) && empty($user_id) && empty($screen_name)) {
89             return true;
90         }
91
92         return false;
93     }
94
95 }