author | Markus Bröker <broeker.markus@googlemail.com> |
Thu, 12 Nov 2015 14:39:16 +0100 | |
changeset 0 | 4869aea77e21 |
permissions | -rw-r--r-- |
0
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
1 |
<?php |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
2 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
3 |
* Smarty Internal Plugin Compile Capture |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
4 |
* Compiles the {capture} tag |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
5 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
6 |
* @package Smarty |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
7 |
* @subpackage Compiler |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
8 |
* @author Uwe Tews |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
9 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
10 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
11 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
12 |
* Smarty Internal Plugin Compile Capture Class |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
13 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
14 |
* @package Smarty |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
15 |
* @subpackage Compiler |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
16 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
17 |
class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase { |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
18 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
19 |
* Attribute definition: Overwrites base class. |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
20 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
21 |
* @var array |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
22 |
* @see Smarty_Internal_CompileBase |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
23 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
24 |
public $shorttag_order = array('name'); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
25 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
26 |
* Attribute definition: Overwrites base class. |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
27 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
28 |
* @var array |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
29 |
* @see Smarty_Internal_CompileBase |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
30 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
31 |
public $optional_attributes = array('name', 'assign', 'append'); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
32 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
33 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
34 |
* Compiles code for the {capture} tag |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
35 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
36 |
* @param array $args array with attributes from parser |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
37 |
* @param object $compiler compiler object |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
38 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
39 |
* @return string compiled code |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
40 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
41 |
public function compile($args, $compiler) { |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
42 |
// check and get attributes |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
43 |
$_attr = $this->getAttributes($compiler, $args); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
44 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
45 |
$buffer = isset($_attr['name']) ? $_attr['name'] : "'default'"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
46 |
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null'; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
47 |
$append = isset($_attr['append']) ? $_attr['append'] : 'null'; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
48 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
49 |
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
50 |
// maybe nocache because of nocache variables |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
51 |
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
52 |
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
53 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
54 |
return $_output; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
55 |
} |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
56 |
} |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
57 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
58 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
59 |
* Smarty Internal Plugin Compile Captureclose Class |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
60 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
61 |
* @package Smarty |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
62 |
* @subpackage Compiler |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
63 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
64 |
class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase { |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
65 |
/** |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
66 |
* Compiles code for the {/capture} tag |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
67 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
68 |
* @param array $args array with attributes from parser |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
69 |
* @param object $compiler compiler object |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
70 |
* |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
71 |
* @return string compiled code |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
72 |
*/ |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
73 |
public function compile($args, $compiler) { |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
74 |
// check and get attributes |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
75 |
$_attr = $this->getAttributes($compiler, $args); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
76 |
// must endblock be nocache? |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
77 |
if ($compiler->nocache) { |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
78 |
$compiler->tag_nocache = true; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
79 |
} |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
80 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
81 |
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]); |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
82 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
83 |
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
84 |
$_output .= "if (!empty(\$_capture_buffer)) {\n"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
85 |
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
86 |
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
87 |
$_output .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
88 |
$_output .= "} else \$_smarty_tpl->capture_error();?>"; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
89 |
|
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
90 |
return $_output; |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
91 |
} |
4869aea77e21
Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff
changeset
|
92 |
} |