123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- defined('GNUSOCIAL') || die();
- class BlockAction extends ProfileFormAction
- {
- public $profile = null;
-
- public function prepare(array $args = []): bool
- {
- if (!parent::prepare($args)) {
- return false;
- }
- $cur = common_current_user();
- assert(!empty($cur));
- if ($cur->hasBlocked($this->profile)) {
-
- $this->clientError(_('You already blocked that user.'));
- }
- return true;
- }
-
- public function handle(): void
- {
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- if ($this->arg('no')) {
- $this->returnToPrevious();
- } elseif ($this->arg('yes')) {
- $this->handlePost();
- $this->returnToPrevious();
- } else {
- $this->showPage();
- }
- } else {
- $this->showPage();
- }
- }
- public function showContent(): void
- {
- $this->areYouSureForm();
- }
- public function title(): string
- {
-
- return _('Block user');
- }
- public function showNoticeForm(): void
- {
-
- }
-
- public function areYouSureForm()
- {
-
- $profile = new ArrayWrapper(array($this->profile));
- $preview = new ProfileList($profile, $this);
- $preview->show();
- $id = $this->profile->id;
- $this->elementStart('form', array('id' => 'block-' . $id,
- 'method' => 'post',
- 'class' => 'form_settings form_entity_block',
- 'action' => common_local_url('block')));
- $this->elementStart('fieldset');
- $this->hidden('token', common_session_token());
-
- $this->element('legend', _('Block user'));
- $this->element(
- 'p',
- null,
-
- _('Are you sure you want to block this user? '
- . 'Afterwards, they will be unsubscribed from you, '
- . 'unable to subscribe to you in the future, and '
- . 'you will not be notified of any @-replies from them.')
- );
- $this->element('input', [
- 'id' => 'blockto-' . $id,
- 'name' => 'profileid',
- 'type' => 'hidden',
- 'value' => $id
- ]);
- 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.')
- );
- $this->submit(
- 'form_action-yes',
-
- _m('BUTTON', 'Yes'),
- 'submit form_action-secondary',
- 'yes',
-
- _('Block this user.')
- );
- $this->elementEnd('fieldset');
- $this->elementEnd('form');
- }
-
- public function handlePost(): void
- {
- $cur = common_current_user();
- if (Event::handle('StartBlockProfile', array($cur, $this->profile))) {
- $result = $cur->block($this->profile);
- if ($result) {
- Event::handle('EndBlockProfile', array($cur, $this->profile));
- }
- }
- if (!$result) {
-
- $this->serverError(_('Failed to save block information.'));
- }
- }
- public function showScripts(): void
- {
- parent::showScripts();
- $this->autofocus('form_action-yes');
- }
-
- public function checkSessionToken(): void
- {
- if (
- $_SERVER['REQUEST_METHOD'] === 'POST'
- || $this->arg('yes')
- || $this->arg('no')
- ) {
- parent::checkSessionToken();
- }
- }
-
- public function defaultReturnTo()
- {
- $user = common_current_user();
- if ($user) {
- return common_local_url(
- 'subscribers',
- ['nickname' => $user->nickname]
- );
- } else {
- return common_local_url('public');
- }
- }
- }
|