/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_block.php
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 */ 14class 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 37 $compiler->template->extract_code = true; 38 $compiler->template->extracted_compiled_code = ''; 39 $compiler->has_code = false; 40 return true; 41 } 42} 43 44/** 45 * Smarty Internal Plugin Compile BlockClose Class 46 */ 47class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase { 48 /** 49 * Compiles code for the {/block} tag 50 * 51 * @param array $args array with attributes from parser 52 * @param object $compiler compiler object 53 * @return string compiled code 54 */ 55 public function compile($args, $compiler) 56 { 57 $this->compiler = $compiler; 58 $this->smarty = $compiler->smarty; 59 $this->compiler->has_code = true; 60 // turn off block code extraction 61 $compiler->template->extract_code = false; 62 // check and get attributes 63 $this->optional_attributes = array('name'); 64 $_attr = $this->_get_attributes($args); 65 $saved_data = $this->_close_tag(array('block')); 66 // if name does match to opening tag 67 if (isset($_attr['name']) && $saved_data[0]['name'] != $_attr['name']) { 68 $this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"'); 69 } 70 $_name = trim($saved_data[0]['name'], "\"'"); 71 if (isset($this->smarty->block_data[$_name])) { 72 $_tpl = $this->smarty->createTemplate('string:' . $this->smarty->block_data[$_name]['source'], null, null, $compiler->template); 73 $_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash']; 74 $_tpl->template_filepath = $this->smarty->block_data[$_name]['file']; 75 if ($compiler->nocache) { 76 $_tpl->forceNocache = 2; 77 } else { 78 $_tpl->forceNocache = 1; 79 } 80 $_tpl->suppressHeader = true; 81 $_tpl->suppressFileDependency = true; 82 if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { 83 $_output = str_replace('%%%%SMARTY_PARENT%%%%', $compiler->template->extracted_compiled_code, $_tpl->getCompiledTemplate()); 84 } elseif ($this->smarty->block_data[$_name]['mode'] == 'prepend') { 85 $_output = $_tpl->getCompiledTemplate() . $compiler->template->extracted_compiled_code; 86 } elseif ($this->smarty->block_data[$_name]['mode'] == 'append') { 87 $_output = $compiler->template->extracted_compiled_code . $_tpl->getCompiledTemplate(); 88 } elseif (!empty($this->smarty->block_data[$_name])) { 89 $_output = $_tpl->getCompiledTemplate(); 90 } 91 $compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']); 92 $compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']); 93 if ($_tpl->has_nocache_code) { 94 $compiler->template->has_nocache_code = true; 95 } 96 foreach($_tpl->required_plugins as $code => $tmp1) { 97 foreach($tmp1 as $name => $tmp) { 98 foreach($tmp as $type => $data) { 99 $compiler->template->required_plugins[$code][$name][$type] = $data; 100 } 101 } 102 } 103 unset($_tpl); 104 } else { 105 $_output = $compiler->template->extracted_compiled_code; 106 } 107 $compiler->template->extracted_compiled_code = $saved_data[1]; 108 $compiler->template->extract_code = $saved_data[2]; 109 $compiler->nocache = $saved_data[3]; 110 // $_output content has already nocache code processed 111 $compiler->suppressNocacheProcessing = true; 112 return $_output; 113 } 114} 115 116?>