X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fdesignadminpanel.php;h=321a8ee5ebcfad1dcb65e52b59acbaa915851944;hb=1543af748c7fe4be28348dfbfcdbde226c05ae29;hp=156c3f1ab505a2bb919caeeb8c9d02e744545f1c;hpb=6165c9601d8f4def5a31f075fdab73eb4086c07b;p=quix0rs-gnu-social.git diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php index 156c3f1ab5..321a8ee5eb 100644 --- a/actions/designadminpanel.php +++ b/actions/designadminpanel.php @@ -59,6 +59,7 @@ class DesignadminpanelAction extends AdminPanelAction function title() { + // TRANS: Message used as title for design settings for the site. return _('Design'); } @@ -70,7 +71,7 @@ class DesignadminpanelAction extends AdminPanelAction function getInstructions() { - return _('Design settings for this StatusNet site.'); + return _('Design settings for this StatusNet site'); } /** @@ -119,40 +120,72 @@ class DesignadminpanelAction extends AdminPanelAction && empty($_POST) && ($_SERVER['CONTENT_LENGTH'] > 0) ) { - $msg = _('The server was unable to handle that much POST ' . - 'data (%s bytes) due to its current configuration.'); + // TRANS: Client error displayed when the number of bytes in a POST request exceeds a limit. + // TRANS: %s is the number of bytes of the CONTENT_LENGTH. + $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', + 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', + intval($_SERVER['CONTENT_LENGTH'])); $this->clientException(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); return; } - // check for an image upload + // check for file uploads $bgimage = $this->saveBackgroundImage(); + $customTheme = $this->saveCustomTheme(); - static $settings = array( - 'site' => array('theme', 'logo'), - 'theme' => array('server', 'dir', 'path'), - 'avatar' => array('server', 'dir', 'path'), - 'background' => array('server', 'dir', 'path') - ); + $oldtheme = common_config('site', 'theme'); + if ($customTheme) { + // This feels pretty hacky :D + $this->args['theme'] = $customTheme; + $themeChanged = true; + } else { + $themeChanged = ($this->trimmed('theme') != $oldtheme); + } + + static $settings = array('theme', 'logo', 'ssllogo'); $values = array(); - foreach ($settings as $section => $parts) { - foreach ($parts as $setting) { - $values[$section][$setting] = $this->trimmed("$section-$setting"); - } + foreach ($settings as $setting) { + $values[$setting] = $this->trimmed($setting); } $this->validate($values); - // assert(all values are valid); + $config = new Config(); + + $config->query('BEGIN'); + + if ($themeChanged) { + // If the theme has changed, reset custom colors and let them pick + // up the new theme's defaults. + $colors = array('background', 'content', 'sidebar', 'text', 'link'); + foreach ($colors as $colorKey) { + // Clear from global config so we see defaults on this page... + $GLOBALS['config']['design'][$colorKey . 'color'] = false; - $bgcolor = new WebColor($this->trimmed('design_background')); - $ccolor = new WebColor($this->trimmed('design_content')); - $sbcolor = new WebColor($this->trimmed('design_sidebar')); - $tcolor = new WebColor($this->trimmed('design_text')); - $lcolor = new WebColor($this->trimmed('design_links')); + // And remove old settings from DB... + $this->deleteSetting('design', $colorKey . 'color'); + } + } else { + // Only save colors from the form if the theme has not changed. + // + // @fixme a future more ajaxy form should allow theme switch + // and color customization in one step. + + $bgcolor = new WebColor($this->trimmed('design_background')); + $ccolor = new WebColor($this->trimmed('design_content')); + $sbcolor = new WebColor($this->trimmed('design_sidebar')); + $tcolor = new WebColor($this->trimmed('design_text')); + $lcolor = new WebColor($this->trimmed('design_links')); + + Config::save('design', 'backgroundcolor', $bgcolor->intValue()); + Config::save('design', 'contentcolor', $ccolor->intValue()); + Config::save('design', 'sidebarcolor', $sbcolor->intValue()); + Config::save('design', 'textcolor', $tcolor->intValue()); + Config::save('design', 'linkcolor', $lcolor->intValue()); + } $onoff = $this->arg('design_background-image_onoff'); @@ -167,35 +200,28 @@ class DesignadminpanelAction extends AdminPanelAction $tile = $this->boolean('design_background-image_repeat'); - $config = new Config(); + // Hack to use Design's bit setter + $scratch = new Design(); + $scratch->setDisposition($on, $off, $tile); - $config->query('BEGIN'); + Config::save('design', 'disposition', $scratch->disposition); - foreach ($settings as $section => $parts) { - foreach ($parts as $setting) { - Config::save($section, $setting, $values[$section][$setting]); - } + foreach ($settings as $setting) { + Config::save('site', $setting, $values[$setting]); } if (isset($bgimage)) { Config::save('design', 'backgroundimage', $bgimage); } - Config::save('design', 'backgroundcolor', $bgcolor->intValue()); - Config::save('design', 'contentcolor', $ccolor->intValue()); - Config::save('design', 'sidebarcolor', $sbcolor->intValue()); - Config::save('design', 'textcolor', $tcolor->intValue()); - Config::save('design', 'linkcolor', $lcolor->intValue()); - - // Hack to use Design's bit setter - $scratch = new Design(); - $scratch->setDisposition($on, $off, $tile); - - Config::save('design', 'disposition', $scratch->disposition); + if (common_config('custom_css', 'enabled')) { + $css = $this->arg('css'); + if ($css != common_config('custom_css', 'css')) { + Config::save('custom_css', 'css', $css); + } + } $config->query('COMMIT'); - - return; } /** @@ -207,6 +233,7 @@ class DesignadminpanelAction extends AdminPanelAction function restoreDefaults() { $this->deleteSetting('site', 'logo'); + $this->deleteSetting('site', 'ssllogo'); $this->deleteSetting('site', 'theme'); $settings = array( @@ -219,6 +246,10 @@ class DesignadminpanelAction extends AdminPanelAction } // XXX: Should we restore the default dir settings, etc.? --Z + + // XXX: I can't get it to show the new settings without forcing + // this terrible reload -- FIX ME! + common_redirect(common_local_url('designadminpanel'), 303); } /** @@ -230,8 +261,8 @@ class DesignadminpanelAction extends AdminPanelAction function saveBackgroundImage() { $filename = null; - - if ($_FILES['design_background-image_file']['error'] == + if (isset($_FILES['design_background-image_file']['error']) && + $_FILES['design_background-image_file']['error'] == UPLOAD_ERR_OK) { $filepath = null; @@ -265,55 +296,52 @@ class DesignadminpanelAction extends AdminPanelAction } /** - * Attempt to validate setting values + * Save the custom theme if the user uploaded one. * - * @return void + * @return mixed custom theme name, if succesful, or null if no theme upload. + * @throws ClientException for invalid theme archives + * @throws ServerException if trouble saving the theme files */ - function validate(&$values) + function saveCustomTheme() { + if (common_config('theme_upload', 'enabled') && + $_FILES['design_upload_theme']['error'] == UPLOAD_ERR_OK) { - if (!empty($values['site']['logo']) && - !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) { - $this->clientError(_("Invalid logo URL.")); - } - - if (!in_array($values['site']['theme'], Theme::listAvailable())) { - $this->clientError(sprintf(_("Theme not available: %s"), $values['site']['theme'])); + $upload = ThemeUploader::fromUpload('design_upload_theme'); + $basedir = common_config('local', 'dir'); + if (empty($basedir)) { + $basedir = INSTALLDIR . '/local'; + } + $name = 'custom'; // @todo allow multiples, custom naming? + $outdir = $basedir . '/theme/' . $name; + $upload->extract($outdir); + return $name; + } else { + return null; } + } - // Make sure the directories are there - - if (!empty($values['theme']['dir']) && !is_readable($values['theme']['dir'])) { - $this->clientError(sprintf(_("Theme directory not readable: %s"), $values['theme']['dir'])); - } + /** + * Attempt to validate setting values + * + * @return void + */ - if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) { - $this->clientError(sprintf(_("Avatar directory not writable: %s"), $values['avatar']['dir'])); + function validate(&$values) + { + if (!empty($values['logo']) && + !Validate::uri($values['logo'], array('allowed_schemes' => array('http', 'https')))) { + $this->clientError(_('Invalid logo URL.')); } - if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) { - $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir'])); + if (!empty($values['ssllogo']) && + !Validate::uri($values['ssllogo'], array('allowed_schemes' => array('https')))) { + $this->clientError(_('Invalid SSL logo URL.')); } - // Do we need to do anything else but validate the - // other fields for length? Design settings are - // validated elsewhere --Z - - static $settings = array( - 'theme' => array('server', 'path'), - 'avatar' => array('server', 'path'), - 'background' => array('server', 'path') - ); - - foreach ($settings as $section => $parts) { - foreach ($parts as $setting) { - if (mb_strlen($values[$section][$setting]) > 255) { - $this->clientError(sprintf(_("Max length for %s %s is 255 characters."), - $section, $setting)); - return; - } - } + if (!in_array($values['theme'], Theme::listAvailable())) { + $this->clientError(sprintf(_("Theme not available: %s."), $values['theme'])); } } @@ -326,7 +354,7 @@ class DesignadminpanelAction extends AdminPanelAction function showStylesheets() { parent::showStylesheets(); - $this->cssLink('css/farbtastic.css','base','screen, projection, tv'); + $this->cssLink('js/farbtastic/farbtastic.css',null,'screen, projection, tv'); } /** @@ -339,8 +367,8 @@ class DesignadminpanelAction extends AdminPanelAction { parent::showScripts(); - $this->script('js/farbtastic/farbtastic.js'); - $this->script('js/userdesign.go.js'); + $this->script('farbtastic/farbtastic.js'); + $this->script('userdesign.go.js'); $this->autofocus('design_background-image_file'); } @@ -407,20 +435,37 @@ class DesignAdminPanelForm extends AdminForm function formData() { + $this->showLogo(); + $this->showTheme(); + $this->showBackground(); + $this->showColors(); + $this->showAdvanced(); + } - $this->out->elementStart('fieldset', array('id' => 'settings_logo')); + function showLogo() + { + $this->out->elementStart('fieldset', array('id' => 'settings_design_logo')); $this->out->element('legend', null, _('Change logo')); $this->out->elementStart('ul', 'form_data'); $this->li(); - $this->input('logo', _('Site logo'), 'Logo for the site (full URL)', 'site'); + $this->input('logo', _('Site logo'), 'Logo for the site (full URL)'); + $this->unli(); + + $this->li(); + $this->input('ssllogo', _('SSL logo'), 'Logo to show on SSL pages'); $this->unli(); $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); - $this->out->elementStart('fieldset', array('id' => 'settings_theme')); + + } + + function showTheme() + { + $this->out->elementStart('fieldset', array('id' => 'settings_design_theme')); $this->out->element('legend', null, _('Change theme')); $this->out->elementStart('ul', 'form_data'); @@ -438,47 +483,28 @@ class DesignAdminPanelForm extends AdminForm $themes = array_combine($themes, $themes); $this->li(); - $this->out->dropdown('site-theme', _('Site theme'), + $this->out->dropdown('theme', _('Site theme'), $themes, _('Theme for the site.'), - false, $this->value('theme', 'site')); - $this->unli(); - - $this->li(); - $this->input('server', _('Theme server'), 'Server for themes', 'theme'); - $this->unli(); - - $this->li(); - $this->input('path', _('Theme path'), 'Web path to themes', 'theme'); + false, $this->value('theme')); $this->unli(); - $this->li(); - $this->input('dir', _('Theme directory'), 'Directory where themes are located', 'theme'); - $this->unli(); - - $this->out->elementEnd('ul'); - - $this->out->elementEnd('fieldset'); - $this->out->elementStart('fieldset', array('id' => 'settings_avatar')); - $this->out->element('legend', null, _('Avatar Settings')); - - $this->out->elementStart('ul', 'form_data'); - - $this->li(); - $this->input('server', _('Avatar server'), 'Server for avatars', 'avatar'); - $this->unli(); - - $this->li(); - $this->input('path', _('Avatar path'), 'Web path to avatars', 'avatar'); - $this->unli(); - - $this->li(); - $this->input('dir', _('Avatar directory'), 'Directory where avatars are located', 'avatar'); - $this->unli(); + if (common_config('theme_upload', 'enabled')) { + $this->li(); + $this->out->element('label', array('for' => 'design_upload_theme'), _('Custom theme')); + $this->out->element('input', array('id' => 'design_upload_theme', + 'name' => 'design_upload_theme', + 'type' => 'file')); + $this->out->element('p', 'form_guide', _('You can upload a custom StatusNet theme as a .ZIP archive.')); + $this->unli(); + } $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); + } + function showBackground() + { $design = $this->out->design; $this->out->elementStart('fieldset', array('id' => @@ -523,6 +549,7 @@ class DesignAdminPanelForm extends AdminForm $this->out->element('label', array('for' => 'design_background-image_on', 'class' => 'radio'), + // TRANS: Used as radio button label to add a background image. _('On')); $attrs = array('name' => 'design_background-image_onoff', @@ -539,6 +566,7 @@ class DesignAdminPanelForm extends AdminForm $this->out->element('label', array('for' => 'design_background-image_off', 'class' => 'radio'), + // TRANS: Used as radio button label to not add a background image. _('Off')); $this->out->element('p', 'form_guide', _('Turn background image on or off.')); $this->unli(); @@ -550,20 +578,13 @@ class DesignAdminPanelForm extends AdminForm $this->unli(); } - $this->li(); - $this->input('server', _('Background server'), 'Server for backgrounds', 'background'); - $this->unli(); - - $this->li(); - $this->input('path', _('Background path'), 'Web path to backgrounds', 'background'); - $this->unli(); - - $this->li(); - $this->input('dir', _('Background directory'), 'Directory where backgrounds are located', 'background'); - $this->unli(); - $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); + } + + function showColors() + { + $design = $this->out->design; $this->out->elementStart('fieldset', array('id' => 'settings_design_color')); $this->out->element('legend', null, _('Change colours')); @@ -571,6 +592,7 @@ class DesignAdminPanelForm extends AdminForm $this->out->elementStart('ul', 'form_data'); try { + // @fixme avoid loop unrolling in non-performance-critical contexts like this $bgcolor = new WebColor($design->backgroundcolor); @@ -638,6 +660,7 @@ class DesignAdminPanelForm extends AdminForm $this->unli(); } catch (WebColorException $e) { + // @fixme normalize them individually! common_log(LOG_ERR, 'Bad color values in site design: ' . $e->getMessage()); } @@ -647,6 +670,27 @@ class DesignAdminPanelForm extends AdminForm $this->out->elementEnd('ul'); } + function showAdvanced() + { + if (common_config('custom_css', 'enabled')) { + $this->out->elementStart('fieldset', array('id' => 'settings_design_advanced')); + $this->out->element('legend', null, _('Advanced')); + $this->out->elementStart('ul', 'form_data'); + + $this->li(); + $this->out->element('label', array('for' => 'css'), _('Custom CSS')); + $this->out->element('textarea', array('name' => 'css', + 'id' => 'css', + 'cols' => '50', + 'rows' => '10'), + strval(common_config('custom_css', 'css'))); + $this->unli(); + + $this->out->elementEnd('fieldset'); + $this->out->elementEnd('ul'); + } + } + /** * Action elements * @@ -668,24 +712,4 @@ class DesignAdminPanelForm extends AdminForm 'save', _('Save design')); } - - /** - * Utility to simplify some of the duplicated code around - * params and settings. Overriding the input() in the base class - * to handle a whole bunch of cases of settings with the same - * name under different sections. - * - * @param string $setting Name of the setting - * @param string $title Title to use for the input - * @param string $instructions Instructions for this field - * @param string $section config section, default = 'site' - * - * @return void - */ - - function input($setting, $title, $instructions, $section='site') - { - $this->out->input("$section-$setting", $title, $this->value($setting, $section), $instructions); - } - }