]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistmembers.php
Merge branch 'master' into 1.0.x
[quix0rs-gnu-social.git] / actions / apilistmembers.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List/add/remove list members.
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/apilistusers.php';
34
35 class ApiListMembersAction extends ApiListUsersAction
36 {
37     /**
38      * Add a user to a list (tag someone)
39      *
40      * @return boolean success
41      */
42     function handlePost()
43     {
44         if($this->auth_user->id != $this->list->tagger) {
45             $this->clientError(
46                 // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
47                 _('You are not allowed to add members to this list.'),
48                 401,
49                 $this->format
50             );
51             return false;
52         }
53
54         if($this->user === false) {
55             $this->clientError(
56                 // TRANS: Client error displayed when trying to modify list members without specifying them.
57                 _('You must specify a member.'),
58                 400,
59                 $this->format
60             );
61             return false;
62         }
63
64         $result = Profile_tag::setTag($this->auth_user->id,
65                         $this->user->id, $this->list->tag);
66
67         if(empty($result)) {
68             $this->clientError(
69                 // TRANS: Client error displayed when an unknown error occurs viewing list members.
70                 _('An error occured.'),
71                 500,
72                 $this->format
73             );
74             return false;
75         }
76
77         switch($this->format) {
78         case 'xml':
79             $this->showSingleXmlList($this->list);
80             break;
81         case 'json':
82             $this->showSingleJsonList($this->list);
83             break;
84         default:
85             $this->clientError(
86                 // TRANS: Client error displayed when coming across a non-supported API method.
87                 _('API method not found.'),
88                 404,
89                 $this->format
90             );
91             return false;
92             break;
93         }
94     }
95
96     /**
97      * Remove a user from a list (untag someone)
98      *
99      * @return boolean success
100      */
101     function handleDelete()
102     {
103         if($this->auth_user->id != $this->list->tagger) {
104             $this->clientError(
105                 // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
106                 _('You are not allowed to remove members from this list.'),
107                 401,
108                 $this->format
109             );
110             return false;
111         }
112
113         if($this->user === false) {
114             $this->clientError(
115                 // TRANS: Client error displayed when trying to modify list members without specifying them.
116                 _('You must specify a member.'),
117                 400,
118                 $this->format
119             );
120             return false;
121         }
122
123         $args = array('tagger' => $this->auth_user->id,
124                       'tagged' => $this->user->id,
125                       'tag' => $this->list->tag);
126         $ptag = Profile_tag::pkeyGet($args);
127
128         if(empty($ptag)) {
129             $this->clientError(
130                 // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
131                 _('The user you are trying to remove from the list is not a member.'),
132                 400,
133                 $this->format
134             );
135             return false;
136         }
137
138         $result = $ptag->delete();
139
140         if(empty($result)) {
141             $this->clientError(
142                 // TRANS: Client error displayed when an unknown error occurs viewing list members.
143                 _('An error occured.'),
144                 500,
145                 $this->format
146             );
147             return false;
148         }
149
150         switch($this->format) {
151         case 'xml':
152             $this->showSingleXmlList($this->list);
153             break;
154         case 'json':
155             $this->showSingleJsonList($this->list);
156             break;
157         default:
158             $this->clientError(
159                 // TRANS: Client error displayed when coming across a non-supported API method.
160                 _('API method not found.'),
161                 404,
162                 $this->format
163             );
164             return false;
165             break;
166         }
167         return true;
168     }
169
170     /**
171      * List the members of a list (people tagged)
172      */
173     function getUsers()
174     {
175         $fn = array($this->list, 'getTagged');
176         list($this->users, $this->next_cursor, $this->prev_cursor) =
177             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
178     }
179 }