3 * Form action extendable class.
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2008, 2009, StatusNet, Inc.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
30 if (!defined('STATUSNET')) {
35 * Form action extendable class
39 * @author Evan Prodromou <evan@status.net>
40 * @author Mikael Nordfeldth <evan@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42 * @link http://status.net/
44 class FormAction extends Action
46 protected $form = null;
47 protected $type = null;
48 protected $needLogin = true;
50 protected function prepare(array $args=array()) {
51 parent::prepare($args);
53 $this->form = $this->form ?: $this->action;
54 $this->args['form'] = $this->form;
56 $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type');
57 $this->args['context'] = $this->trimmed('action'); // reply for notice for example
66 protected function handle()
70 if ($this->isPost()) {
72 $msg = $this->handlePost();
73 $this->showForm($msg, true);
74 } catch (Exception $e) {
75 $this->showForm($e->getMessage());
82 public function isReadOnly($args) {
83 return !$this->isPost();
86 public function showPageNotice()
88 $this->showInstructions();
89 if ($msg = $this->getError()) {
90 $this->element('div', 'error', $msg);
92 if ($msg = $this->getInfo()) {
93 $this->element('div', 'info', $msg);
98 * Outputs the instructions for the form
102 public function showInstructions()
104 // instructions are nice, so users know what to do
105 $this->raw(common_markup_to_html($this->getInstructions()));
109 * @return string with instructions to pass into common_markup_to_html()
111 public function getInstructions()
116 public function showForm($msg=null, $success=false)
127 * Gets called from handle() if isPost() is true;
130 protected function handlePost()
132 // check for this before token since all POST and FILES data
133 // is losts when size is exceeded
134 if (empty($_POST) && $_SERVER['CONTENT_LENGTH']>0) {
135 // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit.
136 // TRANS: %s is the number of bytes of the CONTENT_LENGTH.
137 $msg = _m('The server was unable to handle that much POST data (%s MiB) due to its current configuration.',
138 'The server was unable to handle that much POST data (%s MiB) due to its current configuration.',
139 round($_SERVER['CONTENT_LENGTH']/1024/1024,2));
140 throw new ClientException($msg);
143 $this->checkSessionToken();