]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/designsettings.php
Merge branch '0.7.x' into 0.8.x
[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
37
38 class DesignsettingsAction extends AccountSettingsAction
39 {
40     /**
41      * Title of the page
42      *
43      * @return string Title of the page
44      */
45
46     function title()
47     {
48         return _('Profile design');
49     }
50
51     /**
52      * Instructions for use
53      *
54      * @return instructions for use
55      */
56
57     function getInstructions()
58     {
59         return _('Customize the way your profile looks with a background image and a colour palette of your choice.');
60     }
61
62     /**
63      * Content area of the page
64      *
65      * Shows a form for changing the password
66      *
67      * @return void
68      */
69
70     function showContent()
71     {
72         $user = common_current_user();
73         $this->elementStart('form', array('method' => 'POST',
74                                           'id' => 'form_settings_design',
75                                           'class' => 'form_settings',
76                                           'action' =>
77                                           common_local_url('designsettings')));
78         $this->elementStart('fieldset');
79         $this->hidden('token', common_session_token());
80
81         $this->elementStart('fieldset', array('id' => 'settings_design_background-image'));
82         $this->element('legend', null, _('Change background image'));
83         $this->elementStart('ul', 'form_data');
84         $this->elementStart('li');
85         $this->element('label', array('for' => 'design_ background-image_file'), 
86                                 _('Upload file'));
87         $this->element('input', array('name' => 'design_background-image_file',
88                                       'type' => 'file',
89                                       'id' => 'design_background-image_file'));
90         $this->element('p', 'form_guide', _('You can upload your personal background image. The maximum file size is 2Mb.'));
91         $this->element('input', array('name' => 'MAX_FILE_SIZE',
92                                       'type' => 'hidden',
93                                       'id' => 'MAX_FILE_SIZE',
94                                       'value' => ImageFile::maxFileSizeInt()));
95         $this->elementEnd('li');
96         $this->elementEnd('ul');
97         $this->elementEnd('fieldset');
98
99         $this->elementStart('fieldset', array('id' => 'settings_design_color'));
100         $this->element('legend', null, _('Change colours'));
101         $this->elementStart('ul', 'form_data');
102
103         //This is a JSON object in the DB field. Here for testing. Remove later.
104         $userSwatch = '{"body":{"background-color":"#F0F2F5"},
105                         "#content":{"background-color":"#FFFFFF"},
106                         "#aside_primary":{"background-color":"#CEE1E9"},
107                         "html body":{"color":"#000000"},
108                         "a":{"color":"#002E6E"}}';
109
110         //Default theme swatch -- Where should this be stored?
111         $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'),
112                                '#content' => array('background-color' => '#FFFFFF'),
113                                '#aside_primary' => array('background-color' => '#CEE1E9'),
114                                'html body' => array('color' => '#000000'),
115                                'a' => array('color' => '#002E6E'));
116
117         $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
118
119         $s = 0;
120         $labelSwatch = array('Background',
121                              'Content',
122                              'Sidebar',
123                              'Text',
124                              'Links');
125         foreach($userSwatch as $propertyvalue => $value) {
126             $foo = array_values($value);
127             $this->elementStart('li');
128             $this->element('label', array('for' => 'swatch-'.$s), _($labelSwatch[$s]));
129             $this->element('input', array('name' => 'swatch-'.$s, //prefer swatch[$s] ?
130                                           'type' => 'text',
131                                           'id' => 'swatch-'.$s,
132                                           'class' => 'swatch',
133                                           'maxlength' => '7',
134                                           'size' => '7',
135                                           'value' => $foo[0]));
136             $this->elementEnd('li');
137             $s++;
138         }
139
140         $this->elementEnd('ul');
141         $this->elementEnd('fieldset');
142
143         $this->element('input', array('id' => 'settings_design_reset',
144                                       'type' => 'reset',
145                                       'value' => 'Reset',
146                                       'class' => 'submit form_action-primary',
147                                       'title' => _('Reset back to default')));
148         $this->submit('save', _('Save'), 'submit form_action-secondary', 'save', _('Save design'));
149
150 /*TODO: Check submitted form values: 
151 json_encode(form values)
152 if submitted Swatch == DefaultSwatch, don't store in DB.
153 else store in BD
154 */
155         $this->elementEnd('fieldset');
156         $this->elementEnd('form');
157
158     }
159
160     /**
161      * Handle a post
162      *
163      * Validate input and save changes. Reload the form with a success
164      * or error message.
165      *
166      * @return void
167      */
168
169     function handlePost()
170     {
171     /*
172         // CSRF protection
173
174         $token = $this->trimmed('token');
175         if (!$token || $token != common_session_token()) {
176             $this->showForm(_('There was a problem with your session token. '.
177                                'Try again, please.'));
178             return;
179         }
180
181         $user = common_current_user();
182         assert(!is_null($user)); // should already be checked
183
184         // FIXME: scrub input
185
186         $newpassword = $this->arg('newpassword');
187         $confirm     = $this->arg('confirm');
188
189         # Some validation
190
191         if (strlen($newpassword) < 6) {
192             $this->showForm(_('Password must be 6 or more characters.'));
193             return;
194         } else if (0 != strcmp($newpassword, $confirm)) {
195             $this->showForm(_('Passwords don\'t match.'));
196             return;
197         }
198
199         if ($user->password) {
200             $oldpassword = $this->arg('oldpassword');
201
202             if (!common_check_user($user->nickname, $oldpassword)) {
203                 $this->showForm(_('Incorrect old password'));
204                 return;
205             }
206         }
207
208         $original = clone($user);
209
210         $user->password = common_munge_password($newpassword, $user->id);
211
212         $val = $user->validate();
213         if ($val !== true) {
214             $this->showForm(_('Error saving user; invalid.'));
215             return;
216         }
217
218         if (!$user->update($original)) {
219             $this->serverError(_('Can\'t save new password.'));
220             return;
221         }
222
223         $this->showForm(_('Password saved.'), true);
224         */
225     }
226
227
228     /**
229      * Add the Farbtastic stylesheet
230      *
231      * @return void
232      */
233
234     function showStylesheets()
235     {
236         parent::showStylesheets();
237         $farbtasticStyle =
238           common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
239
240         $this->element('link', array('rel' => 'stylesheet',
241                                      'type' => 'text/css',
242                                      'href' => $farbtasticStyle,
243                                      'media' => 'screen, projection, tv'));
244     }
245
246     /**
247      * Add the Farbtastic scripts
248      *
249      * @return void
250      */
251
252     function showScripts()
253     {
254         parent::showScripts();
255
256         $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
257         $farbtasticGo   = common_path('js/farbtastic/farbtastic.go.js');
258
259         $this->element('script', array('type' => 'text/javascript',
260                                        'src' => $farbtasticPack));
261         $this->element('script', array('type' => 'text/javascript',
262                                        'src' => $farbtasticGo));
263     }
264 }