]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/designform.php
Merge remote branch 'gitorious/1.0.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / designform.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Form for choosing a design
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  Form
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('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Form for choosing a design
37  *
38  * Used for choosing a site design, user design, or group design.
39  *
40  * @category Form
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Sarven Capadisli <csarven@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  *
47  */
48
49 class DesignForm extends Form
50 {
51     /**
52      * Return-to args
53      */
54
55     var $design     = null;
56     var $actionurl  = null;
57
58     /**
59      * Constructor
60      *
61      * @param HTMLOutputter $out       output channel
62      * @param Design        $design    initial design
63      * @param Design        $actionurl url of action (for form posting)
64      */
65
66     function __construct($out, $design, $actionurl)
67     {
68         parent::__construct($out);
69
70         $this->design     = $design;
71         $this->actionurl = $actionurl;
72     }
73
74     /**
75      * ID of the form
76      *
77      * @return int ID of the form
78      */
79
80     function id()
81     {
82         return 'design';
83     }
84
85     /**
86      * class of the form
87      *
88      * @return string class of the form
89      */
90
91     function formClass()
92     {
93         return 'form_design';
94     }
95
96     /**
97      * Action of the form
98      *
99      * @return string URL of the action
100      */
101
102     function action()
103     {
104         return $this->actionurl;
105     }
106
107     /**
108      * Legend of the Form
109      *
110      * @return void
111      */
112     function formLegend()
113     {
114         $this->out->element('legend', null, _('Change design'));
115     }
116
117     /**
118      * Data elements of the form
119      *
120      * @return void
121      */
122
123     function formData()
124     {
125         $this->backgroundData();
126
127         $this->out->elementEnd('fieldset');
128
129         $this->out->elementStart('fieldset', array('id' => 'settings_design_color'));
130         $this->out->element('legend', null, _('Change colours'));
131         $this->colourData();
132         $this->out->elementEnd('fieldset');
133
134         $this->out->elementStart('fieldset');
135
136         $this->out->submit('defaults', _('Use defaults'), 'submit form_action-default',
137                            'defaults', _('Restore default designs'));
138
139         $this->out->element('input', array('id' => 'settings_design_reset',
140                                            'type' => 'reset',
141                                            'value' => 'Reset',
142                                            'class' => 'submit form_action-primary',
143                                            'title' => _('Reset back to default')));
144     }
145
146     function backgroundData()
147     {
148         $this->out->elementStart('ul', 'form_data');
149         $this->out->elementStart('li');
150         $this->out->element('label', array('for' => 'design_background-image_file'),
151                             _('Upload file'));
152         $this->out->element('input', array('name' => 'design_background-image_file',
153                                            'type' => 'file',
154                                            'id' => 'design_background-image_file'));
155         $this->out->element('p', 'form_guide', _('You can upload your personal ' .
156                                                  'background image. The maximum file size is 2Mb.'));
157         $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
158                                            'type' => 'hidden',
159                                            'id' => 'MAX_FILE_SIZE',
160                                            'value' => ImageFile::maxFileSizeInt()));
161         $this->out->elementEnd('li');
162
163         if (!empty($this->design->backgroundimage)) {
164
165             $this->out->elementStart('li', array('id' =>
166                                                  'design_background-image_onoff'));
167
168             $this->out->element('img', array('src' =>
169                                              Design::url($this->design->backgroundimage)));
170
171             $attrs = array('name' => 'design_background-image_onoff',
172                            'type' => 'radio',
173                            'id' => 'design_background-image_on',
174                            'class' => 'radio',
175                            'value' => 'on');
176
177             if ($this->design->disposition & BACKGROUND_ON) {
178                 $attrs['checked'] = 'checked';
179             }
180
181             $this->out->element('input', $attrs);
182
183             $this->out->element('label', array('for' => 'design_background-image_on',
184                                                'class' => 'radio'),
185                                 _('On'));
186
187             $attrs = array('name' => 'design_background-image_onoff',
188                            'type' => 'radio',
189                            'id' => 'design_background-image_off',
190                            'class' => 'radio',
191                            'value' => 'off');
192
193             if ($this->design->disposition & BACKGROUND_OFF) {
194                 $attrs['checked'] = 'checked';
195             }
196
197             $this->out->element('input', $attrs);
198
199             $this->out->element('label', array('for' => 'design_background-image_off',
200                                                'class' => 'radio'),
201                                 _('Off'));
202             $this->out->element('p', 'form_guide', _('Turn background image on or off.'));
203             $this->out->elementEnd('li');
204
205             $this->out->elementStart('li');
206             $this->out->checkbox('design_background-image_repeat',
207                                  _('Tile background image'),
208                                  ($this->design->disposition & BACKGROUND_TILE) ? true : false);
209             $this->out->elementEnd('li');
210         }
211
212         $this->out->elementEnd('ul');
213     }
214
215     function colourData()
216     {
217         $this->out->elementStart('ul', 'form_data');
218
219         try {
220
221             $bgcolor = new WebColor($this->design->backgroundcolor);
222
223             $this->out->elementStart('li');
224             $this->out->element('label', array('for' => 'swatch-1'), _('Background'));
225             $this->out->element('input', array('name' => 'design_background',
226                                                'type' => 'text',
227                                                'id' => 'swatch-1',
228                                                'class' => 'swatch',
229                                                'maxlength' => '7',
230                                                'size' => '7',
231                                                'value' => ''));
232             $this->out->elementEnd('li');
233
234             $ccolor = new WebColor($this->design->contentcolor);
235
236             $this->out->elementStart('li');
237             $this->out->element('label', array('for' => 'swatch-2'), _('Content'));
238             $this->out->element('input', array('name' => 'design_content',
239                                                'type' => 'text',
240                                                'id' => 'swatch-2',
241                                                'class' => 'swatch',
242                                                'maxlength' => '7',
243                                                'size' => '7',
244                                                'value' => ''));
245             $this->out->elementEnd('li');
246
247             $sbcolor = new WebColor($this->design->sidebarcolor);
248
249             $this->out->elementStart('li');
250             $this->out->element('label', array('for' => 'swatch-3'), _('Sidebar'));
251             $this->out->element('input', array('name' => 'design_sidebar',
252                                                'type' => 'text',
253                                                'id' => 'swatch-3',
254                                                'class' => 'swatch',
255                                                'maxlength' => '7',
256                                                'size' => '7',
257                                                'value' => ''));
258             $this->out->elementEnd('li');
259
260             $tcolor = new WebColor($this->design->textcolor);
261
262             $this->out->elementStart('li');
263             $this->out->element('label', array('for' => 'swatch-4'), _('Text'));
264             $this->out->element('input', array('name' => 'design_text',
265                                                'type' => 'text',
266                                                'id' => 'swatch-4',
267                                                'class' => 'swatch',
268                                                'maxlength' => '7',
269                                                'size' => '7',
270                                                'value' => ''));
271             $this->out->elementEnd('li');
272
273             $lcolor = new WebColor($this->design->linkcolor);
274
275             $this->out->elementStart('li');
276             $this->out->element('label', array('for' => 'swatch-5'), _('Links'));
277             $this->out->element('input', array('name' => 'design_links',
278                                                'type' => 'text',
279                                                'id' => 'swatch-5',
280                                                'class' => 'swatch',
281                                                'maxlength' => '7',
282                                                'size' => '7',
283                                                'value' => ''));
284             $this->out->elementEnd('li');
285
286         } catch (WebColorException $e) {
287             common_log(LOG_ERR, 'Bad color values in design ID: ' .$this->design->id);
288         }
289
290         $this->out->elementEnd('ul');
291     }
292
293     /**
294      * Action elements
295      *
296      * @return void
297      */
298
299     function formActions()
300     {
301         $this->out->submit('save', _('Save'), 'submit form_action-secondary',
302                            'save', _('Save design'));
303     }
304 }