]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/designform.php
Merge branch '0.9.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         // TRANS: Fieldset legend on profile design page to change profile page colours.
131         $this->out->element('legend', null, _('Change colours'));
132         $this->colourData();
133         $this->out->elementEnd('fieldset');
134
135         $this->out->elementStart('fieldset');
136
137         // TRANS: Button text on profile design page to immediately reset all colour settings to default.
138         $this->out->submit('defaults', _('Use defaults'), 'submit form_action-default',
139                            // TRANS: Title for button on profile design page to reset all colour settings to default.
140                            'defaults', _('Restore default designs'));
141
142         $this->out->element('input', array('id' => 'settings_design_reset',
143                                            'type' => 'reset',
144                                            // TRANS: Button text on profile design page to reset all colour settings to default without saving.
145                                            'value' => _m('BUTTON', 'Reset'),
146                                            'class' => 'submit form_action-primary',
147                                            // TRANS: Title for button on profile design page to reset all colour settings to default without saving.
148                                            'title' => _('Reset back to default')));
149     }
150
151     function backgroundData()
152     {
153         $this->out->elementStart('ul', 'form_data');
154         $this->out->elementStart('li');
155         $this->out->element('label', array('for' => 'design_background-image_file'),
156                             // TRANS: Label in form on profile design page.
157                             // TRANS: Field contains file name on user's computer that could be that user's custom profile background image.
158                             _('Upload file'));
159         $this->out->element('input', array('name' => 'design_background-image_file',
160                                            'type' => 'file',
161                                            'id' => 'design_background-image_file'));
162         // TRANS: Instructions for form on profile design page.
163         $this->out->element('p', 'form_guide', _('You can upload your personal ' .
164                                                  'background image. The maximum file size is 2Mb.'));
165         $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
166                                            'type' => 'hidden',
167                                            'id' => 'MAX_FILE_SIZE',
168                                            'value' => ImageFile::maxFileSizeInt()));
169         $this->out->elementEnd('li');
170
171         if (!empty($this->design->backgroundimage)) {
172
173             $this->out->elementStart('li', array('id' =>
174                                                  'design_background-image_onoff'));
175
176             $this->out->element('img', array('src' =>
177                                              Design::url($this->design->backgroundimage)));
178
179             $attrs = array('name' => 'design_background-image_onoff',
180                            'type' => 'radio',
181                            'id' => 'design_background-image_on',
182                            'class' => 'radio',
183                            'value' => 'on');
184
185             if ($this->design->disposition & BACKGROUND_ON) {
186                 $attrs['checked'] = 'checked';
187             }
188
189             $this->out->element('input', $attrs);
190
191             $this->out->element('label', array('for' => 'design_background-image_on',
192                                                'class' => 'radio'),
193                                 // TRANS: Radio button on profile design page that will enable use of the uploaded profile image.
194                                 _m('RADIO', 'On'));
195
196             $attrs = array('name' => 'design_background-image_onoff',
197                            'type' => 'radio',
198                            'id' => 'design_background-image_off',
199                            'class' => 'radio',
200                            'value' => 'off');
201
202             if ($this->design->disposition & BACKGROUND_OFF) {
203                 $attrs['checked'] = 'checked';
204             }
205
206             $this->out->element('input', $attrs);
207
208             $this->out->element('label', array('for' => 'design_background-image_off',
209                                                'class' => 'radio'),
210                                 // TRANS: Radio button on profile design page that will disable use of the uploaded profile image.
211                                 _m('RADIO', 'Off'));
212             // TRANS: Form guide for a set of radio buttons on the profile design page that will enable or disable
213             // TRANS: use of the uploaded profile image.
214             $this->out->element('p', 'form_guide', _('Turn background image on or off.'));
215             $this->out->elementEnd('li');
216
217             $this->out->elementStart('li');
218             $this->out->checkbox('design_background-image_repeat',
219                                  // TRANS: Checkbox label on profile design page that will cause the profile image to be tiled.
220                                  _('Tile background image'),
221                                  ($this->design->disposition & BACKGROUND_TILE) ? true : false);
222             $this->out->elementEnd('li');
223         }
224
225         $this->out->elementEnd('ul');
226     }
227
228     function colourData()
229     {
230         $this->out->elementStart('ul', 'form_data');
231
232         try {
233
234             $bgcolor = new WebColor($this->design->backgroundcolor);
235
236             $this->out->elementStart('li');
237             // TRANS: Label on profile design page for setting a profile page background colour.
238             $this->out->element('label', array('for' => 'swatch-1'), _('Background'));
239             $this->out->element('input', array('name' => 'design_background',
240                                                'type' => 'text',
241                                                'id' => 'swatch-1',
242                                                'class' => 'swatch',
243                                                'maxlength' => '7',
244                                                'size' => '7',
245                                                'value' => ''));
246             $this->out->elementEnd('li');
247
248             $ccolor = new WebColor($this->design->contentcolor);
249
250             $this->out->elementStart('li');
251             // TRANS: Label on profile design page for setting a profile page content colour.
252             $this->out->element('label', array('for' => 'swatch-2'), _('Content'));
253             $this->out->element('input', array('name' => 'design_content',
254                                                'type' => 'text',
255                                                'id' => 'swatch-2',
256                                                'class' => 'swatch',
257                                                'maxlength' => '7',
258                                                'size' => '7',
259                                                'value' => ''));
260             $this->out->elementEnd('li');
261
262             $sbcolor = new WebColor($this->design->sidebarcolor);
263
264             $this->out->elementStart('li');
265             // TRANS: Label on profile design page for setting a profile page sidebar colour.
266             $this->out->element('label', array('for' => 'swatch-3'), _('Sidebar'));
267             $this->out->element('input', array('name' => 'design_sidebar',
268                                                'type' => 'text',
269                                                'id' => 'swatch-3',
270                                                'class' => 'swatch',
271                                                'maxlength' => '7',
272                                                'size' => '7',
273                                                'value' => ''));
274             $this->out->elementEnd('li');
275
276             $tcolor = new WebColor($this->design->textcolor);
277
278             $this->out->elementStart('li');
279             // TRANS: Label on profile design page for setting a profile page text colour.
280             $this->out->element('label', array('for' => 'swatch-4'), _('Text'));
281             $this->out->element('input', array('name' => 'design_text',
282                                                'type' => 'text',
283                                                'id' => 'swatch-4',
284                                                'class' => 'swatch',
285                                                'maxlength' => '7',
286                                                'size' => '7',
287                                                'value' => ''));
288             $this->out->elementEnd('li');
289
290             $lcolor = new WebColor($this->design->linkcolor);
291
292             $this->out->elementStart('li');
293             // TRANS: Label on profile design page for setting a profile page links colour.
294             $this->out->element('label', array('for' => 'swatch-5'), _('Links'));
295             $this->out->element('input', array('name' => 'design_links',
296                                                'type' => 'text',
297                                                'id' => 'swatch-5',
298                                                'class' => 'swatch',
299                                                'maxlength' => '7',
300                                                'size' => '7',
301                                                'value' => ''));
302             $this->out->elementEnd('li');
303
304         } catch (WebColorException $e) {
305             common_log(LOG_ERR, 'Bad color values in design ID: ' .$this->design->id);
306         }
307
308         $this->out->elementEnd('ul');
309     }
310
311     /**
312      * Action elements
313      *
314      * @return void
315      */
316
317     function formActions()
318     {
319         // TRANS: Button text on profile design page to save settings.
320         $this->out->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary',
321                            // TRANS: Title for button on profile design page to save settings.
322                            'save', _('Save design'));
323     }
324 }