3 * StatusNet, the distributed open-source microblogging tool
5 * List existing lists or create a new 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';
36 * Action handler for Twitter list_memeber methods
40 * @author Shashi Gowda <connect2shashi@gmail.com>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42 * @link http://status.net/
43 * @see ApiBareAuthAction
45 class ApiListsAction extends ApiBareAuthAction
54 * Set the flags for handling the request. List lists created by user if this
55 * is a GET request, create a new list if it is a POST request.
58 * - user: the user id or nickname
59 * Parameters for POST request
60 * - name: name of the new list (the people tag itself)
61 * - mode: (optional) mode for the new list private/public
62 * - description: (optional) description for the list
64 * @return boolean success flag
66 function prepare($args)
68 parent::prepare($args);
70 $this->create = ($_SERVER['REQUEST_METHOD'] == 'POST');
74 $this->user = $this->getTargetUser($this->arg('user'));
76 if (empty($this->user)) {
77 // TRANS: Client error displayed trying to perform an action related to a non-existing user.
78 $this->clientError(_('No such user.'), 404, $this->format);
88 * require authentication if it is a write action or user is ambiguous
91 function requiresAuth()
93 return parent::requiresAuth() ||
94 $this->create || $this->delete;
99 * Show the lists the user has created if the request method is GET
100 * Create a new list by diferring to handlePost() if it is POST.
102 function handle($args)
104 parent::handle($args);
107 return $this->handlePost();
110 switch($this->format) {
112 $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
115 $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
119 // TRANS: Client error displayed when coming across a non-supported API method.
120 _('API method not found.'),
131 * @return boolean success
133 function handlePost()
135 $name=$this->arg('name');
138 // TRANS: Client error displayed when trying to create a list without a name.
139 print _("A list must have a name.");
143 // twitter creates a new list by appending a number to the end
144 // if the list by the given name already exists
145 // it makes more sense to return the existing list instead
148 if ($this->arg('mode') === 'public') {
150 } else if ($this->arg('mode') === 'private') {
154 $list = Profile_list::ensureTag($this->auth_user->id,
156 $this->arg('description'),
162 switch($this->format) {
164 $this->showSingleXmlList($list);
167 $this->showSingleJsonList($list);
171 // TRANS: Client error displayed when coming across a non-supported API method.
172 _('API method not found.'),
186 $cursor = (int) $this->arg('cursor', -1);
188 // twitter fixes count at 20
189 // there is no argument named count
191 $profile = $this->user->getProfile();
192 $fn = array($profile, 'getLists');
196 $this->prev_cursor) = Profile_list::getAtCursor($fn, array($this->auth_user), $cursor, $count);
199 function isReadOnly($args)
204 function lastModified()
206 if (!$this->create && !empty($this->lists) && (count($this->lists) > 0)) {
207 return strtotime($this->lists[0]->created);
214 * An entity tag for this list of lists
216 * Returns an Etag based on the action name, language, user ID and
217 * timestamps of the first and last list the user has joined
219 * @return string etag
223 if (!$this->create && !empty($this->lists) && (count($this->lists) > 0)) {
225 $last = count($this->lists) - 1;
227 return '"' . implode(
229 array($this->arg('action'),
232 strtotime($this->lists[0]->created),
233 strtotime($this->lists[$last]->created))