/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_capture.php
PHP | 72 lines | 33 code | 8 blank | 31 comment | 2 complexity | e515fa40207308fb704c39ea452ad896 MD5 | raw file
1<?php 2/** 3* Smarty Internal Plugin Compile Capture 4* 5* Compiles the {capture} tag 6* 7* @package Smarty 8* @subpackage Compiler 9* @author Uwe Tews 10*/ 11/** 12* Smarty Internal Plugin Compile Capture Class 13*/ 14class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase { 15 /** 16 * Compiles code for the {capture} tag 17 * 18 * @param array $args array with attributes from parser 19 * @param object $compiler compiler object 20 * @return string compiled code 21 */ 22 public function compile($args, $compiler) 23 { 24 $this->compiler = $compiler; 25 $this->optional_attributes = array('name', 'assign', 'append'); 26 // check and get attributes 27 $_attr = $this->_get_attributes($args); 28 29 $buffer = isset($_attr['name']) ? $_attr['name'] : "'default'"; 30 $assign = isset($_attr['assign']) ? $_attr['assign'] : null; 31 $append = isset($_attr['append']) ? $_attr['append'] : null; 32 33 $this->compiler->_capture_stack[] = array($buffer, $assign, $append); 34 35 $_output = "<?php ob_start(); ?>"; 36 37 return $_output; 38 } 39} 40 41/** 42* Smarty Internal Plugin Compile Captureclose Class 43*/ 44class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase { 45 /** 46 * Compiles code for the {/capture} tag 47 * 48 * @param array $args array with attributes from parser 49 * @param object $compiler compiler object 50 * @return string compiled code 51 */ 52 public function compile($args, $compiler) 53 { 54 $this->compiler = $compiler; 55 // check and get attributes 56 $_attr = $this->_get_attributes($args); 57 58 list($buffer, $assign, $append) = array_pop($this->compiler->_capture_stack); 59 60 $_output = "<?php "; 61 if (isset($assign)) { 62 $_output .= " \$_smarty_tpl->assign($assign, ob_get_contents());"; 63 } 64 if (isset($append)) { 65 $_output .= " \$_smarty_tpl->append($append, ob_get_contents());"; 66 } 67 $_output .= " \$_smarty_tpl->smarty->_smarty_vars['capture'][$buffer]=ob_get_clean();?>"; 68 return $_output; 69 } 70} 71 72?>