You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_compile_private_registered_block.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Registered Block
  4. * Compiles code for the execution of a registered block function
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Registered Block Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $optional_attributes = array('_any');
  25. /**
  26. * Compiles code for the execution of a block function
  27. *
  28. * @param array $args array with attributes from parser
  29. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  30. * @param array $parameter array with compilation parameter
  31. * @param string $tag name of block function
  32. *
  33. * @return string compiled code
  34. */
  35. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag)
  36. {
  37. if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
  38. // opening tag of block plugin
  39. // check and get attributes
  40. $_attr = $this->getAttributes($compiler, $args);
  41. if ($_attr['nocache']) {
  42. $compiler->tag_nocache = true;
  43. }
  44. unset($_attr['nocache']);
  45. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
  46. $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
  47. } else {
  48. $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
  49. }
  50. // convert attributes into parameter array string
  51. $_paramsArray = array();
  52. foreach ($_attr as $_key => $_value) {
  53. if (is_int($_key)) {
  54. $_paramsArray[] = "$_key=>$_value";
  55. } elseif ($compiler->template->caching && in_array($_key, $tag_info[2])) {
  56. $_value = str_replace("'", "^#^", $_value);
  57. $_paramsArray[] = "'$_key'=>^#^.var_export($_value,true).^#^";
  58. } else {
  59. $_paramsArray[] = "'$_key'=>$_value";
  60. }
  61. }
  62. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  63. $this->openTag($compiler, $tag, array($_params, $compiler->nocache));
  64. // maybe nocache because of nocache variables or nocache plugin
  65. $compiler->nocache = !$tag_info[1] | $compiler->nocache | $compiler->tag_nocache;
  66. $function = $tag_info[0];
  67. // compile code
  68. if (!is_array($function)) {
  69. $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  70. } elseif (is_object($function[0])) {
  71. $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  72. } else {
  73. $output = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  74. }
  75. } else {
  76. // must endblock be nocache?
  77. if ($compiler->nocache) {
  78. $compiler->tag_nocache = true;
  79. }
  80. $base_tag = substr($tag, 0, - 5);
  81. // closing tag of block plugin, restore nocache
  82. list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag);
  83. // This tag does create output
  84. $compiler->has_output = true;
  85. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag])) {
  86. $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
  87. } else {
  88. $function = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
  89. }
  90. // compile code
  91. if (!isset($parameter['modifier_list'])) {
  92. $mod_pre = $mod_post = '';
  93. } else {
  94. $mod_pre = ' ob_start(); ';
  95. $mod_post = 'echo ' .
  96. $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
  97. 'value' => 'ob_get_clean()')) . ';';
  98. }
  99. if (!is_array($function)) {
  100. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
  101. " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat);" . $mod_post .
  102. " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
  103. } elseif (is_object($function[0])) {
  104. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
  105. " echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
  106. $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
  107. } else {
  108. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
  109. " echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
  110. $mod_post . "} array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
  111. }
  112. }
  113. return $output . "\n";
  114. }
  115. }