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/
45 class BlockAction extends ProfileFormAction
50 * Take arguments for running
52 * @param array $args $_REQUEST args
54 * @return boolean success flag
56 function prepare($args)
58 if (!parent::prepare($args)) {
62 $cur = common_current_user();
64 assert(!empty($cur)); // checked by parent
66 if ($cur->hasBlocked($this->profile)) {
67 // TRANS: Client error displayed when blocking a user that has already been blocked.
68 $this->clientError(_('You already blocked that user.'));
77 * Shows a page with list of favorite notices
79 * @param array $args $_REQUEST args; handled in prepare()
83 function handle($args)
85 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
86 if ($this->arg('no')) {
87 $this->returnToPrevious();
88 } elseif ($this->arg('yes')) {
90 $this->returnToPrevious();
99 function showContent() {
100 $this->areYouSureForm();
104 // TRANS: Title for block user page.
105 return _('Block user');
108 function showNoticeForm() {
115 * Shows a confirmation form.
119 function areYouSureForm()
121 // @fixme if we ajaxify the confirmation form, skip the preview on ajax hits
122 $profile = new ArrayWrapper(array($this->profile));
123 $preview = new ProfileList($profile, $this);
127 $id = $this->profile->id;
128 $this->elementStart('form', array('id' => 'block-' . $id,
130 'class' => 'form_settings form_entity_block',
131 'action' => common_local_url('block')));
132 $this->elementStart('fieldset');
133 $this->hidden('token', common_session_token());
134 // TRANS: Legend for block user form.
135 $this->element('legend', _('Block user'));
136 $this->element('p', null,
137 // TRANS: Explanation of consequences when blocking a user on the block user page.
138 _('Are you sure you want to block this user? '.
139 'Afterwards, they will be unsubscribed from you, '.
140 'unable to subscribe to you in the future, and '.
141 'you will not be notified of any @-replies from them.'));
142 $this->element('input', array('id' => 'blockto-' . $id,
143 'name' => 'profileid',
146 foreach ($this->args as $k => $v) {
147 if (substr($k, 0, 9) == 'returnto-') {
148 $this->hidden($k, $v);
151 $this->submit('form_action-no',
152 // TRANS: Button label on the user block form.
154 'submit form_action-primary',
156 // TRANS: Submit button title for 'No' when blocking a user.
157 _('Do not block this user.'));
158 $this->submit('form_action-yes',
159 // TRANS: Button label on the user block form.
161 'submit form_action-secondary',
163 // TRANS: Submit button title for 'Yes' when blocking a user.
164 _('Block this user.'));
165 $this->elementEnd('fieldset');
166 $this->elementEnd('form');
170 * Actually block a user.
175 function handlePost()
177 $cur = common_current_user();
179 if (Event::handle('StartBlockProfile', array($cur, $this->profile))) {
180 $result = $cur->block($this->profile);
182 Event::handle('EndBlockProfile', array($cur, $this->profile));
187 // TRANS: Server error displayed when blocking a user fails.
188 $this->serverError(_('Failed to save block information.'));
192 function showScripts()
194 parent::showScripts();
195 $this->autofocus('form_action-yes');
199 * Override for form session token checks; on our first hit we're just
200 * requesting confirmation, which doesn't need a token. We need to be
201 * able to take regular GET requests from email!
203 * @throws ClientException if token is bad on POST request or if we have
204 * confirmation parameters which could trigger something.
206 function checkSessionToken()
208 if ($_SERVER['REQUEST_METHOD'] == 'POST' ||
212 return parent::checkSessionToken();
217 * If we reached this form without returnto arguments, return to the
218 * current user's subscription list.
222 function defaultReturnTo()
224 $user = common_current_user();
226 return common_local_url('subscribers',
227 array('nickname' => $user->nickname));
229 return common_local_url('public');