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('p', null, _('Upload background image'));
86 $this->elementEnd('li');
87 $this->elementEnd('ul');
88 $this->elementEnd('fieldset');
90 $this->elementStart('fieldset', array('id' => 'settings_design_color'));
91 $this->element('legend', null, _('Change colours'));
92 $this->elementStart('ul', 'form_data');
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"}}';
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'));
108 $userSwatch = ($userSwatch) ? json_decode($userSwatch, true) : $defaultSwatch;
111 $labelSwatch = array('Background color',
112 'Content background color',
113 'Sidebar background 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');
124 $this->elementEnd('ul');
125 $this->elementEnd('fieldset');
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.
133 $this->elementEnd('fieldset');
134 $this->elementEnd('form');
141 * Validate input and save changes. Reload the form with a success
147 function handlePost()
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.'));
159 $user = common_current_user();
160 assert(!is_null($user)); // should already be checked
162 // FIXME: scrub input
164 $newpassword = $this->arg('newpassword');
165 $confirm = $this->arg('confirm');
169 if (strlen($newpassword) < 6) {
170 $this->showForm(_('Password must be 6 or more characters.'));
172 } else if (0 != strcmp($newpassword, $confirm)) {
173 $this->showForm(_('Passwords don\'t match.'));
177 if ($user->password) {
178 $oldpassword = $this->arg('oldpassword');
180 if (!common_check_user($user->nickname, $oldpassword)) {
181 $this->showForm(_('Incorrect old password'));
186 $original = clone($user);
188 $user->password = common_munge_password($newpassword, $user->id);
190 $val = $user->validate();
192 $this->showForm(_('Error saving user; invalid.'));
196 if (!$user->update($original)) {
197 $this->serverError(_('Can\'t save new password.'));
201 $this->showForm(_('Password saved.'), true);
207 * Add the Farbtastic stylesheet
212 function showStylesheets()
214 parent::showStylesheets();
216 common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
218 $this->element('link', array('rel' => 'stylesheet',
219 'type' => 'text/css',
220 'href' => $farbtasticStyle,
221 'media' => 'screen, projection, tv'));
225 * Add the Farbtastic scripts
230 function showScripts()
232 parent::showScripts();
234 $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
235 $farbtasticGo = common_path('js/farbtastic/farbtastic.go.js');
237 $this->element('script', array('type' => 'text/javascript',
238 'src' => $farbtasticPack));
239 $this->element('script', array('type' => 'text/javascript',
240 'src' => $farbtasticGo));