]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistsubscribers.php
Leding tabs to spaces.
[quix0rs-gnu-social.git] / actions / apilistsubscribers.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show/add/remove list subscribers.
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  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
25  * @link      http://status.net/
26  */
27
28 if (!defined('STATUSNET')) {
29     exit(1);
30 }
31
32 require_once INSTALLDIR . '/lib/apilistusers.php';
33
34 class ApiListSubscribersAction extends ApiListUsersAction
35 {
36     /**
37      * Subscribe to list
38      *
39      * @return boolean success
40      */
41
42     function handlePost()
43     {
44         $result = Profile_tag_subscription::add($this->list,
45                             $this->auth_user);
46
47         if(empty($result)) {
48             $this->clientError(
49                 _('An error occured.'),
50                 500,
51                 $this->format
52             );
53             return false;
54         }
55
56         switch($this->format) {
57         case 'xml':
58             $this->showSingleXmlList($this->list);
59             break;
60         case 'json':
61             $this->showSingleJsonList($this->list);
62             break;
63         default:
64             $this->clientError(
65                 _('API method not found.'),
66                 404,
67                 $this->format
68             );
69             return false;
70             break;
71         }
72     }
73
74     function handleDelete()
75     {
76         $args = array('profile_tag_id' => $this->list->id,
77                       'profile_id' => $this->auth_user->id);
78         $ptag = Profile_tag_subscription::pkeyGet($args);
79
80         if(empty($ptag)) {
81             $this->clientError(
82                 _('You are not subscribed to this list'),
83                 400,
84                 $this->format
85             );
86             return false;
87         }
88
89         Profile_tag_subscription::remove($this->list, $this->auth_user);
90
91         if(empty($result)) {
92             $this->clientError(
93                 _('An error occured.'),
94                 500,
95                 $this->format
96             );
97             return false;
98         }
99
100         switch($this->format) {
101         case 'xml':
102             $this->showSingleXmlList($this->list);
103             break;
104         case 'json':
105             $this->showSingleJsonList($this->list);
106             break;
107         default:
108             $this->clientError(
109                 _('API method not found.'),
110                 404,
111                 $this->format
112             );
113             return false;
114             break;
115         }
116         return true;
117     }
118
119     function getUsers()
120     {
121         $fn = array($this->list, 'getSubscribers');
122         list($this->users, $this->next_cursor, $this->prev_cursor) =
123             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
124     }
125 }