2009-12-27 15:06:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-07-01 19:57:56 +00:00
|
|
|
* Smarty Internal Plugin Compile Modifier
|
|
|
|
*
|
|
|
|
* Compiles code for modifier execution
|
|
|
|
*
|
|
|
|
* @package Smarty
|
|
|
|
* @subpackage Compiler
|
|
|
|
* @author Uwe Tews
|
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-12-27 15:06:49 +00:00
|
|
|
/**
|
2010-07-01 19:57:56 +00:00
|
|
|
* Smarty Internal Plugin Compile Modifier Class
|
|
|
|
*/
|
2009-12-27 15:06:49 +00:00
|
|
|
class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase {
|
|
|
|
/**
|
2010-07-01 19:57:56 +00:00
|
|
|
* Compiles code for modifier execution
|
|
|
|
*
|
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param object $compiler compiler object
|
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2009-12-27 15:06:49 +00:00
|
|
|
public function compile($args, $compiler)
|
|
|
|
{
|
|
|
|
$this->compiler = $compiler;
|
|
|
|
$this->smarty = $this->compiler->smarty;
|
2010-07-23 12:53:04 +00:00
|
|
|
$this->required_attributes = array('value', 'modifierlist');
|
2009-12-27 15:06:49 +00:00
|
|
|
// check and get attributes
|
2010-07-23 12:53:04 +00:00
|
|
|
$_attr = $this->_get_attributes($args);
|
2010-07-24 23:34:19 +00:00
|
|
|
$output = $_attr['value'];
|
2010-07-23 12:53:04 +00:00
|
|
|
// loop over list of modifiers
|
|
|
|
foreach ($_attr['modifierlist'] as $single_modifier) {
|
2010-10-25 18:53:43 +00:00
|
|
|
$modifier = $single_modifier[0];
|
|
|
|
$single_modifier[0] = $output;
|
|
|
|
$params = implode(',', $single_modifier);
|
2010-07-23 12:53:04 +00:00
|
|
|
// check for registered modifier
|
|
|
|
if (isset($compiler->smarty->registered_plugins['modifier'][$modifier])) {
|
|
|
|
$function = $compiler->smarty->registered_plugins['modifier'][$modifier][0];
|
|
|
|
if (!is_array($function)) {
|
|
|
|
$output = "{$function}({$params})";
|
2010-07-01 19:57:56 +00:00
|
|
|
} else {
|
2010-07-23 12:53:04 +00:00
|
|
|
if (is_object($function[0])) {
|
|
|
|
$output = '$_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
|
|
|
|
} else {
|
|
|
|
$output = $function[0] . '::' . $function[1] . '(' . $params . ')';
|
|
|
|
}
|
2010-07-01 19:57:56 +00:00
|
|
|
}
|
2010-08-05 17:50:16 +00:00
|
|
|
// check for plugin modifiercompiler
|
|
|
|
} else if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
|
|
|
|
$plugin = 'smarty_modifiercompiler_' . $modifier;
|
2010-10-25 18:53:43 +00:00
|
|
|
$output = $plugin($single_modifier, $compiler);
|
2010-07-23 12:53:04 +00:00
|
|
|
// check for plugin modifier
|
|
|
|
} else if ($function = $this->compiler->getPlugin($modifier, 'modifier')) {
|
|
|
|
$output = "{$function}({$params})";
|
|
|
|
// check if trusted PHP function
|
|
|
|
} else if (is_callable($modifier)) {
|
|
|
|
// check if modifier allowed
|
|
|
|
if (!$this->compiler->template->security || $this->smarty->security_handler->isTrustedModifier($modifier, $this->compiler)) {
|
|
|
|
$output = "{$modifier}({$params})";
|
|
|
|
}
|
|
|
|
} else {
|
2010-10-25 18:53:43 +00:00
|
|
|
$this->compiler->trigger_template_error ("unknown modifier \"" . $modifier . "\"", $this->compiler->lex->taglineno);
|
2009-12-28 15:27:13 +00:00
|
|
|
}
|
2009-12-27 15:06:49 +00:00
|
|
|
}
|
2009-12-28 15:27:13 +00:00
|
|
|
return $output;
|
2009-12-27 15:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-01 19:57:56 +00:00
|
|
|
?>
|