From: Alexander Ebert Date: Mon, 24 Sep 2012 17:21:44 +0000 (+0200) Subject: variables.less is now replaced by wcf1_style_variable X-Git-Tag: 2.0.0_Beta_1~925 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4d9f605856bdb6b2c56ddaa042526798fbb49adf;p=GitHub%2FWoltLab%2FWCF.git variables.less is now replaced by wcf1_style_variable --- diff --git a/wcfsetup/install/files/lib/data/style/Style.class.php b/wcfsetup/install/files/lib/data/style/Style.class.php index c7da1bb1f1..af45d16a48 100644 --- a/wcfsetup/install/files/lib/data/style/Style.class.php +++ b/wcfsetup/install/files/lib/data/style/Style.class.php @@ -36,18 +36,18 @@ class Style extends DatabaseObject { /** * Returns the styles variables of this style. * - * @return array + * @return array */ public function getVariables() { $variables = array(); - $sql = "SELECT variableName, variableValue - FROM wcf".WCF_N."_style_variable - WHERE styleID = ? - ORDER BY variableName ASC"; + $sql = "SELECT variable.variableName, variable.defaultValue, value.variableValue + FROM wcf".WCF_N."_style_variable variable + LEFT JOIN wcf".WCF_N."_style_variable_value value + ON (value.variableID = variable.variableID AND value.styleID = ?)"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->styleID)); while ($row = $statement->fetchArray()) { - $variables[$row['variableName']] = $row['variableValue']; + $variables[$row['variableName']] = (isset($row['variableValue'])) ? $row['variableValue'] : $row['defaultValue']; } return $variables; diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index aa42dafa59..fa77b0f293 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -83,8 +83,12 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $statement->execute(array($this->styleID)); // delete style files - @unlink(WCF_DIR.'style/style-'.$this->styleID.'.css'); - @unlink(WCF_DIR.'style/style-'.$this->styleID.'-rtl.css'); + $files = @glob(WCF_DIR.'style/style-*-'.$this->styleID.'*.css'); + if (is_array($files)) { + foreach ($files as $file) { + @unlink($file); + } + } // delete preview image if ($this->image) { @@ -300,7 +304,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $statement->execute(array($templateGroupName)); $row = $statement->fetchArray(); if (!$row['count']) break; - $templateGroupName = $originalTemplateGroupName . '_' . $i; //TODO: undefined variable + $templateGroupName = $originalTemplateGroupName . '_' . $i; $i++; } @@ -525,6 +529,9 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject * @param boolean $icons */ public function export($templates = false, $images = false, $icons = false) { + // TODO: Fix this method! + throw new SystemException("FIX ME!"); + // create style tar $styleTarName = FileUtil::getTemporaryFilename('style_', '.tgz'); $styleTar = new TarWriter($styleTarName, true); @@ -696,35 +703,49 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject /** * Sets the variables of a style. + * + * @param array $variables */ - public function setVariables($variables) { + public function setVariables(array $variables = array()) { // delete old variables - $sql = "DELETE FROM wcf".WCF_N."_style_variable + $sql = "DELETE FROM wcf".WCF_N."_style_variable_value WHERE styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($this->styleID)); // insert new variables - $statementParameters = array(); - foreach ($variables as $name => $value) { - $statementParameters[] = array( - 'name' => $name, - 'value' => $value - ); - } - - if (count($statementParameters)) { - $sql = "INSERT INTO wcf".WCF_N."_style_variable - (styleID, variableName, variableValue) - VALUES (?, ?, ?)"; + if (!empty($variables)) { + $sql = "SELECT * + FROM wcf".WCF_N."_style_variable"; $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + $styleVariables = array(); + while ($row = $statement->fetchArray()) { + $variableName = $row['variableName']; + + if (isset($variables[$variableName])) { + // compare value, save only if differs from default + if ($variables[$variableName] != $row['defaultValue']) { + $styleVariables[$row['variableID']] = $variables[$variableName]; + } + } + } - foreach ($statementParameters as $parameter) { - $statement->execute(array( - $this->styleID, - $parameter['name'], - $parameter['value'] - )); + if (!empty($styleVariables)) { + $sql = "INSERT INTO wcf".WCF_N."_style_variable_value + (styleID, variableID, variableValue) + VALUES (?, ?, ?)"; + $statement = WCF::getDB()->prepareStatement($sql); + + WCF::getDB()->beginTransaction(); + foreach ($styleVariables as $variableID => $variableValue) { + $statement->execute(array( + $this->styleID, + $variableID, + $variableValue + )); + } + WCF::getDB()->commitTransaction(); } } diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index 3073e16f02..5af9868393 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -62,23 +62,12 @@ class StyleCompiler extends SingletonFactory { $files[] = WCF_DIR.$row['packageDir'].$row['filename']; } - // load style variables - $sql = "SELECT variableName, variableValue - FROM wcf".WCF_N."_style_variable - WHERE styleID = ?"; - $statement = WCF::getDB()->prepareStatement($sql); - $variables = array(); - $individualCss = $individualLess = ''; - while ($row = $statement->fetchArray()) { - if ($row['variableName'] == 'individualCss') { - $individualCss = $row['variableValue']; - } - else if ($row['variableName'] == 'individualLess') { - $individualLess = $row['variableValue']; - } - else { - $variables[$row['variableName']] = $row['variableValue']; - } + // get style variables + $variables = $style->getVariables(); + $individualCss = ''; + if (isset($variables['individualCss'])) { + $individualCss = $variables['individualCss']; + unset($variables['individualCss']); } $this->compileStylesheet( @@ -86,7 +75,6 @@ class StyleCompiler extends SingletonFactory { $files, $variables, $individualCss, - $individualLess, new Callback(function($content) use ($style) { return "/* stylesheet for '".$style->styleName."', generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; }) @@ -104,7 +92,6 @@ class StyleCompiler extends SingletonFactory { $files, array(), '', - '', new Callback(function($content) { // fix relative paths $content = str_replace('../icon/', '../../icon/', $content); @@ -116,36 +103,15 @@ class StyleCompiler extends SingletonFactory { } /** - * Prepares the style compiler, adding variables to environment and appending - * individual LESS declarations to override variables.less's values. + * Prepares the style compiler by adding variables to environment. * * @param array $variables - * @param string $individualLess * @return string */ - protected function bootstrap(array $variables, $individualLess = '') { + protected function bootstrap(array $variables) { // add reset like a boss $content = $this->prepareFile(WCF_DIR.'style/bootstrap/reset.less'); - // override LESS variables - $variablesContent = $this->prepareFile(WCF_DIR.'style/bootstrap/variables.less'); - if ($individualLess) { - list($keywords, $values) = explode('=', explode("\n", $individualLess)); - if (count($keywords) != count($values)) { - throw new SystemException("Could not override LESS variables, invalid input"); - } - - foreach ($keywords as $i => $keyword) { - $variablesContent = preg_replace( - '~^@'.$keyword.':.*$~imU', - '@'.$keyword.': '.$values[$i].';', - $variablesContent - ); - } - } - $content .= $variablesContent; - - // apply style variables $this->compiler->setVariables($variables); @@ -179,12 +145,11 @@ class StyleCompiler extends SingletonFactory { * @param array $files * @param array $variables * @param string $individualCss - * @param string $individualLess * @param wcf\system\Callback $callback */ - protected function compileStylesheet($filename, array $files, array $variables, $individualCss, $individualLess, Callback $callback) { + protected function compileStylesheet($filename, array $files, array $variables, $individualCss, Callback $callback) { // build LESS bootstrap - $less = $this->bootstrap($variables, $individualLess); + $less = $this->bootstrap($variables); foreach ($files as $file) { $less .= $this->prepareFile($file); } diff --git a/wcfsetup/install/files/style/bootstrap/variables.less b/wcfsetup/install/files/style/bootstrap/variables.less index daf068aef5..3053f7607a 100644 --- a/wcfsetup/install/files/style/bootstrap/variables.less +++ b/wcfsetup/install/files/style/bootstrap/variables.less @@ -1,3 +1,12 @@ +/* + *** + *** W A R N I N G + *** + *** This file is no longer in use and was replaced by wcf1_style_variable. + *** It will be removed in the near feature. + *** +*/ + /* ###### sxf values ###### */ /* these values will be defined by the style editor (don't it touch here) */ diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 191b104bb8..e5807bd57c 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -587,10 +587,18 @@ CREATE TABLE wcf1_style_to_package ( DROP TABLE IF EXISTS wcf1_style_variable; CREATE TABLE wcf1_style_variable ( + variableID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, + variableName VARCHAR(50) NOT NULL, + defaultValue MEDIUMTEXT, + UNIQUE KEY variableName (variableName) +); + +DROP TABLE IF EXISTS wcf1_style_variable_value; +CREATE TABLE wcf1_style_variable_value ( styleID INT(10) NOT NULL, - variableName VARCHAR(50) NOT NULL DEFAULT '', + variableID INT(10) NOT NULL, variableValue MEDIUMTEXT, - UNIQUE KEY (styleID, variableName) + UNIQUE KEY (styleID, variableID) ); DROP TABLE IF EXISTS wcf1_template; @@ -871,7 +879,8 @@ ALTER TABLE wcf1_style ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (pack ALTER TABLE wcf1_style_to_package ADD FOREIGN KEY (styleID) REFERENCES wcf1_style (styleID) ON DELETE CASCADE; ALTER TABLE wcf1_style_to_package ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; -ALTER TABLE wcf1_style_variable ADD FOREIGN KEY (styleID) REFERENCES wcf1_style (styleID) ON DELETE CASCADE; +ALTER TABLE wcf1_style_variable_value ADD FOREIGN KEY (styleID) REFERENCES wcf1_style (styleID) ON DELETE CASCADE; +ALTER TABLE wcf1_style_variable_value ADD FOREIGN KEY (variableID) REFERENCES wcf1_style_variable (variableID) ON DELETE CASCADE; ALTER TABLE wcf1_template ADD FOREIGN KEY (packageID) REFERENCES wcf1_package (packageID) ON DELETE CASCADE; ALTER TABLE wcf1_template ADD FOREIGN KEY (templateGroupID) REFERENCES wcf1_template_group (templateGroupID) ON DELETE CASCADE; @@ -925,3 +934,77 @@ INSERT INTO wcf1_user_group_option_value (groupID, optionID, optionValue) VALUES -- default update servers INSERT INTO wcf1_package_update_server (serverURL, status, disabled, errorMessage, lastUpdateTime, loginUsername, loginPassword) VALUES ('http://update.woltlab.com/maelstrom/', 'online', 0, NULL, 0, '', ''); INSERT INTO wcf1_package_update_server (serverURL, status, disabled, errorMessage, lastUpdateTime, loginUsername, loginPassword) VALUES ('http://store.woltlab.com/maelstrom/', 'online', 0, NULL, 0, '', ''); + +-- style default values +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContentBackgroundColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfColor', '#666'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLinkColor', '#369'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLinkHoverColor', '#036'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContainerBackgroundColor', 'rgba(252, 253, 254, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContainerAccentBackgroundColor', 'rgba(241, 245, 250, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContainerHoverBackgroundColor', 'rgba(216, 231, 245, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContainerBorderColor', '#ccc; //#bcd'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfContainerBorderRadius', '6px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTabularBoxBackgroundColor', '#369'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTabularBoxColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTabularBoxHoverColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfUserPanelBackgroundColor', 'rgba(0, 0, 0, .5)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfUserPanelColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfUserPanelHoverColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonBackgroundColor', '#e3e3e3'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonBorderColor', '#bbb'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonColor', '#999'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonPrimaryBackgroundColor', 'rgba(216, 231, 245, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonPrimaryBorderColor', '#69C'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonPrimaryColor', '#69C'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonHoverBackgroundColor', 'rgba(255, 229, 200, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonHoverBorderColor', '#fa2'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfButtonHoverColor', '#666'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInputBackgroundColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInputColor', '#666'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInputBorderColor', '#ccc'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInputHoverBackgroundColor', 'rgba(255, 249, 244, 1)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInputHoverBorderColor', '#fa2'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfBaseFontSize', '13px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfBaseFontFamily', '"Trebuchet MS", Arial, sans-serif'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLayoutFluidGap', '21px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLayoutFixedWidth', '1200px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageBackgroundColor', '@wcfContentBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageColor', '@wcfColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageLinkColor', '@wcfLinkColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageLinkHoverColor', '@wcfLinkHoverColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSidebarBackgroundColor', '@wcfContentBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfDimmedColor', 'lighten(@wcfColor, 10%)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLabelColor', '@wcfColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfHeadlineColor', '@wcfColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfHeadlineFontFamily', '@wcfBaseFontFamily'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfDropdownBackgroundColor', '@wcfContentBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfDropdownColor', '@wcfColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfDropdownBorderColor', '@wcfContainerBorderColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfDropdownHoverBackgroundColor', '@wcfContainerHoverBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfBaseLineHeight', '1.27'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfHeadlineFontSize', '170%'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSubHeadlineFontSize', '140%'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTitleFontSize', '120%'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSmallFontSize', '85%'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfWarningColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfWarningBackgroundColor', '#ffb800'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfErrorColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfErrorBackgroundColor', '#c95145'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSuccessColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSuccessBackgroundColor', '#74a446'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInfoColor', '#fff'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfInfoBackgroundColor', '#4674a4'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTooltipBackgroundColor', 'rgba(0, 0, 0, .8)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfTooltipColor', 'white'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfGapTiny', '4px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfGapSmall', '7px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfGapMedium', '14px'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfGapLarge', '21px'); +-- TODO: The variables below are from blue sunrise, remove them later! +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageBackgroundColor', '@wcfTabularBoxBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfSidebarBackgroundColor', '@wcfContainerHoverBackgroundColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageLinkColor', 'lighten(@wcfLinkColor, 10%)'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfPageLinkHoverColor', '@wcfUserPanelHoverColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfLabelColor', '@wcfLinkColor'); +INSERT INTO wcf1_style_variable (variableName, defaultValue) VALUES ('wcfNavigationBackgroundColor', 'lighten(@wcfSidebarBackgroundColor, 3%)'); \ No newline at end of file