]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/form.php
Merge branch 'master' of /var/www/trunk 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                                        '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     /**
93      * Name of the form
94      *
95      * Sub-classes should overload this with the name of their form.
96      *
97      * @return void
98      */
99
100     function formLegend()
101     {
102     }
103
104
105     /**
106      * Visible or invisible data elements
107      *
108      * Display the form fields that make up the data of the form.
109      * Sub-classes should overload this to show their data.
110      *
111      * @return void
112      */
113
114     function formData()
115     {
116     }
117
118     /**
119      * Buttons for form actions
120      *
121      * Submit and cancel buttons (or whatever)
122      * Sub-classes should overload this to show their own buttons.
123      *
124      * @return void
125      */
126
127     function formActions()
128     {
129     }
130
131     /**
132      * ID of the form
133      *
134      * Should be unique on the page. Sub-classes should overload this
135      * to show their own IDs.
136      *
137      * @return int ID of the form
138      */
139
140     function id()
141     {
142         return null;
143     }
144
145     /**
146      * Action of the form.
147      *
148      * URL to post to. Should be overloaded by subclasses to give
149      * somewhere to post to.
150      *
151      * @return string URL to post to
152      */
153
154     function action()
155     {
156     }
157     
158     /**
159      * Class of the form.
160      *
161      * @return string the form's class
162      */
163
164     function formClass()
165     {
166         return 'form';
167     }
168 }