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');
137 $this->elementStart('li');
138 $this->checkbox('design_background-image_repeat',
139 _('Tile background image'),
140 ($design->disposition & BACKGROUND_TILE) ? true : false );
141 $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()));
216 $this->elementEnd('li');
218 } catch (WebColorException $e) {
219 common_log(LOG_ERR, 'Bad color values in design ID: ' .
223 $this->elementEnd('ul');
224 $this->elementEnd('fieldset');
226 $this->element('input', array('id' => 'settings_design_reset',
229 'class' => 'submit form_action-primary',
230 'title' => _('Reset back to default')));
232 $this->submit('save', _('Save'), 'submit form_action-secondary',
233 'save', _('Save design'));
235 $this->elementEnd('fieldset');
236 $this->elementEnd('form');
242 * Validate input and save changes. Reload the form with a success
248 function handlePost()
250 // XXX: Robin's workaround for a bug in PHP where $_POST
251 // and $_FILE are empty in the case that the uploaded
252 // file is bigger than PHP is configured to handle.
254 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
255 if (empty($_POST) && $_SERVER['CONTENT_LENGTH']) {
257 $msg = _('The server was unable to handle that much POST ' .
258 'data (%s bytes) due to its current configuration.');
260 $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
265 $token = $this->trimmed('token');
266 if (!$token || $token != common_session_token()) {
267 $this->showForm(_('There was a problem with your session token. '.
268 'Try again, please.'));
272 if ($this->arg('save')) {
274 } else if ($this->arg('reset')) {
275 $this->resetDesign();
277 $this->showForm(_('Unexpected form submission.'));
282 * Add the Farbtastic stylesheet
287 function showStylesheets()
289 parent::showStylesheets();
291 common_path('theme/base/css/farbtastic.css?version='.LACONICA_VERSION);
293 $this->element('link', array('rel' => 'stylesheet',
294 'type' => 'text/css',
295 'href' => $farbtasticStyle,
296 'media' => 'screen, projection, tv'));
300 * Add the Farbtastic scripts
305 function showScripts()
307 parent::showScripts();
309 $farbtasticPack = common_path('js/farbtastic/farbtastic.js');
310 $userDesignGo = common_path('js/userdesign.go.js');
312 $this->element('script', array('type' => 'text/javascript',
313 'src' => $farbtasticPack));
314 $this->element('script', array('type' => 'text/javascript',
315 'src' => $userDesignGo));
319 * Get a default user design
321 * @return Design design
324 function defaultDesign()
326 $defaults = common_config('site', 'design');
328 $design = new Design();
332 $color = new WebColor();
334 $color->parseColor($defaults['backgroundcolor']);
335 $design->backgroundcolor = $color->intValue();
337 $color->parseColor($defaults['contentcolor']);
338 $design->contentcolor = $color->intValue();
340 $color->parseColor($defaults['sidebarcolor']);
341 $design->sidebarcolor = $color->intValue();
343 $color->parseColor($defaults['textcolor']);
344 $design->textcolor = $color->intValue();
346 $color->parseColor($defaults['linkcolor']);
347 $design->linkcolor = $color->intValue();
349 $design->backgroundimage = $defaults['backgroundimage'];
351 $design->disposition = $defaults['disposition'];
353 } catch (WebColorException $e) {
354 common_log(LOG_ERR, _('Bad default color settings: ' .
361 function saveBackgroundImage($design) {
363 // Now that we have a Design ID we can add a file to the design.
364 // XXX: This is an additional DB hit, but figured having the image
365 // associated with the Design rather than the User was worth
368 if ($_FILES['design_background-image_file']['error'] ==
375 ImageFile::fromUpload('design_background-image_file');
376 } catch (Exception $e) {
377 $this->showForm($e->getMessage());
381 $filename = Design::filename($design->id,
382 image_type_to_extension($imagefile->type),
385 $filepath = Design::path($filename);
387 move_uploaded_file($imagefile->filepath, $filepath);
389 $original = clone($design);
390 $design->backgroundimage = $filename;
391 $design->setDisposition(true, false, false);
392 $result = $design->update($original);
394 if ($result === false) {
395 common_log_db_error($design, 'UPDATE', __FILE__);
396 $this->showForm(_('Couldn\'t update your design.'));