From: Mikael Nordfeldth <mmn@hethane.se>
Date: Sat, 11 Jul 2015 09:16:08 +0000 (+0200)
Subject: DeletenoticeForm is its own class now
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7d524307d247d15687065be75f4524bc9e638a2b;p=quix0rs-gnu-social.git

DeletenoticeForm is its own class now
---

diff --git a/actions/deletenotice.php b/actions/deletenotice.php
index 8f0211f8f9..d8037ab444 100644
--- a/actions/deletenotice.php
+++ b/actions/deletenotice.php
@@ -33,15 +33,13 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 // @todo FIXME: documentation needed.
 class DeletenoticeAction extends FormAction
 {
-    protected $form = 'deletenotice';
-
     protected $notice = null;
 
     protected function doPreparation()
     {
-        $this->notice = Notice::getByID($this->int('notice'));
+        $this->notice = Notice::getByID($this->trimmed('notice'));
 
-        if ($this->notice->profile_id != $this->scoped->getID() &&
+        if (!$this->scoped->sameAs($this->notice->getProfile()) &&
                    !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
             // TRANS: Error message displayed trying to delete a notice that was not made by the current user.
             $this->clientError(_('Cannot delete this notice.'));
diff --git a/lib/deletenoticeform.php b/lib/deletenoticeform.php
new file mode 100644
index 0000000000..d06004613a
--- /dev/null
+++ b/lib/deletenoticeform.php
@@ -0,0 +1,67 @@
+<?php
+
+if (!defined('GNUSOCIAL')) { exit(1); }
+
+class DeletenoticeForm extends Form
+{
+    protected $notice = null;
+
+    function __construct(HTMLOutputter $out=null, array $formOpts=array())
+    {
+        if (!array_key_exists('notice', $formOpts) || !$formOpts['notice'] instanceof Notice) {
+            throw new ServerException('No notice provided to DeletenoticeForm');
+        }
+
+        parent::__construct($out);
+
+        $this->notice = $formOpts['notice'];
+    }
+
+    function id()
+    {
+        return 'form_notice_delete-' . $this->notice->getID();
+    }
+
+    function formClass()
+    {
+        return 'form_settings';
+    }
+
+    function action()
+    {
+        return common_local_url('deletenotice', array('notice' => $this->notice->getID()));
+    }
+
+    function formLegend()
+    {
+        $this->out->element('legend', null, _('Delete notice'));
+    }
+
+    function formData()
+    {
+        $this->out->element('p', null, _('Are you sure you want to delete this notice?'));
+    }
+
+    /**
+     * Action elements
+     *
+     * @return void
+     */
+    function formActions()
+    {
+        $this->out->submit('form_action-no',
+                      // TRANS: Button label on the delete notice form.
+                      _m('BUTTON','No'),
+                      'submit form_action-primary',
+                      'no',
+                      // TRANS: Submit button title for 'No' when deleting a notice.
+                      _('Do not delete this notice.'));
+        $this->out->submit('form_action-yes',
+                      // TRANS: Button label on the delete notice form.
+                      _m('BUTTON','Yes'),
+                      'submit form_action-secondary',
+                      'yes',
+                      // TRANS: Submit button title for 'Yes' when deleting a notice.
+                      _('Delete this notice.'));
+    }
+}
diff --git a/lib/formaction.php b/lib/formaction.php
index 5cf05d4a32..7d74fc4713 100644
--- a/lib/formaction.php
+++ b/lib/formaction.php
@@ -50,7 +50,7 @@ class FormAction extends ManagedAction
     protected function prepare(array $args=array()) {
         parent::prepare($args);
 
-        $this->form = $this->form ?: $this->action;
+        $this->form = $this->form ?: ucfirst($this->action);
         $this->args['form'] = $this->form;
 
         $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type');