Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 1
<?php
2
/**
3
 * This file is part of Smarty.
4
 *
5
 * (c) 2015 Uwe Tews
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * Smarty Internal Plugin Compile Child Class
13
 *
14
 * @author Uwe Tews <uwe.tews@googlemail.com>
15
 */
16
class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase
17
{
18
    /**
19
     * Attribute definition: Overwrites base class.
20
     *
21
     * @var array
22
     * @see Smarty_Internal_CompileBase
23
     */
24
    public $optional_attributes = array('assign');
25
 
26
    /**
27
     * Tag name
28
     *
29
     * @var string
30
     */
31
    public $tag = 'child';
32
 
33
    /**
34
     * Block type
35
     *
36
     * @var string
37
     */
38
    public $blockType = 'Child';
39
 
40
    /**
41
     * Compiles code for the {child} tag
42
     *
43
     * @param array                                 $args      array with attributes from parser
44
     * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
45
     * @param array                                 $parameter array with compilation parameter
46
     *
47
     * @return string compiled code
48
     * @throws \SmartyCompilerException
49
     */
50
    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
51
    {
52
        // check and get attributes
53
        $_attr = $this->getAttributes($compiler, $args);
54
        $tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
55
        if (!isset($compiler->_cache[ 'blockNesting' ])) {
56
            $compiler->trigger_template_error(
57
                "{$tag} used outside {block} tags ",
58
                $compiler->parser->lex->taglineno
59
            );
60
        }
61
        $compiler->has_code = true;
62
        $compiler->suppressNocacheProcessing = true;
63
        if ($this->blockType === 'Child') {
64
            $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true';
65
        }
66
        $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null;
67
        $output = "<?php \n";
68
        if (isset($_assign)) {
69
            $output .= "ob_start();\n";
70
        }
71
        $output .= '$_smarty_tpl->inheritance->call' . $this->blockType . '($_smarty_tpl, $this' .
72
                   ($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n";
73
        if (isset($_assign)) {
74
            $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n";
75
        }
76
        $output .= "?>\n";
77
        return $output;
78
    }
79
}