]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/block.php
* improve L10n consistency for English. For example proper punctuation for all button...
[quix0rs-gnu-social.git] / actions / block.php
index 408f16434b3fab2c1a37efd250b19fc3facbe81f..f195fb5a88ffc8663373feccf94898c6811b4253 100644 (file)
@@ -42,9 +42,10 @@ 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
      *
@@ -54,26 +55,20 @@ class BlockAction extends Action
      */
     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)) {
+            // TRANS: Client error displayed when blocking a user that has already been blocked.
+            $this->clientError(_('You already blocked that user.'));
             return false;
         }
+
         return true;
     }
 
@@ -88,18 +83,17 @@ class BlockAction extends Action
      */
     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->returnToPrevious();
             } elseif ($this->arg('yes')) {
-                $this->blockProfile();
-            } elseif ($this->arg('blockto')) {
+                $this->handlePost();
+                $this->returnToPrevious();
+            } else {
                 $this->showPage();
             }
+        } else {
+            $this->showPage();
         }
     }
 
@@ -108,6 +102,7 @@ class BlockAction extends Action
     }
 
     function title() {
+        // TRANS: Title for block user page.
         return _('Block user');
     }
 
@@ -124,6 +119,12 @@ class BlockAction extends Action
      */
     function areYouSureForm()
     {
+        // @fixme if we ajaxify the confirmation form, skip the preview on ajax hits
+        $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',
@@ -131,14 +132,16 @@ class BlockAction extends Action
                                            'action' => common_local_url('block')));
         $this->elementStart('fieldset');
         $this->hidden('token', common_session_token());
+        // TRANS: Legend for block user form.
         $this->element('legend', _('Block user'));
         $this->element('p', null,
+                       // TRANS: Explanation of consequences when blocking a user on the block user page.
                        _('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', array('id' => 'blockto-' . $id,
-                                      'name' => 'blockto',
+                                      'name' => 'profileid',
                                       'type' => 'hidden',
                                       'value' => $id));
         foreach ($this->args as $k => $v) {
@@ -146,8 +149,20 @@ class BlockAction extends Action
                 $this->hidden($k, $v);
             }
         }
-        $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user from this group"));
-        $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Block this user from this group'));
+        $this->submit('form_action-no',
+                      // TRANS: Button label on the user block form.
+                      _m('BUTTON','No'),
+                      'submit form_action-primary',
+                      'no',
+                      // TRANS: Submit button title for 'No' when blocking a user.
+                      _('Do not block this user.'));
+        $this->submit('form_action-yes',
+                      // TRANS: Button label on the user block form.
+                      _m('BUTTON','Yes'),
+                      'submit form_action-secondary',
+                      'yes',
+                      // TRANS: Submit button title for 'Yes' when blocking a user.
+                      _('Block this user.'));
         $this->elementEnd('fieldset');
         $this->elementEnd('form');
     }
@@ -157,36 +172,63 @@ 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;
+        if (Event::handle('StartBlockProfile', array($cur, $this->profile))) {
+            $result = $cur->block($this->profile);
+            if ($result) {
+                Event::handle('EndBlockProfile', array($cur, $this->profile));
+            }
         }
-        $result = $cur->block($this->profile);
+
         if (!$result) {
+            // TRANS: Server error displayed when blocking a user fails.
             $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;
-            }
+    function showScripts()
+    {
+        parent::showScripts();
+        $this->autofocus('form_action-yes');
+    }
+
+    /**
+     * Override for form session token checks; on our first hit we're just
+     * requesting confirmation, which doesn't need a token. We need to be
+     * able to take regular GET requests from email!
+     *
+     * @throws ClientException if token is bad on POST request or if we have
+     *         confirmation parameters which could trigger something.
+     */
+    function checkSessionToken()
+    {
+        if ($_SERVER['REQUEST_METHOD'] == 'POST' ||
+            $this->arg('yes') ||
+            $this->arg('no')) {
+
+            return parent::checkSessionToken();
         }
+    }
 
-        if ($action) {
-            common_redirect(common_local_url($action, $args), 303);
+    /**
+     * If we reached this form without returnto arguments, return to the
+     * current user's subscription list.
+     *
+     * @return string URL
+     */
+    function defaultReturnTo()
+    {
+        $user = common_current_user();
+        if ($user) {
+            return common_local_url('subscribers',
+                                    array('nickname' => $user->nickname));
         } else {
-            common_redirect(common_local_url('subscribers',
-                                             array('nickname' => $cur->nickname)),
-                            303);
+            return common_local_url('public');
         }
     }
 }
-