From fa83e8f768ef2daed901de393e4958715033bddc Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 25 Sep 2012 13:12:42 +0200 Subject: [PATCH] Fixed style handling and removed PNG support for icons --- .../lib/data/style/ActiveStyle.class.php | 7 +-- .../lib/data/style/StyleEditor.class.php | 12 +++-- .../cache/builder/IconCacheBuilder.class.php | 44 +++++++------------ .../IconCompilerTemplatePlugin.class.php | 29 ++---------- .../IconPrefilterTemplatePlugin.class.php | 8 ++-- wcfsetup/setup/db/install.sql | 3 +- 6 files changed, 38 insertions(+), 65 deletions(-) diff --git a/wcfsetup/install/files/lib/data/style/ActiveStyle.class.php b/wcfsetup/install/files/lib/data/style/ActiveStyle.class.php index fd2fd6956b..28ca347815 100644 --- a/wcfsetup/install/files/lib/data/style/ActiveStyle.class.php +++ b/wcfsetup/install/files/lib/data/style/ActiveStyle.class.php @@ -2,6 +2,7 @@ namespace wcf\data\style; use wcf\data\DatabaseObjectDecorator; use wcf\system\cache\CacheHandler; +use wcf\system\WCF; use wcf\util\FileUtil; use wcf\util\StringUtil; @@ -67,8 +68,8 @@ class ActiveStyle extends DatabaseObjectDecorator { * @param string $iconName * @return string */ - public function getIconPath($iconName, $size = 'L') { - if (isset($this->iconCache[$iconName][$size])) return $this->iconCache[$iconName][$size]; - return RELATIVE_WCF_DIR.'icon/'.$iconName.'.svg'; + public function getIconPath($iconName) { + if (isset($this->iconCache[$iconName])) return $this->iconCache[$iconName]; + return WCF::getPath().'icon/'.$iconName.'.svg'; } } diff --git a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php index fa77b0f293..29170f24db 100644 --- a/wcfsetup/install/files/lib/data/style/StyleEditor.class.php +++ b/wcfsetup/install/files/lib/data/style/StyleEditor.class.php @@ -135,7 +135,7 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $data = array( 'name' => '', 'description' => '', 'version' => '', 'image' => '', 'copyright' => '', 'license' => '', 'authorName' => '', 'authorURL' => '', 'templates' => '', 'images' => '', - 'variables' => '', 'date' => '0000-00-00', 'icons' => '' + 'variables' => '', 'date' => '0000-00-00', 'icons' => '', 'iconPath' => '', 'imagePath' => '' ); $categories = $xpath->query('/ns:style/*'); @@ -160,6 +160,9 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $elements = $xpath->query('child::*', $category); foreach ($elements as $element) { $data[$element->tagName] = $element->nodeValue; + if ($element->hasAttribute('path')) { + $data[$element->tagName.'Path'] = $element->getAttribute('path'); + } } break; @@ -283,8 +286,8 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject $data = self::readStyleData($tar); // get image locations - $iconsLocation = FileUtil::addTrailingSlash($data['variables']['global.icons.location']); - $imagesLocation = $data['variables']['global.images.location']; + $iconsLocation = FileUtil::addTrailingSlash('icon/'.$data['iconPath']); + $imagesLocation = FileUtil::addTrailingSlash('images/'.$data['imagePath']); // create template group $templateGroupID = 0; @@ -345,7 +348,8 @@ class StyleEditor extends DatabaseObjectEditor implements IEditableCachedObject 'copyright' => $data['copyright'], 'license' => $data['license'], 'authorName' => $data['authorName'], - 'authorURL' => $data['authorURL'] + 'authorURL' => $data['authorURL'], + 'iconPath' => $data['iconPath'] ); if ($style !== null) { $style->update($styleData); diff --git a/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php b/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php index 8afc9060c2..8148f9a734 100644 --- a/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php +++ b/wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php @@ -47,14 +47,13 @@ class IconCacheBuilder implements ICacheBuilder { // get style icon path $iconDirs = array(); - $sql = "SELECT variableValue - FROM wcf".WCF_N."_style_variable - WHERE styleID = ? - AND variableName = ?"; + $sql = "SELECT iconPath + FROM wcf".WCF_N."_style + WHERE styleID = ?"; $statement = WCF::getDB()->prepareStatement($sql); - $statement->execute(array($styleID, 'global.icons.location')); + $statement->execute(array($styleID)); $row = $statement->fetchArray(); - if (!empty($row['variableValue'])) $iconDirs[] = FileUtil::addTrailingSlash($row['variableValue']); + if (!empty($row['iconPath'])) $iconDirs[] = FileUtil::addTrailingSlash($row['iconPath']); if (!in_array('icon/', $iconDirs)) $iconDirs[] = 'icon/'; // get icons @@ -64,30 +63,13 @@ class IconCacheBuilder implements ICacheBuilder { foreach ($iconDirs as $iconDir) { $path = FileUtil::addTrailingSlash($packageDir.$iconDir); - // get png icons - $icons = self::getIconFiles($path, 'png'); - foreach ($icons as $icon) { - $icon = str_replace($path, '', $icon); - if (preg_match('/^(.*)(S|M|L)\.png$/', $icon, $match)) { - if (!isset($data[$match[1]][$match[2]])) { - $data[$match[1]][$match[2]] = $relativePackageDir.$iconDir.$icon; - } - } - } - // get svg icons - $icons = self::getIconFiles($path, 'svg'); + $icons = self::getIconFiles($path); foreach ($icons as $icon) { $icon = str_replace($path, '', $icon); if (preg_match('/^(.*)\.svg$/', $icon, $match)) { - if (!isset($data[$match[1]]['S'])) { - $data[$match[1]]['S'] = $relativePackageDir.$iconDir.$icon; - } - if (!isset($data[$match[1]]['M'])) { - $data[$match[1]]['M'] = $relativePackageDir.$iconDir.$icon; - } - if (!isset($data[$match[1]]['L'])) { - $data[$match[1]]['L'] = $relativePackageDir.$iconDir.$icon; + if (!isset($data[$match[1]])) { + $data[$match[1]] = $relativePackageDir.$iconDir.$icon; } } } @@ -97,12 +79,18 @@ class IconCacheBuilder implements ICacheBuilder { return $data; } - protected static function getIconFiles($path, $extension = 'svg') { + /** + * Returns a list of SVG icons. + * + * @param string $path + * @return array + */ + protected static function getIconFiles($path) { $files = array(); if (is_dir($path)) { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); foreach ($iterator as $file) { - if (preg_match('/\.'.$extension.'$/', $file->getFilename())) { + if (preg_match('/\.svg$/', $file->getFilename())) { $files[] = FileUtil::unifyDirSeperator($file->getPathname()); } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php index f05207438a..0061ff9a32 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php @@ -6,41 +6,20 @@ use wcf\system\template\TemplateScriptingCompiler; * The 'icon' compiler function compiles dynamic icon paths. * * Usage: - * {icon size='L'}{$foo}{/icon} - * + * {icon}{$foo}{/icon} + * * @author Marcel Werk - * @copyright 2001-2011 WoltLab GmbH + * @copyright 2001-2012 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin { - /** - * icon size - * @var string - */ - protected $size = ''; - - /** - * valid icon sizes - * @var array - */ - protected static $validSizes = array('S', 'M', 'L'); - /** * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() */ public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - // set default size - $this->size = 'L'; - - // get size - if (isset($tagArgs['size'])) { - if (strlen($tagArgs['size']) > 1) $tagArgs['size'] = substr($tagArgs['size'], 1, 1); - if (in_array($tagArgs['size'], self::$validSizes)) $this->size = $tagArgs['size']; - } - $compiler->pushTag('icon'); return ""; } @@ -50,6 +29,6 @@ class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin { */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('icon'); - return "getStyle()->getIconPath(ob_get_clean(), '".$this->size."'); ?>"; + return "getStyle()->getIconPath(ob_get_clean()); ?>"; } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php index 8d4581f292..5e57e5562b 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php @@ -6,10 +6,10 @@ use wcf\system\template\TemplateScriptingCompiler; * The 'icon' prefilter compiles static icon paths. * * Usage: - * {icon size='L'}iconS.png{/icon} - * + * {icon}iconName{/icon} + * * @author Marcel Werk - * @copyright 2001-2011 WoltLab GmbH + * @copyright 2001-2012 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template.plugin @@ -22,7 +22,7 @@ class IconPrefilterTemplatePlugin implements IPrefilterTemplatePlugin { public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler) { $ldq = preg_quote($compiler->getLeftDelimiter(), '~'); $rdq = preg_quote($compiler->getRightDelimiter(), '~'); - $sourceContent = preg_replace("~{$ldq}icon size='?([SML])'?{$rdq}([\w\.]+){$ldq}/icon{$rdq}~", '{literal}getStyle()->getIconPath(\'$2\', \'$1\'); ?>{/literal}', $sourceContent); + $sourceContent = preg_replace("~{$ldq}icon{$rdq}([\w\.]+){$ldq}/icon{$rdq}~", '{literal}getStyle()->getIconPath(\'$1\'); ?>{/literal}', $sourceContent); return $sourceContent; } diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index ff25a7ddd2..9108338e25 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -573,7 +573,8 @@ CREATE TABLE wcf1_style ( copyright VARCHAR(255) NOT NULL DEFAULT '', license VARCHAR(255) NOT NULL DEFAULT '', authorName VARCHAR(255) NOT NULL DEFAULT '', - authorURL VARCHAR(255) NOT NULL DEFAULT '' + authorURL VARCHAR(255) NOT NULL DEFAULT '', + iconPath VARCHAR(255) NOT NULL DEFAULT '', ); DROP TABLE IF EXISTS wcf1_style_to_package; -- 2.20.1