304995465da4b057dcdafeb457dfb517db0c1d7c
3 * Template prefiler plugin which allows inserting code dynamically upon the contents
10 * {if $foo}<li>bar</li>{/if}
17 * @author Alexander Ebert
18 * @copyright 2001-2014 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package com.woltlab.wcf
21 * @subpackage system.template.plugin
22 * @category Community Framework
25 function smarty_prefilter_hascontent($source, &$smarty) {
26 $ldq = preg_quote($smarty->left_delimiter
, '~');
27 $rdq = preg_quote($smarty->right_delimiter
, '~');
29 $source = preg_replace_callback("~{$ldq}hascontent( assign='(?P<assign>.*)')?{$rdq}(?P<before>.*){$ldq}content{$rdq}(?P<content>.*){$ldq}\/content{$rdq}(?P<after>.*)({$ldq}hascontentelse{$rdq}(?P<else>.*))?{$ldq}\/hascontent{$rdq}~sU", function ($matches) {
30 $beforeContent = $matches['before'];
31 $content = $matches['content'];
32 $afterContent = $matches['after'];
33 $elseContent = (isset($matches['else'])) ?
$matches['else'] : '';
34 $assignContent = (isset($matches['assign']) && !empty($matches['assign'])) ?
$matches['assign'] : '';
35 $variable = 'hascontent_' . sha1(time());
37 $newContent = '{capture assign='.$variable.'}'.$content.'{/capture}'."\n";
38 $newContent .= '{assign var='.$variable.' value=$'.$variable.'|trim}'."\n";
40 if ($assignContent) $newContent .= '{capture assign='.$assignContent.'}'."\n";
41 $newContent .= '{if $'.$variable.'}'.$beforeContent.'{$'.$variable.'}'."\n".$afterContent;
43 if (!empty($elseContent)) {
44 $newContent .= '{else}'.$elseContent."\n";
47 $newContent .= '{/if}'."\n";
49 if ($assignContent) $newContent .= "{/capture}\n{\$".$assignContent."}\n";