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 class ApiListUsersAction extends ApiBareAuthAction
43 protected function prepare(array $args=array())
45 // delete list member if method is DELETE or if method is POST and an argument
46 // _method is set to DELETE
47 $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
48 ($this->trimmed('_method') == 'DELETE' &&
49 $_SERVER['REQUEST_METHOD'] == 'POST'));
51 // add member if method is POST
52 $this->create = (!$this->delete &&
53 $_SERVER['REQUEST_METHOD'] == 'POST');
55 if ($this->arg('id')) {
56 $this->target = $this->getTargetProfile($this->arg('id'));
59 parent::prepare($args);
61 $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
63 if (empty($this->list)) {
64 // TRANS: Client error displayed when referring to a non-existing list.
65 $this->clientError(_('List not found.'), 404, $this->format);
68 if(!$this->create && !$this->delete) {
74 function requiresAuth()
76 return parent::requiresAuth() ||
77 $this->create || $this->delete;
80 protected function handle()
85 return $this->handleDelete();
89 return $this->handlePost();
92 switch($this->format) {
94 $this->initDocument('xml');
95 $this->elementStart('users_list', array('xmlns:statusnet' =>
96 'http://status.net/schema/api/1/'));
97 $this->elementStart('users', array('type' => 'array'));
99 if (is_array($this->users)) {
100 foreach ($this->users as $u) {
101 $twitter_user = $this->twitterUserArray($u, true);
102 $this->showTwitterXmlUser($twitter_user);
105 while ($this->users->fetch()) {
106 $twitter_user = $this->twitterUserArray($this->users, true);
107 $this->showTwitterXmlUser($twitter_user);
111 $this->elementEnd('users');
112 $this->element('next_cursor', null, $this->next_cursor);
113 $this->element('previous_cursor', null, $this->prev_cursor);
114 $this->elementEnd('users_list');
117 $this->initDocument('json');
121 if (is_array($this->users)) {
122 foreach ($this->users as $u) {
123 $twitter_user = $this->twitterUserArray($u, true);
124 array_push($users, $twitter_user);
127 while ($this->users->fetch()) {
128 $twitter_user = $this->twitterUserArray($this->users, true);
129 array_push($users, $twitter_user);
133 $users_list = array('users' => $users,
134 'next_cursor' => $this->next_cursor,
135 'next_cursor_str' => strval($this->next_cursor),
136 'previous_cursor' => $this->prev_cursor,
137 'previous_cursor_str' => strval($this->prev_cursor));
139 $this->showJsonObjects($users_list);
141 $this->endDocument('json');
145 // TRANS: Client error displayed when coming across a non-supported API method.
146 _('API method not found.'),
154 function handlePost()
158 function handleDelete()
166 function isReadOnly($args)
171 function lastModified()
173 if(!empty($this->list)) {
174 return strtotime($this->list->modified);
180 * An entity tag for this list
182 * Returns an Etag based on the action name, language, user ID and
183 * timestamps of the first and last list the user has joined
185 * @return string etag
189 if (!empty($this->list)) {
191 return '"' . implode(
193 array($this->arg('action'),
196 strtotime($this->list->created),
197 strtotime($this->list->modified))