smarty_internal_compile_private_block_plugin.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Private_Block_Plugin 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 plugin
  32. * @param string $function PHP function name
  33. * @return string compiled code
  34. */
  35. public function compile($args, $compiler, $parameter, $tag, $function)
  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, 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}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  60. } else {
  61. // must endblock be nocache?
  62. if ($compiler->nocache) {
  63. $compiler->tag_nocache = true;
  64. }
  65. // closing tag of block plugin, restore nocache
  66. list($_params, $compiler->nocache) = $this->closeTag($compiler, substr($tag, 0, -5));
  67. // This tag does create output
  68. $compiler->has_output = true;
  69. // compile code
  70. if (!isset($parameter['modifier_list'])) {
  71. $mod_pre = $mod_post ='';
  72. } else {
  73. $mod_pre = ' ob_start(); ';
  74. $mod_post = 'echo '.$compiler->compileTag('private_modifier',array(),array('modifierlist'=>$parameter['modifier_list'],'value'=>'ob_get_clean()')).';';
  75. }
  76. $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);?>";
  77. }
  78. return $output . "\n";
  79. }
  80. }
  81. ?>