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
44 * Is this an update request?
50 * Is this a delete request?
56 * Set the flags for handling the request. Show list if this is a GET
57 * request, update it if it is POST, delete list if method is DELETE
58 * or if method is POST and an argument _method is set to DELETE. Act
59 * like we don't know if the current user has no access to the list.
62 * - user: the user id or nickname
63 * - id: the id of the tag or the tag itself
65 * @return boolean success flag
68 function prepare($args)
70 parent::prepare($args);
72 $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
73 ($this->trimmed('_method') == 'DELETE' &&
74 $_SERVER['REQUEST_METHOD'] == 'POST'));
76 // update list if method is POST or PUT and $this->delete is not true
77 $this->update = (!$this->delete &&
78 in_array($_SERVER['REQUEST_METHOD'], array('POST', 'PUT')));
80 $this->user = $this->getTargetUser($this->arg('user'));
81 $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
83 if (empty($this->list)) {
84 $this->clientError(_('Not found'), 404, $this->format);
94 * @return boolean success flag
97 function handle($args)
99 parent::handle($args);
102 $this->handleDelete();
111 switch($this->format) {
113 $this->showSingleXmlList($this->list);
116 $this->showSingleJsonList($this->list);
120 _('API method not found.'),
129 * require authentication if it is a write action or user is ambiguous
133 function requiresAuth()
135 return parent::requiresAuth() ||
136 $this->create || $this->delete;
142 * @return boolean success
147 if($this->auth_user->id != $this->list->tagger) {
149 _('You can not update lists that don\'t belong to you.'),
155 $new_list = clone($this->list);
156 $new_list->tag = common_canonical_tag($this->arg('name'));
157 $new_list->description = common_canonical_tag($this->arg('description'));
158 $new_list->private = ($this->arg('mode') === 'private') ? true : false;
160 $result = $new_list->update($this->list);
164 _('An error occured.'),
170 switch($this->format) {
172 $this->showSingleXmlList($new_list);
175 $this->showSingleJsonList($new_list);
179 _('API method not found.'),
190 * @return boolean success
193 function handleDelete()
195 if($this->auth_user->id != $this->list->tagger) {
197 _('You can not delete lists that don\'t belong to you.'),
203 $record = clone($this->list);
204 $this->list->delete();
206 switch($this->format) {
208 $this->showSingleXmlList($record);
211 $this->showSingleJsonList($record);
215 _('API method not found.'),
224 * Indicate that this resource is not read-only.
226 * @return boolean is_read-only=false
229 function isReadOnly($args)
235 * When was the list (people tag) last updated?
237 * @return String time_last_modified
240 function lastModified()
242 if(!empty($this->list)) {
243 return strtotime($this->list->modified);
249 * An entity tag for this list
251 * Returns an Etag based on the action name, language, user ID and
252 * timestamps of the first and last list the user has joined
254 * @return string etag
259 if (!empty($this->list)) {
261 return '"' . implode(
263 array($this->arg('action'),
266 strtotime($this->list->created),
267 strtotime($this->list->modified))