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 * @author Zach Copley <zach@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!defined('LACONICA')) {
35 require_once INSTALLDIR . '/lib/accountsettingsaction.php';
36 require_once INSTALLDIR . '/lib/webcolor.php';
38 class DesignSettingsAction extends AccountSettingsAction
41 var $submitaction = null;
46 * @return string Title of the page
51 return _('Profile design');
55 * Instructions for use
57 * @return instructions for use
60 function getInstructions()
62 return _('Customize the way your profile looks ' .
63 'with a background image and a colour palette of your choice.');
66 function showDesignForm($design)
69 $this->elementStart('form', array('method' => 'post',
70 'enctype' => 'multipart/form-data',
71 'id' => 'form_settings_design',
72 'class' => 'form_settings',
73 'action' => $this->submitaction));
74 $this->elementStart('fieldset');
75 $this->hidden('token', common_session_token());
77 $this->elementStart('fieldset', array('id' =>
78 'settings_design_background-image'));
79 $this->element('legend', null, _('Change background image'));
80 $this->elementStart('ul', 'form_data');
81 $this->elementStart('li');
82 $this->element('label', array('for' => 'design_background-image_file'),
84 $this->element('input', array('name' => 'design_background-image_file',
86 'id' => 'design_background-image_file'));
87 $this->element('p', 'form_guide', _('You can upload your personal ' .
88 'background image. The maximum file size is 2Mb.'));
89 $this->element('input', array('name' => 'MAX_FILE_SIZE',
91 'id' => 'MAX_FILE_SIZE',
92 'value' => ImageFile::maxFileSizeInt()));
93 $this->elementEnd('li');
95 if (!empty($design->backgroundimage)) {
97 $this->elementStart('li', array('id' => 'design_background-image_onoff'));
99 $this->element('img', array('src' =>
100 Design::url($design->backgroundimage)));
102 $attrs = array('name' => 'design_background-image_onoff',
104 'id' => 'design_background-image_on',
108 if ($design->disposition & BACKGROUND_ON) {
109 $attrs['checked'] = 'checked';
112 $this->element('input', $attrs);
114 $this->element('label', array('for' => 'design_background-image_on',
118 $attrs = array('name' => 'design_background-image_onoff',
120 'id' => 'design_background-image_off',
124 if ($design->disposition & BACKGROUND_OFF) {
125 $attrs['checked'] = 'checked';
128 $this->element('input', $attrs);
130 $this->element('label', array('for' => 'design_background-image_off',
133 $this->element('p', 'form_guide', _('Turn background image on or off.'));
134 $this->elementEnd('li');
136 $this->elementStart('li');
137 $this->checkbox('design_background-image_repeat',
138 _('Tile background image'),
139 ($design->disposition & BACKGROUND_TILE) ? true : false );
140 $this->elementEnd('li');
143 $this->elementEnd('ul');
144 $this->elementEnd('fieldset');
146 $this->elementStart('fieldset', array('id' => 'settings_design_color'));
147 $this->element('legend', null, _('Change colours'));
148 $this->elementStart('ul', 'form_data');
152 $bgcolor = new WebColor($design->backgroundcolor);
154 $this->elementStart('li');
155 $this->element('label', array('for' => 'swatch-1'), _('Background'));
156 $this->element('input', array('name' => 'design_background',
162 'value' => '#' . $bgcolor->hexValue()));
163 $this->elementEnd('li');
165 $ccolor = new WebColor($design->contentcolor);
167 $this->elementStart('li');
168 $this->element('label', array('for' => 'swatch-2'), _('Content'));
169 $this->element('input', array('name' => 'design_content',
175 'value' => '#' . $ccolor->hexValue()));
176 $this->elementEnd('li');
178 $sbcolor = new WebColor($design->sidebarcolor);
180 $this->elementStart('li');
181 $this->element('label', array('for' => 'swatch-3'), _('Sidebar'));
182 $this->element('input', array('name' => 'design_sidebar',
188 'value' => '#' . $sbcolor->hexValue()));
189 $this->elementEnd('li');
191 $tcolor = new WebColor($design->textcolor);
193 $this->elementStart('li');
194 $this->element('label', array('for' => 'swatch-4'), _('Text'));
195 $this->element('input', array('name' => 'design_text',
201 'value' => '#' . $tcolor->hexValue()));
202 $this->elementEnd('li');
204 $lcolor = new WebColor($design->linkcolor);
206 $this->elementStart('li');
207 $this->element('label', array('for' => 'swatch-5'), _('Links'));
208 $this->element('input', array('name' => 'design_links',
214 'value' => '#' . $lcolor->hexValue()));
215 $this->elementEnd('li');
217 } catch (WebColorException $e) {
218 common_log(LOG_ERR, 'Bad color values in design ID: ' .$design->id);
221 $this->elementEnd('ul');
222 $this->elementEnd('fieldset');
224 $this->submit('defaults', _('Use defaults'), 'submit form_action-default',
225 'defaults', _('Restore default designs'));
227 $this->element('input', array('id' => 'settings_design_reset',
230 'class' => 'submit form_action-primary',
231 'title' => _('Reset back to default')));
233 $this->submit('save', _('Save'), 'submit form_action-secondary',
234 'save', _('Save design'));
236 $this->elementEnd('fieldset');
237 $this->elementEnd('form');
243 * Validate input and save changes. Reload the form with a success
249 function handlePost()
251 // XXX: Robin's workaround for a bug in PHP where $_POST
252 // and $_FILE are empty in the case that the uploaded
253 // file is bigger than PHP is configured to handle.
255 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
256 if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
258 $msg = _('The server was unable to handle that much POST ' .
259 'data (%s bytes) due to its current configuration.');
261 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
266 $token = $this->trimmed('token');
267 if (!$token || $token != common_session_token()) {
268 $this->showForm(_('There was a problem with your session token. '.
269 'Try again, please.'));
273 if ($this->arg('save')) {
275 } else if ($this->arg('defaults')) {
276 $this->restoreDefaults();
278 $this->showForm(_('Unexpected form submission.'));
283 * Add the Farbtastic stylesheet
288 function showStylesheets()
290 parent::showStylesheets();
292 common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
294 $this->element('link', array('rel' => 'stylesheet',
295 'type' => 'text/css',
296 'href' => $farbtasticStyle,
297 'media' => 'screen, projection, tv'));
301 * Add the Farbtastic scripts
306 function showScripts()
308 parent::showScripts();
310 $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
311 $userDesignGo = common_path('js/userdesign.go.js');
313 $this->element('script', array('type' => 'text/javascript',
314 'src' => $farbtasticPack));
315 $this->element('script', array('type' => 'text/javascript',
316 'src' => $userDesignGo));
320 * Get a default design
322 * @return Design design
325 function defaultDesign()
327 $defaults = common_config('site', 'design');
329 $design = new Design();
333 $color = new WebColor();
335 $color->parseColor($defaults['backgroundcolor']);
336 $design->backgroundcolor = $color->intValue();
338 $color->parseColor($defaults['contentcolor']);
339 $design->contentcolor = $color->intValue();
341 $color->parseColor($defaults['sidebarcolor']);
342 $design->sidebarcolor = $color->intValue();
344 $color->parseColor($defaults['textcolor']);
345 $design->textcolor = $color->intValue();
347 $color->parseColor($defaults['linkcolor']);
348 $design->linkcolor = $color->intValue();
350 $design->backgroundimage = $defaults['backgroundimage'];
352 $design->disposition = $defaults['disposition'];
354 } catch (WebColorException $e) {
355 common_log(LOG_ERR, _('Bad default color settings: ' .
363 * Save the background image, if any, and set its disposition
368 function saveBackgroundImage($design) {
370 // Now that we have a Design ID we can add a file to the design.
371 // XXX: This is an additional DB hit, but figured having the image
372 // associated with the Design rather than the User was worth
375 if ($_FILES['design_background-image_file']['error'] ==
382 ImageFile::fromUpload('design_background-image_file');
383 } catch (Exception $e) {
384 $this->showForm($e->getMessage());
388 $filename = Design::filename($design->id,
389 image_type_to_extension($imagefile->type),
392 $filepath = Design::path($filename);
394 move_uploaded_file($imagefile->filepath, $filepath);
396 $original = clone($design);
397 $design->backgroundimage = $filename;
399 // default to on, no tile
401 $design->setDisposition(true, false, false);
403 $result = $design->update($original);
405 if ($result === false) {
406 common_log_db_error($design, 'UPDATE', __FILE__);
407 $this->showForm(_('Couldn\'t update your design.'));
414 * Restore the user or group design to system defaults
419 function restoreDefaults()
421 $design = $this->getWorkingDesign();
422 $default = $this->defaultDesign();
423 $original = clone($design);
425 $design->backgroundcolor = $default->backgroundcolor;
426 $design->contentcolor = $default->contentcolor;
427 $design->sidebarcolor = $default->sidebarcolor;
428 $design->textcolor = $default->textcolor;
429 $design->linkcolor = $default->linkcolor;
431 $design->setDisposition(false, true, false);
433 $result = $design->update($original);
435 if ($result === false) {
436 common_log_db_error($design, 'UPDATE', __FILE__);
437 $this->showForm(_('Couldn\'t update your design.'));
441 $this->showForm(_('Design defaults restored.'), true);