]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/repeat.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / actions / repeat.php
index b75523498b447cdfdbb489f53ed15d75d891a5c8..501570ebf0f7d6c6e9ba08cdd0760196ec8354b0 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Repeat action.
  *
@@ -28,9 +27,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Repeat action
@@ -41,54 +38,35 @@ if (!defined('STATUSNET')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  * @link     http://status.net/
  */
-
-class RepeatAction extends Action
+class RepeatAction extends FormAction
 {
-    var $user = null;
-    var $notice = null;
+    protected $needPost = true; // At least for now, until repeat interface is available
 
-    function prepare($args)
+    protected $notice = null;   // Notice that is being repeated.
+    protected $repeat = null;   // The resulting repeat object/notice.
+
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
-        $this->user = common_current_user();
-
-        if (empty($this->user)) {
-            $this->clientError(_("Only logged-in users can repeat notices."));
-            return false;
-        }
-
         $id = $this->trimmed('notice');
 
         if (empty($id)) {
-            $this->clientError(_("No notice specified."));
-            return false;
+            // TRANS: Client error displayed when trying to repeat a notice while not providing a notice ID.
+            $this->clientError(_('No notice specified.'));
         }
 
-        $this->notice = Notice::staticGet('id', $id);
+        $this->notice = Notice::getKV('id', $id);
 
-        if (empty($this->notice)) {
-            $this->clientError(_("No notice specified."));
-            return false;
+        if (!$this->notice instanceof Notice) {
+            // TRANS: Client error displayed when trying to repeat a non-existing notice.
+            $this->clientError(_('Notice not found.'));
         }
 
-        if ($this->user->id == $this->notice->profile_id) {
-            $this->clientError(_("You can't repeat your own notice."));
-            return false;
-        }
-
-        $token  = $this->trimmed('token-'.$id);
-
-        if (empty($token) || $token != common_session_token()) {
-            $this->clientError(_("There was a problem with your session token. Try again, please."));
-            return false;
-        }
-
-        $profile = $this->user->getProfile();
-
-        if ($profile->hasRepeated($id)) {
-            $this->clientError(_("You already repeated that notice."));
-            return false;
+        $this->repeat = $this->notice->repeat($this->scoped, 'web');
+        if (!$this->repeat instanceof Notice) {
+            // TRANS: Error when unable to repeat a notice for unknown reason.
+            $this->clientError(_('Could not repeat notice for unknown reason. Please contact the webmaster!'));
         }
 
         return true;
@@ -101,26 +79,11 @@ class RepeatAction extends Action
      *
      * @return void
      */
-
-    function handle($args)
+    protected function showContent()
     {
-        $repeat = $this->notice->repeat($this->user->id, 'web');
-
-        common_broadcast_notice($repeat);
-
-        if ($this->boolean('ajax')) {
-            $this->startHTML('text/xml;charset=utf-8');
-            $this->elementStart('head');
-            $this->element('title', null, _('Repeated'));
-            $this->elementEnd('head');
-            $this->elementStart('body');
-            $this->element('p', array('id' => 'repeat_response',
-                                      'class' => 'repeated'),
-                                _('Repeated!'));
-            $this->elementEnd('body');
-            $this->elementEnd('html');
-        } else {
-            // FIXME!
-        }
+        $this->element('p', array('id' => 'repeat_response',
+                                  'class' => 'repeated'),
+                            // TRANS: Confirmation text after repeating a notice.
+                            _('Repeated!'));
     }
 }