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 Action
49 * Take arguments for running
51 * @param array $args $_REQUEST args
53 * @return boolean success flag
55 function prepare($args)
57 parent::prepare($args);
58 if (!common_logged_in()) {
59 $this->clientError(_('Not logged in.'));
62 $token = $this->trimmed('token');
63 if (!$token || $token != common_session_token()) {
64 $this->clientError(_('There was a problem with your session token. Try again, please.'));
67 $id = $this->trimmed('blockto');
69 $this->clientError(_('No profile specified.'));
72 $this->profile = Profile::staticGet('id', $id);
73 if (!$this->profile) {
74 $this->clientError(_('No profile with that ID.'));
83 * Shows a page with list of favorite notices
85 * @param array $args $_REQUEST args; handled in prepare()
89 function handle($args)
91 parent::handle($args);
92 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
93 if ($this->arg('no')) {
94 $cur = common_current_user();
95 $other = Profile::staticGet('id', $this->arg('blockto'));
96 common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)),
98 } elseif ($this->arg('yes')) {
99 $this->blockProfile();
100 } elseif ($this->arg('blockto')) {
106 function showContent() {
107 $this->areYouSureForm();
111 return _('Block user');
114 function showNoticeForm() {
121 * Shows a confirmation form.
125 function areYouSureForm()
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 $this->element('legend', _('Block user'));
135 $this->element('p', null,
136 _('Are you sure you want to block this user? '.
137 'Afterwards, they will be unsubscribed from you, '.
138 'unable to subscribe to you in the future, and '.
139 'you will not be notified of any @-replies from them.'));
140 $this->element('input', array('id' => 'blockto-' . $id,
144 foreach ($this->args as $k => $v) {
145 if (substr($k, 0, 9) == 'returnto-') {
146 $this->hidden($k, $v);
149 $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user from this group"));
150 $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Block this user from this group'));
151 $this->elementEnd('fieldset');
152 $this->elementEnd('form');
156 * Actually block a user.
160 function blockProfile()
162 $cur = common_current_user();
164 if ($cur->hasBlocked($this->profile)) {
165 $this->clientError(_('You have already blocked this user.'));
168 $result = $cur->block($this->profile);
170 $this->serverError(_('Failed to save block information.'));
174 // Now, gotta figure where we go back to
175 foreach ($this->args as $k => $v) {
176 if ($k == 'returnto-action') {
178 } elseif (substr($k, 0, 9) == 'returnto-') {
179 $args[substr($k, 9)] = $v;
184 common_redirect(common_local_url($action, $args), 303);
186 common_redirect(common_local_url('subscribers',
187 array('nickname' => $cur->nickname)),