123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- if (!defined('GNUSOCIAL')) { exit(1); }
- class LeavegroupAction extends Action
- {
- var $group = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- if (!common_logged_in()) {
-
- $this->clientError(_('You must be logged in to leave a group.'));
- }
- $nickname_arg = $this->trimmed('nickname');
- $id = intval($this->arg('id'));
- if ($id) {
- $this->group = User_group::getKV('id', $id);
- } else if ($nickname_arg) {
- $nickname = common_canonical_nickname($nickname_arg);
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- common_redirect(common_local_url('leavegroup', $args), 301);
- }
- $local = Local_group::getKV('nickname', $nickname);
- if (!$local) {
-
- $this->clientError(_('No such group.'), 404);
- }
- $this->group = User_group::getKV('id', $local->group_id);
- } else {
-
- $this->clientError(_('No nickname or ID.'), 404);
- }
- if (!$this->group) {
-
- $this->clientError(_('No such group.'), 404);
- }
- if (!$this->scoped->isMember($this->group)) {
-
- $this->clientError(_('You are not a member of that group.'), 403);
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- try {
- $this->scoped->leaveGroup($this->group);
- } catch (Exception $e) {
- common_log(LOG_ERR, "Error when {$this->scoped->nickname} tried to leave {$this->group->nickname}: " . $e->getMessage());
-
-
- $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'),
- $this->scoped->nickname, $this->group->nickname));
- return;
- }
- if ($this->boolean('ajax')) {
- $this->startHTML('text/xml;charset=utf-8');
- $this->elementStart('head');
-
- $this->element('title', null, sprintf(_m('TITLE','%1$s left group %2$s'),
- $this->scoped->nickname,
- $this->group->nickname));
- $this->elementEnd('head');
- $this->elementStart('body');
- $jf = new JoinForm($this, $this->group);
- $jf->show();
- $this->elementEnd('body');
- $this->endHTML();
- } else {
- common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname)), 303);
- }
- }
- }
|