]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/sysplugins/smarty_internal_compile_extends.php
add smarty engine, remove some obsolete zot1 stuff
[friendica.git] / library / Smarty / libs / sysplugins / smarty_internal_compile_extends.php
1 <?php
2
3 /**
4 * Smarty Internal Plugin Compile extend
5 *
6 * Compiles the {extends} tag
7 *
8 * @package Smarty
9 * @subpackage Compiler
10 * @author Uwe Tews
11 */
12
13 /**
14 * Smarty Internal Plugin Compile extend Class
15 *
16 * @package Smarty
17 * @subpackage Compiler
18 */
19 class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
20
21     /**
22     * Attribute definition: Overwrites base class.
23     *
24     * @var array
25     * @see Smarty_Internal_CompileBase
26     */
27     public $required_attributes = array('file');
28     /**
29     * Attribute definition: Overwrites base class.
30     *
31     * @var array
32     * @see Smarty_Internal_CompileBase
33     */
34     public $shorttag_order = array('file');
35     /**
36     * mbstring.overload flag
37     *
38     * @var int
39     */
40     public $mbstring_overload = 0;
41
42     /**
43     * Compiles code for the {extends} tag
44     *
45     * @param array  $args     array with attributes from parser
46     * @param object $compiler compiler object
47     * @return string compiled code
48     */
49     public function compile($args, $compiler)
50     {
51         static $_is_stringy = array('string' => true, 'eval' => true);
52         $this->_rdl = preg_quote($compiler->smarty->right_delimiter);
53         $this->_ldl = preg_quote($compiler->smarty->left_delimiter);
54         $filepath = $compiler->template->source->filepath;
55         $this->mbstring_overload = ini_get('mbstring.func_overload') & 2;
56         // check and get attributes
57         $_attr = $this->getAttributes($compiler, $args);
58         if ($_attr['nocache'] === true) {
59             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
60         }
61
62         $_smarty_tpl = $compiler->template;
63         $include_file = null;
64         if (strpos($_attr['file'], '$_tmp') !== false) {
65             $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
66         }
67         eval('$include_file = ' . $_attr['file'] . ';');
68         // create template object
69         $_template = new $compiler->smarty->template_class($include_file, $compiler->smarty, $compiler->template);
70         // save file dependency
71         if (isset($_is_stringy[$_template->source->type])) {
72             $template_sha1 = sha1($include_file);
73         } else {
74             $template_sha1 = sha1($_template->source->filepath);
75         }
76         if (isset($compiler->template->properties['file_dependency'][$template_sha1])) {
77             $compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1);
78         }
79         $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
80         $_content = ($this->mbstring_overload ? mb_substr($compiler->template->source->content, $compiler->lex->counter - 1, 20000000, 'latin1') : substr($compiler->template->source->content, $compiler->lex->counter - 1));
81         if (preg_match_all("!({$this->_ldl}block\s(.+?){$this->_rdl})!", $_content, $s) !=
82         preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) {
83             $compiler->trigger_template_error('unmatched {block} {/block} pairs');
84         }
85         preg_match_all("!{$this->_ldl}block\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}|{$this->_ldl}\*([\S\s]*?)\*{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE);
86         $_result_count = count($_result[0]);
87         $_start = 0;
88         while ($_start+1 < $_result_count) {
89             $_end = 0;
90             $_level = 1;
91             if (($this->mbstring_overload ? mb_substr($_result[0][$_start][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') {
92                 $_start++;
93                 continue;
94             }
95             while ($_level != 0) {
96                 $_end++;
97                 if (($this->mbstring_overload ? mb_substr($_result[0][$_start + $_end][0],0,mb_strlen($compiler->smarty->left_delimiter,'latin1')+1, 'latin1') : substr($_result[0][$_start + $_end][0],0,strlen($compiler->smarty->left_delimiter)+1)) == $compiler->smarty->left_delimiter.'*') {
98                     continue;
99                 }
100                 if (!strpos($_result[0][$_start + $_end][0], '/')) {
101                     $_level++;
102                 } else {
103                     $_level--;
104                 }
105             }
106             $_block_content = str_replace($compiler->smarty->left_delimiter . '$smarty.block.parent' . $compiler->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
107             ($this->mbstring_overload ? mb_substr($_content, $_result[0][$_start][1] + mb_strlen($_result[0][$_start][0], 'latin1'), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + mb_strlen($_result[0][$_start][0], 'latin1'), 'latin1') : substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - + strlen($_result[0][$_start][0]))));
108             Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath);
109             $_start = $_start + $_end + 1;
110         }
111         if ($_template->source->type == 'extends') {
112             $_template->block_data = $compiler->template->block_data;
113         }
114         $compiler->template->source->content = $_template->source->content;
115         if ($_template->source->type == 'extends') {
116             $compiler->template->block_data = $_template->block_data;
117             foreach ($_template->source->components as $key => $component) {
118                 $compiler->template->properties['file_dependency'][$key] = array($component->filepath, $component->timestamp, $component->type);
119             }
120         }
121         $compiler->template->source->filepath = $_template->source->filepath;
122         $compiler->abort_and_recompile = true;
123         return '';
124     }
125
126 }
127
128 ?>