function get_filtered_var($variable, &$varname, $accept_string = NULL)
{
$this->var_is_safe = FALSE;
if ($accept_string === NULL && is_array($variable[0]) && !Haanga_AST::is_exec($variable[0])) {
$accept_string = !empty($variable[0]['string']) || $variable[0][0] === 'block';
}
if (count($variable) > 1) {
$count = count($variable);
if ($accept_string && isset($variable[0]['string'])) {
$target = $variable[0];
} else {
if (Haanga_AST::is_exec($variable[0])) {
$target = $variable[0];
} else {
$target = $this->generate_variable_name($variable[0]);
}
}
if (!empty($variable[0][0]) && $variable[0][0] == 'block') {
/* block.super can't have any filter */
throw new Exception("This variable can't have any filter");
}
if (!empty($target['var']) && $this->isMethod($target['var'], $return)) {
$target = $return;
}
for ($i = 1; $i < $count; $i++) {
$func_name = $variable[$i];
if ($func_name == 'escape') {
/* to avoid double cleaning */
$this->var_is_safe = TRUE;
}
$args = array(isset($exec) ? $exec : $target);
$exec = $this->do_filtering($func_name, $args);
}
unset($variable);
$varname = $args[0];
$details = $exec;
} else {
if (Haanga_AST::is_exec($variable[0])) {
return $variable[0];
}
$details = $this->generate_variable_name($variable[0]);
$varname = $variable[0];
if ($this->isMethod($varname, $return)) {
return $return;
}
if (!Haanga_AST::is_var($details) && !$accept_string) {
/* generate_variable_name didn't replied a variable, weird case
currently just used for {{block.super}}.
*/
throw new Exception("Invalid variable name {$variable[0]}");
}
}
return $details;
}