]> git.mxchange.org Git - friendica.git/blob - library/Smarty/libs/sysplugins/smarty_internal_compile_extends.php
Merge pull request #1124 from tobiasd/duepuntoderivs
[friendica.git] / library / Smarty / libs / sysplugins / smarty_internal_compile_extends.php
1 <?php
2
3 /**
4  * Smarty Internal Plugin Compile extend
5  * Compiles the {extends} tag
6  *
7  * @package    Smarty
8  * @subpackage Compiler
9  * @author     Uwe Tews
10  */
11
12 /**
13  * Smarty Internal Plugin Compile extend Class
14  *
15  * @package    Smarty
16  * @subpackage Compiler
17  */
18 class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase
19 {
20     /**
21      * Attribute definition: Overwrites base class.
22      *
23      * @var array
24      * @see Smarty_Internal_CompileBase
25      */
26     public $required_attributes = array('file');
27     /**
28      * Attribute definition: Overwrites base class.
29      *
30      * @var array
31      * @see Smarty_Internal_CompileBase
32      */
33     public $shorttag_order = array('file');
34
35     /**
36      * Compiles code for the {extends} tag
37      *
38      * @param array  $args     array with attributes from parser
39      * @param object $compiler compiler object
40      *
41      * @return string compiled code
42      */
43     public function compile($args, $compiler)
44     {
45         // check and get attributes
46         $_attr = $this->getAttributes($compiler, $args);
47         if ($_attr['nocache'] === true) {
48             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
49         }
50         if (strpos($_attr['file'], '$_tmp') !== false) {
51             $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
52         }
53
54         $name = $_attr['file'];
55         /** @var Smarty_Internal_Template $_smarty_tpl
56          * used in evaluated code
57          */
58         $_smarty_tpl = $compiler->template;
59         eval("\$tpl_name = $name;");
60         // create template object
61         $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
62         // check for recursion
63         $uid = $_template->source->uid;
64         if (isset($compiler->extends_uid[$uid])) {
65             $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
66         }
67         $compiler->extends_uid[$uid] = true;
68         if (empty($_template->source->components)) {
69             array_unshift($compiler->sources, $_template->source);
70         } else {
71             foreach ($_template->source->components as $source) {
72                 array_unshift($compiler->sources, $source);
73                 $uid = $source->uid;
74                 if (isset($compiler->extends_uid[$uid])) {
75                     $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
76                 }
77                 $compiler->extends_uid[$uid] = true;
78             }
79         }
80         unset ($_template);
81         $compiler->inheritance_child = true;
82         $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
83         return '';
84     }
85 }