smarty_internal_compile_private_object_block_function.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Private_Object_Block_Function 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 block plugin
  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 object
  32. * @param string $method name of method to call
  33. * @return string compiled code
  34. */
  35. public function compile($args, $compiler, $parameter, $tag, $method)
  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'] === true) {
  42. $compiler->tag_nocache = true;
  43. }
  44. unset($_attr['nocache']);
  45. // convert attributes into parameter array string
  46. $_paramsArray = array();
  47. foreach ($_attr as $_key => $_value) {
  48. if (is_int($_key)) {
  49. $_paramsArray[] = "$_key=>$_value";
  50. } else {
  51. $_paramsArray[] = "'$_key'=>$_value";
  52. }
  53. }
  54. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  55. $this->openTag($compiler, $tag . '->' . $method, array($_params, $compiler->nocache));
  56. // maybe nocache because of nocache variables or nocache plugin
  57. $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
  58. // compile code
  59. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}->{$method}', {$_params}); \$_block_repeat=true; echo \$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  60. } else {
  61. $base_tag = substr($tag, 0, -5);
  62. // must endblock be nocache?
  63. if ($compiler->nocache) {
  64. $compiler->tag_nocache = true;
  65. }
  66. // closing tag of block plugin, restore nocache
  67. list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag . '->' . $method);
  68. // This tag does create output
  69. $compiler->has_output = true;
  70. // compile code
  71. if (!isset($parameter['modifier_list'])) {
  72. $mod_pre = $mod_post = '';
  73. } else {
  74. $mod_pre = ' ob_start(); ';
  75. $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'], 'value' => 'ob_get_clean()')) . ';';
  76. }
  77. $output = "<?php \$_block_content = ob_get_contents(); ob_end_clean(); \$_block_repeat=false;" . $mod_pre . " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post . " } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  78. }
  79. return $output . "\n";
  80. }
  81. }
  82. ?>