From: Matthias Schmidt Date: Fri, 12 Aug 2011 19:51:11 +0000 (+0200) Subject: Changed names of the template plugin classes X-Git-Tag: 2.0.0_Beta_1~1878^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=349976a8fabe40a8e732526ea4d3e6c88cd70f61;p=GitHub%2FWoltLab%2FWCF.git Changed names of the template plugin classes During my tests, I found out that some template plugins don't work anymore. I added a todo each time so you can fix that and replaced the return value with an empty string so that at least no exception is thrown anymore. I myself fixed a bug in the staticlang compiler (caused: "Class 'WCF' not found in …"). --- diff --git a/wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php new file mode 100644 index 0000000000..2abe51478d --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php @@ -0,0 +1,40 @@ + + * @package com.woltlab.wcf + * @subpackage system.template + * @category Community Framework + */ +interface IBlockTemplatePlugin { + /** + * Executes this template block. + * + * @param array $tagArgs + * @param string $blockContent + * @param wcf\system\template\TemplateEngine $tplObj + * @return string output + */ + public function execute($tagArgs, $blockContent, TemplateEngine $tplObj); + + /** + * Initialises this template block. + * + * @param array $tagArgs + * @param wcf\system\template\TemplateEngine $tplObj + */ + public function init($tagArgs, TemplateEngine $tplObj); + + /** + * This function is called before every execution of this block function. + * + * @param wcf\system\template\TemplateEngine $tplObj + * @return boolean + */ + public function next(TemplateEngine $tplObj); +} diff --git a/wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..0b37d89047 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php @@ -0,0 +1,31 @@ + + * @package com.woltlab.wcf + * @subpackage system.template + * @category Community Framework + */ +interface ICompilerTemplatePlugin { + /** + * Executes the start tag of this compiler function. + * + * @param array $tagArgs + * @param wcf\system\template\TemplateScriptingCompiler $compiler + * @return string php code + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler); + + /** + * Executes the end tag of this compiler function. + * + * @param wcf\system\template\TemplateScriptingCompiler $compiler + * @return string php code + */ + public function executeEnd(TemplateScriptingCompiler $compiler); +} diff --git a/wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..862c7931cc --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php @@ -0,0 +1,23 @@ + + * @package com.woltlab.wcf + * @subpackage system.template + * @category Community Framework + */ +interface IFunctionTemplatePlugin { + /** + * Executes this template function. + * + * @param array $tagArgs + * @param wcf\system\template\TemplateEngine $tplObj + * @return string output + */ + public function execute($tagArgs, TemplateEngine $tplObj); +} diff --git a/wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..2c240f2795 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php @@ -0,0 +1,24 @@ + + * @package com.woltlab.wcf + * @subpackage system.template + * @category Community Framework + */ +interface IModifierTemplatePlugin { + /** + * Executes this modifier. + * + * @param array $tagArgs + * @param wcf\system\template\TemplateEngine $tplObj + * @return string output + */ + public function execute($tagArgs, TemplateEngine $tplObj); +} diff --git a/wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php new file mode 100644 index 0000000000..455a03b94d --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php @@ -0,0 +1,24 @@ + + * @package com.woltlab.wcf + * @subpackage system.template + * @category Community Framework + */ +interface IPrefilterTemplatePlugin { + /** + * Executes this prefilter. + * + * @param string $templateName + * @param string $sourceContent + * @param wcf\system\template\TemplateScriptingCompiler $compiler + * @return string + */ + public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler); +} diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php b/wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php deleted file mode 100644 index 9c6487ef54..0000000000 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php +++ /dev/null @@ -1,40 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template - * @category Community Framework - */ -interface ITemplatePluginBlock { - /** - * Executes this template block. - * - * @param array $tagArgs - * @param string $blockContent - * @param wcf\system\template\TemplateEngine $tplObj - * @return string output - */ - public function execute($tagArgs, $blockContent, TemplateEngine $tplObj); - - /** - * Initialises this template block. - * - * @param array $tagArgs - * @param wcf\system\template\TemplateEngine $tplObj - */ - public function init($tagArgs, TemplateEngine $tplObj); - - /** - * This function is called before every execution of this block function. - * - * @param wcf\system\template\TemplateEngine $tplObj - * @return boolean - */ - public function next(TemplateEngine $tplObj); -} diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php b/wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php deleted file mode 100644 index ab579e9dba..0000000000 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template - * @category Community Framework - */ -interface ITemplatePluginCompiler { - /** - * Executes the start tag of this compiler function. - * - * @param array $tagArgs - * @param wcf\system\template\TemplateScriptingCompiler $compiler - * @return string php code - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler); - - /** - * Executes the end tag of this compiler function. - * - * @param wcf\system\template\TemplateScriptingCompiler $compiler - * @return string php code - */ - public function executeEnd(TemplateScriptingCompiler $compiler); -} diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php b/wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php deleted file mode 100644 index ac0b7d222c..0000000000 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php +++ /dev/null @@ -1,23 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template - * @category Community Framework - */ -interface ITemplatePluginFunction { - /** - * Executes this template function. - * - * @param array $tagArgs - * @param wcf\system\template\TemplateEngine $tplObj - * @return string output - */ - public function execute($tagArgs, TemplateEngine $tplObj); -} diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php b/wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php deleted file mode 100644 index 478ebfd7fc..0000000000 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template - * @category Community Framework - */ -interface ITemplatePluginModifier { - /** - * Executes this modifier. - * - * @param array $tagArgs - * @param wcf\system\template\TemplateEngine $tplObj - * @return string output - */ - public function execute($tagArgs, TemplateEngine $tplObj); -} diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php b/wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php deleted file mode 100644 index 4701713b37..0000000000 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template - * @category Community Framework - */ -interface ITemplatePluginPrefilter { - /** - * Executes this prefilter. - * - * @param string $templateName - * @param string $sourceContent - * @param wcf\system\template\TemplateScriptingCompiler $compiler - * @return string - */ - public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler); -} diff --git a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php index 3f55efde4e..0a1335c42d 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateEngine.class.php @@ -482,7 +482,7 @@ class TemplateEngine extends SingletonFactory { * @return string class name */ public function getPluginClassName($type, $tag) { - return $this->pluginNamespace.'TemplatePlugin'.StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($type)).StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($tag)); + return $this->pluginNamespace.StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($tag)).StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($type)).'TemplatePlugin'; } /** diff --git a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php index 402ac610f5..6604c11f2b 100644 --- a/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php @@ -132,7 +132,7 @@ class TemplateScriptingCompiler { /** * list of loaded compiler plugin objects - * @var array + * @var array */ protected $compilerPlugins = array(); @@ -494,8 +494,8 @@ class TemplateScriptingCompiler { $this->compilerPlugins[$className] = new $className(); - if (!($this->compilerPlugins[$className] instanceof ITemplatePluginCompiler)) { - throw new SystemException($this->formatSyntaxError("Compiler plugin '".$tagCommand."' does not implement the interface 'ITemplatePluginCompiler'", $this->currentIdentifier)); + if (!($this->compilerPlugins[$className] instanceof ICompilerTemplatePlugin)) { + throw new SystemException($this->formatSyntaxError("Compiler plugin '".$tagCommand."' does not implement the interface 'ICompilerTemplatePlugin'", $this->currentIdentifier)); } } @@ -1364,11 +1364,11 @@ class TemplateScriptingCompiler { $prefilter = new $className(); } - if ($prefilter instanceof ITemplatePluginPrefilter) { + if ($prefilter instanceof IPrefilterTemplatePlugin) { $string = $prefilter->execute($templateName, $string, $this); } else { - throw new SystemException($this->formatSyntaxError("Prefilter '".$prefilter."' does not implement the interface 'ITemplatePluginPrefilter'", $this->currentIdentifier)); + throw new SystemException($this->formatSyntaxError("Prefilter '".$prefilter."' does not implement the interface 'IPrefilterTemplatePlugin'", $this->currentIdentifier)); } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..c443f2517e --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php @@ -0,0 +1,41 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class AppendCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + if (!isset($tagArgs['var'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in append tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + if (!isset($tagArgs['value'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in append tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + + return "append(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + throw new SystemException($compiler->formatSyntaxError("unknown tag {/append}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..209f07f607 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php @@ -0,0 +1,35 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class ArrayfromlistModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // TODO: doesn't work + // return Option::parseSelectOptions($tagArgs[0]); + return ''; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..965da43c35 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php @@ -0,0 +1,41 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class AssignCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + if (!isset($tagArgs['var'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in assign tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + if (!isset($tagArgs['value'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in assign tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + + return "assign(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + throw new SystemException($compiler->formatSyntaxError("unknown tag {/assign}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..31f3dde2a7 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php @@ -0,0 +1,37 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class ConcatModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\ITemplatePluginModifier::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + if (count($tagArgs) < 2) { + throw new SystemException("concat modifier needs two or more arguments"); + } + + $result = ''; + foreach ($tagArgs as $arg) { + $result .= $arg; + } + + return $result; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..0dd3c0967f --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php @@ -0,0 +1,77 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class CounterFunctionTemplatePlugin implements IFunctionTemplatePlugin { + protected $counters = array(); + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + if (!isset($tagArgs['name'])) { + $tagArgs['name'] = 'default'; + } + + if (!isset($this->counters[$tagArgs['name']])) { + $this->counters[$tagArgs['name']] = array( + 'start' => 1, + 'skip' => 1, + 'direction' => 'up', + 'count' => 1 + ); + } + + $counter =& $this->counters[$tagArgs['name']]; + + if (isset($tagArgs['start'])) { + $counter['start'] = $counter['count'] = intval($tagArgs['start']); + } + + if (isset($tagArgs['assign']) && !empty($tagArgs['assign'])) { + $counter['assign'] = $tagArgs['assign']; + } + + if (isset($counter['assign'])) { + $tplObj->assign($counter['assign'], $counter['count']); + } + + $result = null; + if (!isset($tagArgs['print']) || $tagArgs['print']) { + $result = $counter['count']; + } + + if (isset($tagArgs['skip'])) { + $counter['skip'] = intval($tagArgs['skip']); + } + + // get direction + if (isset($tagArgs['direction'])) { + $counter['direction'] = $tagArgs['direction']; + } + + if ($counter['direction'] == 'down') { + $counter['count'] -= $counter['skip']; + } + else { + $counter['count'] += $counter['skip']; + } + + return $result; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..c427079d7f --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php @@ -0,0 +1,92 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class CycleFunctionTemplatePlugin implements IFunctionTemplatePlugin { + protected $cycles = array(); + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // get params + $name = isset($tagArgs['name']) ? $tagArgs['name'] : 'default'; + $print = isset($tagArgs['print']) ? $tagArgs['print'] : 1; + $advance = isset($tagArgs['advance']) ? $tagArgs['advance'] : 1; + $reset = isset($tagArgs['reset']) ? $tagArgs['reset'] : 0; + + // get values + if (!isset($tagArgs['values']) ) { + if (!isset($this->cycles[$name]['values'])) { + throw new SystemException("missing 'values' argument in cycle tag"); + } + } + else { + if (isset($this->cycles[$name]['values']) && $this->cycles[$name]['values'] != $tagArgs['values'] ) { + $this->cycles[$name]['index'] = 0; + } + $this->cycles[$name]['values'] = $tagArgs['values']; + } + + // get delimiter + if (!isset($this->cycles[$name]['delimiter'])) { + // set default delimiter + $this->cycles[$name]['delimiter'] = ','; + } + if (isset($tagArgs['delimiter'])) { + $this->cycles[$name]['delimiter'] = $tagArgs['delimiter']; + } + + // split values + if (is_array($this->cycles[$name]['values'])) { + $cycleArray = $this->cycles[$name]['values']; + } + else { + $cycleArray = explode($this->cycles[$name]['delimiter'], $this->cycles[$name]['values']); + } + + // set index + if (!isset($this->cycles[$name]['index']) || $reset) { + $this->cycles[$name]['index'] = 0; + } + + // get result + $result = $cycleArray[$this->cycles[$name]['index']]; + + // assign result to template var + if (isset($tagArgs['assign'])) { + $print = false; + $tplObj->assign($tagArgs['assign'], $result); + } + + // update index + if ($advance) { + if ($this->cycles[$name]['index'] >= count($cycleArray) - 1) { + $this->cycles[$name]['index'] = 0; + } + else { + $this->cycles[$name]['index']++; + } + } + + // print var + if ($print) { + return $result; + } + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/DateModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/DateModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..ba81a4a1d3 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/DateModifierTemplatePlugin.class.php @@ -0,0 +1,29 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class DateModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + return DateUtil::format(DateUtil::getDateTimeByTimestamp($tagArgs[0]), (!empty($tagArgs[2]) ? $tagArgs[2] : DateUtil::DATE_FORMAT)); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/DatediffModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/DatediffModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..2025c7fb5a --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/DatediffModifierTemplatePlugin.class.php @@ -0,0 +1,35 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class DatediffModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // get timestamps + if (!isset($tagArgs[1])) $tagArgs[1] = TIME_NOW; + $start = min($tagArgs[0], $tagArgs[1]); + $end = max($tagArgs[0], $tagArgs[1]); + + // TODO: method doesn't exists anymore + // return DateUtil::diff($start, $end, 'string'); + return ''; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/EncodejsModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/EncodejsModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..0935ec65fa --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/EncodejsModifierTemplatePlugin.class.php @@ -0,0 +1,41 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class EncodejsModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // escape backslash + $tagArgs[0] = StringUtil::replace("\\", "\\\\", $tagArgs[0]); + + // escape singe quote + $tagArgs[0] = StringUtil::replace("'", "\'", $tagArgs[0]); + + // escape new lines + $tagArgs[0] = StringUtil::replace("\n", '\n', $tagArgs[0]); + + // escape slashes + $tagArgs[0] = StringUtil::replace("/", '\/', $tagArgs[0]); + + return $tagArgs[0]; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/EventPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/EventPrefilterTemplatePlugin.class.php new file mode 100644 index 0000000000..1d256907c8 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/EventPrefilterTemplatePlugin.class.php @@ -0,0 +1,30 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class EventPrefilterTemplatePlugin implements IPrefilterTemplatePlugin { + /** + * @see wcf\system\template\IPrefilterTemplatePlugin::execute() + */ + public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler) { + $ldq = preg_quote($compiler->getLeftDelimiter(), '~'); + $rdq = preg_quote($compiler->getRightDelimiter(), '~'); + $sourceContent = preg_replace("~{$ldq}event\ name\=\'([\w]+)\'{$rdq}~e", 'wcf\system\WCF::getTPL()->getTemplateListenerCode(\''.$templateName.'\', \'$1\')', $sourceContent); + + return $sourceContent; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..106fd61a31 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php @@ -0,0 +1,44 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class FetchCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + if (!isset($tagArgs['file'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'file' argument in fetch tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + + if (isset($tagArgs['assign'])) { + return "assign(".$tagArgs['assign'].", @file_get_contents(".$tagArgs['file'].")); ?>"; + } + else { + return ""; + } + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + throw new SystemException($compiler->formatSyntaxError("unknown tag {/fetch}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/FilesizeBinaryModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/FilesizeBinaryModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..27aacf0c06 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/FilesizeBinaryModifierTemplatePlugin.class.php @@ -0,0 +1,28 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class FilesizeBinaryModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + return FileUtil::formatFilesizeBinary($tagArgs[0]); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/FilesizeModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/FilesizeModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..1cbfcf8273 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/FilesizeModifierTemplatePlugin.class.php @@ -0,0 +1,28 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class FilesizeModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + return FileUtil::formatFilesize($tagArgs[0]); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/HascontentPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/HascontentPrefilterTemplatePlugin.class.php new file mode 100644 index 0000000000..12d3fb6f90 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/HascontentPrefilterTemplatePlugin.class.php @@ -0,0 +1,70 @@ + + * {content} + * {if $foo}
  • bar
  • {/if} + * {/content} + * + * {hascontentelse} + *

    baz

    + * {/hascontent} + * + * @author Alexander Ebert + * @copyright 2001-2011 WoltLab GmbH + * @license GNU Lesser General Public License + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class HascontentPrefilterTemplatePlugin implements IPrefilterTemplatePlugin { + /** + * @see wcf\system\template\IPrefilterTemplatePlugin::execute() + */ + public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler) { + $ldq = preg_quote($compiler->getLeftDelimiter(), '~'); + $rdq = preg_quote($compiler->getRightDelimiter(), '~'); + + $sourceContent = preg_replace_callback("~{$ldq}hascontent{$rdq}(.*){$ldq}content{$rdq}(.*){$ldq}\/content{$rdq}(.*)({$ldq}hascontentelse{$rdq}(.*))?{$ldq}\/hascontent{$rdq}~sU", array('self', 'replaceContentCallback'), $sourceContent); + + return $sourceContent; + } + + /** + * Reorders content to provide a logical order. In fact the content of + * '{content}' is moved outside the if-condition in order to capture + * the content during runtime, safely determining wether content is empty + * or not. + * + * @param array $matches + * @return string + */ + protected static function replaceContentCallback(array $matches) { + $beforeContent = $matches[1]; + $content = $matches[2]; + $afterContent = $matches[3]; + $elseContent = (isset($matches[5])) ? $matches[5] : ''; + + $variable = 'hascontent_' . StringUtil::getRandomID(); + + $newContent = '{capture assign='.$variable.'}'.$content.'{/capture}'."\n"; + $newContent .= '{assign var='.$variable.' value=$'.$variable.'|trim}'."\n"; + $newContent .= '{if $'.$variable.'}'.$beforeContent.'{@$'.$variable.'}'."\n".$afterContent; + + if (!empty($elseContent)) { + $newContent .= '{else}'.$elseContent."\n"; + } + + $newContent .= '{/if}'."\n"; + + return $newContent; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..68cbb284d0 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php @@ -0,0 +1,88 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class HtmlcheckboxesFunctionTemplatePlugin implements IFunctionTemplatePlugin { + protected $disableEncoding = false; + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // get options + if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { + if (isset($tagArgs['values']) && is_array($tagArgs['values'])) { + $tagArgs['options'] = array_combine($tagArgs['values'], $tagArgs['output']); + } + else { + $tagArgs['options'] = array_combine($tagArgs['output'], $tagArgs['output']); + } + } + + if (!isset($tagArgs['options']) || !is_array($tagArgs['options'])) { + throw new SystemException("missing 'options' argument in htmlCheckboxes tag"); + } + + if (!isset($tagArgs['name'])) { + throw new SystemException("missing 'name' argument in htmlCheckboxes tag"); + } + + if (isset($tagArgs['disableEncoding']) && $tagArgs['disableEncoding']) { + $this->disableEncoding = true; + } + else { + $this->disableEncoding = false; + } + + // get selected values + if (isset($tagArgs['selected'])) { + if (!is_array($tagArgs['selected'])) $tagArgs['selected'] = array($tagArgs['selected']); + } + else { + $tagArgs['selected'] = array(); + } + if (!isset($tagArgs['separator'])) { + $tagArgs['separator'] = ''; + } + + // build html + $html = ''; + foreach ($tagArgs['options'] as $key => $value) { + if (!empty($html)) $html .= $tagArgs['separator']; + $html .= ''; + } + + return $html; + } + + /** + * Executes StringUtil::encodeHTML on the given text if disableEncoding is false. + * @see wcf\util\StringUtil::encodeHTML() + */ + protected function encodeHTML($text) { + if (!$this->disableEncoding) { + $text = StringUtil::encodeHTML($text); + } + + return $text; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..e474cc017b --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php @@ -0,0 +1,128 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class HtmloptionsFunctionTemplatePlugin extends HtmlcheckboxesFunctionTemplatePlugin { + protected $selected = array(); + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { + if (count($tagArgs['output'])) { + if (isset($tagArgs['values']) && is_array($tagArgs['values'])) { + if (count($tagArgs['output']) == count($tagArgs['values'])) { + $tagArgs['options'] = array_combine($tagArgs['values'], $tagArgs['output']); + } + else { + $tagArgs['options'] = array(); + } + } + else { + $tagArgs['options'] = array_combine($tagArgs['output'], $tagArgs['output']); + } + } + else { + $tagArgs['options'] = array(); + } + } + + if (!isset($tagArgs['options']) || !is_array($tagArgs['options'])) { + throw new SystemException("missing 'options' argument in htmloptions tag"); + } + + if (isset($tagArgs['disableEncoding']) && $tagArgs['disableEncoding']) { + $this->disableEncoding = true; + } + else { + $this->disableEncoding = false; + } + + // get selected values + $this->selected = array(); + if (isset($tagArgs['selected'])) { + $this->selected = $tagArgs['selected']; + if (!is_array($this->selected)) $this->selected = array($this->selected); + } + + // create option list + $htmloptions = $this->makeOptionGroup(null, $tagArgs['options']); + + // create also a 'select' tag + if (isset($tagArgs['name'])) { + // unset all system vars + unset($tagArgs['options'], $tagArgs['selected'], $tagArgs['output'], $tagArgs['values'], $tagArgs['disableEncoding']); + + // generate 'select' parameters + $params = ''; + foreach ($tagArgs as $key => $value) { + $params .= ' '.$key.'="'.$this->encodeHTML($value).'"'; + } + + $htmloptions = ''."\n".$htmloptions."\n"; + } + + return $htmloptions; + } + + /** + * Makes the html for an option group. + * + * @param string $key + * @param array $values + * @return string html code of an option group + */ + protected function makeOptionGroup($key, $values) { + $html = ''; + if ($key !== null) { + $html = ''."\n"; + } + + foreach ($values as $childKey => $value) { + if (is_array($value)) { + $html .= $this->makeOptionGroup($childKey, $value); + } + else { + $html .= $this->makeOption($childKey, $value); + } + } + + if ($key !== null) { + $html .= "\n"; + } + + return $html; + } + + /** + * Makes the html for an option. + * + * @param string $key + * @param string $value + * @return string html code of an option tag + */ + protected function makeOption($key, $value) { + $value = $this->encodeHTML($value); + return '\n"; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..192c73f3a0 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php @@ -0,0 +1,37 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class IconCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + $compiler->pushTag('icon'); + return ""; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + $compiler->popTag('icon'); + $hash = StringUtil::getRandomID(); + return "getStyle()->getIconPath(\$_icon".$hash."); ?>"; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php new file mode 100644 index 0000000000..b05bc4d1bb --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php @@ -0,0 +1,30 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class IconPrefilterTemplatePlugin implements IPrefilterTemplatePlugin { + /** + * @see wcf\system\template\ITemplatePluginPrefilter::execute() + */ + public function execute($sourceContent, TemplateScriptingCompiler $compiler) { + $ldq = preg_quote($compiler->getLeftDelimiter(), '~'); + $rdq = preg_quote($compiler->getRightDelimiter(), '~'); + $sourceContent = preg_replace("~{$ldq}icon{$rdq}([\w\.]+){$ldq}/icon{$rdq}~", '{literal}getStyle()->getIconPath(\'$1\'); ?>{/literal}', $sourceContent); + + return $sourceContent; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..b99a6e683c --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php @@ -0,0 +1,61 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class ImplodeCompilerTemplatePlugin implements ICompilerTemplatePlugin { + protected $tagStack = array(); + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + $compiler->pushTag('implode'); + + if (!isset($tagArgs['from'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'from' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + if (!isset($tagArgs['item'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'item' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + + $hash = StringUtil::getRandomID(); + $glue = isset($tagArgs['glue']) ? $tagArgs['glue'] : "', '"; + $this->tagStack[] = array('hash' => $hash, 'glue' => $glue); + + $phpCode = "v[".$tagArgs['key']."]" : $tagArgs['key'])." => " : '').(StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[".$tagArgs['item']."]" : $tagArgs['item']).") { ?>"; + return $phpCode; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + $compiler->popTag('implode'); + $tagArgs = array_pop($this->tagStack); + + $phpCode = ""; + + return $phpCode; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..baa16960be --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php @@ -0,0 +1,45 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class LangCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + $compiler->pushTag('lang'); + + $newTagArgs = array(); + foreach ($tagArgs as $key => $arg) { + $newTagArgs[$key] = 'wcf\util\StringUtil::encodeHTML('.$arg.')'; + } + + $tagArgs = $compiler->makeArgString($newTagArgs); + return "tagStack[] = array('lang', array($tagArgs)); ob_start(); ?>"; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + $compiler->popTag('lang'); + $hash = StringUtil::getRandomID(); + return "getDynamicVariable(\$_lang".$hash.", \$this->tagStack[count(\$this->tagStack) - 1][1]); array_pop(\$this->tagStack); ?>"; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php new file mode 100644 index 0000000000..03cbdd09a2 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php @@ -0,0 +1,34 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class LangPrefilterTemplatePlugin implements IPrefilterTemplatePlugin { + /** + * @see wcf\system\template\IPrefilterTemplatePlugin::execute() + */ + public function execute($templateName, $sourceContent, TemplateScriptingCompiler $compiler) { + $ldq = preg_quote($compiler->getLeftDelimiter(), '~'); + $rdq = preg_quote($compiler->getRightDelimiter(), '~'); + $sourceContent = preg_replace("~{$ldq}lang{$rdq}([\w\.]+){$ldq}/lang{$rdq}~e", 'wcf\system\WCF::getLanguage()->get(\'$1\')', $sourceContent); + + return $sourceContent; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php new file mode 100644 index 0000000000..33b496cb38 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php @@ -0,0 +1,57 @@ +getLink() in template scripting. + * + * Usage: + * {link application='wcf'}index.php{/link} + * + * @author Marcel Werk + * @copyright 2001-2011 WoltLab GmbH + * @license GNU Lesser General Public License + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class LinkBlockTemplatePlugin implements IBlockTemplatePlugin { + /** + * internal loop counter + * @var integer + */ + protected $counter = 0; + + /** + * @see wcf\system\template\IBlockTemplatePlugin::execute() + */ + public function execute($tagArgs, $blockContent, TemplateEngine $tplObj) { + $application = 'wcf'; + if (!empty($tagArgs['application'])) { + $application = $tagArgs['application']; + } + + return LinkHandler::getInstance()->getLink($blockContent, $application); + } + + /** + * @see wcf\system\template\IBlockTemplatePlugin::init() + */ + public function init($tagArgs, TemplateEngine $tplObj) { + $this->counter = 0; + } + + /** + * @see wcf\system\template\IBlockTemplatePlugin::next() + */ + public function next(TemplateEngine $tplObj) { + if ($this->counter == 0) { + $this->counter++; + return true; + } + + return false; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..72495b4c17 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php @@ -0,0 +1,220 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin { + const SHOW_LINKS = 11; + const SHOW_SUB_LINKS = 20; + + /** + * Inserts the page number into the link. + * + * @param string $link + * @param integer $pageNo + * @return string final link + */ + protected static function insertPageNumber($link, $pageNo) { + $startPos = StringUtil::indexOf($link, '%d'); + if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2); + return $link; + } + + /** + * Generates html code of a link. + * + * @param string $link + * @param integer $pageNo + * @param integer $activePage + * @param boolean $break + * @return string + */ + protected function makeLink($link, $pageNo, $activePage, $break = false) { + // first page + if ($activePage != $pageNo) { + return ''.StringUtil::formatInteger($pageNo).''."\n"; + } + else { + return '
  • '.StringUtil::formatInteger($pageNo).'
  • '."\n"; + } + } + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // needed params: link, page, pages + if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in pages tag"); + if (!isset($tagArgs['pages'])) { + if (($tagArgs['pages'] = $tplObj->get('pages')) === null) { + throw new SystemException("missing 'pages' argument in pages tag"); + } + } + + $html = ''; + + if ($tagArgs['pages'] > 1) { + // define page link for js function + $html .= ""; + + // encode link + $tagArgs['link'] = StringUtil::encodeHTML($tagArgs['link']); + + if (!isset($tagArgs['page'])) { + if (($tagArgs['page'] = $tplObj->get('pageNo')) === null) { + $tagArgs['page'] = 0; + } + } + + // open div and ul + $html .= "
    \n
      \n"; + + // previous page + $previousTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.previous'); + if ($tagArgs['page'] > 1) { + $html .= ''."\n"; + } + else { + $html .= ''."\n"; + } + + // first page + $html .= $this->makeLink($tagArgs['link'], 1, $tagArgs['page']); + + // calculate page links + $maxLinks = self::SHOW_LINKS - 4; + $linksBeforePage = $tagArgs['page'] - 2; + if ($linksBeforePage < 0) $linksBeforePage = 0; + $linksAfterPage = $tagArgs['pages'] - ($tagArgs['page'] + 1); + if ($linksAfterPage < 0) $linksAfterPage = 0; + if ($tagArgs['page'] > 1 && $tagArgs['page'] < $tagArgs['pages']) { + $maxLinks--; + } + + $half = $maxLinks / 2; + $left = $right = $tagArgs['page']; + if ($left < 1) $left = 1; + if ($right < 1) $right = 1; + if ($right > $tagArgs['pages'] - 1) $right = $tagArgs['pages'] - 1; + + if ($linksBeforePage >= $half) { + $left -= $half; + } + else { + $left -= $linksBeforePage; + $right += $half - $linksBeforePage; + } + + if ($linksAfterPage >= $half) { + $right += $half; + } + else { + $right += $linksAfterPage; + $left -= $half - $linksAfterPage; + } + + $right = intval(ceil($right)); + $left = intval(ceil($left)); + if ($left < 1) $left = 1; + if ($right > $tagArgs['pages']) $right = $tagArgs['pages']; + + // left ... links + if ($left > 1) { + if ($left - 1 < 2) { + $html .= $this->makeLink($tagArgs['link'], 2, $tagArgs['page']); + } + else { + $html .= '
      • '."\n"; + + $k = 0; + $step = intval(ceil(($left - 2) / self::SHOW_SUB_LINKS)); + for ($i = 2; $i <= $left; $i += $step) { + $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0); + $k++; + } + + $html .= "
    • \n"; + } + } + + // visible links + for ($i = $left + 1; $i < $right; $i++) { + $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page']); + } + + // right ... links + if ($right < $tagArgs['pages']) { + if ($tagArgs['pages'] - $right < 2) { + $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'] - 1, $tagArgs['page']); + } + else { + $html .= '
      • '."\n"; + + $k = 0; + $step = intval(ceil(($tagArgs['pages'] - $right) / self::SHOW_SUB_LINKS)); + for ($i = $right; $i < $tagArgs['pages']; $i += $step) { + $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0); + $k++; + } + + $html .= "
    • \n"; + } + } + + // last page + $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'], $tagArgs['page']); + + // next page + $nextTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.next'); + if ($tagArgs['page'] && $tagArgs['page'] < $tagArgs['pages']) { + $html .= ''."\n"; + } + else { + $html .= ''."\n"; + } + + // close div and ul + $html .= "
    \n"; + } + + // assign html output to template var + if (isset($tagArgs['assign'])) { + $tplObj->assign($tagArgs['assign'], $html); + if (!isset($tagArgs['print']) || !$tagArgs['print']) return ''; + } + + return $html; + } + + private static function getIconPath($filename) { + if (class_exists('StyleManager')) { + return StyleManager::getStyle()->getIconPath($filename); + } + else { + return RELATIVE_WCF_DIR.'icon/'.$filename; + } + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/PlainTimeModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/PlainTimeModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..941153ad10 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/PlainTimeModifierTemplatePlugin.class.php @@ -0,0 +1,31 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class PlainTimeModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + $dateTime = DateUtil::getDateTimeByTimestamp($tagArgs[0]); + return str_replace('%time%', DateUtil::format($dateTime, DateUtil::TIME_FORMAT), str_replace('%date%', DateUtil::format($dateTime, DateUtil::DATE_FORMAT), WCF::getLanguage()->get('wcf.global.date.dateTimeFormat'))); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php new file mode 100644 index 0000000000..5400da72ae --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php @@ -0,0 +1,42 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class PrependCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + if (!isset($tagArgs['var'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in prepend tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + if (!isset($tagArgs['value'])) { + throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in prepend tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } + + return "prepend(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + throw new SystemException($compiler->formatSyntaxError("unknown tag {/prepend}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php new file mode 100644 index 0000000000..d0022e6b8b --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php @@ -0,0 +1,105 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class SmallpagesFunctionTemplatePlugin implements IFunctionTemplatePlugin { + const SHOW_LINKS = 5; + + /** + * Inserts the page number into the link. + * + * @param string $link + * @param integer $pageNo + * @return string final link + */ + protected static function insertPageNumber($link, $pageNo) { + $startPos = StringUtil::indexOf($link, '%d'); + if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2); + return $link; + } + + /** + * Generates html code of a link. + * + * @param string $link + * @param integer $pageNo + * @return string + */ + protected function makeLink($link, $pageNo) { + return '
  • '.StringUtil::formatInteger($pageNo).'
  • '."\n"; + } + + /** + * @see wcf\system\template\IFunctionTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // needed params: link, pages + if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in pages tag"); + if (!isset($tagArgs['pages'])) { + if (($tagArgs['pages'] = $tplObj->get('pages')) === null) { + throw new SystemException("missing 'pages' argument in pages tag"); + } + } + + $html = ''; + if ($tagArgs['pages'] > 1) { + // encode link + $link = StringUtil::encodeHTML($tagArgs['link']); + + // open div and ul + $html .= "
    \n
      \n"; + + // generate simple links + $simpleLinks = $tagArgs['pages']; + if ($simpleLinks > self::SHOW_LINKS) { + $simpleLinks = self::SHOW_LINKS - 2; + } + + for ($i = 1; $i <= $simpleLinks; $i++) { + $html .= $this->makeLink($link, $i); + } + + if ($tagArgs['pages'] > self::SHOW_LINKS) { + // jumper + $html .= '
    • '."\n"; + + // last page + $html .= $this->makeLink($link, $tagArgs['pages']); + } + + // close div and ul + $html .= "
    \n"; + } + + // assign html output to template var + if (isset($tagArgs['assign'])) { + $tplObj->assign($tagArgs['assign'], $html); + if (!isset($tagArgs['print']) || !$tagArgs['print']) return ''; + } + + return $html; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php new file mode 100644 index 0000000000..0b76cd8056 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php @@ -0,0 +1,38 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class StaticlangCompilerTemplatePlugin implements ICompilerTemplatePlugin { + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() + */ + public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { + $compiler->pushTag('staticlang'); + + return ""; + } + + /** + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() + */ + public function executeEnd(TemplateScriptingCompiler $compiler) { + $compiler->popTag('staticlang'); + $hash = StringUtil::getRandomID(); + return "get(\$_lang".$hash."); ?>"; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginBlockLink.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginBlockLink.class.php deleted file mode 100644 index 7861d47b1d..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginBlockLink.class.php +++ /dev/null @@ -1,57 +0,0 @@ -getLink() in template scripting. - * - * Usage: - * {link application='wcf'}index.php{/link} - * - * @author Marcel Werk - * @copyright 2001-2011 WoltLab GmbH - * @license GNU Lesser General Public License - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginBlockLink implements ITemplatePluginBlock { - /** - * internal loop counter - * @var integer - */ - protected $counter = 0; - - /** - * @see wcf\system\template\ITemplatePluginBlock::execute() - */ - public function execute($tagArgs, $blockContent, TemplateEngine $tplObj) { - $application = 'wcf'; - if (!empty($tagArgs['application'])) { - $application = $tagArgs['application']; - } - - return LinkHandler::getInstance()->getLink($blockContent, $application); - } - - /** - * @see wcf\system\template\ITemplatePluginBlock::init() - */ - public function init($tagArgs, TemplateEngine $tplObj) { - $this->counter = 0; - } - - /** - * @see wcf\system\template\ITemplatePluginBlock::next() - */ - public function next(TemplateEngine $tplObj) { - if ($this->counter == 0) { - $this->counter++; - return true; - } - - return false; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAppend.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAppend.class.php deleted file mode 100644 index cbb480821a..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAppend.class.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerAppend implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - if (!isset($tagArgs['var'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in append tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - if (!isset($tagArgs['value'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in append tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - - return "append(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - throw new SystemException($compiler->formatSyntaxError("unknown tag {/append}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php deleted file mode 100644 index 9ae7d4da40..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerAssign implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - if (!isset($tagArgs['var'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in assign tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - if (!isset($tagArgs['value'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in assign tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - - return "assign(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - throw new SystemException($compiler->formatSyntaxError("unknown tag {/assign}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerFetch.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerFetch.class.php deleted file mode 100644 index 378b7be0cf..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerFetch.class.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerFetch implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - if (!isset($tagArgs['file'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'file' argument in fetch tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - - if (isset($tagArgs['assign'])) { - return "assign(".$tagArgs['assign'].", @file_get_contents(".$tagArgs['file'].")); ?>"; - } - else { - return ""; - } - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - throw new SystemException($compiler->formatSyntaxError("unknown tag {/fetch}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php deleted file mode 100644 index a4b0b109e6..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerIcon implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - $compiler->pushTag('icon'); - return ""; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - $compiler->popTag('icon'); - $hash = StringUtil::getRandomID(); - return "getStyle()->getIconPath(\$_icon".$hash."); ?>"; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerImplode.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerImplode.class.php deleted file mode 100644 index 25bb79a33b..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerImplode.class.php +++ /dev/null @@ -1,61 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerImplode implements ITemplatePluginCompiler { - protected $tagStack = array(); - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - $compiler->pushTag('implode'); - - if (!isset($tagArgs['from'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'from' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - if (!isset($tagArgs['item'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'item' argument in implode tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - - $hash = StringUtil::getRandomID(); - $glue = isset($tagArgs['glue']) ? $tagArgs['glue'] : "', '"; - $this->tagStack[] = array('hash' => $hash, 'glue' => $glue); - - $phpCode = "v[".$tagArgs['key']."]" : $tagArgs['key'])." => " : '').(StringUtil::substring($tagArgs['item'], 0, 1) != '$' ? "\$this->v[".$tagArgs['item']."]" : $tagArgs['item']).") { ?>"; - return $phpCode; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - $compiler->popTag('implode'); - $tagArgs = array_pop($this->tagStack); - - $phpCode = ""; - - return $phpCode; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php deleted file mode 100644 index a1a76c612a..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerLang implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - $compiler->pushTag('lang'); - - $newTagArgs = array(); - foreach ($tagArgs as $key => $arg) { - $newTagArgs[$key] = 'wcf\util\StringUtil::encodeHTML('.$arg.')'; - } - - $tagArgs = $compiler->makeArgString($newTagArgs); - return "tagStack[] = array('lang', array($tagArgs)); ob_start(); ?>"; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - $compiler->popTag('lang'); - $hash = StringUtil::getRandomID(); - return "getDynamicVariable(\$_lang".$hash.", \$this->tagStack[count(\$this->tagStack) - 1][1]); array_pop(\$this->tagStack); ?>"; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerPrepend.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerPrepend.class.php deleted file mode 100644 index 4ac7471a21..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerPrepend.class.php +++ /dev/null @@ -1,41 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerPrepend implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - if (!isset($tagArgs['var'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'var' argument in prepend tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - if (!isset($tagArgs['value'])) { - throw new SystemException($compiler->formatSyntaxError("missing 'value' argument in prepend tag", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } - - return "prepend(".$tagArgs['var'].", ".$tagArgs['value']."); ?>"; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - throw new SystemException($compiler->formatSyntaxError("unknown tag {/prepend}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php deleted file mode 100644 index f92a62be59..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginCompilerStaticlang implements ITemplatePluginCompiler { - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() - */ - public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { - $compiler->pushTag('staticlang'); - - return ""; - } - - /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() - */ - public function executeEnd(TemplateScriptingCompiler $compiler) { - $compiler->popTag('staticlang'); - $hash = StringUtil::getRandomID(); - return "get(\$_lang".$hash."); ?>"; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php deleted file mode 100644 index ccc80f0ef4..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php +++ /dev/null @@ -1,77 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionCounter implements ITemplatePluginFunction { - protected $counters = array(); - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - if (!isset($tagArgs['name'])) { - $tagArgs['name'] = 'default'; - } - - if (!isset($this->counters[$tagArgs['name']])) { - $this->counters[$tagArgs['name']] = array( - 'start' => 1, - 'skip' => 1, - 'direction' => 'up', - 'count' => 1 - ); - } - - $counter =& $this->counters[$tagArgs['name']]; - - if (isset($tagArgs['start'])) { - $counter['start'] = $counter['count'] = intval($tagArgs['start']); - } - - if (isset($tagArgs['assign']) && !empty($tagArgs['assign'])) { - $counter['assign'] = $tagArgs['assign']; - } - - if (isset($counter['assign'])) { - $tplObj->assign($counter['assign'], $counter['count']); - } - - $result = null; - if (!isset($tagArgs['print']) || $tagArgs['print']) { - $result = $counter['count']; - } - - if (isset($tagArgs['skip'])) { - $counter['skip'] = intval($tagArgs['skip']); - } - - // get direction - if (isset($tagArgs['direction'])) { - $counter['direction'] = $tagArgs['direction']; - } - - if ($counter['direction'] == 'down') { - $counter['count'] -= $counter['skip']; - } - else { - $counter['count'] += $counter['skip']; - } - - return $result; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php deleted file mode 100644 index b6e9750fc0..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionCycle implements ITemplatePluginFunction { - protected $cycles = array(); - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - // get params - $name = isset($tagArgs['name']) ? $tagArgs['name'] : 'default'; - $print = isset($tagArgs['print']) ? $tagArgs['print'] : 1; - $advance = isset($tagArgs['advance']) ? $tagArgs['advance'] : 1; - $reset = isset($tagArgs['reset']) ? $tagArgs['reset'] : 0; - - // get values - if (!isset($tagArgs['values']) ) { - if (!isset($this->cycles[$name]['values'])) { - throw new SystemException("missing 'values' argument in cycle tag"); - } - } - else { - if (isset($this->cycles[$name]['values']) && $this->cycles[$name]['values'] != $tagArgs['values'] ) { - $this->cycles[$name]['index'] = 0; - } - $this->cycles[$name]['values'] = $tagArgs['values']; - } - - // get delimiter - if (!isset($this->cycles[$name]['delimiter'])) { - // set default delimiter - $this->cycles[$name]['delimiter'] = ','; - } - if (isset($tagArgs['delimiter'])) { - $this->cycles[$name]['delimiter'] = $tagArgs['delimiter']; - } - - // split values - if (is_array($this->cycles[$name]['values'])) { - $cycleArray = $this->cycles[$name]['values']; - } - else { - $cycleArray = explode($this->cycles[$name]['delimiter'], $this->cycles[$name]['values']); - } - - // set index - if (!isset($this->cycles[$name]['index']) || $reset) { - $this->cycles[$name]['index'] = 0; - } - - // get result - $result = $cycleArray[$this->cycles[$name]['index']]; - - // assign result to template var - if (isset($tagArgs['assign'])) { - $print = false; - $tplObj->assign($tagArgs['assign'], $result); - } - - // update index - if ($advance) { - if ($this->cycles[$name]['index'] >= count($cycleArray) - 1) { - $this->cycles[$name]['index'] = 0; - } - else { - $this->cycles[$name]['index']++; - } - } - - // print var - if ($print) { - return $result; - } - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmlcheckboxes.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmlcheckboxes.class.php deleted file mode 100644 index f80658a6da..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmlcheckboxes.class.php +++ /dev/null @@ -1,88 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionHtmlcheckboxes implements ITemplatePluginFunction { - protected $disableEncoding = false; - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - // get options - if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { - if (isset($tagArgs['values']) && is_array($tagArgs['values'])) { - $tagArgs['options'] = array_combine($tagArgs['values'], $tagArgs['output']); - } - else { - $tagArgs['options'] = array_combine($tagArgs['output'], $tagArgs['output']); - } - } - - if (!isset($tagArgs['options']) || !is_array($tagArgs['options'])) { - throw new SystemException("missing 'options' argument in htmlCheckboxes tag"); - } - - if (!isset($tagArgs['name'])) { - throw new SystemException("missing 'name' argument in htmlCheckboxes tag"); - } - - if (isset($tagArgs['disableEncoding']) && $tagArgs['disableEncoding']) { - $this->disableEncoding = true; - } - else { - $this->disableEncoding = false; - } - - // get selected values - if (isset($tagArgs['selected'])) { - if (!is_array($tagArgs['selected'])) $tagArgs['selected'] = array($tagArgs['selected']); - } - else { - $tagArgs['selected'] = array(); - } - if (!isset($tagArgs['separator'])) { - $tagArgs['separator'] = ''; - } - - // build html - $html = ''; - foreach ($tagArgs['options'] as $key => $value) { - if (!empty($html)) $html .= $tagArgs['separator']; - $html .= ''; - } - - return $html; - } - - /** - * Executes StringUtil::encodeHTML on the given text if disableEncoding is false. - * @see wcf\util\StringUtil::encodeHTML() - */ - protected function encodeHTML($text) { - if (!$this->disableEncoding) { - $text = StringUtil::encodeHTML($text); - } - - return $text; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php deleted file mode 100644 index 7fa8c19e9a..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionHtmloptions extends TemplatePluginFunctionHtmlcheckboxes { - protected $selected = array(); - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { - if (count($tagArgs['output'])) { - if (isset($tagArgs['values']) && is_array($tagArgs['values'])) { - if (count($tagArgs['output']) == count($tagArgs['values'])) { - $tagArgs['options'] = array_combine($tagArgs['values'], $tagArgs['output']); - } - else { - $tagArgs['options'] = array(); - } - } - else { - $tagArgs['options'] = array_combine($tagArgs['output'], $tagArgs['output']); - } - } - else { - $tagArgs['options'] = array(); - } - } - - if (!isset($tagArgs['options']) || !is_array($tagArgs['options'])) { - throw new SystemException("missing 'options' argument in htmloptions tag"); - } - - if (isset($tagArgs['disableEncoding']) && $tagArgs['disableEncoding']) { - $this->disableEncoding = true; - } - else { - $this->disableEncoding = false; - } - - // get selected values - $this->selected = array(); - if (isset($tagArgs['selected'])) { - $this->selected = $tagArgs['selected']; - if (!is_array($this->selected)) $this->selected = array($this->selected); - } - - // create option list - $htmloptions = $this->makeOptionGroup(null, $tagArgs['options']); - - // create also a 'select' tag - if (isset($tagArgs['name'])) { - // unset all system vars - unset($tagArgs['options'], $tagArgs['selected'], $tagArgs['output'], $tagArgs['values'], $tagArgs['disableEncoding']); - - // generate 'select' parameters - $params = ''; - foreach ($tagArgs as $key => $value) { - $params .= ' '.$key.'="'.$this->encodeHTML($value).'"'; - } - - $htmloptions = ''."\n".$htmloptions."\n"; - } - - return $htmloptions; - } - - /** - * Makes the html for an option group. - * - * @param string $key - * @param array $values - * @return string html code of an option group - */ - protected function makeOptionGroup($key, $values) { - $html = ''; - if ($key !== null) { - $html = ''."\n"; - } - - foreach ($values as $childKey => $value) { - if (is_array($value)) { - $html .= $this->makeOptionGroup($childKey, $value); - } - else { - $html .= $this->makeOption($childKey, $value); - } - } - - if ($key !== null) { - $html .= "\n"; - } - - return $html; - } - - /** - * Makes the html for an option. - * - * @param string $key - * @param string $value - * @return string html code of an option tag - */ - protected function makeOption($key, $value) { - $value = $this->encodeHTML($value); - return '\n"; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php deleted file mode 100644 index 86f85c6608..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php +++ /dev/null @@ -1,220 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionPages implements ITemplatePluginFunction { - const SHOW_LINKS = 11; - const SHOW_SUB_LINKS = 20; - - /** - * Inserts the page number into the link. - * - * @param string $link - * @param integer $pageNo - * @return string final link - */ - protected static function insertPageNumber($link, $pageNo) { - $startPos = StringUtil::indexOf($link, '%d'); - if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2); - return $link; - } - - /** - * Generates html code of a link. - * - * @param string $link - * @param integer $pageNo - * @param integer $activePage - * @param boolean $break - * @return string - */ - protected function makeLink($link, $pageNo, $activePage, $break = false) { - // first page - if ($activePage != $pageNo) { - return ''.StringUtil::formatInteger($pageNo).''."\n"; - } - else { - return '
  • '.StringUtil::formatInteger($pageNo).'
  • '."\n"; - } - } - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - // needed params: link, page, pages - if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in pages tag"); - if (!isset($tagArgs['pages'])) { - if (($tagArgs['pages'] = $tplObj->get('pages')) === null) { - throw new SystemException("missing 'pages' argument in pages tag"); - } - } - - $html = ''; - - if ($tagArgs['pages'] > 1) { - // define page link for js function - $html .= ""; - - // encode link - $tagArgs['link'] = StringUtil::encodeHTML($tagArgs['link']); - - if (!isset($tagArgs['page'])) { - if (($tagArgs['page'] = $tplObj->get('pageNo')) === null) { - $tagArgs['page'] = 0; - } - } - - // open div and ul - $html .= "
    \n
      \n"; - - // previous page - $previousTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.previous'); - if ($tagArgs['page'] > 1) { - $html .= ''."\n"; - } - else { - $html .= ''."\n"; - } - - // first page - $html .= $this->makeLink($tagArgs['link'], 1, $tagArgs['page']); - - // calculate page links - $maxLinks = self::SHOW_LINKS - 4; - $linksBeforePage = $tagArgs['page'] - 2; - if ($linksBeforePage < 0) $linksBeforePage = 0; - $linksAfterPage = $tagArgs['pages'] - ($tagArgs['page'] + 1); - if ($linksAfterPage < 0) $linksAfterPage = 0; - if ($tagArgs['page'] > 1 && $tagArgs['page'] < $tagArgs['pages']) { - $maxLinks--; - } - - $half = $maxLinks / 2; - $left = $right = $tagArgs['page']; - if ($left < 1) $left = 1; - if ($right < 1) $right = 1; - if ($right > $tagArgs['pages'] - 1) $right = $tagArgs['pages'] - 1; - - if ($linksBeforePage >= $half) { - $left -= $half; - } - else { - $left -= $linksBeforePage; - $right += $half - $linksBeforePage; - } - - if ($linksAfterPage >= $half) { - $right += $half; - } - else { - $right += $linksAfterPage; - $left -= $half - $linksAfterPage; - } - - $right = intval(ceil($right)); - $left = intval(ceil($left)); - if ($left < 1) $left = 1; - if ($right > $tagArgs['pages']) $right = $tagArgs['pages']; - - // left ... links - if ($left > 1) { - if ($left - 1 < 2) { - $html .= $this->makeLink($tagArgs['link'], 2, $tagArgs['page']); - } - else { - $html .= '
      • '."\n"; - - $k = 0; - $step = intval(ceil(($left - 2) / self::SHOW_SUB_LINKS)); - for ($i = 2; $i <= $left; $i += $step) { - $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0); - $k++; - } - - $html .= "
    • \n"; - } - } - - // visible links - for ($i = $left + 1; $i < $right; $i++) { - $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page']); - } - - // right ... links - if ($right < $tagArgs['pages']) { - if ($tagArgs['pages'] - $right < 2) { - $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'] - 1, $tagArgs['page']); - } - else { - $html .= '
      • '."\n"; - - $k = 0; - $step = intval(ceil(($tagArgs['pages'] - $right) / self::SHOW_SUB_LINKS)); - for ($i = $right; $i < $tagArgs['pages']; $i += $step) { - $html .= $this->makeLink($tagArgs['link'], $i, $tagArgs['page'], $k != 0 && $k % 4 == 0); - $k++; - } - - $html .= "
    • \n"; - } - } - - // last page - $html .= $this->makeLink($tagArgs['link'], $tagArgs['pages'], $tagArgs['page']); - - // next page - $nextTitle = WCF::getLanguage()->getDynamicVariable('wcf.global.page.next'); - if ($tagArgs['page'] && $tagArgs['page'] < $tagArgs['pages']) { - $html .= ''."\n"; - } - else { - $html .= ''."\n"; - } - - // close div and ul - $html .= "
    \n"; - } - - // assign html output to template var - if (isset($tagArgs['assign'])) { - $tplObj->assign($tagArgs['assign'], $html); - if (!isset($tagArgs['print']) || !$tagArgs['print']) return ''; - } - - return $html; - } - - private static function getIconPath($filename) { - if (class_exists('StyleManager')) { - return StyleManager::getStyle()->getIconPath($filename); - } - else { - return RELATIVE_WCF_DIR.'icon/'.$filename; - } - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php deleted file mode 100644 index 2a6d12dff5..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginFunctionSmallpages implements ITemplatePluginFunction { - const SHOW_LINKS = 5; - - /** - * Inserts the page number into the link. - * - * @param string $link - * @param integer $pageNo - * @return string final link - */ - protected static function insertPageNumber($link, $pageNo) { - $startPos = StringUtil::indexOf($link, '%d'); - if ($startPos !== null) $link = StringUtil::substring($link, 0, $startPos) . $pageNo . StringUtil::substring($link, $startPos + 2); - return $link; - } - - /** - * Generates html code of a link. - * - * @param string $link - * @param integer $pageNo - * @return string - */ - protected function makeLink($link, $pageNo) { - return '
  • '.StringUtil::formatInteger($pageNo).'
  • '."\n"; - } - - /** - * @see wcf\system\template\ITemplatePluginFunction::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - // needed params: link, pages - if (!isset($tagArgs['link'])) throw new SystemException("missing 'link' argument in pages tag"); - if (!isset($tagArgs['pages'])) { - if (($tagArgs['pages'] = $tplObj->get('pages')) === null) { - throw new SystemException("missing 'pages' argument in pages tag"); - } - } - - $html = ''; - if ($tagArgs['pages'] > 1) { - // encode link - $link = StringUtil::encodeHTML($tagArgs['link']); - - // open div and ul - $html .= "
    \n
      \n"; - - // generate simple links - $simpleLinks = $tagArgs['pages']; - if ($simpleLinks > self::SHOW_LINKS) { - $simpleLinks = self::SHOW_LINKS - 2; - } - - for ($i = 1; $i <= $simpleLinks; $i++) { - $html .= $this->makeLink($link, $i); - } - - if ($tagArgs['pages'] > self::SHOW_LINKS) { - // jumper - $html .= '
    • '."\n"; - - // last page - $html .= $this->makeLink($link, $tagArgs['pages']); - } - - // close div and ul - $html .= "
    \n"; - } - - // assign html output to template var - if (isset($tagArgs['assign'])) { - $tplObj->assign($tagArgs['assign'], $html); - if (!isset($tagArgs['print']) || !$tagArgs['print']) return ''; - } - - return $html; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php deleted file mode 100644 index 49ae1c8fc0..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php +++ /dev/null @@ -1,33 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginModifierArrayfromlist implements ITemplatePluginModifier { - /** - * @see wcf\system\template\ITemplatePluginModifier::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - return Option::parseSelectOptions($tagArgs[0]); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierConcat.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierConcat.class.php deleted file mode 100644 index f8cd763686..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierConcat.class.php +++ /dev/null @@ -1,37 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginModifierConcat implements ITemplatePluginModifier { - /** - * @see wcf\system\template\ITemplatePluginModifier::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - if (count($tagArgs) < 2) { - throw new SystemException("concat modifier needs two or more arguments"); - } - - $result = ''; - foreach ($tagArgs as $arg) { - $result .= $arg; - } - - return $result; - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierDate.class.php b/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierDate.class.php deleted file mode 100644 index 6c5c37368e..0000000000 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierDate.class.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @package com.woltlab.wcf - * @subpackage system.template.plugin - * @category Community Framework - */ -class TemplatePluginModifierDate implements ITemplatePluginModifier { - /** - * @see wcf\system\template\ITemplatePluginModifier::execute() - */ - public function execute($tagArgs, TemplateEngine $tplObj) { - return DateUtil::format(DateUtil::getDateTimeByTimestamp($tagArgs[0]), (!empty($tagArgs[2]) ? $tagArgs[2] : DateUtil::DATE_FORMAT)); - } -} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TimeModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/TimeModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..57f6b5d367 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/TimeModifierTemplatePlugin.class.php @@ -0,0 +1,36 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class TimeModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + $timestamp = intval($tagArgs[0]); + $dateTimeObject = DateUtil::getDateTimeByTimestamp($timestamp); + $date = DateUtil::format($dateTimeObject, DateUtil::DATE_FORMAT); + $time = DateUtil::format($dateTimeObject, DateUtil::TIME_FORMAT); + $dateTime = str_replace('%time%', $time, str_replace('%date%', $date, WCF::getLanguage()->get('wcf.global.date.dateTimeFormat'))); + + return ''; + } +} diff --git a/wcfsetup/install/files/lib/system/template/plugin/TruncateModifierTemplatePlugin.class.php b/wcfsetup/install/files/lib/system/template/plugin/TruncateModifierTemplatePlugin.class.php new file mode 100644 index 0000000000..de59e25199 --- /dev/null +++ b/wcfsetup/install/files/lib/system/template/plugin/TruncateModifierTemplatePlugin.class.php @@ -0,0 +1,54 @@ + + * @package com.woltlab.wcf + * @subpackage system.template.plugin + * @category Community Framework + */ +class TruncateModifierTemplatePlugin implements IModifierTemplatePlugin { + /** + * @see wcf\system\template\IModifierTemplatePlugin::execute() + */ + public function execute($tagArgs, TemplateEngine $tplObj) { + // default values + $length = 80; + $etc = '...'; + $breakWords = false; + + // get values + $string = $tagArgs[0]; + if (isset($tagArgs[1])) $length = intval($tagArgs[1]); + if (isset($tagArgs[2])) $etc = $tagArgs[2]; + if (isset($tagArgs[3])) $breakWords = $tagArgs[3]; + + // execute plugin + if ($length == 0) { + return ''; + } + + if (StringUtil::length($string) > $length) { + $length -= StringUtil::length($etc); + + if (!$breakWords) { + $string = preg_replace('/\s+?(\S+)?$/', '', StringUtil::substring($string, 0, $length + 1)); + } + + return StringUtil::substring($string, 0, $length).$etc; + } + else { + return $string; + } + } +}