]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistmember.php
Merge remote-tracking branch 'mainline/1.0.x' into people_tags_rebase
[quix0rs-gnu-social.git] / actions / apilistmember.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * API method to check if a user belongs to a list.
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   StatusNet
24  * @author    Shashi Gowda <connect2shashi@gmail.com>
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 require_once INSTALLDIR . '/lib/apibareauth.php';
34
35 /**
36  * Action handler for Twitter list_memeber methods
37  *
38  * @category API
39  * @package  StatusNet
40  * @author   Shashi Gowda <connect2shashi@gmail.com>
41  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42  * @link     http://status.net/
43  * @see      ApiBareAuthAction
44  */
45
46 class ApiListMemberAction extends ApiBareAuthAction
47 {
48     /**
49      * Set the flags for handling the request. Show the profile if this
50      * is a GET request AND the profile is a member of the list, add a member
51      * if it is a POST, remove the profile from the list if method is DELETE
52      * or if method is POST and an argument _method is set to DELETE. Act
53      * like we don't know if the current user has no access to the list.
54      *
55      * Takes parameters:
56      *     - user: the user id or nickname
57      *     - list_id: the id of the tag or the tag itself
58      *     - id: the id of the member being looked for/added/removed
59      *
60      * @return boolean success flag
61      */
62
63     function prepare($args)
64     {
65         parent::prepare($args);
66
67         $this->user = $this->getTargetUser($this->arg('id'));
68         $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
69
70         if (empty($this->list)) {
71             $this->clientError(_('Not found'), 404, $this->format);
72             return false;
73         }
74
75         if (empty($this->user)) {
76             $this->clientError(_('No such user'), 404, $this->format);
77             return false;
78         }
79         return true;
80     }
81
82     /**
83      * Handle the request
84      *
85      * @return boolean success flag
86      */
87
88     function handle($args)
89     {
90         parent::handle($args);
91
92         $arr = array('tagger' => $this->list->tagger,
93                       'tag' => $this->list->tag,
94                       'tagged' => $this->user->id);
95         $ptag = Profile_tag::pkeyGet($arr);
96
97         if(empty($ptag)) {
98             $this->clientError(
99                 _('The specified user is not a member of this list'),
100                 400,
101                 $this->format
102             );
103         }
104
105         $user = $this->twitterUserArray($this->user->getProfile(), true);
106
107         switch($this->format) {
108         case 'xml':
109             $this->showTwitterXmlUser($user, 'user', true);
110             break;
111         case 'json':
112             $this->showSingleJsonUser($user);
113             break;
114         default:
115             $this->clientError(
116                 _('API method not found.'),
117                 404,
118                 $this->format
119             );
120             break;
121         }
122         return true;
123     }
124 }