]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/designadminpanel.php
Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / designadminpanel.php
index 30e8bde1a4e5d344ffa221a770183720cbfda204..321a8ee5ebcfad1dcb65e52b59acbaa915851944 100644 (file)
@@ -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,17 +120,30 @@ 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('theme', 'logo');
+        $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();
 
@@ -139,15 +153,26 @@ class DesignadminpanelAction extends AdminPanelAction
 
         $this->validate($values);
 
-        $oldtheme = common_config('site', 'theme');
-
         $config = new Config();
 
         $config->query('BEGIN');
 
-        // Only update colors if the theme has not changed.
+        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;
 
-        if ($oldtheme == $values['theme']) {
+                // 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'));
@@ -189,6 +214,13 @@ class DesignadminpanelAction extends AdminPanelAction
             Config::save('design', 'backgroundimage', $bgimage);
         }
 
+        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');
     }
 
@@ -201,6 +233,7 @@ class DesignadminpanelAction extends AdminPanelAction
     function restoreDefaults()
     {
         $this->deleteSetting('site', 'logo');
+        $this->deleteSetting('site', 'ssllogo');
         $this->deleteSetting('site', 'theme');
 
         $settings = array(
@@ -228,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;
@@ -262,6 +295,33 @@ class DesignadminpanelAction extends AdminPanelAction
         }
     }
 
+    /**
+     * Save the custom theme if the user uploaded one.
+     *
+     * @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 saveCustomTheme()
+    {
+        if (common_config('theme_upload', 'enabled') &&
+            $_FILES['design_upload_theme']['error'] == UPLOAD_ERR_OK) {
+
+            $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;
+        }
+    }
+
     /**
      * Attempt to validate setting values
      *
@@ -272,11 +332,16 @@ class DesignadminpanelAction extends AdminPanelAction
     {
         if (!empty($values['logo']) &&
             !Validate::uri($values['logo'], array('allowed_schemes' => array('http', 'https')))) {
-            $this->clientError(_("Invalid logo URL."));
+            $this->clientError(_('Invalid logo URL.'));
+        }
+
+        if (!empty($values['ssllogo']) &&
+            !Validate::uri($values['ssllogo'], array('allowed_schemes' => array('https')))) {
+            $this->clientError(_('Invalid SSL logo URL.'));
         }
 
         if (!in_array($values['theme'], Theme::listAvailable())) {
-            $this->clientError(sprintf(_("Theme not available: %s"), $values['theme']));
+            $this->clientError(sprintf(_("Theme not available: %s."), $values['theme']));
         }
     }
 
@@ -370,7 +435,15 @@ class DesignAdminPanelForm extends AdminForm
 
     function formData()
     {
+        $this->showLogo();
+        $this->showTheme();
+        $this->showBackground();
+        $this->showColors();
+        $this->showAdvanced();
+    }
 
+    function showLogo()
+    {
         $this->out->elementStart('fieldset', array('id' => 'settings_design_logo'));
         $this->out->element('legend', null, _('Change logo'));
 
@@ -380,9 +453,18 @@ class DesignAdminPanelForm extends AdminForm
         $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');
+
+    }
+
+    function showTheme()
+    {
         $this->out->elementStart('fieldset', array('id' => 'settings_design_theme'));
         $this->out->element('legend', null, _('Change theme'));
 
@@ -406,10 +488,23 @@ class DesignAdminPanelForm extends AdminForm
                              false, $this->value('theme'));
         $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' =>
@@ -454,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',
@@ -470,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();
@@ -483,6 +580,11 @@ class DesignAdminPanelForm extends AdminForm
 
         $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'));
@@ -490,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);
 
@@ -557,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());
         }
@@ -566,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
      *