]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apilistsubscribers.php
Some better context for notices as arrays
[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             $this->clientError(
48                 // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
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                 // TRANS: Client error displayed when coming across a non-supported API method.
66                 _('API method not found.'),
67                 404,
68                 $this->format
69             );
70             return false;
71             break;
72         }
73     }
74
75     function handleDelete()
76     {
77         $args = array('profile_tag_id' => $this->list->id,
78                       'profile_id' => $this->auth_user->id);
79         $ptag = Profile_tag_subscription::pkeyGet($args);
80
81         if(empty($ptag)) {
82             $this->clientError(
83                 // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
84                 _('You are not subscribed to this list.'),
85                 400,
86                 $this->format
87             );
88             return false;
89         }
90
91         Profile_tag_subscription::remove($this->list, $this->auth_user);
92
93         if(empty($result)) {
94             $this->clientError(
95                 // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
96                 _('An error occured.'),
97                 500,
98                 $this->format
99             );
100             return false;
101         }
102
103         switch($this->format) {
104         case 'xml':
105             $this->showSingleXmlList($this->list);
106             break;
107         case 'json':
108             $this->showSingleJsonList($this->list);
109             break;
110         default:
111             $this->clientError(
112                 // TRANS: Client error displayed when coming across a non-supported API method.
113                 _('API method not found.'),
114                 404,
115                 $this->format
116             );
117             return false;
118             break;
119         }
120         return true;
121     }
122
123     function getUsers()
124     {
125         $fn = array($this->list, 'getSubscribers');
126         list($this->users, $this->next_cursor, $this->prev_cursor) =
127             Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
128     }
129 }