]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/designsettings.php
add design classes
[quix0rs-gnu-social.git] / actions / designsettings.php
1 <?php
2 /**
3  * Laconica, the distributed open-source microblogging tool
4  *
5  * Change user password
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  Settings
23  * @package   Laconica
24  * @author    Sarven Capadisli <csarven@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/accountsettingsaction.php';
35
36 class DesignsettingsAction extends AccountSettingsAction
37 {
38     /**
39      * Title of the page
40      *
41      * @return string Title of the page
42      */
43
44     function title()
45     {
46         return _('Profile design');
47     }
48
49     /**
50      * Instructions for use
51      *
52      * @return instructions for use
53      */
54
55     function getInstructions()
56     {
57         return _('Customize the way your profile looks with a background image and a colour palette of your choice.');
58     }
59
60     /**
61      * Content area of the page
62      *
63      * Shows a form for changing the password
64      *
65      * @return void
66      */
67
68     function showContent()
69     {
70         $user = common_current_user();
71         $this->elementStart('form', array('method' => 'POST',
72                                           'id' => 'form_settings_design',
73                                           'class' => 'form_settings',
74                                           'action' =>
75                                           common_local_url('designsettings')));
76         $this->elementStart('fieldset');
77         $this->hidden('token', common_session_token());
78
79         $this->elementStart('fieldset', array('id' => 'settings_design_background-image'));
80         $this->element('legend', null, _('Change background image'));
81         $this->elementStart('ul', 'form_data');
82         $this->elementStart('li');
83         $this->element('label', array('for' => 'design_ background-image_file'),
84                        _('Upload file'));
85         $this->element('input', array('name' => 'design_background-image_file',
86                                       'type' => 'file',
87                                       'id' => 'design_background-image_file'));
88         $this->element('p', 'form_guide', _('You can upload your personal background image. The maximum file size is 2Mb.'));
89         $this->element('input', array('name' => 'MAX_FILE_SIZE',
90                                       'type' => 'hidden',
91                                       'id' => 'MAX_FILE_SIZE',
92                                       'value' => ImageFile::maxFileSizeInt()));
93         $this->elementEnd('li');
94         $this->elementEnd('ul');
95         $this->elementEnd('fieldset');
96
97         $this->elementStart('fieldset', array('id' => 'settings_design_color'));
98         $this->element('legend', null, _('Change colours'));
99         $this->elementStart('ul', 'form_data');
100
101         //This is a JSON object in the DB field. Here for testing. Remove later.
102         $userSwatch = '{"body":{"background-color":"#F0F2F5"},'.
103           '"#content":{"background-color":"#FFFFFF"},'.
104           '"#aside_primary":{"background-color":"#CEE1E9"},'.
105           '"html body":{"color":"#000000"},'.
106           '"a":{"color":"#002E6E"}}';
107
108         //Default theme swatch -- Where should this be stored?
109         $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'),
110                                '#content' => array('background-color' => '#FFFFFF'),
111                                '#aside_primary' => array('background-color' => '#CEE1E9'),
112                                'html body' => array('color' => '#000000'),
113                                'a' => array('color' => '#002E6E'));
114
115         $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
116
117         $s = 0;
118         $labelSwatch = array('Background',
119                              'Content',
120                              'Sidebar',
121                              'Text',
122                              'Links');
123         foreach($userSwatch as $propertyvalue => $value) {
124             $foo = array_values($value);
125             $this->elementStart('li');
126             $this->element('label', array('for' => 'swatch-'.$s), _($labelSwatch[$s]));
127             $this->element('input', array('name' => 'swatch-'.$s, //prefer swatch[$s] ?
128                                           'type' => 'text',
129                                           'id' => 'swatch-'.$s,
130                                           'class' => 'swatch',
131                                           'maxlength' => '7',
132                                           'size' => '7',
133                                           'value' => $foo[0]));
134             $this->elementEnd('li');
135             $s++;
136         }
137
138         $this->elementEnd('ul');
139         $this->elementEnd('fieldset');
140
141         $this->element('input', array('id' => 'settings_design_reset',
142                                       'type' => 'reset',
143                                       'value' => 'Reset',
144                                       'class' => 'submit form_action-primary',
145                                       'title' => _('Reset back to default')));
146         $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design'));
147
148         /*TODO: Check submitted form values:
149          json_encode(form values)
150          if submitted Swatch == DefaultSwatch, don't store in DB.
151          else store in BD
152          */
153         $this->elementEnd('fieldset');
154         $this->elementEnd('form');
155     }
156
157     /**
158      * Handle a post
159      *
160      * Validate input and save changes. Reload the form with a success
161      * or error message.
162      *
163      * @return void
164      */
165
166     function handlePost()
167     {
168         // TODO: implement this
169         return;
170     }
171
172     /**
173      * Add the Farbtastic stylesheet
174      *
175      * @return void
176      */
177
178     function showStylesheets()
179     {
180         parent::showStylesheets();
181         $farbtasticStyle =
182           common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
183
184         $this->element('link', array('rel' => 'stylesheet',
185                                      'type' => 'text/css',
186                                      'href' => $farbtasticStyle,
187                                      'media' => 'screen, projection, tv'));
188     }
189
190     /**
191      * Add the Farbtastic scripts
192      *
193      * @return void
194      */
195
196     function showScripts()
197     {
198         parent::showScripts();
199
200         $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
201         $farbtasticGo   = common_path('js/farbtastic/farbtastic.go.js');
202
203         $this->element('script', array('type' => 'text/javascript',
204                                        'src' => $farbtasticPack));
205         $this->element('script', array('type' => 'text/javascript',
206                                        'src' => $farbtasticGo));
207     }
208 }