123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php
-
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiQvitterBlocksAction extends ApiPrivateAuthAction
- {
- var $profiles = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->format = 'json';
- $this->count = (int)$this->arg('count', 100);
- $arg_user = $this->getTargetUser($this->arg('id'));
- $this->target = ($this->auth_user) ? $this->auth_user->getProfile() : null;
- if (!($this->target instanceof Profile)) {
-
- $this->clientError(_('No such user.'), 404);
- } else if($this->auth_user->id != $arg_user->id) {
- $this->clientError(_('You are only allowed to view your own blocks.'), 403);
- }
- $this->profiles = $this->getProfiles();
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $this->initDocument('json');
- print json_encode($this->showProfiles());
- $this->endDocument('json');
- }
-
- protected function getProfiles()
- {
- $offset = ($this->page - 1) * $this->count;
- $limit = $this->count + 1;
- $blocks = null;
- $blocks = QvitterBlocked::getBlocked($this->target->id, $offset, $limit);
- if($blocks) {
- $profiles = array();
- while ($blocks->fetch()) {
- $this_profile_block = clone($blocks);
- $profiles[] = $this->getTargetProfile($this_profile_block->blocked);
- }
- return $profiles;
- } else {
- return false;
- }
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- if (!empty($this->profiles) && (count($this->profiles) > 0)) {
- return strtotime($this->profiles[0]->modified);
- }
- 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,
- 'Profiles',
- strtotime($this->profiles[0]->modified),
- strtotime($this->profiles[$last]->modified))
- )
- . '"';
- }
- return null;
- }
-
- function showProfiles()
- {
- $user_arrays = array();
- foreach ($this->profiles as $profile) {
- $user_arrays[] = $this->twitterUserArray($profile, false );
- }
- return $user_arrays;
- }
- }
|