123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiListUsersAction extends ApiBareAuthAction
- {
- var $list = null;
- var $user = false;
- var $create = false;
- var $delete = false;
- var $cursor = -1;
- var $next_cursor = 0;
- var $prev_cursor = 0;
- var $users = null;
- protected function prepare(array $args=array())
- {
-
-
- $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
- ($this->trimmed('_method') == 'DELETE' &&
- $_SERVER['REQUEST_METHOD'] == 'POST'));
-
- $this->create = (!$this->delete &&
- $_SERVER['REQUEST_METHOD'] == 'POST');
- if ($this->arg('id')) {
- $this->target = $this->getTargetProfile($this->arg('id'));
- }
- parent::prepare($args);
- $this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
- if (empty($this->list)) {
-
- $this->clientError(_('List not found.'), 404, $this->format);
- }
- if(!$this->create && !$this->delete) {
- $this->getUsers();
- }
- return true;
- }
- function requiresAuth()
- {
- return parent::requiresAuth() ||
- $this->create || $this->delete;
- }
- protected function handle()
- {
- parent::handle();
- if($this->delete) {
- return $this->handleDelete();
- }
- if($this->create) {
- return $this->handlePost();
- }
- switch($this->format) {
- case 'xml':
- $this->initDocument('xml');
- $this->elementStart('users_list', array('xmlns:statusnet' =>
- 'http://status.net/schema/api/1/'));
- $this->elementStart('users', array('type' => 'array'));
- if (is_array($this->users)) {
- foreach ($this->users as $u) {
- $twitter_user = $this->twitterUserArray($u, true);
- $this->showTwitterXmlUser($twitter_user);
- }
- } else {
- while ($this->users->fetch()) {
- $twitter_user = $this->twitterUserArray($this->users, true);
- $this->showTwitterXmlUser($twitter_user);
- }
- }
- $this->elementEnd('users');
- $this->element('next_cursor', null, $this->next_cursor);
- $this->element('previous_cursor', null, $this->prev_cursor);
- $this->elementEnd('users_list');
- break;
- case 'json':
- $this->initDocument('json');
- $users = array();
- if (is_array($this->users)) {
- foreach ($this->users as $u) {
- $twitter_user = $this->twitterUserArray($u, true);
- array_push($users, $twitter_user);
- }
- } else {
- while ($this->users->fetch()) {
- $twitter_user = $this->twitterUserArray($this->users, true);
- array_push($users, $twitter_user);
- }
- }
- $users_list = array('users' => $users,
- 'next_cursor' => $this->next_cursor,
- 'next_cursor_str' => strval($this->next_cursor),
- 'previous_cursor' => $this->prev_cursor,
- 'previous_cursor_str' => strval($this->prev_cursor));
- $this->showJsonObjects($users_list);
- $this->endDocument('json');
- break;
- default:
- $this->clientError(
-
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
- }
- }
- function handlePost()
- {
- }
- function handleDelete()
- {
- }
- function getUsers()
- {
- }
- function isReadOnly($args)
- {
- return false;
- }
- function lastModified()
- {
- if(!empty($this->list)) {
- return strtotime($this->list->modified);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->list)) {
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_language(),
- $this->list->id,
- strtotime($this->list->created),
- strtotime($this->list->modified))
- )
- . '"';
- }
- return null;
- }
- }
|