PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/fsn-site-central/mediatheque/include/smarty/libs/sysplugins/smarty_internal_compile_private_block_plugin.php

https://gitlab.com/team_fsn/fsn-php
PHP | 89 lines | 45 code | 4 blank | 40 comment | 10 complexity | 61532d3d7954cd41afaade3c0e90e3c5 MD5 | raw file
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Block Plugin
  4. * Compiles code for the execution of block plugin
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Block Plugin Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Block_Plugin 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 plugin
  32. * @param string $function PHP function name
  33. *
  34. * @return string compiled code
  35. */
  36. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
  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, 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 = "<?php \$_smarty_tpl->smarty->_cache['tag_stack'][] = array('{$tag}', {$_params}); \$_block_repeat=true; echo {$function}({$_params}, null, \$_smarty_tpl, \$_block_repeat);while (\$_block_repeat) { ob_start();?>";
  61. } else {
  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, substr($tag, 0, - 5));
  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 ' .
  76. $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifier_list'],
  77. 'value' => 'ob_get_clean()')) . ';';
  78. }
  79. $output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false;" . $mod_pre .
  80. " echo {$function}({$_params}, \$_block_content, \$_smarty_tpl, \$_block_repeat); " . $mod_post .
  81. " } array_pop(\$_smarty_tpl->smarty->_cache['tag_stack']);?>";
  82. }
  83. return $output . "\n";
  84. }
  85. }