summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-06-11 12:04:03 -0700
committerBrion Vibber <brion@pobox.com>2010-06-11 12:04:03 -0700
commit47665e845ae74e6ee5b9a39565fb45dd9a93f921 (patch)
treea24680e60e250f085c7290c8fa0ecbc3ec4c6ea8 /actions
parentec155464765db36591bbb183b335abbc1ec8638c (diff)
parent054ac909bf6222254cf9b2c3a4eda824f4f4eb8f (diff)
Merge branch 'testing' of gitorious.org:statusnet/mainline into testing
Diffstat (limited to 'actions')
-rw-r--r--actions/designadminpanel.php104
1 files changed, 100 insertions, 4 deletions
diff --git a/actions/designadminpanel.php b/actions/designadminpanel.php
index 41d917e3c..a3f2dd055 100644
--- a/actions/designadminpanel.php
+++ b/actions/designadminpanel.php
@@ -125,9 +125,19 @@ class DesignadminpanelAction extends AdminPanelAction
return;
}
- // check for an image upload
+ // check for file uploads
$bgimage = $this->saveBackgroundImage();
+ $customTheme = $this->saveCustomTheme();
+
+ $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');
@@ -139,15 +149,13 @@ 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 ($oldtheme == $values['theme']) {
+ if (!$themeChanged) {
$bgcolor = new WebColor($this->trimmed('design_background'));
$ccolor = new WebColor($this->trimmed('design_content'));
@@ -189,6 +197,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');
}
@@ -263,6 +278,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
*
* @return void
@@ -370,7 +412,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'));
@@ -383,6 +433,11 @@ class DesignAdminPanelForm extends AdminForm
$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 +461,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' =>
@@ -483,6 +551,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 +563,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 +631,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 +641,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
*