]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/designadminpanel.php
show forwards in the inbox
[quix0rs-gnu-social.git] / actions / designadminpanel.php
index 156c3f1ab505a2bb919caeeb8c9d02e744545f1c..f862aff0ebed5a11b8cf2962c2176fd51734a861 100644 (file)
@@ -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']));
         }
     }
 
@@ -408,19 +371,19 @@ class DesignAdminPanelForm extends AdminForm
     function formData()
     {
 
-        $this->out->elementStart('fieldset', array('id' => 'settings_logo'));
+        $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->out->elementEnd('ul');
 
         $this->out->elementEnd('fieldset');
-        $this->out->elementStart('fieldset', array('id' => 'settings_theme'));
+        $this->out->elementStart('fieldset', array('id' => 'settings_design_theme'));
         $this->out->element('legend', null, _('Change theme'));
 
         $this->out->elementStart('ul', 'form_data');
@@ -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_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);
-    }
-
 }