/library/vendor/Smarty/sysplugins/smarty_internal_compile_extends.php

https://gitlab.com/piotr-zuralski/demo-zuralski-trojmiastopl-articles · PHP · 90 lines · 62 code · 5 blank · 23 comment · 11 complexity · 82d34f5aa06dfecc6090f7160a1a3390 MD5 · raw file

  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile extend
  4. *
  5. * Compiles the {extends} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile extend Class
  13. */
  14. class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
  15. // attribute definitions
  16. public $required_attributes = array('file');
  17. public $shorttag_order = array('file');
  18. /**
  19. * Compiles code for the {extends} tag
  20. *
  21. * @param array $args array with attributes from parser
  22. * @param object $compiler compiler object
  23. * @return string compiled code
  24. */
  25. public function compile($args, $compiler)
  26. {
  27. $this->compiler = $compiler;
  28. $this->smarty = $compiler->smarty;
  29. $this->_rdl = preg_quote($this->smarty->right_delimiter);
  30. $this->_ldl = preg_quote($this->smarty->left_delimiter);
  31. $filepath = $compiler->template->getTemplateFilepath();
  32. // check and get attributes
  33. $_attr = $this->_get_attributes($args);
  34. if ($_attr['nocache'] === true) {
  35. $this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno);
  36. }
  37. $_smarty_tpl = $compiler->template;
  38. $include_file = null;
  39. if (strpos($_attr['file'],'$_tmp') !== false) {
  40. $this->compiler->trigger_template_error('illegal value for file attribute', $this->compiler->lex->taglineno);
  41. }
  42. eval('$include_file = ' . $_attr['file'] . ';');
  43. // create template object
  44. $_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template);
  45. // save file dependency
  46. if (in_array($_template->resource_type,array('eval','string'))) {
  47. $template_sha1 = sha1($include_file);
  48. } else {
  49. $template_sha1 = sha1($_template->getTemplateFilepath());
  50. }
  51. if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
  52. $this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"",$compiler->lex->line-1);
  53. }
  54. $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp(),$_template->resource_type);
  55. $_content = substr($compiler->template->template_source,$compiler->lex->counter-1);
  56. if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
  57. preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
  58. $this->compiler->trigger_template_error('unmatched {block} {/block} pairs');
  59. }
  60. preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
  61. $_result_count = count($_result[0]);
  62. $_start = 0;
  63. while ($_start < $_result_count) {
  64. $_end = 0;
  65. $_level = 1;
  66. while ($_level != 0) {
  67. $_end++;
  68. if (!strpos($_result[0][$_start + $_end][0], '/')) {
  69. $_level++;
  70. } else {
  71. $_level--;
  72. }
  73. }
  74. $_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
  75. 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])));
  76. Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
  77. $_start = $_start + $_end + 1;
  78. }
  79. $compiler->template->template_source = $_template->getTemplateSource();
  80. $compiler->template->template_filepath = $_template->getTemplateFilepath();
  81. $compiler->abort_and_recompile = true;
  82. return '';
  83. }
  84. }
  85. ?>