]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistsubscribers.php
Profile/Peopletag file splitting for autoload
[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     function handlePost()
42     {
43         $result = Profile_tag_subscription::add($this->list,
44                             $this->auth_user);
45
46         if(empty($result)) {
47             // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
48             $this->clientError(_('An error occured.'), 500);
49         }
50
51         switch($this->format) {
52         case 'xml':
53             $this->showSingleXmlList($this->list);
54             break;
55         case 'json':
56             $this->showSingleJsonList($this->list);
57             break;
58         default:
59             // TRANS: Client error displayed when coming across a non-supported API method.
60             $this->clientError(_('API method not found.'), 404);
61         }
62     }
63
64     function handleDelete()
65     {
66         $args = array('profile_tag_id' => $this->list->id,
67                       'profile_id' => $this->auth_user->id);
68         $ptag = Profile_tag_subscription::pkeyGet($args);
69
70         if(empty($ptag)) {
71             // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
72             $this->clientError(_('You are not subscribed to this list.'));
73         }
74
75         $result = Profile_tag_subscription::remove($this->list, $this->auth_user);
76
77         if (empty($result)) {
78             // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
79             $this->clientError(_('An error occured.'), 500);
80         }
81
82         switch($this->format) {
83         case 'xml':
84             $this->showSingleXmlList($this->list);
85             break;
86         case 'json':
87             $this->showSingleJsonList($this->list);
88             break;
89         default:
90             // TRANS: Client error displayed when coming across a non-supported API method.
91             $this->clientError(_('API method not found.'), 404);
92         }
93         return true;
94     }
95
96     function getUsers()
97     {
98         $fn = array($this->list, 'getSubscribers');
99         list($this->users, $this->next_cursor, $this->prev_cursor) =
100             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
101     }
102 }