]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/designsettings.php
Merge branch '0.8.x' of git://gitorious.org/laconica/dev 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('p', null, _('Upload background image'));
86         $this->elementEnd('li');
87         $this->elementEnd('ul');
88         $this->elementEnd('fieldset');
89
90         $this->elementStart('fieldset', array('id' => 'settings_design_color'));
91         $this->element('legend', null, _('Change colours'));
92         $this->elementStart('ul', 'form_data');
93
94         //This is a JSON object in the DB field. Here for testing. Remove later.
95         $userSwatch = '{"body":{"background-color":"#F0F2F5"},
96                         "#content":{"background-color":"#FFFFFF"},
97                         "#aside_primary":{"background-color":"#CEE1E9"},
98                         "html body":{"color":"#000000"},
99                         "a":{"color":"#002E6E"}}';
100
101         //Default theme swatch -- Where should this be stored?
102         $defaultSwatch = array('body' => array('background-color' => '#F0F2F5'),
103                                '#content' => array('background-color' => '#FFFFFF'),
104                                '#aside_primary' => array('background-color' => '#CEE1E9'),
105                                'html body' => array('color' => '#000000'),
106                                'a' => array('color' => '#002E6E'));
107
108         $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
109
110         $s = 0;
111         $labelSwatch = array('Background color',
112                              'Content background color',
113                              'Sidebar background color',
114                              'Text color',
115                              'Link color');
116         foreach($userSwatch as $propertyvalue => $value) {
117             $foo = array_values($value); //Is this necessary? $value[0] doesn't work because of invalid key
118             $this->elementStart('li');
119             $this->input("swatch-".$s, $labelSwatch[$s], $foo[0]);
120             $this->elementEnd('li');
121             $s++;
122         }
123
124         $this->elementEnd('ul');
125         $this->elementEnd('fieldset');
126
127         $this->submit('save', _('Save'));
128 /*TODO: Check submitted form values: 
129 json_encode(form values)
130 if submitted Swatch == DefaultSwatch, don't store in DB.
131 else store in BD
132 */
133         $this->elementEnd('fieldset');
134         $this->elementEnd('form');
135
136     }
137
138     /**
139      * Handle a post
140      *
141      * Validate input and save changes. Reload the form with a success
142      * or error message.
143      *
144      * @return void
145      */
146
147     function handlePost()
148     {
149     /*
150         // CSRF protection
151
152         $token = $this->trimmed('token');
153         if (!$token || $token != common_session_token()) {
154             $this->showForm(_('There was a problem with your session token. '.
155                                'Try again, please.'));
156             return;
157         }
158
159         $user = common_current_user();
160         assert(!is_null($user)); // should already be checked
161
162         // FIXME: scrub input
163
164         $newpassword = $this->arg('newpassword');
165         $confirm     = $this->arg('confirm');
166
167         # Some validation
168
169         if (strlen($newpassword) < 6) {
170             $this->showForm(_('Password must be 6 or more characters.'));
171             return;
172         } else if (0 != strcmp($newpassword, $confirm)) {
173             $this->showForm(_('Passwords don\'t match.'));
174             return;
175         }
176
177         if ($user->password) {
178             $oldpassword = $this->arg('oldpassword');
179
180             if (!common_check_user($user->nickname, $oldpassword)) {
181                 $this->showForm(_('Incorrect old password'));
182                 return;
183             }
184         }
185
186         $original = clone($user);
187
188         $user->password = common_munge_password($newpassword, $user->id);
189
190         $val = $user->validate();
191         if ($val !== true) {
192             $this->showForm(_('Error saving user; invalid.'));
193             return;
194         }
195
196         if (!$user->update($original)) {
197             $this->serverError(_('Can\'t save new password.'));
198             return;
199         }
200
201         $this->showForm(_('Password saved.'), true);
202         */
203     }
204
205
206     /**
207      * Add the Farbtastic stylesheet
208      *
209      * @return void
210      */
211
212     function showStylesheets()
213     {
214         parent::showStylesheets();
215         $farbtasticStyle =
216           common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
217
218         $this->element('link', array('rel' => 'stylesheet',
219                                      'type' => 'text/css',
220                                      'href' => $farbtasticStyle,
221                                      'media' => 'screen, projection, tv'));
222     }
223
224     /**
225      * Add the Farbtastic scripts
226      *
227      * @return void
228      */
229
230     function showScripts()
231     {
232         parent::showScripts();
233
234         $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
235         $farbtasticGo   = common_path('js/farbtastic/farbtastic.go.js');
236
237         $this->element('script', array('type' => 'text/javascript',
238                                        'src' => $farbtasticPack));
239         $this->element('script', array('type' => 'text/javascript',
240                                        'src' => $farbtasticGo));
241     }
242 }