smarty_internal_compile_private_object_block_function.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Object Block Function
  4. *
  5. * Compiles code for registered objects as block function
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Object Block Function Class
  13. */
  14. class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the execution of block plugin
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param string $tag name of block function
  20. * @param string $methode name of methode to call
  21. * @param object $compiler compiler object
  22. * @return string compiled code
  23. */
  24. public function compile($args, $compiler, $tag, $methode)
  25. {
  26. $this->compiler = $compiler;
  27. if (strlen($tag) < 5 || substr($tag, -5) != 'close') {
  28. // opening tag of block plugin
  29. $this->required_attributes = array();
  30. $this->optional_attributes = array('_any');
  31. // check and get attributes
  32. $_attr = $this->_get_attributes($args);
  33. // convert attributes into parameter array string
  34. $_paramsArray = array();
  35. foreach ($_attr as $_key => $_value) {
  36. if (is_int($_key)) {
  37. $_paramsArray[] = "$_key=>$_value";
  38. } else {
  39. $_paramsArray[] = "'$_key'=>$_value";
  40. }
  41. }
  42. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  43. $this->_open_tag($tag . '->' . $methode, $_params);
  44. // compile code
  45. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$methode}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
  46. } else {
  47. $base_tag = substr($tag, 0, -5);
  48. // closing tag of block plugin
  49. $_params = $this->_close_tag($base_tag . '->' . $methode);
  50. // This tag does create output
  51. $this->compiler->has_output = true;
  52. // compile code
  53. $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false; echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$methode}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  54. }
  55. return $output."\n";
  56. }
  57. }
  58. ?>