3 * StatusNet, the distributed open-source microblogging tool
5 * Base class for showing subscription information in the 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 * @author Dan Moore <dan@moore.cx>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Zach Copley <zach@status.net>
27 * @copyright 2009 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
36 require_once INSTALLDIR . '/lib/apibareauth.php';
39 * This class outputs a list of profiles as Twitter-style user and status objects.
40 * It is used by the API methods /api/statuses/(friends|followers). To support the
41 * social graph methods it also can output a simple list of IDs.
45 * @author Dan Moore <dan@moore.cx>
46 * @author Evan Prodromou <evan@status.net>
47 * @author Zach Copley <zach@status.net>
48 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
49 * @link http://status.net/
52 class ApiSubscriptionsAction extends ApiBareAuthAction
60 * Take arguments for running
62 * @param array $args $_REQUEST args
64 * @return boolean success flag
68 function prepare($args)
70 parent::prepare($args);
72 $this->tag = $this->arg('tag');
74 // Note: Twitter no longer supports 'lite'
75 $this->lite = $this->arg('lite');
77 $this->ids_only = $this->arg('ids_only');
79 // If called as a social graph method, show 5000 per page, otherwise 100
81 $this->count = isset($this->ids_only) ?
82 5000 : (int)$this->arg('count', 100);
84 $this->user = $this->getTargetUser($this->arg('id'));
86 if (empty($this->user)) {
87 $this->clientError(_('No such user.'), 404, $this->format);
91 $this->profiles = $this->getProfiles();
101 * @param array $args $_REQUEST data (unused)
106 function handle($args)
108 parent::handle($args);
110 if (!in_array($this->format, array('xml', 'json'))) {
111 $this->clientError(_('API method not found!'), $code = 404);
115 $this->initDocument($this->format);
117 if (isset($this->ids_only)) {
120 $this->showProfiles(isset($this->lite) ? false : true);
123 $this->endDocument($this->format);
127 * Get profiles - should get overrrided
129 * @return array Profiles
132 function getProfiles()
137 * Is this action read only?
139 * @param array $args other arguments
141 * @return boolean true
144 function isReadOnly($args)
150 * When was this feed last modified?
152 * @return string datestamp of the latest profile in the stream
155 function lastModified()
157 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
158 return strtotime($this->profiles[0]->created);
165 * An entity tag for this action
167 * Returns an Etag based on the action name, language, user ID, and
168 * timestamps of the first and last profiles in the subscriptions list
169 * There's also an indicator to show whether this action is being called
170 * as /api/statuses/(friends|followers) or /api/(friends|followers)/ids
172 * @return string etag
177 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
179 $last = count($this->profiles) - 1;
181 return '"' . implode(
183 array($this->arg('action'),
186 isset($this->ids_only) ? 'IDs' : 'Profiles',
187 strtotime($this->profiles[0]->created),
188 strtotime($this->profiles[$last]->created))
197 * Show the profiles as Twitter-style useres and statuses
199 * @param boolean $include_statuses Whether to include the latest status
200 * with each user. Default true.
205 function showProfiles($include_statuses = true)
207 switch ($this->format) {
209 $this->elementStart('users', array('type' => 'array'));
210 foreach ($this->profiles as $profile) {
218 $this->elementEnd('users');
222 foreach ($this->profiles as $profile) {
223 $arrays[] = $this->twitterUserArray(
228 print json_encode($arrays);
231 $this->clientError(_('Unsupported format.'));
237 * Show the IDs of the profiles only. 5000 per page. To support
238 * the 'social graph' methods: /api/(friends|followers)/ids
245 switch ($this->format) {
247 $this->elementStart('ids');
248 foreach ($this->profiles as $profile) {
249 $this->element('id', null, $profile->id);
251 $this->elementEnd('ids');
255 foreach ($this->profiles as $profile) {
256 $ids[] = (int)$profile->id;
258 print json_encode($ids);
261 $this->clientError(_('Unsupported format.'));