Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

smarty_internal_compile_private_object_block_function.php 3.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Object Block Function
  4. * Compiles code for registered objects as block function
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Object Block Function Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_CompileBase
  17. {
  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 \Smarty_Internal_TemplateCompilerBase $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. *
  34. * @return string compiled code
  35. */
  36. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
  37. {
  38. if (!isset($tag[5]) || substr($tag, - 5) != 'close') {
  39. // opening tag of block plugin
  40. // check and get attributes
  41. $_attr = $this->getAttributes($compiler, $args);
  42. if ($_attr['nocache'] === true) {
  43. $compiler->tag_nocache = true;
  44. }
  45. unset($_attr['nocache']);
  46. // convert attributes into parameter array string
  47. $_paramsArray = array();
  48. foreach ($_attr as $_key => $_value) {
  49. if (is_int($_key)) {
  50. $_paramsArray[] = "$_key=>$_value";
  51. } else {
  52. $_paramsArray[] = "'$_key'=>$_value";
  53. }
  54. }
  55. $_params = 'array(' . implode(",", $_paramsArray) . ')';
  56. $this->openTag($compiler, $tag . '->' . $method, array($_params, $compiler->nocache));
  57. // maybe nocache because of nocache variables or nocache plugin
  58. $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
  59. // compile code
  60. $output =
  61. "<?php \$_smarty_tpl->smarty->_cache['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();?>";
  62. } else {
  63. $base_tag = substr($tag, 0, - 5);
  64. // must endblock be nocache?
  65. if ($compiler->nocache) {
  66. $compiler->tag_nocache = true;
  67. }
  68. // closing tag of block plugin, restore nocache
  69. list($_params, $compiler->nocache) = $this->closeTag($compiler, $base_tag . '->' . $method);
  70. // This tag does create output
  71. $compiler->has_output = true;
  72. // compile code
  73. if (!isset($parameter['modifier_list'])) {
  74. $mod_pre = $mod_post = '';
  75. } else {
  76. $mod_pre = ' ob_start(); ';
  77. $mod_post = 'echo ' . $compiler->compileTag('private_modifier', array(),
  78. array('modifierlist' => $parameter['modifier_list'],
  79. 'value' => 'ob_get_clean()')) . ';';
  80. }
  81. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
  82. " echo \$_smarty_tpl->smarty->registered_objects['{$base_tag}'][0]->{$method}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " .
  83. $mod_post . " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
  84. }
  85. return $output . "\n";
  86. }
  87. }