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 $this->clientError(_('Not found'), 404, $this->format);
70 if(!$this->create && !$this->delete) {
76 function requiresAuth()
78 return parent::requiresAuth() ||
79 $this->create || $this->delete;
82 function handle($args)
84 parent::handle($args);
87 return $this->handleDelete();
91 return $this->handlePost();
94 switch($this->format) {
96 $this->initDocument('xml');
97 $this->elementStart('users_list', array('xmlns:statusnet' =>
98 'http://status.net/schema/api/1/'));
99 $this->elementStart('users', array('type' => 'array'));
101 if (is_array($this->users)) {
102 foreach ($this->users as $u) {
103 $twitter_user = $this->twitterUserArray($u, true);
104 $this->showTwitterXmlUser($twitter_user);
107 while ($this->users->fetch()) {
108 $twitter_user = $this->twitterUserArray($this->users, true);
109 $this->showTwitterXmlUser($twitter_user);
113 $this->elementEnd('users');
114 $this->element('next_cursor', null, $this->next_cursor);
115 $this->element('previous_cursor', null, $this->prev_cursor);
116 $this->elementEnd('users_list');
119 $this->initDocument('json');
123 if (is_array($this->users)) {
124 foreach ($this->users as $u) {
125 $twitter_user = $this->twitterUserArray($u, true);
126 array_push($users, $twitter_user);
129 while ($this->users->fetch()) {
130 $twitter_user = $this->twitterUserArray($this->users, true);
131 array_push($users, $twitter_user);
135 $users_list = array('users' => $users,
136 'next_cursor' => $this->next_cursor,
137 'next_cursor_str' => strval($this->next_cursor),
138 'previous_cursor' => $this->prev_cursor,
139 'previous_cursor_str' => strval($this->prev_cursor));
141 $this->showJsonObjects($users_list);
143 $this->endDocument('json');
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
191 if (!empty($this->list)) {
193 return '"' . implode(
195 array($this->arg('action'),
198 strtotime($this->list->created),
199 strtotime($this->list->modified))