]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistmembers.php
ShowprofiletagAction now extends ShowstreamAction
[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             // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
46             $this->clientError(_('You are not allowed to add members to this list.'), 401);
47         }
48
49         if (!($this->target instanceof Profile)) {
50             // TRANS: Client error displayed when trying to modify list members without specifying them.
51             $this->clientError(_('You must specify a member.'));
52         }
53
54         $result = Profile_tag::setTag($this->auth_user->id,
55                         $this->target->id, $this->list->tag);
56
57         if(empty($result)) {
58             // TRANS: Client error displayed when an unknown error occurs viewing list members.
59             $this->clientError(_('An error occured.'), 500);
60         }
61
62         switch($this->format) {
63         case 'xml':
64             $this->showSingleXmlList($this->list);
65             break;
66         case 'json':
67             $this->showSingleJsonList($this->list);
68             break;
69         default:
70             // TRANS: Client error displayed when coming across a non-supported API method.
71             $this->clientError(_('API method not found.'), 404);
72         }
73     }
74
75     /**
76      * Remove a user from a list (untag someone)
77      *
78      * @return boolean success
79      */
80     function handleDelete()
81     {
82         if($this->auth_user->id != $this->list->tagger) {
83             // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
84             $this->clientError(_('You are not allowed to remove members from this list.'), 401);
85         }
86
87         if (!($this->target instanceof Profile)) {
88             // TRANS: Client error displayed when trying to modify list members without specifying them.
89             $this->clientError(_('You must specify a member.'));
90         }
91
92         $args = array('tagger' => $this->auth_user->id,
93                       'tagged' => $this->target->id,
94                       'tag' => $this->list->tag);
95         $ptag = Profile_tag::pkeyGet($args);
96
97         if (empty($ptag)) {
98             // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
99             $this->clientError(_('The user you are trying to remove from the list is not a member.'));
100         }
101
102         if (!$ptag->delete()) {
103             // TRANS: Client error displayed when an unknown error occurs viewing list members.
104             $this->clientError(_('An error occured.'), 500);
105         }
106
107         switch($this->format) {
108         case 'xml':
109             $this->showSingleXmlList($this->list);
110             break;
111         case 'json':
112             $this->showSingleJsonList($this->list);
113             break;
114         default:
115             // TRANS: Client error displayed when coming across a non-supported API method.
116             $this->clientError(_('API method not found.'), 404);
117         }
118
119         return true;
120     }
121
122     /**
123      * List the members of a list (people tagged)
124      */
125     function getUsers()
126     {
127         $fn = array($this->list, 'getTagged');
128         list($this->users, $this->next_cursor, $this->prev_cursor) =
129             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
130     }
131 }