]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistmembers.php
Twitter lists compatible people tags api
[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
43     function handlePost()
44     {
45         if($this->auth_user->id != $this->list->tagger) {
46             $this->clientError(
47                 _('You aren\'t 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                 _('You must specify a member'),
57                 400,
58                 $this->format
59             );
60             return false;
61         }
62
63         $result = Profile_tag::setTag($this->auth_user->id,
64                         $this->user->id, $this->list->tag);
65
66         if(empty($result)) {
67             $this->clientError(
68                 _('An error occured.'),
69                 500,
70                 $this->format
71             );
72             return false;
73         }
74
75         switch($this->format) {
76         case 'xml':
77             $this->showSingleXmlList($this->list);
78             break;
79         case 'json':
80             $this->showSingleJsonList($this->list);
81             break;
82         default:
83             $this->clientError(
84                 _('API method not found.'),
85                 404,
86                 $this->format
87             );
88             return false;
89             break;
90         }
91     }
92
93     /**
94      * Remove a user from a list (untag someone)
95      *
96      * @return boolean success
97      */
98
99     function handleDelete()
100     {
101         if($this->auth_user->id != $this->list->tagger) {
102             $this->clientError(
103                 _('You aren\'t allowed to remove members from this list'),
104                 401,
105                 $this->format
106             );
107             return false;
108         }
109
110         if($this->user === false) {
111             $this->clientError(
112                 _('You must specify a member'),
113                 400,
114                 $this->format
115             );
116             return false;
117         }
118
119         $args = array('tagger' => $this->auth_user->id,
120                       'tagged' => $this->user->id,
121                       'tag' => $this->list->tag);
122         $ptag = Profile_tag::pkeyGet($args);
123
124         if(empty($ptag)) {
125             $this->clientError(
126                 _('The user you are trying to remove from the list is not a member'),
127                 400,
128                 $this->format
129             );
130             return false;
131         }
132
133         $result = $ptag->delete();
134
135         if(empty($result)) {
136             $this->clientError(
137                 _('An error occured.'),
138                 500,
139                 $this->format
140             );
141             return false;
142         }
143
144         switch($this->format) {
145         case 'xml':
146             $this->showSingleXmlList($this->list);
147             break;
148         case 'json':
149             $this->showSingleJsonList($this->list);
150             break;
151         default:
152             $this->clientError(
153                 _('API method not found.'),
154                 404,
155                 $this->format
156             );
157             return false;
158             break;
159         }
160         return true;
161     }
162
163     /**
164      * List the members of a list (people tagged)
165      */
166
167     function getUsers()
168     {
169         $fn = array($this->list, 'getTagged');
170         list($this->users, $this->next_cursor, $this->prev_cursor) =
171             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
172     }
173 }