summaryrefslogtreecommitdiff
path: root/actions/block.php
diff options
context:
space:
mode:
Diffstat (limited to 'actions/block.php')
-rw-r--r--actions/block.php69
1 files changed, 22 insertions, 47 deletions
diff --git a/actions/block.php b/actions/block.php
index b125d2d8b..71a34e087 100644
--- a/actions/block.php
+++ b/actions/block.php
@@ -42,9 +42,11 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*/
-class BlockAction extends Action
+
+class BlockAction extends ProfileFormAction
{
var $profile = null;
+
/**
* Take arguments for running
*
@@ -52,28 +54,22 @@ class BlockAction extends Action
*
* @return boolean success flag
*/
+
function prepare($args)
{
- parent::prepare($args);
- if (!common_logged_in()) {
- $this->clientError(_('Not logged in.'));
- return false;
- }
- $token = $this->trimmed('token');
- if (!$token || $token != common_session_token()) {
- $this->clientError(_('There was a problem with your session token. Try again, please.'));
- return;
- }
- $id = $this->trimmed('blockto');
- if (!$id) {
- $this->clientError(_('No profile specified.'));
+ if (!parent::prepare($args)) {
return false;
}
- $this->profile = Profile::staticGet('id', $id);
- if (!$this->profile) {
- $this->clientError(_('No profile with that ID.'));
+
+ $cur = common_current_user();
+
+ assert(!empty($cur)); // checked by parent
+
+ if ($cur->hasBlocked($this->profile)) {
+ $this->clientError(_("You already blocked that user."));
return false;
}
+
return true;
}
@@ -86,18 +82,16 @@ class BlockAction extends Action
*
* @return void
*/
+
function handle($args)
{
- parent::handle($args);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($this->arg('no')) {
- $cur = common_current_user();
- $other = Profile::staticGet('id', $this->arg('blockto'));
- common_redirect(common_local_url('showstream', array('nickname' => $other->nickname)),
- 303);
+ $this->returnToArgs();
} elseif ($this->arg('yes')) {
- $this->blockProfile();
- } elseif ($this->arg('blockto')) {
+ $this->handlePost();
+ $this->returnToArgs();
+ } else {
$this->showPage();
}
}
@@ -138,7 +132,7 @@ class BlockAction extends Action
'unable to subscribe to you in the future, and '.
'you will not be notified of any @-replies from them.'));
$this->element('input', array('id' => 'blockto-' . $id,
- 'name' => 'blockto',
+ 'name' => 'profileid',
'type' => 'hidden',
'value' => $id));
foreach ($this->args as $k => $v) {
@@ -157,36 +151,17 @@ class BlockAction extends Action
*
* @return void
*/
- function blockProfile()
+
+ function handlePost()
{
$cur = common_current_user();
- if ($cur->hasBlocked($this->profile)) {
- $this->clientError(_('You have already blocked this user.'));
- return;
- }
$result = $cur->block($this->profile);
+
if (!$result) {
$this->serverError(_('Failed to save block information.'));
return;
}
-
- // Now, gotta figure where we go back to
- foreach ($this->args as $k => $v) {
- if ($k == 'returnto-action') {
- $action = $v;
- } elseif (substr($k, 0, 9) == 'returnto-') {
- $args[substr($k, 9)] = $v;
- }
- }
-
- if ($action) {
- common_redirect(common_local_url($action, $args), 303);
- } else {
- common_redirect(common_local_url('subscribers',
- array('nickname' => $cur->nickname)),
- 303);
- }
}
}