]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/form.php
b5547dbcdc5c341d4e803ac85590c2f6f168aaf5
[quix0rs-gnu-social.git] / lib / form.php
1 <?php
2 /**
3  * StatusNet, 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
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  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @author   Sarven Capadisli <csarven@status.net>
47  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48  * @link     http://status.net/
49  *
50  * @see      HTMLOutputter
51  */
52
53 class Form extends Widget
54 {
55     var $enctype = null;
56
57     /**
58      * Show the form
59      *
60      * Uses a recipe to output the form.
61      *
62      * @return void
63      * @see Widget::show()
64      */
65
66     function show()
67     {
68         $attributes = array('id' => $this->id(),
69             'class' => $this->formClass(),
70             'method' => 'post',
71             'action' => $this->action());
72
73         if (!empty($this->enctype)) {
74             $attributes['enctype'] = $this->enctype;
75         }
76         $this->out->elementStart('form', $attributes);
77         $this->out->elementStart('fieldset');
78         $this->formLegend();
79         $this->sessionToken();
80         $this->formData();
81         $this->formActions();
82         $this->out->elementEnd('fieldset');
83         $this->out->elementEnd('form');
84     }
85
86     /**
87      * Include a session token for CSRF protection
88      *
89      * @return void
90      */
91
92     function sessionToken()
93     {
94         $this->out->hidden('token', common_session_token());
95     }
96
97     /**
98      * Name of the form
99      *
100      * Sub-classes should overload this with the name of their form.
101      *
102      * @return void
103      */
104
105     function formLegend()
106     {
107     }
108
109     /**
110      * Visible or invisible data elements
111      *
112      * Display the form fields that make up the data of the form.
113      * Sub-classes should overload this to show their data.
114      *
115      * @return void
116      */
117
118     function formData()
119     {
120     }
121
122     /**
123      * Buttons for form actions
124      *
125      * Submit and cancel buttons (or whatever)
126      * Sub-classes should overload this to show their own buttons.
127      *
128      * @return void
129      */
130
131     function formActions()
132     {
133     }
134
135     /**
136      * ID of the form
137      *
138      * Should be unique on the page. Sub-classes should overload this
139      * to show their own IDs.
140      *
141      * @return int ID of the form
142      */
143
144     function id()
145     {
146         return null;
147     }
148
149     /**
150      * Action of the form.
151      *
152      * URL to post to. Should be overloaded by subclasses to give
153      * somewhere to post to.
154      *
155      * @return string URL to post to
156      */
157
158     function action()
159     {
160     }
161
162     /**
163      * Class of the form.
164      *
165      * @return string the form's class
166      */
167
168     function formClass()
169     {
170         return 'form';
171     }
172 }