You are here

function Smarty_Compiler::_compile_registered_object_tag in Quiz 6.5

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

compile a registered object tag

Parameters

string $tag_command:

array $attrs:

string $tag_modifier:

Return value

string

1 call to Smarty_Compiler::_compile_registered_object_tag()
Smarty_Compiler::_compile_tag in includes/moodle/lib/smarty/Smarty_Compiler.class.php
Compile a template tag

File

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

Class

Smarty_Compiler
Template compiling class @package Smarty

Code

function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) {
  if ($tag_command[0] == '/') {
    $start_tag = false;
    $tag_command = substr($tag_command, 1);
  }
  else {
    $start_tag = true;
  }
  list($object, $obj_comp) = explode('->', $tag_command);
  $arg_list = array();
  if (count($attrs)) {
    $_assign_var = false;
    foreach ($attrs as $arg_name => $arg_value) {
      if ($arg_name == 'assign') {
        $_assign_var = $arg_value;
        unset($attrs['assign']);
        continue;
      }
      if (is_bool($arg_value)) {
        $arg_value = $arg_value ? 'true' : 'false';
      }
      $arg_list[] = "'{$arg_name}' => {$arg_value}";
    }
  }
  if ($this->_reg_objects[$object][2]) {

    // smarty object argument format
    $args = "array(" . implode(',', (array) $arg_list) . "), \$this";
  }
  else {

    // traditional argument format
    $args = implode(',', array_values($attrs));
    if (empty($args)) {
      $args = 'null';
    }
  }
  $prefix = '';
  $postfix = '';
  $newline = '';
  if (!is_object($this->_reg_objects[$object][0])) {
    $this
      ->_trigger_fatal_error("registered '{$object}' is not an object", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
  }
  elseif (!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp, $this->_reg_objects[$object][1])) {
    $this
      ->_trigger_fatal_error("'{$obj_comp}' is not a registered component of object '{$object}'", $this->_current_file, $this->_current_line_no, __FILE__, __LINE__);
  }
  elseif (method_exists($this->_reg_objects[$object][0], $obj_comp)) {

    // method
    if (in_array($obj_comp, $this->_reg_objects[$object][3])) {

      // block method
      if ($start_tag) {
        $prefix = "\$this->_tag_stack[] = array('{$obj_comp}', {$args}); ";
        $prefix .= "\$this->_reg_objects['{$object}'][0]->{$obj_comp}(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], null, \$this, \$_block_repeat=true); ";
        $prefix .= "while (\$_block_repeat) { ob_start();";
        $return = null;
        $postfix = '';
      }
      else {
        $prefix = "\$_obj_block_content = ob_get_contents(); ob_end_clean(); ";
        $return = "\$this->_reg_objects['{$object}'][0]->{$obj_comp}(\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$_obj_block_content, \$this, \$_block_repeat=false)";
        $postfix = "} array_pop(\$this->_tag_stack);";
      }
    }
    else {

      // non-block method
      $return = "\$this->_reg_objects['{$object}'][0]->{$obj_comp}({$args})";
    }
  }
  else {

    // property
    $return = "\$this->_reg_objects['{$object}'][0]->{$obj_comp}";
  }
  if ($return != null) {
    if ($tag_modifier != '') {
      $this
        ->_parse_modifiers($return, $tag_modifier);
    }
    if (!empty($_assign_var)) {
      $output = "\$this->assign('" . $this
        ->_dequote($_assign_var) . "',  {$return});";
    }
    else {
      $output = 'echo ' . $return . ';';
      $newline = $this->_additional_newline;
    }
  }
  else {
    $output = '';
  }
  return '<?php ' . $prefix . $output . $postfix . "?>" . $newline;
}