]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/formaction.php
Improved type-hint for following methods:
[quix0rs-gnu-social.git] / lib / formaction.php
index 844038d57a24ff6745a29d79425c12330b3ae3ef..2599153870cf426c54adaba956fed7a14523776b 100644 (file)
@@ -41,10 +41,13 @@ if (!defined('STATUSNET')) {
  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  * @link     http://status.net/
  */
-class FormAction extends Action
+class FormAction extends ManagedAction
 {
     protected $form = null;
+    protected $formOpts = array();
     protected $type = null;
+    protected $needLogin = true;
+    protected $canPost = true;
 
     protected function prepare(array $args=array()) {
         parent::prepare($args);
@@ -62,41 +65,68 @@ class FormAction extends Action
         return true;
     }
 
-    protected function handle()
+    public function isReadOnly(array $args=array()) {
+        return !$this->isPost();
+    }
+
+    public function showPageNotice()
     {
-        parent::handle();
-
-        if ($this->isPost()) {
-            try {
-                $msg = $this->handlePost();
-                $this->showForm($msg, true);
-            } catch (Exception $e) {
-                $this->showForm($e->getMessage());
-            }
-        } else {
-            $this->showForm();
+        $this->showInstructions();
+        if ($msg = $this->getError()) {
+            $this->element('div', 'error', $msg);
+        }
+        if ($msg = $this->getInfo()) {
+            $this->element('div', 'info', $msg);
         }
     }
 
-    public function isReadOnly($args) {
-        return !$this->isPost();
+    /**
+     * Outputs the instructions for the form
+     *
+     * SHOULD overload
+     */
+    public function showInstructions()
+    {
+        // instructions are nice, so users know what to do
+        $this->raw(common_markup_to_html($this->getInstructions()));
+    }
+
+    /**
+     * @return string with instructions to pass into common_markup_to_html()
+     */
+    public function getInstructions()
+    {
+        return null;
     }
 
     public function showForm($msg=null, $success=false)
     {
-        if ($success) {
-            $this->msg = $msg;
-        } else {
-            $this->error = $msg;
-        }
+        $this->msg = $msg;
+        $this->success = $success;
         $this->showPage();
     }
 
+    protected function showContent()
+    {
+        $form = $this->getForm();
+        $form->show();
+    }
+
+    protected function getForm()
+    {
+        $class = $this->form.'Form';
+        $form = new $class($this, $this->formOpts);
+        return $form;
+    }
+
     /**
      * Gets called from handle() if isPost() is true;
      * @return void
      */
-    protected function handlePost() {
+    protected function handlePost()
+    {
+        parent::handlePost();
+
         // check for this before token since all POST and FILES data
         // is losts when size is exceeded
         if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {