summaryrefslogtreecommitdiff
path: root/libs/sysplugins/smarty_internal_compile_config_load.php
blob: bb0103ed59efb27e841d497d56538e0fb2c83ec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

/**
 * Smarty Internal Plugin Compile Config Load
 * 
 * Compiles the {config load} tag
 * 
 * @package Smarty
 * @subpackage Compiler
 * @author Uwe Tews 
 */

/**
 * Smarty Internal Plugin Compile Config Load Class
 */
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase {
    /**
     * Compiles code for the {config_load} tag
     * 
     * @param array $args array with attributes from parser
     * @param object $compiler compiler object
     * @return string compiled code
     */
    public function compile($args, $compiler)
    {
        $this->compiler = $compiler;
        $this->required_attributes = array('file');
        $this->optional_attributes = array('section', 'scope'); 
        // check and get attributes
        $_attr = $this->_get_attributes($args); 
        // save posible attributes
        $conf_file = $_attr['file'];
        if (isset($_attr['section'])) {
            $section = $_attr['section'];
        } else {
            $section = 'null';
        } 
        $scope = '$_smarty_tpl->smarty';
        if (isset($_attr['scope'])) {
            $_attr['scope'] = trim($_attr['scope'], "'\"");
            if ($_attr['scope'] == 'local') {
                $scope = '$_smarty_tpl';
            } elseif ($_attr['scope'] == 'parent') {
                $scope = '$_smarty_tpl->parent';
            } 
        } 
        // create config object
        $_output = "<?php  \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
        $_output .= "\$_config->loadConfigVars($section, $scope); ?>";
        return $_output;
    } 
} 

?>