3 * Block a user action class.
9 * @author Evan Prodromou <evan@status.net>
10 * @author Robin Millette <millette@status.net>
11 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12 * @link http://status.net/
14 * StatusNet - the distributed open-source microblogging tool
15 * Copyright (C) 2008, 2009, StatusNet, Inc.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Affero General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Affero General Public License for more details.
27 * You should have received a copy of the GNU Affero General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 * Block a user action class.
40 * @author Evan Prodromou <evan@status.net>
41 * @author Robin Millette <millette@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://status.net/
46 class BlockAction extends ProfileFormAction
51 * Take arguments for running
53 * @param array $args $_REQUEST args
55 * @return boolean success flag
58 function prepare($args)
60 if (!parent::prepare($args)) {
64 $cur = common_current_user();
66 assert(!empty($cur)); // checked by parent
68 if ($cur->hasBlocked($this->profile)) {
69 $this->clientError(_("You already blocked that user."));
79 * Shows a page with list of favorite notices
81 * @param array $args $_REQUEST args; handled in prepare()
86 function handle($args)
88 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
89 if ($this->arg('no')) {
90 $this->returnToArgs();
91 } elseif ($this->arg('yes')) {
93 $this->returnToArgs();
100 function showContent() {
101 $this->areYouSureForm();
105 return _('Block user');
108 function showNoticeForm() {
115 * Shows a confirmation form.
119 function areYouSureForm()
121 $id = $this->profile->id;
122 $this->elementStart('form', array('id' => 'block-' . $id,
124 'class' => 'form_settings form_entity_block',
125 'action' => common_local_url('block')));
126 $this->elementStart('fieldset');
127 $this->hidden('token', common_session_token());
128 $this->element('legend', _('Block user'));
129 $this->element('p', null,
130 _('Are you sure you want to block this user? '.
131 'Afterwards, they will be unsubscribed from you, '.
132 'unable to subscribe to you in the future, and '.
133 'you will not be notified of any @-replies from them.'));
134 $this->element('input', array('id' => 'blockto-' . $id,
135 'name' => 'profileid',
138 foreach ($this->args as $k => $v) {
139 if (substr($k, 0, 9) == 'returnto-') {
140 $this->hidden($k, $v);
143 $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user"));
144 $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Block this user'));
145 $this->elementEnd('fieldset');
146 $this->elementEnd('form');
150 * Actually block a user.
155 function handlePost()
157 $cur = common_current_user();
159 if (Event::handle('StartBlockProfile', array($cur, $this->profile))) {
160 $result = $cur->block($this->profile);
162 Event::handle('EndBlockProfile', array($cur, $this->profile));
167 $this->serverError(_('Failed to save block information.'));