+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\util\DateUtil;
-
-/**
- * The 'datediff' modifier calculates the difference between two unix timestamps.
- *
- * Usage:
- * {$timestamp|datediff}
- * {"123456789"|datediff:$timestamp}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierDatediff implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::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]);
-
- return DateUtil::diff($start, $end, 'string');
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\util\StringUtil;
-
-/**
- * The 'encodejs' modifier formats a string for usage in a single quoted javascript string.
- * Escapes single quotes and new lines.
- *
- * Usage:
- * {$string|encodejs}
- * {"bl''ah"|encodejs}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierEncodejs implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::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];
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\util\FileUtil;
-
-/**
- * The 'filesize' modifier formats a filesize (given in bytes).
- *
- * Usage:
- * {$string|filesize}
- * {123456789|filesize}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierFilesize implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::execute()
- */
- public function execute($tagArgs, TemplateEngine $tplObj) {
- return FileUtil::formatFilesize($tagArgs[0]);
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\util\FileUtil;
-
-/**
- * The 'filesize' modifier formats a filesize (binary) (given in bytes).
- *
- * Usage:
- * {$string|filesizeBinary}
- * {123456789|filesizeBinary}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierFilesizeBinary implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::execute()
- */
- public function execute($tagArgs, TemplateEngine $tplObj) {
- return FileUtil::formatFilesizeBinary($tagArgs[0]);
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\system\WCF;
-use wcf\util\DateUtil;
-
-/**
- * The 'plainTime' modifier formats a unix timestamp.
- * Default date format contains year, month, day, hour and minute.
- *
- * Usage:
- * {$timestamp|plainTime}
- * {"132845333"|plainTime}
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierPlainTime implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::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')));
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\system\WCF;
-use wcf\util\DateUtil;
-
-/**
- * The 'time' modifier formats a unix timestamp.
- * Default date format contains year, month, day, hour and minute.
- *
- * Usage:
- * {$timestamp|time}
- * {"132845333"|time}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierTime implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::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 '<time datetime="'.DateUtil::format($dateTimeObject, 'c').'" class="datetime" data-timestamp="'.$timestamp.'" data-date="'.$date.'" data-time="'.$time.'" data-offset="'.$dateTimeObject->getOffset().'">'.$dateTime.'</time>';
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\TemplateEngine;
-use wcf\system\template\ITemplatePluginModifier;
-use wcf\util\StringUtil;
-
-/**
- * The 'truncate' modifier truncates a string.
- *
- * Usage:
- * {$foo|truncate:35:'...'}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginModifierTruncate implements ITemplatePluginModifier {
- /**
- * @see wcf\system\template\ITemplatePluginModifier::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;
- }
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\ITemplatePluginPrefilter;
-use wcf\system\template\TemplateScriptingCompiler;
-
-/**
- * The 'event' prefilter inserts template listener's code before compilation.
- *
- * Usage:
- * {event name='foo'}
- *
- * @author Alexander Ebert
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginPrefilterEvent implements ITemplatePluginPrefilter {
- /**
- * @see wcf\system\template\ITemplatePluginPrefilter::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;
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\ITemplatePluginPrefilter;
-use wcf\system\template\TemplateScriptingCompiler;
-use wcf\util\StringUtil;
-
-/**
- * The 'hascontent' prefilter inserts ability to insert code dynamically upon the contents of 'content'.
- *
- * Usage:
- * {hascontent}
- * <ul>
- * {content}
- * {if $foo}<li>bar</li>{/if}
- * {/content}
- * </ul>
- * {hascontentelse}
- * <p>baz</p>
- * {/hascontent}
- *
- * @author Alexander Ebert
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginPrefilterHascontent implements ITemplatePluginPrefilter {
- /**
- * @see wcf\system\template\ITemplatePluginPrefilter::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;
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\ITemplatePluginPrefilter;
-use wcf\system\template\TemplateScriptingCompiler;
-
-/**
- * The 'icon' prefilter compiles static icon paths.
- *
- * Usage:
- * {icon}iconS.png{/icon}
- *
- * @author Marcel Werk
- * @copyright 2001-2011 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginPrefilterIcon implements ITemplatePluginPrefilter {
- /**
- * @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}<?php echo wcf\system\style\StyleHandler::getInstance()->getStyle()->getIconPath(\'$1\'); ?>{/literal}', $sourceContent);
-
- return $sourceContent;
- }
-}
+++ /dev/null
-<?php
-namespace wcf\system\template\plugin;
-use wcf\system\template\ITemplatePluginPrefilter;
-use wcf\system\template\TemplateScriptingCompiler;
-use wcf\system\WCF;
-
-/**
- * The 'lang' prefilter compiles static language variables.
- * Dynamic language variables will catched by the 'lang' compiler function.
- * It is recommended to use static language variables.
- *
- * Usage:
- * {lang}foo{/lang}
- * {lang}lang.foo.bar{/lang}
- *
- * @author Marcel Werk
- * @copyright 2001-2009 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package com.woltlab.wcf
- * @subpackage system.template.plugin
- * @category Community Framework
- */
-class TemplatePluginPrefilterLang implements ITemplatePluginPrefilter {
- /**
- * @see wcf\system\template\ITemplatePluginPrefilter::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;
- }
-}