123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiGroupListAction extends ApiBareAuthAction
- {
- var $groups = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
-
- $this->target = $this->getTargetProfile(null);
- if (!($this->target instanceof Profile)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- $this->groups = $this->getGroups();
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $sitename = common_config('site', 'name');
-
- $title = sprintf(_("%s's groups"), $this->target->nickname);
- $taguribase = TagURI::base();
- $id = "tag:$taguribase:Groups";
- $link = common_local_url(
- 'usergroups',
- array('nickname' => $this->target->nickname)
- );
- $subtitle = sprintf(
-
- _('%1$s groups %2$s is a member of.'),
- $sitename,
- $this->target->nickname
- );
- switch($this->format) {
- case 'xml':
- $this->showXmlGroups($this->groups);
- break;
- case 'rss':
- $this->showRssGroups($this->groups, $title, $link, $subtitle);
- break;
- case 'atom':
- $selfuri = common_local_url('ApiGroupList', array('id'=>$this->target->id, 'format'=>'atom'));
- $this->showAtomGroups(
- $this->groups,
- $title,
- $id,
- $link,
- $subtitle,
- $selfuri
- );
- break;
- case 'json':
- $this->showJsonGroups($this->groups);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function getGroups()
- {
- $groups = array();
- $group = $this->target->getGroups(
- ($this->page - 1) * $this->count,
- $this->count,
- $this->since_id,
- $this->max_id
- );
- while ($group->fetch()) {
- $groups[] = clone($group);
- }
- return $groups;
- }
-
- function isReadOnly($args)
- {
- return true;
- }
-
- function lastModified()
- {
- if (!empty($this->groups) && (count($this->groups) > 0)) {
- return strtotime($this->groups[0]->created);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->groups) && (count($this->groups) > 0)) {
- $last = count($this->groups) - 1;
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_user_cache_hash($this->auth_user),
- common_language(),
- $this->target->id,
- strtotime($this->groups[0]->created),
- strtotime($this->groups[$last]->created))
- )
- . '"';
- }
- return null;
- }
- }
|