123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class GroupunblockAction extends Action
- {
- var $profile = null;
- var $group = null;
-
- function prepare(array $args = array())
- {
- parent::prepare($args);
- if (!common_logged_in()) {
-
- $this->clientError(_('Not logged in.'));
- }
- $token = $this->trimmed('token');
- if (empty($token) || $token != common_session_token()) {
-
- $this->clientError(_('There was a problem with your session token. Try again, please.'));
- }
- $id = $this->trimmed('unblockto');
- if (empty($id)) {
-
- $this->clientError(_('No profile specified.'));
- }
- $this->profile = Profile::getKV('id', $id);
- if (empty($this->profile)) {
-
- $this->clientError(_('No profile with that ID.'));
- }
- $group_id = $this->trimmed('unblockgroup');
- if (empty($group_id)) {
-
- $this->clientError(_('No group specified.'));
- }
- $this->group = User_group::getKV('id', $group_id);
- if (empty($this->group)) {
-
- $this->clientError(_('No such group.'));
- }
- $user = common_current_user();
- if (!$user->isAdmin($this->group)) {
-
- $this->clientError(_('Only an admin can unblock group members.'), 401);
- }
- if (!Group_block::isBlocked($this->group, $this->profile)) {
-
- $this->clientError(_('User is not blocked from group.'));
- }
- return true;
- }
-
- function handle()
- {
- parent::handle();
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->unblockProfile();
- }
- }
-
- function unblockProfile()
- {
- $result = Group_block::unblockProfile($this->group, $this->profile);
- if (!$result) {
-
- $this->serverError(_('Error removing the block.'));
- }
- foreach ($this->args as $k => $v) {
- if ($k == 'returnto-action') {
- $action = $v;
- } else if (substr($k, 0, 9) == 'returnto-') {
- $args[substr($k, 9)] = $v;
- }
- }
- if ($action) {
- common_redirect(common_local_url($action, $args), 303);
- } else {
- common_redirect(common_local_url('blockedfromgroup', array('nickname' => $this->group->nickname)), 303);
- }
- }
- }
|