]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_capture.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_capture.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Capture
4  * Compiles the {capture} tag
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile Capture Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Attribute definition: Overwrites base class.
21      *
22      * @var array
23      * @see Smarty_Internal_CompileBase
24      */
25     public $shorttag_order = array('name');
26
27     /**
28      * Attribute definition: Overwrites base class.
29      *
30      * @var array
31      * @see Smarty_Internal_CompileBase
32      */
33     public $optional_attributes = array('name', 'assign', 'append');
34
35     /**
36      * Compiles code for the {$smarty.capture.xxx}
37      *
38      * @param  array                            $args      array with attributes from parser
39      * @param \Smarty_Internal_TemplateCompilerBase$compiler  compiler object
40      * @param  array                            $parameter array with compilation parameter
41      *
42      * @return string compiled code
43      * @throws \SmartyCompilerException
44      */
45     public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
46     {
47         $tag = trim($parameter[ 0 ], '"\'');
48         $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
49         if (!$name) {
50             $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
51         }
52         return "\$_smarty_tpl->smarty->ext->_capture->getBuffer(\$_smarty_tpl, '{$name}')";
53     }
54
55     /**
56      * Compiles code for the {capture} tag
57      *
58      * @param  array                            $args     array with attributes from parser
59      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
60      * @param null                              $parameter
61      *
62      * @return string compiled code
63      */
64     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null)
65     {
66         // check and get attributes
67         $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
68
69         $buffer = isset($_attr[ 'name' ]) ? $_attr[ 'name' ] : "'default'";
70         $assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : 'null';
71         $append = isset($_attr[ 'append' ]) ? $_attr[ 'append' ] : 'null';
72
73         $compiler->_cache[ 'capture_stack' ][] = array($compiler->nocache);
74         // maybe nocache because of nocache variables
75         $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
76         $_output = "<?php \$_smarty_tpl->smarty->ext->_capture->open(\$_smarty_tpl, $buffer, $assign, $append);?>";
77
78         return $_output;
79     }
80 }
81
82 /**
83  * Smarty Internal Plugin Compile Captureclose Class
84  *
85  * @package    Smarty
86  * @subpackage Compiler
87  */
88 class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
89 {
90     /**
91      * Compiles code for the {/capture} tag
92      *
93      * @param  array                            $args     array with attributes from parser
94      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
95      * @param null                              $parameter
96      *
97      * @return string compiled code
98      */
99     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
100     {
101         // check and get attributes
102         $_attr = $this->getAttributes($compiler, $args, $parameter, '/capture');
103         // must endblock be nocache?
104         if ($compiler->nocache) {
105             $compiler->tag_nocache = true;
106         }
107
108         list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]);
109
110         return "<?php \$_smarty_tpl->smarty->ext->_capture->close(\$_smarty_tpl);?>";
111     }
112 }