smarty_internal_compile_private_block_plugin.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Block Plugin
  4. *
  5. * Compiles code for the execution of block plugin
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Block Plugin Class
  13. */
  14. class Smarty_Internal_Compile_Private_Block_Plugin 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 object $compiler compiler object
  21. * @return string compiled code
  22. */
  23. public function compile($args, $compiler, $tag, $function)
  24. {
  25. $this->compiler = $compiler;
  26. if (strlen($tag) < 6 || substr($tag, -5) != 'close') {
  27. // opening tag of block plugin
  28. $this->required_attributes = array();
  29. $this->optional_attributes = array('_any');
  30. // check and get attributes
  31. $_attr = $this->_get_attributes($args);
  32. // convert attributes into parameter array string
  33. $_paramsArray = array();
  34. foreach ($_attr as $_key => $_value) {
  35. if (is_int($_key)) {
  36. $_paramsArray[] = "$_key=>$_value";
  37. } else {
  38. $_paramsArray[] = "'$_key'=>$_value";
  39. }
  40. }
  41. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  42. $this->_open_tag($tag, array($_params, $this->compiler->nocache));
  43. // maybe nocache because of nocache variables or nocache plugin
  44. $this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
  45. // compile code
  46. $output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
  47. } else {
  48. // must endblock be nocache?
  49. if ($this->compiler->nocache) {
  50. $this->compiler->tag_nocache = true;
  51. }
  52. // closing tag of block plugin, restore nocache
  53. list($_params, $this->compiler->nocache) = $this->_close_tag(substr($tag, 0, -5));
  54. // This tag does create output
  55. $this->compiler->has_output = true;
  56. // compile code
  57. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
  58. }
  59. return $output . "\n";
  60. }
  61. }
  62. ?>