3 * Laconica, the distributed open-source microblogging tool
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.
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.
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/>.
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/
30 if (!defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/accountsettingsaction.php';
38 class DesignsettingsAction extends AccountSettingsAction
43 * @return string Title of the page
48 return _('Profile design');
52 * Instructions for use
54 * @return instructions for use
57 function getInstructions()
59 return _('Customize the way your profile looks with a background image and a colour palette of your choice.');
63 * Content area of the page
65 * Shows a form for changing the password
70 function showContent()
72 $user = common_current_user();
73 $this->elementStart('form', array('method' => 'POST',
74 'id' => 'form_settings_design',
75 'class' => 'form_settings',
77 common_local_url('designsettings')));
78 $this->elementStart('fieldset');
79 $this->hidden('token', common_session_token());
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'),
87 $this->element('input', array('name' => 'design_background-image_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',
93 'id' => 'MAX_FILE_SIZE',
94 'value' => ImageFile::maxFileSizeInt()));
95 $this->elementEnd('li');
96 $this->elementEnd('ul');
97 $this->elementEnd('fieldset');
99 $this->elementStart('fieldset', array('id' => 'settings_design_color'));
100 $this->element('legend', null, _('Change colours'));
101 $this->elementStart('ul', 'form_data');
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"}}';
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'));
117 $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
120 $labelSwatch = array('Background',
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] ?
131 'id' => 'swatch-'.$s,
135 'value' => $foo[0]));
136 $this->elementEnd('li');
140 $this->elementEnd('ul');
141 $this->elementEnd('fieldset');
143 $this->element('input', array('id' => 'settings_design_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'));
150 /*TODO: Check submitted form values:
151 json_encode(form values)
152 if submitted Swatch == DefaultSwatch, don't store in DB.
155 $this->elementEnd('fieldset');
156 $this->elementEnd('form');
163 * Validate input and save changes. Reload the form with a success
169 function handlePost()
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.'));
181 $user = common_current_user();
182 assert(!is_null($user)); // should already be checked
184 // FIXME: scrub input
186 $newpassword = $this->arg('newpassword');
187 $confirm = $this->arg('confirm');
191 if (strlen($newpassword) < 6) {
192 $this->showForm(_('Password must be 6 or more characters.'));
194 } else if (0 != strcmp($newpassword, $confirm)) {
195 $this->showForm(_('Passwords don\'t match.'));
199 if ($user->password) {
200 $oldpassword = $this->arg('oldpassword');
202 if (!common_check_user($user->nickname, $oldpassword)) {
203 $this->showForm(_('Incorrect old password'));
208 $original = clone($user);
210 $user->password = common_munge_password($newpassword, $user->id);
212 $val = $user->validate();
214 $this->showForm(_('Error saving user; invalid.'));
218 if (!$user->update($original)) {
219 $this->serverError(_('Can\'t save new password.'));
223 $this->showForm(_('Password saved.'), true);
229 * Add the Farbtastic stylesheet
234 function showStylesheets()
236 parent::showStylesheets();
238 common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
240 $this->element('link', array('rel' => 'stylesheet',
241 'type' => 'text/css',
242 'href' => $farbtasticStyle,
243 'media' => 'screen, projection, tv'));
247 * Add the Farbtastic scripts
252 function showScripts()
254 parent::showScripts();
256 $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
257 $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js');
259 $this->element('script', array('type' => 'text/javascript',
260 'src' => $farbtasticPack));
261 $this->element('script', array('type' => 'text/javascript',
262 'src' => $farbtasticGo));