[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/Smarty/libs/sysplugins/ -> smarty_internal_compile_extends.php (source)

   1  <?php
   2  
   3  /**
   4  * Smarty Internal Plugin Compile extend
   5  *
   6  * Compiles the {extends} tag
   7  *
   8  * @package Smarty
   9  * @subpackage Compiler
  10  * @author Uwe Tews
  11  */
  12  
  13  /**
  14  * Smarty Internal Plugin Compile extend Class
  15  *
  16  * @package Smarty
  17  * @subpackage Compiler
  18  */
  19  class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
  20  
  21      /**
  22      * Attribute definition: Overwrites base class.
  23      *
  24      * @var array
  25      * @see Smarty_Internal_CompileBase
  26      */
  27      public $required_attributes = array('file');
  28      /**
  29      * Attribute definition: Overwrites base class.
  30      *
  31      * @var array
  32      * @see Smarty_Internal_CompileBase
  33      */
  34      public $shorttag_order = array('file');
  35  
  36      /**
  37      * Compiles code for the {extends} tag
  38      *
  39      * @param array  $args     array with attributes from parser
  40      * @param object $compiler compiler object
  41      * @return string compiled code
  42      */
  43      public function compile($args, $compiler)
  44      {
  45          static $_is_stringy = array('string' => true, 'eval' => true);
  46          $this->_rdl = preg_quote($compiler->smarty->right_delimiter);
  47          $this->_ldl = preg_quote($compiler->smarty->left_delimiter);
  48          $filepath = $compiler->template->source->filepath;
  49          // check and get attributes
  50          $_attr = $this->getAttributes($compiler, $args);
  51          if ($_attr['nocache'] === true) {
  52              $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
  53          }
  54  
  55          $_smarty_tpl = $compiler->template;
  56          $include_file = null;
  57          if (strpos($_attr['file'], '$_tmp') !== false) {
  58              $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
  59          }
  60          eval('$include_file = ' . $_attr['file'] . ';');
  61          // create template object
  62          $_template = new $compiler->smarty->template_class($include_file, $compiler->smarty, $compiler->template);
  63          // save file dependency
  64          if (isset($_is_stringy[$_template->source->type])) {
  65              $template_sha1 = sha1($include_file);
  66          } else {
  67              $template_sha1 = sha1($_template->source->filepath);
  68          }
  69          if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
  70              $compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1);
  71          }
  72          $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
  73          $_content = substr($compiler->template->source->content, $compiler->lex->counter - 1);
  74          if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
  75          preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
  76              $compiler->trigger_template_error('unmatched {block} {/block} pairs');
  77          }
  78          preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
  79          $_result_count = count($_result[0]);
  80          $_start = 0;
  81          while ($_start+1 < $_result_count) {
  82              $_end = 0;
  83              $_level = 1;
  84              if (substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') {
  85                  $_start++;
  86                  continue;
  87              }
  88              while ($_level != 0) {
  89                  $_end++;
  90                  if (substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1) == $compiler->smarty->left_delimiter.'*') {
  91                      continue;
  92                  }
  93                  if (!strpos($_result[0][$_start + $_end][0], '/')) {
  94                      $_level++;
  95                  } else {
  96                      $_level--;
  97                  }
  98              }
  99              $_block_content = str_replace($compiler->smarty->left_delimiter . '$smarty.block.parent' . $compiler->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
 100              substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0])));
 101              Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
 102              $_start = $_start + $_end + 1;
 103          }
 104          if ($_template->source->type == 'extends') {
 105              $_template->block_data = $compiler->template->block_data;
 106          }
 107          $compiler->template->source->content = $_template->source->content;
 108          if ($_template->source->type == 'extends') {
 109              $compiler->template->block_data = $_template->block_data;
 110              foreach ($_template->source->components as $key => $component) {
 111                  $compiler->template->properties['file_dependency'][$key] = array($component->filepath, $component->timestamp, $component->type);
 112              }
 113          }
 114          $compiler->template->source->filepath = $_template->source->filepath;
 115          $compiler->abort_and_recompile = true;
 116          return '';
 117      }
 118  
 119  }
 120  
 121  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1