From 349976a8fabe40a8e732526ea4d3e6c88cd70f61 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 12 Aug 2011 21:51:11 +0200 Subject: [PATCH] Changed names of the template plugin classes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 …"). --- ...ass.php => IBlockTemplatePlugin.class.php} | 2 +- ....php => ICompilerTemplatePlugin.class.php} | 2 +- ....php => IFunctionTemplatePlugin.class.php} | 2 +- ....php => IModifierTemplatePlugin.class.php} | 2 +- ...php => IPrefilterTemplatePlugin.class.php} | 2 +- .../system/template/TemplateEngine.class.php | 2 +- .../TemplateScriptingCompiler.class.php | 10 +-- ...=> AppendCompilerTemplatePlugin.class.php} | 8 +-- ...yfromlistModifierTemplatePlugin.class.php} | 10 +-- ...=> AssignCompilerTemplatePlugin.class.php} | 10 +-- ...=> ConcatModifierTemplatePlugin.class.php} | 6 +- ...> CounterFunctionTemplatePlugin.class.php} | 8 +-- ... => CycleFunctionTemplatePlugin.class.php} | 6 +- ...p => DateModifierTemplatePlugin.class.php} | 6 +- .../DatediffModifierTemplatePlugin.class.php | 35 ++++++++++ .../EncodejsModifierTemplatePlugin.class.php | 41 +++++++++++ .../EventPrefilterTemplatePlugin.class.php | 30 ++++++++ ... => FetchCompilerTemplatePlugin.class.php} | 8 +-- ...sizeBinaryModifierTemplatePlugin.class.php | 28 ++++++++ .../FilesizeModifierTemplatePlugin.class.php | 28 ++++++++ ...ascontentPrefilterTemplatePlugin.class.php | 70 +++++++++++++++++++ ...heckboxesFunctionTemplatePlugin.class.php} | 8 +-- ...mloptionsFunctionTemplatePlugin.class.php} | 6 +- ...p => IconCompilerTemplatePlugin.class.php} | 8 +-- .../IconPrefilterTemplatePlugin.class.php | 30 ++++++++ ...> ImplodeCompilerTemplatePlugin.class.php} | 10 +-- ...p => LangCompilerTemplatePlugin.class.php} | 8 +-- .../LangPrefilterTemplatePlugin.class.php | 34 +++++++++ ....php => LinkBlockTemplatePlugin.class.php} | 10 +-- ... => PagesFunctionTemplatePlugin.class.php} | 10 +-- .../PlainTimeModifierTemplatePlugin.class.php | 31 ++++++++ ...> PrependCompilerTemplatePlugin.class.php} | 9 +-- ...mallpagesFunctionTemplatePlugin.class.php} | 8 +-- ...taticlangTemplatePluginCompiler.class.php} | 12 ++-- .../TimeModifierTemplatePlugin.class.php | 36 ++++++++++ .../TruncateModifierTemplatePlugin.class.php | 54 ++++++++++++++ 36 files changed, 505 insertions(+), 85 deletions(-) rename wcfsetup/install/files/lib/system/template/{ITemplatePluginBlock.class.php => IBlockTemplatePlugin.class.php} (97%) rename wcfsetup/install/files/lib/system/template/{ITemplatePluginCompiler.class.php => ICompilerTemplatePlugin.class.php} (96%) rename wcfsetup/install/files/lib/system/template/{ITemplatePluginFunction.class.php => IFunctionTemplatePlugin.class.php} (94%) rename wcfsetup/install/files/lib/system/template/{ITemplatePluginModifier.class.php => IModifierTemplatePlugin.class.php} (94%) rename wcfsetup/install/files/lib/system/template/{ITemplatePluginPrefilter.class.php => IPrefilterTemplatePlugin.class.php} (94%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerAppend.class.php => AppendCompilerTemplatePlugin.class.php} (84%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginModifierArrayfromlist.class.php => ArrayfromlistModifierTemplatePlugin.class.php} (71%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerAssign.class.php => AssignCompilerTemplatePlugin.class.php} (82%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginModifierConcat.class.php => ConcatModifierTemplatePlugin.class.php} (84%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionCounter.class.php => CounterFunctionTemplatePlugin.class.php} (88%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionCycle.class.php => CycleFunctionTemplatePlugin.class.php} (92%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginModifierDate.class.php => DateModifierTemplatePlugin.class.php} (80%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/DatediffModifierTemplatePlugin.class.php create mode 100644 wcfsetup/install/files/lib/system/template/plugin/EncodejsModifierTemplatePlugin.class.php create mode 100644 wcfsetup/install/files/lib/system/template/plugin/EventPrefilterTemplatePlugin.class.php rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerFetch.class.php => FetchCompilerTemplatePlugin.class.php} (84%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/FilesizeBinaryModifierTemplatePlugin.class.php create mode 100644 wcfsetup/install/files/lib/system/template/plugin/FilesizeModifierTemplatePlugin.class.php create mode 100644 wcfsetup/install/files/lib/system/template/plugin/HascontentPrefilterTemplatePlugin.class.php rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionHtmlcheckboxes.class.php => HtmlcheckboxesFunctionTemplatePlugin.class.php} (91%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionHtmloptions.class.php => HtmloptionsFunctionTemplatePlugin.class.php} (94%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerIcon.class.php => IconCompilerTemplatePlugin.class.php} (79%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/IconPrefilterTemplatePlugin.class.php rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerImplode.class.php => ImplodeCompilerTemplatePlugin.class.php} (88%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerLang.class.php => LangCompilerTemplatePlugin.class.php} (84%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/LangPrefilterTemplatePlugin.class.php rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginBlockLink.class.php => LinkBlockTemplatePlugin.class.php} (79%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionPages.class.php => PagesFunctionTemplatePlugin.class.php} (97%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/PlainTimeModifierTemplatePlugin.class.php rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerPrepend.class.php => PrependCompilerTemplatePlugin.class.php} (82%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginFunctionSmallpages.class.php => SmallpagesFunctionTemplatePlugin.class.php} (93%) rename wcfsetup/install/files/lib/system/template/plugin/{TemplatePluginCompilerStaticlang.class.php => StaticlangTemplatePluginCompiler.class.php} (70%) create mode 100644 wcfsetup/install/files/lib/system/template/plugin/TimeModifierTemplatePlugin.class.php create mode 100644 wcfsetup/install/files/lib/system/template/plugin/TruncateModifierTemplatePlugin.class.php diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php b/wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php similarity index 97% rename from wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php rename to wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php index 9c6487ef54..2abe51478d 100644 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginBlock.class.php +++ b/wcfsetup/install/files/lib/system/template/IBlockTemplatePlugin.class.php @@ -11,7 +11,7 @@ namespace wcf\system\template; * @subpackage system.template * @category Community Framework */ -interface ITemplatePluginBlock { +interface IBlockTemplatePlugin { /** * Executes this template block. * diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php b/wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php similarity index 96% rename from wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php rename to wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php index ab579e9dba..0b37d89047 100644 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginCompiler.class.php +++ b/wcfsetup/install/files/lib/system/template/ICompilerTemplatePlugin.class.php @@ -11,7 +11,7 @@ namespace wcf\system\template; * @subpackage system.template * @category Community Framework */ -interface ITemplatePluginCompiler { +interface ICompilerTemplatePlugin { /** * Executes the start tag of this compiler function. * diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php b/wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php similarity index 94% rename from wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php rename to wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php index ac0b7d222c..862c7931cc 100644 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginFunction.class.php +++ b/wcfsetup/install/files/lib/system/template/IFunctionTemplatePlugin.class.php @@ -11,7 +11,7 @@ namespace wcf\system\template; * @subpackage system.template * @category Community Framework */ -interface ITemplatePluginFunction { +interface IFunctionTemplatePlugin { /** * Executes this template function. * diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php b/wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php similarity index 94% rename from wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php rename to wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php index 478ebfd7fc..2c240f2795 100644 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginModifier.class.php +++ b/wcfsetup/install/files/lib/system/template/IModifierTemplatePlugin.class.php @@ -12,7 +12,7 @@ namespace wcf\system\template; * @subpackage system.template * @category Community Framework */ -interface ITemplatePluginModifier { +interface IModifierTemplatePlugin { /** * Executes this modifier. * diff --git a/wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php b/wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php similarity index 94% rename from wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php rename to wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php index 4701713b37..455a03b94d 100644 --- a/wcfsetup/install/files/lib/system/template/ITemplatePluginPrefilter.class.php +++ b/wcfsetup/install/files/lib/system/template/IPrefilterTemplatePlugin.class.php @@ -11,7 +11,7 @@ namespace wcf\system\template; * @subpackage system.template * @category Community Framework */ -interface ITemplatePluginPrefilter { +interface IPrefilterTemplatePlugin { /** * Executes this prefilter. * 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/TemplatePluginCompilerAppend.class.php b/wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php similarity index 84% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAppend.class.php rename to wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php index cbb480821a..c443f2517e 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAppend.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/AppendCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ formatSyntaxError("unknown tag {/append}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php b/wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php similarity index 71% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php rename to wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php index 49ae1c8fc0..209f07f607 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierArrayfromlist.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/ArrayfromlistModifierTemplatePlugin.class.php @@ -2,7 +2,7 @@ namespace wcf\system\template\plugin; use wcf\data\option\Option; use wcf\system\template\TemplateEngine; -use wcf\system\template\ITemplatePluginModifier; +use wcf\system\template\IModifierTemplatePlugin; /** * The 'arrayfromlist' modifier generates an associative array out of a key-value list. @@ -23,11 +23,13 @@ use wcf\system\template\ITemplatePluginModifier; * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginModifierArrayfromlist implements ITemplatePluginModifier { +class ArrayfromlistModifierTemplatePlugin implements IModifierTemplatePlugin { /** - * @see wcf\system\template\ITemplatePluginModifier::execute() + * @see wcf\system\template\IModifierTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { - return Option::parseSelectOptions($tagArgs[0]); + // TODO: doesn't work + // return Option::parseSelectOptions($tagArgs[0]); + return ''; } } diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php b/wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php similarity index 82% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php rename to wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php index 9ae7d4da40..965da43c35 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerAssign.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/AssignCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginCompilerAssign implements ITemplatePluginCompiler { +class AssignCompilerTemplatePlugin implements ICompilerTemplatePlugin { /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() */ public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { if (!isset($tagArgs['var'])) { @@ -33,7 +33,7 @@ class TemplatePluginCompilerAssign implements ITemplatePluginCompiler { } /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() + * @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/TemplatePluginModifierConcat.class.php b/wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php similarity index 84% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierConcat.class.php rename to wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php index f8cd763686..31f3dde2a7 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginModifierConcat.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/ConcatModifierTemplatePlugin.class.php @@ -2,7 +2,7 @@ namespace wcf\system\template\plugin; use wcf\system\exception\SystemException; use wcf\system\template\TemplateEngine; -use wcf\system\template\ITemplatePluginModifier; +use wcf\system\template\IModifierTemplatePlugin; /** * The 'concat' modifier returns the string that results from concatenating the arguments. @@ -12,13 +12,13 @@ use wcf\system\template\ITemplatePluginModifier; * {"left"|concat:$right} * * @author Marcel Werk - * @copyright 2001-2009 WoltLab GmbH + * @copyright 2001-2011 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginModifierConcat implements ITemplatePluginModifier { +class ConcatModifierTemplatePlugin implements IModifierTemplatePlugin { /** * @see wcf\system\template\ITemplatePluginModifier::execute() */ diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php b/wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php similarity index 88% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php rename to wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php index ccc80f0ef4..0dd3c0967f 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCounter.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/CounterFunctionTemplatePlugin.class.php @@ -1,6 +1,6 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginFunctionCounter implements ITemplatePluginFunction { +class CounterFunctionTemplatePlugin implements IFunctionTemplatePlugin { protected $counters = array(); /** - * @see wcf\system\template\ITemplatePluginFunction::execute() + * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { if (!isset($tagArgs['name'])) { diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php b/wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php similarity index 92% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php rename to wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php index b6e9750fc0..c427079d7f 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionCycle.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/CycleFunctionTemplatePlugin.class.php @@ -1,7 +1,7 @@ + * @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/TemplatePluginCompilerFetch.class.php b/wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php similarity index 84% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerFetch.class.php rename to wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php index 378b7be0cf..106fd61a31 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerFetch.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/FetchCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ 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/TemplatePluginFunctionHtmlcheckboxes.class.php b/wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php similarity index 91% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmlcheckboxes.class.php rename to wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php index f80658a6da..68cbb284d0 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmlcheckboxes.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/HtmlcheckboxesFunctionTemplatePlugin.class.php @@ -1,7 +1,7 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginFunctionHtmlcheckboxes implements ITemplatePluginFunction { +class HtmlcheckboxesFunctionTemplatePlugin implements IFunctionTemplatePlugin { protected $disableEncoding = false; /** - * @see wcf\system\template\ITemplatePluginFunction::execute() + * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // get options diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php b/wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php similarity index 94% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php rename to wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php index 7fa8c19e9a..e474cc017b 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionHtmloptions.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/HtmloptionsFunctionTemplatePlugin.class.php @@ -15,17 +15,17 @@ use wcf\util\StringUtil; * {htmloptions output=$outputArray values=$valueArray} * * @author Marcel Werk - * @copyright 2001-2009 WoltLab GmbH + * @copyright 2001-2011 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginFunctionHtmloptions extends TemplatePluginFunctionHtmlcheckboxes { +class HtmloptionsFunctionTemplatePlugin extends HtmlcheckboxesFunctionTemplatePlugin { protected $selected = array(); /** - * @see wcf\system\template\ITemplatePluginFunction::execute() + * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { if (isset($tagArgs['output']) && is_array($tagArgs['output'])) { diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php similarity index 79% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php rename to wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php index a4b0b109e6..192c73f3a0 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerIcon.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/IconCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ pushTag('icon'); @@ -27,7 +27,7 @@ class TemplatePluginCompilerIcon implements ITemplatePluginCompiler { } /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('icon'); 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/TemplatePluginCompilerImplode.class.php b/wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php similarity index 88% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerImplode.class.php rename to wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php index 25bb79a33b..b99a6e683c 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerImplode.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/ImplodeCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginCompilerImplode implements ITemplatePluginCompiler { +class ImplodeCompilerTemplatePlugin implements ICompilerTemplatePlugin { protected $tagStack = array(); /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() */ public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { $compiler->pushTag('implode'); @@ -46,7 +46,7 @@ class TemplatePluginCompilerImplode implements ITemplatePluginCompiler { } /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('implode'); diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php similarity index 84% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php rename to wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php index a1a76c612a..baa16960be 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerLang.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/LangCompilerTemplatePlugin.class.php @@ -1,6 +1,6 @@ pushTag('lang'); @@ -35,7 +35,7 @@ class TemplatePluginCompilerLang implements ITemplatePluginCompiler { } /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('lang'); 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/TemplatePluginBlockLink.class.php b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php similarity index 79% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginBlockLink.class.php rename to wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php index 7861d47b1d..33b496cb38 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginBlockLink.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/LinkBlockTemplatePlugin.class.php @@ -1,7 +1,7 @@ counter = 0; } /** - * @see wcf\system\template\ITemplatePluginBlock::next() + * @see wcf\system\template\IBlockTemplatePlugin::next() */ public function next(TemplateEngine $tplObj) { if ($this->counter == 0) { diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php similarity index 97% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php rename to wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php index 86f85c6608..72495b4c17 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionPages.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/PagesFunctionTemplatePlugin.class.php @@ -1,9 +1,9 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginFunctionPages implements ITemplatePluginFunction { +class PagesFunctionTemplatePlugin implements IFunctionTemplatePlugin { const SHOW_LINKS = 11; const SHOW_SUB_LINKS = 20; @@ -63,7 +63,7 @@ class TemplatePluginFunctionPages implements ITemplatePluginFunction { } /** - * @see wcf\system\template\ITemplatePluginFunction::execute() + * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // needed params: link, page, pages 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/TemplatePluginCompilerPrepend.class.php b/wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php similarity index 82% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerPrepend.class.php rename to wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php index 4ac7471a21..5400da72ae 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerPrepend.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/PrependCompilerTemplatePlugin.class.php @@ -1,6 +1,7 @@ formatSyntaxError("unknown tag {/prepend}", $compiler->getCurrentIdentifier(), $compiler->getCurrentLineNo())); diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php b/wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php similarity index 93% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php rename to wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php index 2a6d12dff5..d0022e6b8b 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginFunctionSmallpages.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/SmallpagesFunctionTemplatePlugin.class.php @@ -3,7 +3,7 @@ namespace wcf\system\template\plugin; use wcf\system\WCF; use wcf\system\exception\SystemException; use wcf\system\template\TemplateEngine; -use wcf\system\template\ITemplatePluginFunction; +use wcf\system\template\IFunctionTemplatePlugin; use wcf\util\StringUtil; /** @@ -19,13 +19,13 @@ use wcf\util\StringUtil; * {smallpages pages=10 link='page-%d.html' assign='output' print=true} * * @author Marcel Werk - * @copyright 2001-2009 WoltLab GmbH + * @copyright 2001-2011 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginFunctionSmallpages implements ITemplatePluginFunction { +class SmallpagesFunctionTemplatePlugin implements IFunctionTemplatePlugin { const SHOW_LINKS = 5; /** @@ -53,7 +53,7 @@ class TemplatePluginFunctionSmallpages implements ITemplatePluginFunction { } /** - * @see wcf\system\template\ITemplatePluginFunction::execute() + * @see wcf\system\template\IFunctionTemplatePlugin::execute() */ public function execute($tagArgs, TemplateEngine $tplObj) { // needed params: link, pages diff --git a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php similarity index 70% rename from wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php rename to wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php index f92a62be59..0b76cd8056 100644 --- a/wcfsetup/install/files/lib/system/template/plugin/TemplatePluginCompilerStaticlang.class.php +++ b/wcfsetup/install/files/lib/system/template/plugin/StaticlangTemplatePluginCompiler.class.php @@ -1,6 +1,6 @@ * @package com.woltlab.wcf * @subpackage system.template.plugin * @category Community Framework */ -class TemplatePluginCompilerStaticlang implements ITemplatePluginCompiler { +class StaticlangCompilerTemplatePlugin implements ICompilerTemplatePlugin { /** - * @see wcf\system\template\ITemplatePluginCompiler::executeStart() + * @see wcf\system\template\ICompilerTemplatePlugin::executeStart() */ public function executeStart($tagArgs, TemplateScriptingCompiler $compiler) { $compiler->pushTag('staticlang'); @@ -28,11 +28,11 @@ class TemplatePluginCompilerStaticlang implements ITemplatePluginCompiler { } /** - * @see wcf\system\template\ITemplatePluginCompiler::executeEnd() + * @see wcf\system\template\ICompilerTemplatePlugin::executeEnd() */ public function executeEnd(TemplateScriptingCompiler $compiler) { $compiler->popTag('staticlang'); $hash = StringUtil::getRandomID(); - return "get(\$_lang".$hash."); ?>"; + return "get(\$_lang".$hash."); ?>"; } } 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; + } + } +} -- 2.20.1