3 * StatusNet, the distributed open-source microblogging tool
5 * Base class for list members and list subscribers api.
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.
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.
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/>.
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/
28 if (!defined('STATUSNET')) {
32 require_once INSTALLDIR . '/lib/apibareauth.php';
34 class ApiListUsersAction extends ApiBareAuthAction
45 function prepare($args)
47 // delete list member if method is DELETE or if method is POST and an argument
48 // _method is set to DELETE
49 $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
50 ($this->trimmed('_method') == 'DELETE' &&
51 $_SERVER['REQUEST_METHOD'] == 'POST'));
53 // add member if method is POST
54 $this->create = (!$this->delete &&
55 $_SERVER['REQUEST_METHOD'] == 'POST');
57 if($this->arg('id')) {
58 $this->user = $this->getTargetUser($this->arg('id'));
61 parent::prepare($args);
63 $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
65 if (empty($this->list)) {
66 // TRANS: Client error displayed when referring to a non-existing list.
67 $this->clientError(_('List not found.'), 404, $this->format);
71 if(!$this->create && !$this->delete) {
77 function requiresAuth()
79 return parent::requiresAuth() ||
80 $this->create || $this->delete;
83 function handle($args)
85 parent::handle($args);
88 return $this->handleDelete();
92 return $this->handlePost();
95 switch($this->format) {
97 $this->initDocument('xml');
98 $this->elementStart('users_list', array('xmlns:statusnet' =>
99 'http://status.net/schema/api/1/'));
100 $this->elementStart('users', array('type' => 'array'));
102 if (is_array($this->users)) {
103 foreach ($this->users as $u) {
104 $twitter_user = $this->twitterUserArray($u, true);
105 $this->showTwitterXmlUser($twitter_user);
108 while ($this->users->fetch()) {
109 $twitter_user = $this->twitterUserArray($this->users, true);
110 $this->showTwitterXmlUser($twitter_user);
114 $this->elementEnd('users');
115 $this->element('next_cursor', null, $this->next_cursor);
116 $this->element('previous_cursor', null, $this->prev_cursor);
117 $this->elementEnd('users_list');
120 $this->initDocument('json');
124 if (is_array($this->users)) {
125 foreach ($this->users as $u) {
126 $twitter_user = $this->twitterUserArray($u, true);
127 array_push($users, $twitter_user);
130 while ($this->users->fetch()) {
131 $twitter_user = $this->twitterUserArray($this->users, true);
132 array_push($users, $twitter_user);
136 $users_list = array('users' => $users,
137 'next_cursor' => $this->next_cursor,
138 'next_cursor_str' => strval($this->next_cursor),
139 'previous_cursor' => $this->prev_cursor,
140 'previous_cursor_str' => strval($this->prev_cursor));
142 $this->showJsonObjects($users_list);
144 $this->endDocument('json');
148 // TRANS: Client error displayed when coming across a non-supported API method.
149 _('API method not found.'),
157 function handlePost()
161 function handleDelete()
169 function isReadOnly($args)
174 function lastModified()
176 if(!empty($this->list)) {
177 return strtotime($this->list->modified);
183 * An entity tag for this list
185 * Returns an Etag based on the action name, language, user ID and
186 * timestamps of the first and last list the user has joined
188 * @return string etag
192 if (!empty($this->list)) {
194 return '"' . implode(
196 array($this->arg('action'),
199 strtotime($this->list->created),
200 strtotime($this->list->modified))