X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fformaction.php;h=7d74fc47130eaf20f6bb23b116e21eab8f9d6664;hb=f134a423f6a9e7bb61d069c4d6281c05417bbd45;hp=844038d57a24ff6745a29d79425c12330b3ae3ef;hpb=8d57fb7dc064bb6000467fa07864856c97dd2bcf;p=quix0rs-gnu-social.git diff --git a/lib/formaction.php b/lib/formaction.php index 844038d57a..7d74fc4713 100644 --- a/lib/formaction.php +++ b/lib/formaction.php @@ -27,9 +27,7 @@ * along with this program. If not, see . */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Form action extendable class @@ -41,15 +39,18 @@ 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); - $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'); @@ -62,52 +63,57 @@ class FormAction extends Action return true; } - protected function handle() - { - parent::handle(); + public function isReadOnly($args) { + return !$this->isPost(); + } - if ($this->isPost()) { - try { - $msg = $this->handlePost(); - $this->showForm($msg, true); - } catch (Exception $e) { - $this->showForm($e->getMessage()); - } - } else { - $this->showForm(); + public function showPageNotice() + { + $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() + */ + protected 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(); } - /** - * Gets called from handle() if isPost() is true; - * @return void - */ - protected function 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) { - // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. - // TRANS: %s is the number of bytes of the CONTENT_LENGTH. - $msg = _m('The server was unable to handle that much POST data (%s MiB) due to its current configuration.', - 'The server was unable to handle that much POST data (%s MiB) due to its current configuration.', - round($_SERVER['CONTENT_LENGTH']/1024/1024,2)); - throw new ClientException($msg); - } + protected function showContent() + { + $form = $this->getForm(); + $form->show(); + } - $this->checkSessionToken(); + protected function getForm() + { + $class = $this->form.'Form'; + $form = new $class($this, $this->formOpts); + return $form; } }