104 lines
2.3 KiB
PHP
104 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Class Smarty_Compiler_Ifmodule.
|
|
*
|
|
* Examples:
|
|
* {ifmodule "review"}blablabla{/ifmodule}
|
|
*/
|
|
class Smarty_Compiler_Ifmodule extends Smarty_Internal_CompileBase
|
|
{
|
|
public $optional_attributes = ['_any'];
|
|
public $shorttag_order = ['module'];
|
|
|
|
/**
|
|
* @var Smarty_Internal_SmartyTemplateCompiler
|
|
*/
|
|
private $compiler;
|
|
|
|
/**
|
|
* @param $compiler Smarty_Internal_SmartyTemplateCompiler
|
|
*
|
|
* @return string
|
|
*/
|
|
public function compile($args, $compiler)
|
|
{
|
|
$_args = $this->getAttributes($compiler, $args);
|
|
|
|
$this->openTag($compiler, 'ifmodule');
|
|
|
|
$key = trim($_args['module'], "\"'");
|
|
$parts = explode('__', $key);
|
|
$module = $parts[0];
|
|
$submodule = getVal(1, $parts);
|
|
|
|
if (\Modules::check($module, $submodule)) {
|
|
return '';
|
|
}
|
|
|
|
eat_code($compiler, $this);
|
|
|
|
return '';
|
|
}
|
|
}
|
|
|
|
class Smarty_Compiler_Elsemodule extends Smarty_Internal_CompileBase
|
|
{
|
|
public $required_attributes = [];
|
|
public $optional_attributes = [];
|
|
public $shorttag_order = [];
|
|
|
|
public function compile($args, $compiler)
|
|
{
|
|
return '<?php /*';
|
|
}
|
|
}
|
|
|
|
class Smarty_Compiler_Ifmoduleclose extends Smarty_Internal_CompileBase
|
|
{
|
|
public $required_attributes = [];
|
|
public $optional_attributes = [];
|
|
public $shorttag_order = [];
|
|
|
|
public function compile($args, $compiler)
|
|
{
|
|
$this->closeTag($compiler, ['ifmodule']);
|
|
|
|
return '<?php /**/ ?>';
|
|
}
|
|
}
|
|
|
|
function eat_code($compiler, $tag)
|
|
{
|
|
/** @var Smarty_Internal_Templatelexer $lexer */
|
|
$lexer = $compiler->parser->lex;
|
|
$counter = 1;
|
|
|
|
while (true) {
|
|
$last = $lexer->value;
|
|
if ($lexer->yylex() === false) {
|
|
return '';
|
|
}
|
|
|
|
$ifModule = strcasecmp($lexer->value, 'ifmodule') === 0;
|
|
|
|
if (mb_strtolower($lexer->value) == '{/ifmodule}') {
|
|
$counter--;
|
|
}
|
|
|
|
if ($ifModule) {
|
|
$counter++;
|
|
}
|
|
|
|
$elseModule = strcasecmp(mb_strtolower($lexer->value), '{elsemodule}') === 0;
|
|
if ($elseModule && $counter == 1) {
|
|
break;
|
|
}
|
|
|
|
if (mb_strtolower($lexer->value) == '{/ifmodule}' && $counter == 0) {
|
|
$tag->closeTag($compiler, ['ifmodule']);
|
|
break;
|
|
}
|
|
}
|
|
}
|