/core/model/smarty/sysplugins/smarty_internal_compile_private_registered_block.php

https://github.com/hatone/revolution · PHP · 86 lines · 51 code · 4 blank · 31 comment · 16 complexity · a2c191811069793afd6ee581433d9465 MD5 · raw file

  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. class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_CompileBase {
  15. // attribute definitions
  16. public $optional_attributes = array('_any');
  17. /**
  18. * Compiles code for the execution of a block function
  19. *
  20. * @param array $args array with attributes from parser
  21. * @param object $compiler compiler object
  22. * @param array $parameter array with compilation parameter
  23. * @param string $tag name of block function
  24. * @return string compiled code
  25. */
  26. public function compile($args, $compiler, $parameter, $tag)
  27. {
  28. $this->compiler = $compiler;
  29. if (strlen($tag) < 6 || substr($tag,-5) != 'close') {
  30. // opening tag of block plugin
  31. // check and get attributes
  32. $_attr = $this->_get_attributes($args);
  33. if ($_attr['nocache']) {
  34. $this->compiler->tag_nocache = true;
  35. }
  36. unset($_attr['nocache']);
  37. // convert attributes into parameter array string
  38. $_paramsArray = array();
  39. foreach ($_attr as $_key => $_value) {
  40. if (is_int($_key)) {
  41. $_paramsArray[] = "$_key=>$_value";
  42. } else {
  43. $_paramsArray[] = "'$_key'=>$_value";
  44. }
  45. }
  46. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  47. $this->_open_tag($tag, array($_params, $this->compiler->nocache));
  48. // maybe nocache because of nocache variables or nocache plugin
  49. $this->compiler->nocache = !$compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag][1] | $this->compiler->nocache | $this->compiler->tag_nocache;
  50. $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag][0];
  51. // compile code
  52. if (!is_array($function)) {
  53. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  54. } else if (is_object($function[0])) {
  55. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  56. } else {
  57. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  58. }
  59. } else {
  60. // must endblock be nocache?
  61. if ($this->compiler->nocache) {
  62. $this->compiler->tag_nocache = true;
  63. }
  64. $base_tag = substr($tag, 0, -5);
  65. // closing tag of block plugin, restore nocache
  66. list($_params, $this->compiler->nocache) = $this->_close_tag($base_tag);
  67. // This tag does create output
  68. $this->compiler->has_output = true;
  69. $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$base_tag][0];
  70. // compile code
  71. if (!is_array($function)) {
  72. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  73. } else if (is_object($function[0])) {
  74. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  75. } else {
  76. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  77. }
  78. }
  79. return $output."\n";
  80. }
  81. }
  82. ?>