/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_block.php

http://zoop.googlecode.com/ · PHP · 116 lines · 81 code · 2 blank · 33 comment · 6 complexity · f54904dba48323bd93c96053ba3480d2 MD5 · raw file

  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Block
  4. *
  5. * Compiles the {block}{/block} tags
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Block Class
  13. */
  14. class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {block} tag
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return boolean true
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->required_attributes = array('name');
  26. $this->optional_attributes = array('assign', 'nocache');
  27. // check and get attributes
  28. $_attr = $this->_get_attributes($args);
  29. $save = array($_attr, $compiler->template->extracted_compiled_code, $compiler->template->extract_code, $this->compiler->nocache);
  30. $this->_open_tag('block', $save);
  31. if (isset($_attr['nocache'])) {
  32. if ($_attr['nocache'] == 'true') {
  33. $compiler->nocache = true;
  34. }
  35. }
  36. $compiler->template->extract_code = true;
  37. $compiler->template->extracted_compiled_code = '';
  38. $compiler->has_code = false;
  39. return true;
  40. }
  41. }
  42. /**
  43. * Smarty Internal Plugin Compile BlockClose Class
  44. */
  45. class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
  46. /**
  47. * Compiles code for the {/block} tag
  48. *
  49. * @param array $args array with attributes from parser
  50. * @param object $compiler compiler object
  51. * @return string compiled code
  52. */
  53. public function compile($args, $compiler)
  54. {
  55. $this->compiler = $compiler;
  56. $this->smarty = $compiler->smarty;
  57. $this->compiler->has_code = true;
  58. // turn off block code extraction
  59. $compiler->template->extract_code = false;
  60. // check and get attributes
  61. $this->optional_attributes = array('name');
  62. $_attr = $this->_get_attributes($args);
  63. $saved_data = $this->_close_tag(array('block'));
  64. // if name does match to opening tag
  65. if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) {
  66. $this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
  67. }
  68. $_name = trim($saved_data[0]['name'], "\"'");
  69. if (isset($this->smarty->block_data[$_name])) {
  70. $_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template);
  71. $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
  72. $_tpl->template_filepath = $this->smarty->block_data[$_name]['file'];
  73. if ($compiler->nocache) {
  74. $_tpl->forceNocache = 2;
  75. } else {
  76. $_tpl->forceNocache = 1;
  77. }
  78. $_tpl->suppressHeader = true;
  79. $_tpl->suppressFileDependency = true;
  80. if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
  81. $_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $_tpl->getCompiledTemplate());
  82. } elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') {
  83. $_output = $_tpl->getCompiledTemplate() . $compiler->template->extracted_compiled_code;
  84. } elseif ($this->smarty->block_data[$_name]['mode'] == 'append') {
  85. $_output = $compiler->template->extracted_compiled_code . $_tpl->getCompiledTemplate();
  86. } elseif (!empty($this->smarty->block_data[$_name])) {
  87. $_output = $_tpl->getCompiledTemplate();
  88. }
  89. $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
  90. $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
  91. if ($_tpl->has_nocache_code) {
  92. $compiler->template->has_nocache_code = true;
  93. }
  94. foreach($_tpl->required_plugins as $code => $tmp1) {
  95. foreach($tmp1 as $name => $tmp) {
  96. foreach($tmp as $type => $data) {
  97. $compiler->template->required_plugins[$code][$name][$type] = $data;
  98. }
  99. }
  100. }
  101. unset($_tpl);
  102. } else {
  103. $_output = $compiler->template->extracted_compiled_code;
  104. }
  105. $compiler->template->extracted_compiled_code = $saved_data[1];
  106. $compiler->template->extract_code = $saved_data[2];
  107. $compiler->nocache = $saved_data[3];
  108. // $_output content has already nocache code processed
  109. $compiler->suppressNocacheProcessing = true;
  110. return $_output;
  111. }
  112. }
  113. ?>