]> 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->element('legend', null, _('Design settings'));
80         $this->hidden('token', common_session_token());
81
82         $this->elementStart('fieldset', array('id' => 'settings_design_background-image'));
83         $this->element('legend', null, _('Change background image'));
84         $this->elementStart('ul', 'form_data');
85         $this->elementStart('li');
86         $this->element('p', null, _('Upload background image'));
87         $this->elementEnd('li');
88         $this->elementEnd('ul');
89         $this->elementEnd('fieldset');
90
91         $this->elementStart('fieldset', array('id' => 'settings_design_color'));
92         $this->element('legend', null, _('Change colours'));
93         $this->elementStart('ul', 'form_data');
94         $this->elementStart('li');
95         $this->input('color-1', _('Background color'), '#F0F2F5', null);
96         $this->elementEnd('li');
97         $this->elementStart('li');
98         $this->input('color-2', _('Content background color'), '#FFFFFF', null);
99         $this->elementEnd('li');
100         $this->elementStart('li');
101         $this->input('color-3', _('Sidebar background color'), '#CEE1E9', null);
102         $this->elementEnd('li');
103         $this->elementStart('li');
104         $this->input('color-4', _('Text color'), '#000000', null);
105         $this->elementEnd('li');
106         $this->elementStart('li');
107         $this->input('color-5', _('Link color'), '#002E6E', null);
108         $this->elementEnd('li');
109         $this->elementEnd('ul');
110         $this->element('div', array('id' => 'color-picker'));
111         $this->elementEnd('fieldset');
112
113
114         $this->submit('save', _('Save'));
115
116         $this->elementEnd('fieldset');
117         $this->elementEnd('form');
118
119     }
120
121     /**
122      * Handle a post
123      *
124      * Validate input and save changes. Reload the form with a success
125      * or error message.
126      *
127      * @return void
128      */
129
130     function handlePost()
131     {
132     /*
133         // CSRF protection
134
135         $token = $this->trimmed('token');
136         if (!$token || $token != common_session_token()) {
137             $this->showForm(_('There was a problem with your session token. '.
138                                'Try again, please.'));
139             return;
140         }
141
142         $user = common_current_user();
143         assert(!is_null($user)); // should already be checked
144
145         // FIXME: scrub input
146
147         $newpassword = $this->arg('newpassword');
148         $confirm     = $this->arg('confirm');
149
150         # Some validation
151
152         if (strlen($newpassword) < 6) {
153             $this->showForm(_('Password must be 6 or more characters.'));
154             return;
155         } else if (0 != strcmp($newpassword, $confirm)) {
156             $this->showForm(_('Passwords don\'t match.'));
157             return;
158         }
159
160         if ($user->password) {
161             $oldpassword = $this->arg('oldpassword');
162
163             if (!common_check_user($user->nickname, $oldpassword)) {
164                 $this->showForm(_('Incorrect old password'));
165                 return;
166             }
167         }
168
169         $original = clone($user);
170
171         $user->password = common_munge_password($newpassword, $user->id);
172
173         $val = $user->validate();
174         if ($val !== true) {
175             $this->showForm(_('Error saving user; invalid.'));
176             return;
177         }
178
179         if (!$user->update($original)) {
180             $this->serverError(_('Can\'t save new password.'));
181             return;
182         }
183
184         $this->showForm(_('Password saved.'), true);
185         */
186     }
187
188
189     /**
190      * Add the jCrop stylesheet
191      *
192      * @return void
193      */
194
195     function showStylesheets()
196     {
197         parent::showStylesheets();
198         $farbtasticStyle =
199           common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
200
201         $this->element('link', array('rel' => 'stylesheet',
202                                      'type' => 'text/css',
203                                      'href' => $farbtasticStyle,
204                                      'media' => 'screen, projection, tv'));
205     }
206
207     /**
208      * Add the jCrop scripts
209      *
210      * @return void
211      */
212
213     function showScripts()
214     {
215         parent::showScripts();
216
217 //        if ($this->mode == 'crop') {
218             $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
219             $farbtasticGo   = common_path('js/farbtastic/farbtastic.go.js');
220
221             $this->element('script', array('type' => 'text/javascript',
222                                            'src' => $farbtasticPack));
223             $this->element('script', array('type' => 'text/javascript',
224                                            'src' => $farbtasticGo));
225 //        }
226     }
227 }