]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/formaction.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / lib / formaction.php
1 <?php
2 /**
3  * Form action extendable class.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2008, 2009, StatusNet, Inc.
15  *
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.
20  *
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.
25  *
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/>.
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Form action extendable class
34  *
35  * @category Action
36  * @package  StatusNet
37  * @author   Evan Prodromou <evan@status.net>
38  * @author   Mikael Nordfeldth <evan@status.net>
39  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
40  * @link     http://status.net/
41  */
42 class FormAction extends ManagedAction
43 {
44     protected $form = null;
45     protected $formOpts = array();
46     protected $type = null;
47     protected $needLogin = true;
48     protected $canPost = true;
49
50     protected function prepare(array $args=array()) {
51         parent::prepare($args);
52
53         $this->form = $this->form ?: ucfirst($this->action);
54         $this->args['form'] = $this->form;
55
56         $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type');
57         $this->args['context'] = $this->trimmed('action');  // reply for notice for example
58
59         if (!$this->type) {
60             $this->type = null;
61         }
62
63         return true;
64     }
65
66     public function isReadOnly($args) {
67         return !$this->isPost();
68     }
69
70     public function showPageNotice()
71     {
72         $this->showInstructions();
73         if ($msg = $this->getError()) {
74             $this->element('div', 'error', $msg);
75         }
76         if ($msg = $this->getInfo()) {
77             $this->element('div', 'info', $msg);
78         }
79     }
80
81     /**
82      * Outputs the instructions for the form
83      *
84      * SHOULD overload
85      */
86     public function showInstructions()
87     {
88         // instructions are nice, so users know what to do
89         $this->raw(common_markup_to_html($this->getInstructions()));
90     }
91
92     /**
93      * @return string with instructions to pass into common_markup_to_html()
94      */
95     protected function getInstructions()
96     {
97         return null;
98     }
99
100     public function showForm($msg=null, $success=false)
101     {
102         $this->msg = $msg;
103         $this->success = $success;
104         $this->showPage();
105     }
106
107     protected function showContent()
108     {
109         $form = $this->getForm();
110         $form->show();
111     }
112
113     protected function getForm()
114     {
115         $class = $this->form.'Form';
116         $form = new $class($this, $this->formOpts);
117         return $form;
118     }
119 }