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
46 class ApiListsAction extends ApiBareAuthAction
55 * Set the flags for handling the request. List lists created by user if this
56 * is a GET request, create a new list if it is a POST request.
59 * - user: the user id or nickname
60 * Parameters for POST request
61 * - name: name of the new list (the people tag itself)
62 * - mode: (optional) mode for the new list private/public
63 * - description: (optional) description for the list
65 * @return boolean success flag
68 function prepare($args)
70 parent::prepare($args);
72 $this->create = ($_SERVER['REQUEST_METHOD'] == 'POST');
76 $this->user = $this->getTargetUser($this->arg('user'));
78 if (empty($this->user)) {
79 $this->clientError(_('No such user.'), 404, $this->format);
89 * require authentication if it is a write action or user is ambiguous
93 function requiresAuth()
95 return parent::requiresAuth() ||
96 $this->create || $this->delete;
101 * Show the lists the user has created if the request method is GET
102 * Create a new list by diferring to handlePost() if it is POST.
105 function handle($args)
107 parent::handle($args);
110 return $this->handlePost();
113 switch($this->format) {
115 $this->showXmlLists($this->lists, $this->next_cursor, $this->prev_cursor);
118 $this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
122 _('API method not found.'),
133 * @return boolean success
136 function handlePost()
138 $name=$this->arg('name');
141 print _("A list's name can't be blank.");
145 // twitter creates a new list by appending a number to the end
146 // if the list by the given name already exists
147 // it makes more sense to return the existing list instead
150 if ($this->arg('mode') === 'public') {
152 } else if ($this->arg('mode') === 'private') {
156 $list = Profile_list::ensureTag($this->auth_user->id,
158 $this->arg('description'),
164 switch($this->format) {
166 $this->showSingleXmlList($list);
169 $this->showSingleJsonList($list);
173 _('API method not found.'),
188 $cursor = (int) $this->arg('cursor', -1);
190 // twitter fixes count at 20
191 // there is no argument named count
193 $profile = $this->user->getProfile();
194 $fn = array($profile, 'getOwnedTags');
198 $this->prev_cursor) = Profile_list::getAtCursor($fn, array($this->auth_user), $cursor, $count);
201 function isReadOnly($args)
206 function lastModified()
208 if (!$this->create && !empty($this->lists) && (count($this->lists) > 0)) {
209 return strtotime($this->lists[0]->created);
216 * An entity tag for this list of lists
218 * Returns an Etag based on the action name, language, user ID and
219 * timestamps of the first and last list the user has joined
221 * @return string etag
226 if (!$this->create && !empty($this->lists) && (count($this->lists) > 0)) {
228 $last = count($this->lists) - 1;
230 return '"' . implode(
232 array($this->arg('action'),
235 strtotime($this->lists[0]->created),
236 strtotime($this->lists[$last]->created))