3 * StatusNet, the distributed open-source microblogging tool
5 * Show, update or delete a list.
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 * @author Shashi Gowda <connect2shashi@gmail.com>
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://status.net/
29 if (!defined('STATUSNET')) {
33 require_once INSTALLDIR . '/lib/apibareauth.php';
35 class ApiListAction extends ApiBareAuthAction
38 * The list in question in the current request
43 * Is this an update request?
48 * Is this a delete request?
53 * Set the flags for handling the request. Show list if this is a GET
54 * request, update it if it is POST, delete list if method is DELETE
55 * or if method is POST and an argument _method is set to DELETE. Act
56 * like we don't know if the current user has no access to the list.
59 * - user: the user id or nickname
60 * - id: the id of the tag or the tag itself
62 * @return boolean success flag
64 function prepare($args)
66 parent::prepare($args);
68 $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
69 ($this->trimmed('_method') == 'DELETE' &&
70 $_SERVER['REQUEST_METHOD'] == 'POST'));
72 // update list if method is POST or PUT and $this->delete is not true
73 $this->update = (!$this->delete &&
74 in_array($_SERVER['REQUEST_METHOD'], array('POST', 'PUT')));
76 $this->user = $this->getTargetUser($this->arg('user'));
77 $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
79 if (empty($this->list)) {
80 // TRANS: Client error displayed when referring to a non-existing list.
81 $this->clientError(_('List not found.'), 404, $this->format);
91 * @return boolean success flag
93 function handle($args)
95 parent::handle($args);
98 $this->handleDelete();
107 switch($this->format) {
109 $this->showSingleXmlList($this->list);
112 $this->showSingleJsonList($this->list);
116 // TRANS: Client error displayed when coming across a non-supported API method.
117 _('API method not found.'),
126 * require authentication if it is a write action or user is ambiguous
129 function requiresAuth()
131 return parent::requiresAuth() ||
132 $this->create || $this->delete;
138 * @return boolean success
142 if($this->auth_user->id != $this->list->tagger) {
144 // TRANS: Client error displayed when trying to update another user's list.
145 _('You cannot update lists that do not belong to you.'),
151 $new_list = clone($this->list);
152 $new_list->tag = common_canonical_tag($this->arg('name'));
153 $new_list->description = common_canonical_tag($this->arg('description'));
154 $new_list->private = ($this->arg('mode') === 'private') ? true : false;
156 $result = $new_list->update($this->list);
160 // TRANS: Client error displayed when an unknown error occurs updating a list.
161 _('An error occured.'),
167 switch($this->format) {
169 $this->showSingleXmlList($new_list);
172 $this->showSingleJsonList($new_list);
176 // TRANS: Client error displayed when coming across a non-supported API method.
177 _('API method not found.'),
188 * @return boolean success
190 function handleDelete()
192 if($this->auth_user->id != $this->list->tagger) {
194 // TRANS: Client error displayed when trying to delete another user's list.
195 _('You cannot delete lists that do not belong to you.'),
201 $record = clone($this->list);
202 $this->list->delete();
204 switch($this->format) {
206 $this->showSingleXmlList($record);
209 $this->showSingleJsonList($record);
213 // TRANS: Client error displayed when coming across a non-supported API method.
214 _('API method not found.'),
223 * Indicate that this resource is not read-only.
225 * @return boolean is_read-only=false
227 function isReadOnly($args)
233 * When was the list (people tag) last updated?
235 * @return String time_last_modified
237 function lastModified()
239 if(!empty($this->list)) {
240 return strtotime($this->list->modified);
246 * An entity tag for this list
248 * Returns an Etag based on the action name, language, user ID and
249 * timestamps of the first and last list the user has joined
251 * @return string etag
255 if (!empty($this->list)) {
257 return '"' . implode(
259 array($this->arg('action'),
262 strtotime($this->list->created),
263 strtotime($this->list->modified))