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);
69 if(!$this->create && !$this->delete) {
75 function requiresAuth()
77 return parent::requiresAuth() ||
78 $this->create || $this->delete;
81 protected function handle()
86 return $this->handleDelete();
90 return $this->handlePost();
93 switch($this->format) {
95 $this->initDocument('xml');
96 $this->elementStart('users_list', array('xmlns:statusnet' =>
97 'http://status.net/schema/api/1/'));
98 $this->elementStart('users', array('type' => 'array'));
100 if (is_array($this->users)) {
101 foreach ($this->users as $u) {
102 $twitter_user = $this->twitterUserArray($u, true);
103 $this->showTwitterXmlUser($twitter_user);
106 while ($this->users->fetch()) {
107 $twitter_user = $this->twitterUserArray($this->users, true);
108 $this->showTwitterXmlUser($twitter_user);
112 $this->elementEnd('users');
113 $this->element('next_cursor', null, $this->next_cursor);
114 $this->element('previous_cursor', null, $this->prev_cursor);
115 $this->elementEnd('users_list');
118 $this->initDocument('json');
122 if (is_array($this->users)) {
123 foreach ($this->users as $u) {
124 $twitter_user = $this->twitterUserArray($u, true);
125 array_push($users, $twitter_user);
128 while ($this->users->fetch()) {
129 $twitter_user = $this->twitterUserArray($this->users, true);
130 array_push($users, $twitter_user);
134 $users_list = array('users' => $users,
135 'next_cursor' => $this->next_cursor,
136 'next_cursor_str' => strval($this->next_cursor),
137 'previous_cursor' => $this->prev_cursor,
138 'previous_cursor_str' => strval($this->prev_cursor));
140 $this->showJsonObjects($users_list);
142 $this->endDocument('json');
146 // TRANS: Client error displayed when coming across a non-supported API method.
147 _('API method not found.'),
155 function handlePost()
159 function handleDelete()
167 function isReadOnly($args)
172 function lastModified()
174 if(!empty($this->list)) {
175 return strtotime($this->list->modified);
181 * An entity tag for this list
183 * Returns an Etag based on the action name, language, user ID and
184 * timestamps of the first and last list the user has joined
186 * @return string etag
190 if (!empty($this->list)) {
192 return '"' . implode(
194 array($this->arg('action'),
197 strtotime($this->list->created),
198 strtotime($this->list->modified))