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;
* @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';
}
}
$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/*');
$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;
$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;
'copyright' => $data['copyright'],
'license' => $data['license'],
'authorName' => $data['authorName'],
- 'authorURL' => $data['authorURL']
+ 'authorURL' => $data['authorURL'],
+ 'iconPath' => $data['iconPath']
);
if ($style !== null) {
$style->update($styleData);
// 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
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;
}
}
}
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());
}
}
* 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(); ?>";
}
*/
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()); ?>";
}
}
* 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
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;
}
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;