3 * StatusNet, the distributed open-source microblogging tool
5 * Design administration panel
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 Evan Prodromou <evan@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @author Sarven Capadisli <csarven@status.net>
27 * @copyright 2008-2009 StatusNet, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
29 * @link http://status.net/
32 if (!defined('STATUSNET')) {
37 * Administer design settings
41 * @author Evan Prodromou <evan@status.net>
42 * @author Zach Copley <zach@status.net>
43 * @author Sarven Capadisli <csarven@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
48 class DesignadminpanelAction extends AdminPanelAction
51 /* The default site design */
55 * Returns the page title
57 * @return string page title
66 * Instructions for using this form.
68 * @return string instructions
71 function getInstructions()
73 return _('Design settings for this StatusNet site.');
77 * Get the default design and show the design admin panel form
84 $this->design = Design::siteDesign();
85 $form = new DesignAdminPanelForm($this);
91 * Save settings from the form
96 function saveSettings()
98 if ($this->arg('save')) {
99 $this->saveDesignSettings();
100 } else if ($this->arg('defaults')) {
101 $this->restoreDefaults();
103 $this->clientError(_('Unexpected form submission.'));
108 * Save the new design settings
113 function saveDesignSettings()
115 // Workaround for PHP returning empty $_POST and $_FILES when POST
116 // length > post_max_size in php.ini
120 && ($_SERVER['CONTENT_LENGTH'] > 0)
122 $msg = _('The server was unable to handle that much POST ' .
123 'data (%s bytes) due to its current configuration.');
124 $this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
128 // check for an image upload
130 $bgimage = $this->saveBackgroundImage();
132 common_debug("background image: $bgimage");
134 static $settings = array('theme', 'logo');
138 foreach ($settings as $setting) {
139 $values[$setting] = $this->trimmed($setting);
142 $this->validate($values);
144 // assert(all values are valid);
146 $bgcolor = new WebColor($this->trimmed('design_background'));
147 $ccolor = new WebColor($this->trimmed('design_content'));
148 $sbcolor = new WebColor($this->trimmed('design_sidebar'));
149 $tcolor = new WebColor($this->trimmed('design_text'));
150 $lcolor = new WebColor($this->trimmed('design_links'));
152 $onoff = $this->arg('design_background-image_onoff');
157 if ($onoff == 'on') {
163 $tile = $this->boolean('design_background-image_repeat');
165 $config = new Config();
167 $config->query('BEGIN');
169 foreach ($settings as $setting) {
170 Config::save('site', $setting, $values[$setting]);
173 if (isset($bgimage)) {
174 Config::save('design', 'backgroundimage', $bgimage);
177 Config::save('design', 'backgroundcolor', $bgcolor->intValue());
178 Config::save('design', 'contentcolor', $ccolor->intValue());
179 Config::save('design', 'sidebarcolor', $sbcolor->intValue());
180 Config::save('design', 'textcolor', $tcolor->intValue());
181 Config::save('design', 'linkcolor', $lcolor->intValue());
183 // Hack to use Design's bit setter
184 $scratch = new Design();
185 $scratch->setDisposition($on, $off, $tile);
187 Config::save('design', 'disposition', $scratch->disposition);
189 $config->query('COMMIT');
195 * Restore the default design
200 function restoreDefaults()
202 $this->deleteSetting('site', 'logo');
203 $this->deleteSetting('site', 'theme');
206 'theme', 'backgroundimage', 'backgroundcolor', 'contentcolor',
207 'sidebarcolor', 'textcolor', 'linkcolor', 'disposition'
210 foreach ($settings as $setting) {
211 $this->deleteSetting('design', $setting);
214 // XXX: Should we restore the default dir settings, etc.? --Z
218 * Save the background image if the user uploaded one
220 * @return string $filename the filename of the image
223 function saveBackgroundImage()
227 if ($_FILES['design_background-image_file']['error'] ==
234 ImageFile::fromUpload('design_background-image_file');
235 } catch (Exception $e) {
236 $this->clientError('Unable to save background image.');
240 // Note: site design background image has a special filename
242 $filename = Design::filename('site-design-background',
243 image_type_to_extension($imagefile->type),
246 $filepath = Design::path($filename);
248 move_uploaded_file($imagefile->filepath, $filepath);
250 // delete any old backround img laying around
252 if (isset($this->design->backgroundimage)) {
253 @unlink(Design::path($design->backgroundimage));
261 * Attempt to validate setting values
266 function validate(&$values)
268 if (!empty($values['logo']) &&
269 !Validate::uri($values['logo'], array('allowed_schemes' => array('http', 'https')))) {
270 $this->clientError(_("Invalid logo URL."));
273 if (!in_array($values['theme'], Theme::listAvailable())) {
274 $this->clientError(sprintf(_("Theme not available: %s"), $values['theme']));
279 * Add the Farbtastic stylesheet
284 function showStylesheets()
286 parent::showStylesheets();
287 $this->cssLink('css/farbtastic.css','base','screen, projection, tv');
291 * Add the Farbtastic scripts
296 function showScripts()
298 parent::showScripts();
300 $this->script('js/farbtastic/farbtastic.js');
301 $this->script('js/userdesign.go.js');
303 $this->autofocus('design_background-image_file');
308 class DesignAdminPanelForm extends AdminForm
314 * @return int ID of the form
319 return 'form_design_admin_panel';
325 * @return string class of the form
330 return 'form_settings';
334 * HTTP method used to submit the form
336 * For image data we need to send multipart/form-data
337 * so we set that here too
339 * @return string the method to use for submitting
344 $this->enctype = 'multipart/form-data';
352 * @return string URL of the action
357 return common_local_url('designadminpanel');
361 * Data elements of the form
369 $this->out->elementStart('fieldset', array('id' => 'settings_design_logo'));
370 $this->out->element('legend', null, _('Change logo'));
372 $this->out->elementStart('ul', 'form_data');
375 $this->input('logo', _('Site logo'), 'Logo for the site (full URL)');
378 $this->out->elementEnd('ul');
380 $this->out->elementEnd('fieldset');
381 $this->out->elementStart('fieldset', array('id' => 'settings_design_theme'));
382 $this->out->element('legend', null, _('Change theme'));
384 $this->out->elementStart('ul', 'form_data');
386 $themes = Theme::listAvailable();
388 // XXX: listAvailable() can return an empty list if you
389 // screw up your settings, so just in case:
391 if (empty($themes)) {
392 $themes = array('default', 'default');
396 $themes = array_combine($themes, $themes);
399 $this->out->dropdown('theme', _('Site theme'),
400 $themes, _('Theme for the site.'),
401 false, $this->value('theme'));
404 $this->out->elementEnd('ul');
406 $this->out->elementEnd('fieldset');
408 $design = $this->out->design;
410 $this->out->elementStart('fieldset', array('id' =>
411 'settings_design_background-image'));
412 $this->out->element('legend', null, _('Change background image'));
413 $this->out->elementStart('ul', 'form_data');
416 $this->out->element('label', array('for' => 'design_background-image_file'),
418 $this->out->element('input', array('name' => 'design_background-image_file',
420 'id' => 'design_background-image_file'));
421 $this->out->element('p', 'form_guide',
422 sprintf(_('You can upload a background image for the site. ' .
423 'The maximum file size is %1$s.'), ImageFile::maxFileSize()));
424 $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
426 'id' => 'MAX_FILE_SIZE',
427 'value' => ImageFile::maxFileSizeInt()));
430 if (!empty($design->backgroundimage)) {
432 $this->out->elementStart('li', array('id' =>
433 'design_background-image_onoff'));
435 $this->out->element('img', array('src' =>
436 Design::url($design->backgroundimage)));
438 $attrs = array('name' => 'design_background-image_onoff',
440 'id' => 'design_background-image_on',
444 if ($design->disposition & BACKGROUND_ON) {
445 $attrs['checked'] = 'checked';
448 $this->out->element('input', $attrs);
450 $this->out->element('label', array('for' => 'design_background-image_on',
454 $attrs = array('name' => 'design_background-image_onoff',
456 'id' => 'design_background-image_off',
460 if ($design->disposition & BACKGROUND_OFF) {
461 $attrs['checked'] = 'checked';
464 $this->out->element('input', $attrs);
466 $this->out->element('label', array('for' => 'design_background-image_off',
469 $this->out->element('p', 'form_guide', _('Turn background image on or off.'));
473 $this->out->checkbox('design_background-image_repeat',
474 _('Tile background image'),
475 ($design->disposition & BACKGROUND_TILE) ? true : false);
479 $this->out->elementEnd('ul');
480 $this->out->elementEnd('fieldset');
482 $this->out->elementStart('fieldset', array('id' => 'settings_design_color'));
483 $this->out->element('legend', null, _('Change colours'));
485 $this->out->elementStart('ul', 'form_data');
489 $bgcolor = new WebColor($design->backgroundcolor);
492 $this->out->element('label', array('for' => 'swatch-1'), _('Background'));
493 $this->out->element('input', array('name' => 'design_background',
502 $ccolor = new WebColor($design->contentcolor);
505 $this->out->element('label', array('for' => 'swatch-2'), _('Content'));
506 $this->out->element('input', array('name' => 'design_content',
515 $sbcolor = new WebColor($design->sidebarcolor);
518 $this->out->element('label', array('for' => 'swatch-3'), _('Sidebar'));
519 $this->out->element('input', array('name' => 'design_sidebar',
528 $tcolor = new WebColor($design->textcolor);
531 $this->out->element('label', array('for' => 'swatch-4'), _('Text'));
532 $this->out->element('input', array('name' => 'design_text',
541 $lcolor = new WebColor($design->linkcolor);
544 $this->out->element('label', array('for' => 'swatch-5'), _('Links'));
545 $this->out->element('input', array('name' => 'design_links',
554 } catch (WebColorException $e) {
555 common_log(LOG_ERR, 'Bad color values in site design: ' .
559 $this->out->elementEnd('fieldset');
561 $this->out->elementEnd('ul');
570 function formActions()
572 $this->out->submit('defaults', _('Use defaults'), 'submit form_action-default',
573 'defaults', _('Restore default designs'));
575 $this->out->element('input', array('id' => 'settings_design_reset',
578 'class' => 'submit form_action-primary',
579 'title' => _('Reset back to default')));
581 $this->out->submit('save', _('Save'), 'submit form_action-secondary',
582 'save', _('Save design'));