123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiGroupJoinAction extends ApiAuthAction
- {
- protected $needPost = true;
- var $group = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->group = $this->getTargetGroup($this->arg('id'));
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (empty($this->scoped)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- if (empty($this->group)) {
-
- $this->clientError(_('Group not found.'), 404);
- }
- if ($this->scoped->isMember($this->group)) {
-
- $this->clientError(_('You are already a member of that group.'), 403);
- }
- if (Group_block::isBlocked($this->group, $this->scoped)) {
-
- $this->clientError(_('You have been blocked from that group by the admin.'), 403);
- }
- try {
- $this->scoped->joinGroup($this->group);
- } catch (Exception $e) {
-
-
- $this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
- $this->scoped->nickname, $this->group->nickname));
- }
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlGroup($this->group);
- break;
- case 'json':
- $this->showSingleJsonGroup($this->group);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
- }
|