123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
- }
- class GroupblockAction extends RedirectingAction
- {
- var $profile = null;
- var $group = null;
-
- function prepare($args)
- {
- 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('blockto');
- 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('blockgroup');
- 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 block group members.'), 401);
- }
- if (Group_block::isBlocked($this->group, $this->profile)) {
-
- $this->clientError(_('User is already blocked from group.'));
- }
-
- if (!$this->profile->isMember($this->group)) {
-
- $this->clientError(_('User is not a member of group.'));
- }
- return true;
- }
-
- function handle($args)
- {
- parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($this->arg('no')) {
- $this->returnToPrevious();
- } elseif ($this->arg('yes')) {
- $this->blockProfile();
- } elseif ($this->arg('blockto')) {
- $this->showPage();
- }
- }
- }
- function showContent() {
- $this->areYouSureForm();
- }
- function title() {
-
- return _('Block user from group');
- }
- function showNoticeForm() {
-
- }
-
- function areYouSureForm()
- {
- $id = $this->profile->id;
- $this->elementStart('form', array('id' => 'block-' . $id,
- 'method' => 'post',
- 'class' => 'form_settings form_entity_block',
- 'action' => common_local_url('groupblock')));
- $this->elementStart('fieldset');
- $this->hidden('token', common_session_token());
-
- $this->element('legend', _('Block user'));
- $this->element('p', null,
-
-
- sprintf(_('Are you sure you want to block user "%1$s" from the group "%2$s"? '.
- 'They will be removed from the group, unable to post, and '.
- 'unable to subscribe to the group in the future.'),
- $this->profile->getBestName(),
- $this->group->getBestName()));
- $this->hidden('blockto-' . $this->profile->id,
- $this->profile->id,
- 'blockto');
- $this->hidden('blockgroup-' . $this->group->id,
- $this->group->id,
- 'blockgroup');
- foreach ($this->args as $k => $v) {
- if (substr($k, 0, 9) == 'returnto-') {
- $this->hidden($k, $v);
- }
- }
- $this->submit('form_action-no',
-
- _m('BUTTON','No'),
- 'submit form_action-primary',
- 'no',
-
- _('Do not block this user from this group.'));
- $this->submit('form_action-yes',
-
- _m('BUTTON','Yes'),
- 'submit form_action-secondary',
- 'yes',
-
- _('Block this user from this group.'));
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
-
- function blockProfile()
- {
- $block = Group_block::blockProfile($this->group, $this->profile,
- common_current_user());
- if (empty($block)) {
-
- $this->serverError(_("Database error blocking user from group."));
- }
- $this->returnToPrevious();
- }
-
- function defaultReturnTo()
- {
- return common_local_url('groupmembers',
- array('nickname' => $this->group->nickname));
- }
- function showScripts()
- {
- parent::showScripts();
- $this->autofocus('form_action-yes');
- }
- }
|