You are here

function Smarty_Compiler::_parse_modifiers in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/lib/smarty/Smarty_Compiler.class.php \Smarty_Compiler::_parse_modifiers()

parse modifier chain into PHP code

sets $output to parsed modified chain

Parameters

string $output:

string $modifier_string:

6 calls to Smarty_Compiler::_parse_modifiers()
Smarty_Compiler::_compile_block_tag in includes/moodle/lib/smarty/Smarty_Compiler.class.php
compile block function tag
Smarty_Compiler::_compile_custom_tag in includes/moodle/lib/smarty/Smarty_Compiler.class.php
compile custom function tag
Smarty_Compiler::_compile_registered_object_tag in includes/moodle/lib/smarty/Smarty_Compiler.class.php
compile a registered object tag
Smarty_Compiler::_parse_conf_var in includes/moodle/lib/smarty/Smarty_Compiler.class.php
parse configuration variable expression into PHP code
Smarty_Compiler::_parse_section_prop in includes/moodle/lib/smarty/Smarty_Compiler.class.php
parse section property expression into PHP code

... See full list

File

includes/moodle/lib/smarty/Smarty_Compiler.class.php, line 1880

Class

Smarty_Compiler
Template compiling class @package Smarty

Code

function _parse_modifiers(&$output, $modifier_string) {
  preg_match_all('~\\|(@?\\w+)((?>:(?:' . $this->_qstr_regexp . '|[^|]+))*)~', '|' . $modifier_string, $_match);
  list(, $_modifiers, $modifier_arg_strings) = $_match;
  for ($_i = 0, $_for_max = count($_modifiers); $_i < $_for_max; $_i++) {
    $_modifier_name = $_modifiers[$_i];
    if ($_modifier_name == 'smarty') {

      // skip smarty modifier
      continue;
    }
    preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match);
    $_modifier_args = $_match[1];
    if ($_modifier_name[0] == '@') {
      $_map_array = false;
      $_modifier_name = substr($_modifier_name, 1);
    }
    else {
      $_map_array = true;
    }
    if (empty($this->_plugins['modifier'][$_modifier_name]) && !$this
      ->_get_plugin_filepath('modifier', $_modifier_name) && function_exists($_modifier_name)) {
      if ($this->security && !in_array($_modifier_name, $this->security_settings['MODIFIER_FUNCS'])) {
        $this
          ->_trigger_fatal_error("[plugin] (secure mode) modifier '{$_modifier_name}' is not allowed", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
      }
      else {
        $this->_plugins['modifier'][$_modifier_name] = array(
          $_modifier_name,
          null,
          null,
          false,
        );
      }
    }
    $this
      ->_add_plugin('modifier', $_modifier_name);
    $this
      ->_parse_vars_props($_modifier_args);
    if ($_modifier_name == 'default') {

      // supress notifications of default modifier vars and args
      if ($output[0] == '$') {
        $output = '@' . $output;
      }
      if (isset($_modifier_args[0]) && $_modifier_args[0][0] == '$') {
        $_modifier_args[0] = '@' . $_modifier_args[0];
      }
    }
    if (count($_modifier_args) > 0) {
      $_modifier_args = ', ' . implode(', ', $_modifier_args);
    }
    else {
      $_modifier_args = '';
    }
    if ($_map_array) {
      $output = "((is_array(\$_tmp={$output})) ? \$this->_run_mod_handler('{$_modifier_name}', true, \$_tmp{$_modifier_args}) : " . $this
        ->_compile_plugin_call('modifier', $_modifier_name) . "(\$_tmp{$_modifier_args}))";
    }
    else {
      $output = $this
        ->_compile_plugin_call('modifier', $_modifier_name) . "({$output}{$_modifier_args})";
    }
  }
}