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 Zach Copley <zach@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR.'/lib/apibareauth.php';
37 * This class outputs a list of profiles as Twitter-style user and status objects.
38 * It is used by the API methods /api/statuses/(friends|followers). To support the
39 * social graph methods it also can output a simple list of IDs.
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 class ApiSubscriptionsAction extends ApiBareAuthAction
56 * Take arguments for running
58 * @param array $args $_REQUEST args
60 * @return boolean success flag
64 function prepare($args)
66 parent::prepare($args);
68 $this->tag = $this->arg('tag');
70 // Note: Twitter no longer supports 'lite'
71 $this->lite = $this->arg('lite');
73 $this->ids_only = $this->arg('ids_only');
75 // If called as a social graph method, show 5000 per page, otherwise 100
77 $this->count = isset($this->ids_only) ?
78 5000 : (int)$this->arg('count', 100);
80 $this->user = $this->getTargetUser($this->arg('id'));
82 if (empty($this->user)) {
83 $this->clientError(_('No such user!'), 404, $this->format);
87 $this->profiles = $this->getProfiles();
97 * @param array $args $_REQUEST data (unused)
102 function handle($args)
104 parent::handle($args);
106 if (!in_array($this->format, array('xml', 'json'))) {
107 $this->clientError(_('API method not found!'), $code = 404);
111 $this->initDocument($this->format);
113 if (isset($this->ids_only)) {
116 $this->showProfiles(isset($this->lite) ? false : true);
119 $this->endDocument($this->format);
123 * Get profiles - should get overrrided
125 * @return array Profiles
128 function getProfiles()
133 * Is this action read only?
135 * @param array $args other arguments
137 * @return boolean true
140 function isReadOnly($args)
146 * When was this feed last modified?
148 * @return string datestamp of the latest profile in the stream
151 function lastModified()
153 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
154 return strtotime($this->profiles[0]->created);
161 * An entity tag for this action
163 * Returns an Etag based on the action name, language, user ID, and
164 * timestamps of the first and last profiles in the subscriptions list
165 * There's also an indicator to show whether this action is being called
166 * as /api/statuses/(friends|followers) or /api/(friends|followers)/ids
168 * @return string etag
173 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
175 $last = count($this->profiles) - 1;
177 return '"' . implode(
179 array($this->arg('action'),
182 isset($this->ids_only) ? 'IDs' : 'Profiles',
183 strtotime($this->profiles[0]->created),
184 strtotime($this->profiles[$last]->created))
193 * Show the profiles as Twitter-style useres and statuses
195 * @param boolean $include_statuses Whether to include the latest status
196 * with each user. Default true.
201 function showProfiles($include_statuses = true)
203 switch ($this->format) {
205 $this->elementStart('users', array('type' => 'array'));
206 foreach ($this->profiles as $profile) {
214 $this->elementEnd('users');
218 foreach ($this->profiles as $profile) {
219 $arrays[] = $this->twitterUserArray(
224 print json_encode($arrays);
227 $this->clientError(_('Unsupported format.'));
233 * Show the IDs of the profiles only. 5000 per page. To support
234 * the 'social graph' methods: /api/(friends|followers)/ids
241 switch ($this->format) {
243 $this->elementStart('ids');
244 foreach ($this->profiles as $profile) {
245 $this->element('id', null, $profile->id);
247 $this->elementEnd('ids');
251 foreach ($this->profiles as $profile) {
252 $ids[] = (int)$profile->id;
254 print json_encode($ids);
257 $this->clientError(_('Unsupported format.'));