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
|
|
|
|
*/
|
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-08-09 14:28:28 +00:00
|
|
|
preg_match_all('/(((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*")[^:]*)+|::?|[^:]+)/', $single_modifier, $mod_array);
|
2010-07-24 23:34:19 +00:00
|
|
|
$modifier = $mod_array[0][0];
|
2010-07-25 11:42:46 +00:00
|
|
|
for ($i = 0, $count = count($mod_array[0]);$i < $count;$i++) {
|
|
|
|
if ($mod_array[0][$i] == ':') {
|
|
|
|
$mod_array[0][$i] = ',';
|
|
|
|
}
|
2010-08-06 15:34:18 +00:00
|
|
|
if ($mod_array[0][$i] == '::') {
|
|
|
|
$mod_array[0][$i-1] = $mod_array[0][$i-1] . $mod_array[0][$i] . $mod_array[0][$i + 1];
|
|
|
|
unset($mod_array[0][$i], $mod_array[0][$i + 1]);
|
|
|
|
$i++;
|
|
|
|
}
|
2010-07-24 23:34:19 +00:00
|
|
|
}
|
2010-08-06 14:38:33 +00:00
|
|
|
unset($mod_array[0][0]);
|
|
|
|
$params = $output . implode('', $mod_array[0]);
|
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-08-06 14:38:33 +00:00
|
|
|
foreach($mod_array[0] as $key => $value) {
|
|
|
|
if ($value == ',') {
|
|
|
|
unset ($mod_array[0][$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$args = array_merge((array)$output, $mod_array[0]);
|
2010-08-05 17:50:16 +00:00
|
|
|
$output = $plugin($args, $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 {
|
|
|
|
$this->compiler->trigger_template_error ("unknown modifier \"" . $modifier . "\"");
|
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
|
|
|
?>
|