$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) {
$statement->execute(array($templateGroupName));
$row = $statement->fetchArray();
if (!$row['count']) break;
- $templateGroupName = $originalTemplateGroupName . '_' . $i; //TODO: undefined variable
+ $templateGroupName = $originalTemplateGroupName . '_' . $i;
$i++;
}
* @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);
/**
* Sets the variables of a style.
+ *
+ * @param array<string> $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();
}
}
$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(
$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;
})
$files,
array(),
'',
- '',
new Callback(function($content) {
// fix relative paths
$content = str_replace('../icon/', '../../icon/', $content);
}
/**
- * 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<string> $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);
* @param array<string> $files
* @param array<string> $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);
}
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;
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;
-- 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