smarty_internal_compile_private_registered_block.php 5.6 KB

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