<?php
namespace wcf\data\style;
use wcf\data\DatabaseObjectDecorator;
+use wcf\system\cache\CacheHandler;
use wcf\system\WCF;
use wcf\util\FileUtil;
use wcf\util\StyleUtil;
// load icon cache
$cacheName = 'icon-'.PACKAGE_ID.'-'.$this->styleID;
- WCF::getCache()->addResource(
+ CacheHandler::getInstance()->addResource(
$cacheName,
WCF_DIR.'cache/cache.'.$cacheName.'.php',
'wcf\system\cache\builder\IconCacheBuilder'
);
- $this->iconCache = WCF::getCache()->get($cacheName);
+ $this->iconCache = CacheHandler::getInstance()->get($cacheName);
}
/**
* @param string $iconName
* @return string
*/
- public function getIconPath($iconName) {
- if (isset($this->iconCache[$iconName])) return $this->iconCache[$iconName];
- return RELATIVE_WCF_DIR.'icon/'.$iconName;
+ public function getIconPath($iconName, $size = 'L') {
+ if (isset($this->iconCache[$iconName][$size])) return $this->iconCache[$iconName][$size];
+ return RELATIVE_WCF_DIR.'icon/'.$iconName.'.svg';
}
}
// get active package
$activePackage = new Package($packageID);
- $activePackageDir = FileUtil::getRealPath(WCF_DIR.$activePackage->getDir());
+ $activePackageDir = FileUtil::getRealPath(WCF_DIR.$activePackage->packageDir);
// get package dirs
$packageDirs = array();
$conditionBuilder = new PreparedStatementConditionBuilder();
- $conditionBuilder->add("packageID IN (?) AND packageDir <> ''", array(PackageDependencyHandler::getDependenciesString()));
- $sql = "SELECT DISTINCT packageDir
- FROM wcf".WCF_N."_package package
+ $conditionBuilder->add("dependency.packageID IN (?) AND package.packageDir <> ''", array(PackageDependencyHandler::getDependencies()));
+ $sql = "SELECT DISTINCT package.packageDir
+ FROM wcf".WCF_N."_package_dependency dependency
+ LEFT JOIN wcf".WCF_N."_package package
+ ON (package.packageID = dependency.dependency)
".$conditionBuilder->__toString()."
- ORDER BY priority DESC";
+ ORDER BY dependency.priority DESC";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditionBuilder->getParameters());
while ($row = $statement->fetchArray()) {
$packageDirs[] = FileUtil::getRealPath(WCF_DIR.$row['packageDir']);
}
- $packageDirs[] = WCF_DIR;
+ $packageDirs[] = FileUtil::unifyDirSeperator(WCF_DIR);
// get style icon path
$iconDirs = array();
// get icons
foreach ($packageDirs as $packageDir) {
$relativePackageDir = ($activePackageDir != $packageDir ? FileUtil::getRelativePath($activePackageDir, $packageDir) : '');
-
+ echo $relativePackageDir."\n";
foreach ($iconDirs as $iconDir) {
$path = FileUtil::addTrailingSlash($packageDir.$iconDir);
- $icons = self::getIconFiles($path);
+
+ // get png icons
+ $icons = self::getIconFiles($path, 'png');
foreach ($icons as $icon) {
$icon = str_replace($path, '', $icon);
- if (!isset($data[$icon])) {
- $data[$icon] = $relativePackageDir.$iconDir.$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');
+ 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;
+ }
}
}
}
return $data;
}
- protected static function getIconFiles($path) {
+ protected static function getIconFiles($path, $extension = 'svg') {
$files = array();
if (is_dir($path)) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
foreach ($iterator as $file) {
- if (preg_match('/\.png$/', $file->getFilename())) {
- $files[] = $file->getPathname();
+ if (preg_match('/\.'.$extension.'$/', $file->getFilename())) {
+ $files[] = FileUtil::unifyDirSeperator($file->getPathname());
}
}
}
* The 'icon' compiler function compiles dynamic icon paths.
*
* Usage:
- * {icon}{$foo}{/icon}
+ * {icon size='L'}{$foo}{/icon}
*
* @author Marcel Werk
* @copyright 2001-2011 WoltLab GmbH
* @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');
$hash = StringUtil::getRandomID();
- return "<?php \$_icon".$hash." = ob_get_contents(); ob_end_clean(); echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\$_icon".$hash."); ?>";
+ return "<?php \$_icon".$hash." = ob_get_contents(); ob_end_clean(); echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\$_icon".$hash.", '".$this->size."'); ?>";
}
}