]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/form.php
Merge branch 'master' of /var/www/mublog
[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                                        'class' => $this->formClass(),
69                                        'method' => 'post',
70                                        'action' => $this->action()));
71         $this->out->elementStart('fieldset');
72         $this->formLegend();
73         $this->sessionToken();
74         $this->formData();
75         $this->formActions();
76         $this->out->elementEnd('fieldset');
77         $this->out->elementEnd('form');
78     }
79
80     /**
81      * Include a session token for CSRF protection
82      *
83      * @return void
84      */
85
86     function sessionToken()
87     {
88         $this->out->hidden('token', common_session_token());
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      * Visible or invisible data elements
105      *
106      * Display the form fields that make up the data of the form.
107      * Sub-classes should overload this to show their data.
108      *
109      * @return void
110      */
111
112     function formData()
113     {
114     }
115
116     /**
117      * Buttons for form actions
118      *
119      * Submit and cancel buttons (or whatever)
120      * Sub-classes should overload this to show their own buttons.
121      *
122      * @return void
123      */
124
125     function formActions()
126     {
127     }
128
129     /**
130      * ID of the form
131      *
132      * Should be unique on the page. Sub-classes should overload this
133      * to show their own IDs.
134      *
135      * @return int ID of the form
136      */
137
138     function id()
139     {
140         return null;
141     }
142
143     /**
144      * Action of the form.
145      *
146      * URL to post to. Should be overloaded by subclasses to give
147      * somewhere to post to.
148      *
149      * @return string URL to post to
150      */
151
152     function action()
153     {
154     }
155
156     /**
157      * Class of the form.
158      *
159      * @return string the form's class
160      */
161
162     function formClass()
163     {
164         return 'form';
165     }
166 }