]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/form.php
Merge branch 'uiredesign' of evan@dev.controlyourself.ca:/var/www/csarven into uiredesign
[quix0rs-gnu-social.git] / lib / form.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Base class for forms
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Widget
23  * @package   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @author    Sarven Capadisli <csarven@controlyourself.ca>
26  * @copyright 2009 Control Yourself, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://laconi.ca/
29  */
30
31 if (!defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/widget.php';
36
37 /**
38  * Base class for forms
39  *
40  * We have a lot of common forms (subscribe, fave, delete) and this superclass
41  * lets us abstract out the basic features of the form.
42  *
43  * @category Widget
44  * @package  Laconica
45  * @author   Evan Prodromou <evan@controlyourself.ca>
46  * @author   Sarven Capadisli <csarven@controlyourself.ca>
47  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link     http://laconi.ca/
49  *
50  * @see      HTMLOutputter
51  */
52
53 class Form extends Widget
54 {
55     /**
56      * Show the form
57      *
58      * Uses a recipe to output the form.
59      *
60      * @return void
61      * @see Widget::show()
62      */
63
64     function show()
65     {
66         $this->out->elementStart('form',
67                                  array('id' => $this->id(),
68                                        'method' => 'POST',
69                                        'action' => $this->action()));
70         $this->out->elementStart('fieldset');
71         $this->formLegend();
72         $this->sessionToken();
73         $this->formData();
74         $this->formActions();
75         $this->out->elementEnd('fieldset');
76         $this->out->elementEnd('form');
77     }
78
79     /**
80      * Include a session token for CSRF protection
81      *
82      * @return void
83      */
84
85     function sessionToken()
86     {
87         $this->out->hidden('token', common_session_token());
88     }
89
90
91     /**
92      * Name of the form
93      *
94      * Sub-classes should overload this with the name of their form.
95      *
96      * @return void
97      */
98
99     function formLegend()
100     {
101     }
102
103
104     /**
105      * Visible or invisible data elements
106      *
107      * Display the form fields that make up the data of the form.
108      * Sub-classes should overload this to show their data.
109      *
110      * @return void
111      */
112
113     function formData()
114     {
115     }
116
117     /**
118      * Buttons for form actions
119      *
120      * Submit and cancel buttons (or whatever)
121      * Sub-classes should overload this to show their own buttons.
122      *
123      * @return void
124      */
125
126     function formActions()
127     {
128     }
129
130     /**
131      * ID of the form
132      *
133      * Should be unique on the page. Sub-classes should overload this
134      * to show their own IDs.
135      *
136      * @return int ID of the form
137      */
138
139     function id()
140     {
141         return null;
142     }
143
144     /**
145      * Action of the form.
146      *
147      * URL to post to. Should be overloaded by subclasses to give
148      * somewhere to post to.
149      *
150      * @return string URL to post to
151      */
152
153     function action()
154     {
155     }
156 }