X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fdesignadminpanel.php;h=30e8bde1a4e5d344ffa221a770183720cbfda204;hb=d5f86f7a8a113991f050425e411287da4f738ca2;hp=7c71c032aeea7a76336e00e2d0cf6fa437eda73d;hpb=4d589e4c2d5c815fb798a6642f4d676b9fda8f7b;p=quix0rs-gnu-social.git diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php index 7c71c032ae..30e8bde1a4 100644 --- a/actions/designadminpanel.php +++ b/actions/designadminpanel.php @@ -129,30 +129,38 @@ class DesignadminpanelAction extends AdminPanelAction $bgimage = $this->saveBackgroundImage(); - static $settings = array( - 'site' => array('theme', 'logo'), - 'theme' => array('server', 'dir', 'path'), - 'avatar' => array('server', 'dir', 'path'), - 'background' => array('server', 'dir', 'path') - ); + static $settings = array('theme', 'logo'); $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); + $oldtheme = common_config('site', 'theme'); - $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 = new Config(); + + $config->query('BEGIN'); + + // Only update colors if the theme has not changed. + + if ($oldtheme == $values['theme']) { + + $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 +175,21 @@ 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); - $config->query('COMMIT'); - - return; } /** @@ -219,6 +213,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); } /** @@ -272,48 +270,13 @@ class DesignadminpanelAction extends AdminPanelAction function validate(&$values) { - - if (!empty($values['site']['logo']) && - !Validate::uri($values['site']['logo'], array('allowed_schemes' => array('http', 'https')))) { + if (!empty($values['logo']) && + !Validate::uri($values['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'])); - } - - // 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'])); - } - - if (empty($values['avatar']['dir']) || !is_writable($values['avatar']['dir'])) { - $this->clientError(sprintf(_("Avatar directory not writable: %s"), $values['avatar']['dir'])); - } - - if (empty($values['background']['dir']) || !is_writable($values['background']['dir'])) { - $this->clientError(sprintf(_("Background directory not writable: %s"), $values['background']['dir'])); - } - - // 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 +289,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 +302,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'); } @@ -414,7 +377,7 @@ class DesignAdminPanelForm extends AdminForm $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->out->elementEnd('ul'); @@ -438,41 +401,9 @@ 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'); - $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_design_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'); + false, $this->value('theme')); $this->unli(); $this->out->elementEnd('ul'); @@ -550,18 +481,6 @@ 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'); @@ -668,24 +587,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); - } - }