Fixed style handling and removed PNG support for icons
authorAlexander Ebert <ebert@woltlab.com>
Tue, 25 Sep 2012 11:12:42 +0000 (13:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 25 Sep 2012 11:12:42 +0000 (13:12 +0200)
wcfsetup/install/files/lib/data/style/ActiveStyle.class.php
wcfsetup/install/files/lib/data/style/StyleEditor.class.php
wcfsetup/install/files/lib/system/cache/builder/IconCacheBuilder.class.php
wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php
wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php
wcfsetup/setup/db/install.sql

index fd2fd6956b2ede63ad8317eb9906ac7a4c0b0a36..28ca347815932a0a82efbd3ce939662dc704fbd2 100644 (file)
@@ -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';
        }
 }
index fa77b0f293679822e766e655db023251bb0d639d..29170f24dbbc390f89f6d36c56646949d569f8fe 100644 (file)
@@ -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);
index 8afc9060c2d1bd0c7ee471130cca65c88449c4d6..8148f9a7345a8912464880309edfca221c5482db 100644 (file)
@@ -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<string>
+        */
+       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());
                                }
                        }
index f05207438a683310646f4baffe5589bfac555528..0061ff9a32bfa9b4f9dc1ae6d7c59431a622af1f 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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<string>
-        */
-       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 "<?php ob_start(); ?>";
        }
@@ -50,6 +29,6 @@ class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin {
         */
        public function executeEnd(TemplateScriptingCompiler $compiler) {
                $compiler->popTag('icon');
-               return "<?php echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(ob_get_clean(), '".$this->size."'); ?>";
+               return "<?php echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(ob_get_clean()); ?>";
        }
 }
index 8d4581f2924b27e3aea8f09f2fba94a3430dd87b..5e57e5562b47d75b1a1bbceeb998050b7a50d2a0 100644 (file)
@@ -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 <http://opensource.org/licenses/lgpl-license.php>
  * @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}<?php echo \wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\'$2\', \'$1\'); ?>{/literal}', $sourceContent);
+               $sourceContent = preg_replace("~{$ldq}icon{$rdq}([\w\.]+){$ldq}/icon{$rdq}~", '{literal}<?php echo \wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\'$1\'); ?>{/literal}', $sourceContent);
 
                return $sourceContent;
        }
index ff25a7ddd24f3d97d8202ec46ee338cec6fc0a60..9108338e25131b49977a750ddbc5585426bd4017 100644 (file)
@@ -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;