123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- abstract class ApiSubscriptionsAction extends ApiBareAuthAction
- {
- var $profiles = null;
- var $tag = null;
- var $lite = null;
- var $ids_only = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->tag = $this->arg('tag');
-
- $this->lite = $this->arg('lite');
- $this->ids_only = $this->arg('ids_only');
-
- $this->count = isset($this->ids_only) ?
- 5000 : (int)$this->arg('count', 100);
- $this->target = $this->getTargetProfile($this->arg('id'));
- if (!($this->target instanceof Profile)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- $this->profiles = $this->getProfiles();
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (!in_array($this->format, array('xml', 'json'))) {
-
- $this->clientError(_('API method not found.'), 404);
- }
- $this->initDocument($this->format);
- if (isset($this->ids_only)) {
- $this->showIds();
- } else {
- $this->showProfiles(isset($this->lite) ? false : true);
- }
- $this->endDocument($this->format);
- }
-
- abstract protected function getProfiles();
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- if (!empty($this->profiles) && (count($this->profiles) > 0)) {
- return strtotime($this->profiles[0]->created);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->profiles) && (count($this->profiles) > 0)) {
- $last = count($this->profiles) - 1;
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- $this->target->id,
-
- isset($this->ids_only) ? 'IDs' : 'Profiles',
- strtotime($this->profiles[0]->created),
- strtotime($this->profiles[$last]->created))
- )
- . '"';
- }
- return null;
- }
-
- function showProfiles($include_statuses = true)
- {
- switch ($this->format) {
- case 'xml':
- $this->elementStart('users', array('type' => 'array',
- 'xmlns:statusnet' => 'http://status.net/schema/api/1/'));
- foreach ($this->profiles as $profile) {
- $this->showProfile(
- $profile,
- $this->format,
- null,
- $include_statuses
- );
- }
- $this->elementEnd('users');
- break;
- case 'json':
- $arrays = array();
- foreach ($this->profiles as $profile) {
- $arrays[] = $this->twitterUserArray(
- $profile,
- $include_statuses
- );
- }
- print json_encode($arrays);
- break;
- default:
-
- $this->clientError(_('Unsupported format.'));
- break;
- }
- }
-
- function showIds()
- {
- switch ($this->format) {
- case 'xml':
- $this->elementStart('ids');
- foreach ($this->profiles as $profile) {
- $this->element('id', null, $profile->id);
- }
- $this->elementEnd('ids');
- break;
- case 'json':
- $ids = array();
- foreach ($this->profiles as $profile) {
- $ids[] = (int)$profile->id;
- }
- print json_encode($ids);
- break;
- default:
-
- $this->clientError(_('Unsupported format.'));
- break;
- }
- }
- }
|