Projekt

Allgemein

Profil

GX-Task #46352 » Smarty_v3_1_29_Integration_Zwischenstand.patch

Moritz Bunjes, 06.05.2016 16:14

Unterschiede anzeigen:

src/includes/classes/Smarty/sysplugins/smarty_internal_compile_while.php (revision )
19 19
    /**
20 20
     * Compiles code for the {while} tag
21 21
     *
22
     * @param  array  $args      array with attributes from parser
22
     * @param  array                                       $args      array with attributes from parser
23
     * @param  object $compiler  compiler object
23
     * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
24
     * @param  array  $parameter array with compilation parameter
24
     * @param  array                                       $parameter array with compilation parameter
25 25
     *
26 26
     * @return string compiled code
27
     * @throws \SmartyCompilerException
27 28
     */
28
    public function compile($args, $compiler, $parameter)
29
    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
29 30
    {
31
        $compiler->loopNesting++;
30 32
        // check and get attributes
31 33
        $_attr = $this->getAttributes($compiler, $args);
32 34
        $this->openTag($compiler, 'while', $compiler->nocache);
33 35

  
34 36
        if (!array_key_exists("if condition", $parameter)) {
35
            $compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno);
37
            $compiler->trigger_template_error("missing while condition", null, true);
36 38
        }
37 39

  
38 40
        // maybe nocache because of nocache variables
39 41
        $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
42
        $_output = "<?php\n";
40 43
        if (is_array($parameter['if condition'])) {
41 44
            if ($compiler->nocache) {
42 45
                $_nocache = ',true';
43 46
                // create nocache var to make it know for further compiling
44 47
                if (is_array($parameter['if condition']['var'])) {
45
                    $compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_variable(null, true);
48
                    $var = trim($parameter['if condition']['var']['var'], "'");
46 49
                } else {
47
                    $compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_variable(null, true);
50
                    $var = trim($parameter['if condition']['var'], "'");
48 51
                }
52
                if (isset($compiler->template->tpl_vars[$var])) {
53
                    $compiler->template->tpl_vars[$var]->nocache = true;
49
            } else {
54
                } else {
55
                    $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
56
                }
57
            } else {
50 58
                $_nocache = '';
51 59
            }
52 60
            if (is_array($parameter['if condition']['var'])) {
53
                $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value)) \$_smarty_tpl->createLocalArrayVariable(" . $parameter['if condition']['var']['var'] . "$_nocache);\n";
54
                $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . $parameter['if condition']['value'] . ") {?>";
61
                $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
62
                    "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
63
                    "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] .
64
                    "$_nocache);\n";
65
                $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
66
                    $parameter['if condition']['var']['smarty_internal_index'] . " = " .
67
                    $parameter['if condition']['value'] . ") {?>";
55 68
            } else {
56
                $_output = "<?php if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "] = new Smarty_Variable(null{$_nocache});";
57
                $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " . $parameter['if condition']['value'] . ") {?>";
69
                $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
70
                    "])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
71
                    "] = new Smarty_Variable(null{$_nocache});";
72
                $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
73
                    $parameter['if condition']['value'] . ") {?>";
58 74
            }
59

  
60
            return $_output;
61 75
        } else {
62
            return "<?php while ({$parameter['if condition']}) {?>";
76
            $_output .= "while ({$parameter['if condition']}) {?>";
63
        }
77
         }
78
        return $_output;
64 79
    }
65 80
}
66 81

  
......
75 90
    /**
76 91
     * Compiles code for the {/while} tag
77 92
     *
78
     * @param  array  $args     array with attributes from parser
93
     * @param  array                                       $args     array with attributes from parser
79
     * @param  object $compiler compiler object
94
     * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
80 95
     *
81 96
     * @return string compiled code
82 97
     */
83
    public function compile($args, $compiler)
98
    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
84 99
    {
100
        $compiler->loopNesting--;
85 101
        // must endblock be nocache?
86 102
        if ($compiler->nocache) {
87 103
            $compiler->tag_nocache = true;
88 104
        }
89 105
        $compiler->nocache = $this->closeTag($compiler, array('while'));
90

  
91
        return "<?php }?>";
106
        return "<?php }?>\n";
92 107
    }
93 108
}
src/includes/classes/Smarty/plugins/function.html_checkboxes.php (revision )
234 234
    $_output .= $separator;
235 235

  
236 236
    return $_output;
237
}
237
}
src/includes/classes/Smarty/sysplugins/smarty_internal_parsetree_template.php (revision )
1
<?php
2
/**
3
 * Smarty Internal Plugin Templateparser Parse Tree
4
 * These are classes to build parse tree in the template parser
5
 *
6
 * @package    Smarty
7
 * @subpackage Compiler
8
 * @author     Thue Kristensen
9
 * @author     Uwe Tews
10
 */
11

  
12
/**
13
 * Template element
14
 *
15
 * @package    Smarty
16
 * @subpackage Compiler
17
 * @ignore
18
 */
19
class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
20
{
21

  
22
    /**
23
     * Array of template elements
24
     *
25
     * @var array
26
     */
27
    public $subtrees = Array();
28

  
29
    /**
30
     * Create root of parse tree for template elements
31
     *
32
     */
33
    public function __construct()
34
    {
35
    }
36

  
37
    /**
38
     * Append buffer to subtree
39
     *
40
     * @param \Smarty_Internal_Templateparser $parser
41
     * @param Smarty_Internal_ParseTree       $subtree
42
     */
43
    public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
44
    {
45
        if (!empty($subtree->subtrees)) {
46
            $this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
47
        } else {
48
            if ($subtree->data !== '') {
49
                $this->subtrees[] = $subtree;
50
            }
51
        }
52
    }
53

  
54
    /**
55
     * Append array to subtree
56
     *
57
     * @param \Smarty_Internal_Templateparser $parser
58
     * @param \Smarty_Internal_ParseTree[]    $array
59
     */
60
    public function append_array(Smarty_Internal_Templateparser $parser, $array = array())
61
    {
62
        if (!empty($array)) {
63
            $this->subtrees = array_merge($this->subtrees, (array) $array);
64
        }
65
    }
66

  
67
    /**
68
     * Prepend array to subtree
69
     *
70
     * @param \Smarty_Internal_Templateparser $parser
71
     * @param \Smarty_Internal_ParseTree[]    $array
72
     */
73
    public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array())
74
    {
75
        if (!empty($array)) {
76
            $this->subtrees = array_merge((array) $array, $this->subtrees);
77
        }
78
    }
79

  
80
    /**
81
     * Sanitize and merge subtree buffers together
82
     *
83
     * @param \Smarty_Internal_Templateparser $parser
84
     *
85
     * @return string template code content
86
     */
87
    public function to_smarty_php(Smarty_Internal_Templateparser $parser)
88
    {
89
        $code = '';
90
        for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key ++) {
91
            if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Text) {
92
                $subtree = $this->subtrees[$key]->to_smarty_php($parser);
93
                while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Text ||
94
                        $this->subtrees[$key + 1]->data == '')) {
95
                    $key ++;
96
                    if ($this->subtrees[$key]->data == '') {
97
                        continue;
98
                    }
99
                    $subtree .= $this->subtrees[$key]->to_smarty_php($parser);
100
                }
101
                if ($subtree == '') {
102
                    continue;
103
                }
104
                $code .= preg_replace('/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/', "<?php echo '\$1'; ?>\n",
105
                                      $subtree);
106
                continue;
107
            }
108
            if ($this->subtrees[$key] instanceof Smarty_Internal_ParseTree_Tag) {
109
                $subtree = $this->subtrees[$key]->to_smarty_php($parser);
110
                while ($key + 1 < $cnt && ($this->subtrees[$key + 1] instanceof Smarty_Internal_ParseTree_Tag ||
111
                        $this->subtrees[$key + 1]->data == '')) {
112
                    $key ++;
113
                    if ($this->subtrees[$key]->data == '') {
114
                        continue;
115
                    }
116
                    $subtree = $parser->compiler->appendCode($subtree, $this->subtrees[$key]->to_smarty_php($parser));
117
                }
118
                if ($subtree == '') {
119
                    continue;
120
                }
121
                $code .= $subtree;
122
                continue;
123
            }
124
            $code .= $this->subtrees[$key]->to_smarty_php($parser);
125
        }
126
        return $code;
127
    }
128
}
src/includes/classes/Smarty/sysplugins/smarty_internal_runtime_codeframe.php (revision )
1
<?php
2
/**
3
 * Smarty Internal Extension
4
 * This file contains the Smarty template extension to create a code frame
5
 *
6
 * @package    Smarty
7
 * @subpackage Template
8
 * @author     Uwe Tews
9
 */
10

  
11
/**
12
 * Class Smarty_Internal_Extension_CodeFrame
13
 * Create code frame for compiled and cached templates
14
 */
15
class Smarty_Internal_Runtime_CodeFrame
16
{
17
    /**
18
     * Create code frame for compiled and cached templates
19
     *
20
     * @param Smarty_Internal_Template              $_template
21
     * @param string                                $content optional template content
22
     * @param string                                $functions compiled template function and block code
23
     * @param bool                                  $cache   flag for cache file
24
     * @param \Smarty_Internal_TemplateCompilerBase $compiler
25
     *
26
     * @return string
27
     */
28
    public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false,
29
                           Smarty_Internal_TemplateCompilerBase $compiler = null)
30
    {
31
        // build property code
32
        $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
33
        $properties[ 'version' ] = Smarty::SMARTY_VERSION;
34
        $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
35
        if (!$cache) {
36
            $properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
37
            $properties[ 'includes' ] = $_template->compiled->includes;
38
            if (!empty($compiler->tpl_function)) {
39
                $properties[ 'tpl_function' ] = $compiler->tpl_function;
40
            }
41
        } else {
42
            $properties[ 'file_dependency' ] = $_template->cached->file_dependency;
43
            $properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
44
            if (!empty($_template->tpl_function)) {
45
                $properties[ 'tpl_function' ] = $_template->tpl_function;
46
            }
47
        }
48
        $output = "<?php\n";
49
        $output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
50
            "\n  from \"" . $_template->source->filepath . "\" */\n\n";
51

  
52
        $dec = "\$_smarty_tpl->smarty->ext->_validateCompiled->decodeProperties(\$_smarty_tpl, " .
53
            var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ")";
54
        $output .= "if ({$dec}) {\n";
55
        $output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
56
        // include code for plugins
57
        if (!$cache) {
58
            if (!empty($_template->compiled->required_plugins[ 'compiled' ])) {
59
                foreach ($_template->compiled->required_plugins[ 'compiled' ] as $tmp) {
60
                    foreach ($tmp as $data) {
61
                        $file = addslashes($data[ 'file' ]);
62
                        if (is_array($data[ 'function' ])) {
63
                            $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
64
                        } else {
65
                            $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
66
                        }
67
                    }
68
                }
69
            }
70
            if ($_template->caching && !empty($_template->compiled->required_plugins[ 'nocache' ])) {
71
                $_template->compiled->has_nocache_code = true;
72
                $output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
73
                foreach ($_template->compiled->required_plugins[ 'nocache' ] as $tmp) {
74
                    foreach ($tmp as $data) {
75
                        $file = addslashes($data[ 'file' ]);
76
                        if (is_Array($data[ 'function' ])) {
77
                            $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
78
                        } else {
79
                            $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
80
                        }
81
                    }
82
                }
83
                $output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
84
            }
85
        }
86
        $output .= "?>\n";
87
        $output .= $content;
88
        $output .= "<?php }\n?>";
89
        $output .= $functions;
90
        $output .= "<?php }\n";
91
        // remove unneeded PHP tags
92
        return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output);
93
    }
94
}
src/includes/classes/Smarty/sysplugins/smarty_internal_templatebase.php (revision )
11 11
/**
12 12
 * Class with shared template methods
13 13
 *
14
 * @package    Smarty
14
 * @package      Smarty
15
 * @subpackage Template
15
 * @subpackage   Template
16
 *
17
 * @property Smarty $smarty
18
 * @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
19
 * @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
20
 * @method array getAutoloadFilters(string $type = null)
21
 * @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null)
22
 * @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
23
 * @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
24
 * @method string getDebugTemplate()
25
 * @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
26
 * @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers)
27
 * @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
28
 * @method array getDefaultModifier()
29
 * @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback)
30
 * @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler)
31
 * @method Smarty_Internal_TemplateBase unregisterResource(string $name)
32
 * @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
33
 * @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
34
 * @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
35
 * @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
36
 * @method object getRegisteredObject(string $object_name)
37
 * @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
38
 * @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
39
 * @method array getTags(mixed $template = null)
16 40
 */
17 41
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
18 42
{
19 43
    /**
44
     * Set this if you want different sets of cache files for the same
45
     * templates.
46
     *
47
     * @var string
48
     */
49
    public $cache_id = null;
50

  
51
    /**
52
     * Set this if you want different sets of compiled files for the same
53
     * templates.
54
     *
55
     * @var string
56
     */
57
    public $compile_id = null;
58

  
59
    /**
60
     * caching enabled
61
     *
62
     * @var boolean
63
     */
64
    public $caching = false;
65

  
66
    /**
67
     * cache lifetime in seconds
68
     *
69
     * @var integer
70
     */
71
    public $cache_lifetime = 3600;
72

  
73
    /**
74
     * universal cache
75
     *
76
     * @var array()
77
     */
78
    public $_cache = array();
79

  
80
    /**
20 81
     * fetches a rendered Smarty template
21 82
     *
22 83
     * @param  string $template         the resource handle of the template file or template object
23 84
     * @param  mixed  $cache_id         cache id to be used with this template
24 85
     * @param  mixed  $compile_id       compile id to be used with this template
25 86
     * @param  object $parent           next higher level of Smarty variables
26
     * @param  bool   $display          true: display, false: fetch
27
     * @param  bool   $merge_tpl_vars   if true parent template variables merged in to local scope
28
     * @param  bool   $no_output_filter if true do not run output filter
29 87
     *
30 88
     * @throws Exception
31 89
     * @throws SmartyException
32 90
     * @return string rendered template output
33 91
     */
34
    public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
92
    public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
35 93
    {
36
        if ($template === null && $this instanceof $this->template_class) {
37
            $template = $this;
94
        $result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
95
        return $result === null ? ob_get_clean() : $result;
38
        }
96
    }
39
        if ($cache_id !== null && is_object($cache_id)) {
40
            $parent = $cache_id;
41
            $cache_id = null;
42
        }
43
        if ($parent === null && ($this instanceof Smarty || is_string($template))) {
44
            $parent = $this;
45
        }
46
        // create template object if necessary
47
        $_template = ($template instanceof $this->template_class)
48
            ? $template
49
            : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
50
        // if called by Smarty object make sure we use current caching status
51
        if ($this instanceof Smarty) {
52
            $_template->caching = $this->caching;
53
        }
54
        // merge all variable scopes into template
55
        if ($merge_tpl_vars) {
56
            // save local variables
57
            $save_tpl_vars = $_template->tpl_vars;
58
            $save_config_vars = $_template->config_vars;
59
            $ptr_array = array($_template);
60
            $ptr = $_template;
61
            while (isset($ptr->parent)) {
62
                $ptr_array[] = $ptr = $ptr->parent;
63
            }
64
            $ptr_array = array_reverse($ptr_array);
65
            $parent_ptr = reset($ptr_array);
66
            $tpl_vars = $parent_ptr->tpl_vars;
67
            $config_vars = $parent_ptr->config_vars;
68
            while ($parent_ptr = next($ptr_array)) {
69
                if (!empty($parent_ptr->tpl_vars)) {
70
                    $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);
71
                }
72
                if (!empty($parent_ptr->config_vars)) {
73
                    $config_vars = array_merge($config_vars, $parent_ptr->config_vars);
74
                }
75
            }
76
            if (!empty(Smarty::$global_tpl_vars)) {
77
                $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);
78
            }
79
            $_template->tpl_vars = $tpl_vars;
80
            $_template->config_vars = $config_vars;
81
        }
82
        // dummy local smarty variable
83
        if (!isset($_template->tpl_vars['smarty'])) {
84
            $_template->tpl_vars['smarty'] = new Smarty_Variable;
85
        }
86
        if (isset($this->smarty->error_reporting)) {
87
            $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);
88
        }
89
        // check URL debugging control
90
        if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {
91
            if (isset($_SERVER['QUERY_STRING'])) {
92
                $_query_string = $_SERVER['QUERY_STRING'];
93
            } else {
94
                $_query_string = '';
95
            }
96
            if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {
97
                if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) {
98
                    // enable debugging for this browser session
99
                    setcookie('SMARTY_DEBUG', true);
100
                    $this->smarty->debugging = true;
101
                } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) {
102
                    // disable debugging for this browser session
103
                    setcookie('SMARTY_DEBUG', false);
104
                    $this->smarty->debugging = false;
105
                } else {
106
                    // enable debugging for this page
107
                    $this->smarty->debugging = true;
108
                }
109
            } else {
110
                if (isset($_COOKIE['SMARTY_DEBUG'])) {
111
                    $this->smarty->debugging = true;
112
                }
113
            }
114
        }
115
        // must reset merge template date
116
        $_template->smarty->merged_templates_func = array();
117
        // get rendered template
118
        // disable caching for evaluated code
119
        if ($_template->source->recompiled) {
120
            $_template->caching = false;
121
        }
122
        // checks if template exists
123
        if (!$_template->source->exists) {
124
            if ($_template->parent instanceof Smarty_Internal_Template) {
125
                $parent_resource = " in '{$_template->parent->template_resource}'";
126
            } else {
127
                $parent_resource = '';
128
            }
129
            throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");
130
        }
131
        // read from cache or render
132
        if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {
133
            // render template (not loaded and not in cache)
134
            if (!$_template->source->uncompiled) {
135
                /** @var Smarty_Internal_Template $_smarty_tpl
136
                 * used in evaluated code
137
                 */
138
                $_smarty_tpl = $_template;
139
                if ($_template->source->recompiled) {
140
                    $code = $_template->compiler->compileTemplate($_template);
141
                    if ($this->smarty->debugging) {
142
                        Smarty_Internal_Debug::start_render($_template);
143
                    }
144
                    try {
145
                        ob_start();
146
                        eval("?>" . $code);
147
                        unset($code);
148
                    }
149
                    catch (Exception $e) {
150
                        ob_get_clean();
151
                        throw $e;
152
                    }
153
                } else {
154
                    if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) {
155
                        $_template->compileTemplateSource();
156
                        $code = file_get_contents($_template->compiled->filepath);
157
                        eval("?>" . $code);
158
                        unset($code);
159
                        $_template->compiled->loaded = true;
160
                        $_template->compiled->isCompiled = true;
161
                    }
162
                    if ($this->smarty->debugging) {
163
                        Smarty_Internal_Debug::start_render($_template);
164
                    }
165
                    if (!$_template->compiled->loaded) {
166
                        include($_template->compiled->filepath);
167
                        if ($_template->mustCompile) {
168
                            // recompile and load again
169
                            $_template->compileTemplateSource();
170
                            $code = file_get_contents($_template->compiled->filepath);
171
                            eval("?>" . $code);
172
                            unset($code);
173
                            $_template->compiled->isCompiled = true;
174
                        }
175
                        $_template->compiled->loaded = true;
176
                    } else {
177
                        $_template->decodeProperties($_template->compiled->_properties, false);
178
                    }
179
                    try {
180
                        ob_start();
181
                        if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
182
                            throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
183
                        }
184
                        array_unshift($_template->_capture_stack, array());
185
                        //
186
                        // render compiled template
187
                        //
188
                        $_template->properties['unifunc']($_template);
189
                        // any unclosed {capture} tags ?
190
                        if (isset($_template->_capture_stack[0][0])) {
191
                            $_template->capture_error();
192
                        }
193
                        array_shift($_template->_capture_stack);
194
                    }
195
                    catch (Exception $e) {
196
                        ob_get_clean();
197
                        throw $e;
198
                    }
199
                }
200
            } else {
201
                if ($_template->source->uncompiled) {
202
                    if ($this->smarty->debugging) {
203
                        Smarty_Internal_Debug::start_render($_template);
204
                    }
205
                    try {
206
                        ob_start();
207
                        $_template->source->renderUncompiled($_template);
208
                    }
209
                    catch (Exception $e) {
210
                        ob_get_clean();
211
                        throw $e;
212
                    }
213
                } else {
214
                    throw new SmartyException("Resource '$_template->source->type' must have 'renderUncompiled' method");
215
                }
216
            }
217
            $_output = ob_get_clean();
218
            if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {
219
                $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);
220
            }
221
            if ($_template->parent instanceof Smarty_Internal_Template) {
222
                $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);
223
                foreach ($_template->required_plugins as $code => $tmp1) {
224
                    foreach ($tmp1 as $name => $tmp) {
225
                        foreach ($tmp as $type => $data) {
226
                            $_template->parent->required_plugins[$code][$name][$type] = $data;
227
                        }
228
                    }
229
                }
230
            }
231
            if ($this->smarty->debugging) {
232
                Smarty_Internal_Debug::end_render($_template);
233
            }
234
            // write to cache when nessecary
235
            if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {
236
                if ($this->smarty->debugging) {
237
                    Smarty_Internal_Debug::start_cache($_template);
238
                }
239
                $_template->properties['has_nocache_code'] = false;
240
                // get text between non-cached items
241
                $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output);
242
                // get non-cached items
243
                preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts);
244
                $output = '';
245
                // loop over items, stitch back together
246
                foreach ($cache_split as $curr_idx => $curr_split) {
247
                    // escape PHP tags in template content
248
                    $output .= preg_replace('/(<%|%>|<\?php|<\?|\?>|<script\s+language\s*=\s*[\"\']?\s*php\s*[\"\']?\s*>)/', "<?php echo '\$1'; ?>\n", $curr_split);
249
                    if (isset($cache_parts[0][$curr_idx])) {
250
                        $_template->properties['has_nocache_code'] = true;
251
                        // remove nocache tags from cache output
252
                        $output .= preg_replace("!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]);
253
                    }
254
                }
255
                if (!$no_output_filter && !$_template->has_nocache_code && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
256
                    $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);
257
                }
258
                // rendering (must be done before writing cache file because of {function} nocache handling)
259
                /** @var Smarty_Internal_Template $_smarty_tpl
260
                 * used in evaluated code
261
                 */
262
                $_smarty_tpl = $_template;
263
                try {
264
                    ob_start();
265
                    eval("?>" . $output);
266
                    $_output = ob_get_clean();
267
                }
268
                catch (Exception $e) {
269
                    ob_get_clean();
270
                    throw $e;
271
                }
272
                // write cache file content
273
                $_template->writeCachedContent($output);
274
                if ($this->smarty->debugging) {
275
                    Smarty_Internal_Debug::end_cache($_template);
276
                }
277
            } else {
278
                // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);
279
                if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {
280
                    // replace nocache_hash
281
                    $_output = str_replace("{$_template->properties['nocache_hash']}", $_template->parent->properties['nocache_hash'], $_output);
282
                    $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;
283
                }
284
            }
285
        } else {
286
            if ($this->smarty->debugging) {
287
                Smarty_Internal_Debug::start_cache($_template);
288
            }
289
            try {
290
                ob_start();
291
                array_unshift($_template->_capture_stack, array());
292
                //
293
                // render cached template
294
                //
295
                $_template->properties['unifunc']($_template);
296
                // any unclosed {capture} tags ?
297
                if (isset($_template->_capture_stack[0][0])) {
298
                    $_template->capture_error();
299
                }
300
                array_shift($_template->_capture_stack);
301
                $_output = ob_get_clean();
302
            }
303
            catch (Exception $e) {
304
                ob_get_clean();
305
                throw $e;
306
            }
307
            if ($this->smarty->debugging) {
308
                Smarty_Internal_Debug::end_cache($_template);
309
            }
310
        }
311
        if ((!$this->caching || $_template->has_nocache_code || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {
312
            $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template);
313
        }
314
        if (isset($this->error_reporting)) {
315
            error_reporting($_smarty_old_error_level);
316
        }
317
        // display or fetch
318
        if ($display) {
319
            if ($this->caching && $this->cache_modified_check) {
320
                $_isCached = $_template->isCached() && !$_template->has_nocache_code;
321
                $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
322
                if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {
323
                    switch (PHP_SAPI) {
324
                        case 'cgi': // php-cgi < 5.3
325
                        case 'cgi-fcgi': // php-cgi >= 5.3
326
                        case 'fpm-fcgi': // php-fpm >= 5.3.3
327
                            header('Status: 304 Not Modified');
328
                            break;
329 97

  
330
                        case 'cli':
331
                            if ( /* ^phpunit */
332
                            !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
333
                            ) {
334
                                $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
335
                            }
336
                            break;
337

  
338
                        default:
339
                            header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
340
                            break;
341
                    }
342
                } else {
343
                    switch (PHP_SAPI) {
344
                        case 'cli':
345
                            if ( /* ^phpunit */
346
                            !empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
347
                            ) {
348
                                $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
349
                            }
350
                            break;
351

  
352
                        default:
353
                            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
354
                            break;
355
                    }
356
                    echo $this->_filterSessionIds($_output);
357
                }
358
            } else {
359
                echo $this->_filterSessionIds($_output);
360
            }
361
            // debug output
362
            if ($this->smarty->debugging) {
363
                Smarty_Internal_Debug::display_debug($_template);
364
            }
365
            if ($merge_tpl_vars) {
366
                // restore local variables
367
                $_template->tpl_vars = $save_tpl_vars;
368
                $_template->config_vars = $save_config_vars;
369
            }
370

  
371
            return;
372
        } else {
373
            if ($merge_tpl_vars) {
374
                // restore local variables
375
                $_template->tpl_vars = $save_tpl_vars;
376
                $_template->config_vars = $save_config_vars;
377
            }
378
            // return fetched content
379
	        $_output = $this->_filterSessionIds($_output);
380
            return $_output;
381
        }
382
    }
383

  
384
	/**
98
    /**
385
	 * Checks if the SessionID in a HTML-Element (e.g. a link) matches the current SessionID.
386
	 * If not it will replace it with the current SessionID to avoid security problems.
387
	 *
388
	 * @param string $p_output
389
	 * @return string
390
	 */
391
	protected function _filterSessionIds($p_output)
392
	{
393
		$newSid	= xtc_session_id();
394
		$sessStr = 'XTCsid';
395
		$sessLength = strlen($newSid);
396
		$agent = false;
397

  
398
		if(function_exists('xtc_check_agent'))
399
		{
400
			$agent = xtc_check_agent();
401
		}
402
		
403
		$pattern  = '/&(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}/s';
404
		$replace = '';
405
		if(!$agent)
406
		{
407
			$replace  = '&$1=' . $newSid;
408
		}
409
		
410
		$output = preg_replace($pattern, $replace, $p_output);
411
		
412
		$pattern  = '/&amp;(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}/s';
413
		$replace = '';
414
		if(!$agent)
415
		{
416
			$replace  = '&amp;$1=' . $newSid;
417
		}
418
		
419
		$output = preg_replace($pattern, $replace, $output);
420
		
421
		$pattern  = '/\?(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}([^&])/s';
422
		$replace = '$2';
423
		if(!$agent)
424
		{
425
			$replace  = '?$1=' . $newSid . '$2';
426
		}
427
		
428
		$output = preg_replace($pattern, $replace, $output);
429
		
430
		$pattern  = '/\?(' . $sessStr . ')=([a-zA-Z0-9,-]{' . $sessLength . '})&amp;/s';
431
		$replace = '?';
432
		if(!$agent)
433
		{
434
			$replace  = '?$1=' . $newSid . '&amp;';
435
		}
436
		
437
		$output = preg_replace($pattern, $replace, $output);
438
		
439
		$pattern  = '/\?(' . $sessStr . ')=([a-zA-Z0-9,-]{' . $sessLength . '})&/s';
440
		$replace = '?';
441
		if(!$agent)
442
		{
443
			$replace  = '?$1=' . $newSid . '&';
444
		}
445
		
446
		$output = preg_replace($pattern, $replace, $output);
447
		
448
		$pattern  = '/(<input[^>]+name="' . $sessStr . '"[^>]+value=")([a-zA-Z0-9,-]{' . $sessLength . '})("[^>]*>)/s';
449
		$replace = '';
450
		if(!$agent)
451
		{
452
			$replace  = '${1}' . $newSid . '$3';
453
		}
454
		$output = preg_replace($pattern, $replace , $output);
455
		
456
		$pattern  = '/(<input[^>]+value=")([a-zA-Z0-9,-]{' . $sessLength . '})("[^>]+name="' . $sessStr . '"[^>]*>)/s';
457
		if(!$agent)
458
		{
459
			$replace  = '${1}' . $newSid . '$3';
460
		}
461
		$output = preg_replace($pattern, $replace, $output);
462

  
463
		return $output;
464
	}
465

  
466
    /**
467 99
     * displays a Smarty template
468 100
     *
469 101
     * @param string $template   the resource handle of the template file or template object
......
474 106
    public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
475 107
    {
476 108
        // display template
477
        $this->fetch($template, $cache_id, $compile_id, $parent, true);
109
        $this->_execute($template, $cache_id, $compile_id, $parent, 1);
478 110
    }
479 111

  
480 112
    /**
481 113
     * test if cache is valid
482 114
     *
483
     * @param  string|object $template   the resource handle of the template file or template object
115
     * @api  Smarty::isCached()
116
     * @link http://www.smarty.net/docs/en/api.is.cached.tpl
117
     *
118
     * @param  null|string|\Smarty_Internal_Template $template   the resource handle of the template file or template object
484
     * @param  mixed         $cache_id   cache id to be used with this template
119
     * @param  mixed                                 $cache_id   cache id to be used with this template
485
     * @param  mixed         $compile_id compile id to be used with this template
120
     * @param  mixed                                 $compile_id compile id to be used with this template
486
     * @param  object        $parent     next higher level of Smarty variables
121
     * @param  object                                $parent     next higher level of Smarty variables
487 122
     *
488 123
     * @return boolean       cache status
489 124
     */
490 125
    public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
491 126
    {
492
        if ($template === null && $this instanceof $this->template_class) {
493
            return $this->cached->valid;
127
        return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
494
        }
128
    }
495
        if (!($template instanceof $this->template_class)) {
496
            if ($parent === null) {
497
                $parent = $this;
498
            }
499
            $template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
500
        }
501
        // return cache status of template
502
        return $template->cached->valid;
503
    }
504 129

  
505 130
    /**
506
     * creates a data object
131
     * fetches a rendered Smarty template
507 132
     *
133
     * @param  string $template   the resource handle of the template file or template object
134
     * @param  mixed  $cache_id   cache id to be used with this template
135
     * @param  mixed  $compile_id compile id to be used with this template
508
     * @param object $parent next higher level of Smarty variables
136
     * @param  object $parent     next higher level of Smarty variables
137
     * @param  string $function  function type 0 = fetch,  1 = display, 2 = isCache
509 138
     *
510
     * @returns Smarty_Data data object
139
     * @return mixed
140
     * @throws \Exception
141
     * @throws \SmartyException
511 142
     */
512
    public function createData($parent = null)
143
    private function _execute($template, $cache_id, $compile_id, $parent, $function)
513 144
    {
514
        return new Smarty_Data($parent, $this);
145
        $smarty = $this->_objType == 1 ? $this : $this->smarty;
146
        if ($template === null) {
147
            if ($this->_objType != 2) {
148
                throw new SmartyException($function . '():Missing \'$template\' parameter');
149
            } else {
150
                $template = clone $this;
515
    }
151
            }
516

  
517
    /**
518
     * Registers plugin to be used in templates
519
     *
520
     * @param  string   $type       plugin type
521
     * @param  string   $tag        name of template tag
522
     * @param  callback $callback   PHP callback to register
523
     * @param  boolean  $cacheable  if true (default) this fuction is cachable
524
     * @param  array    $cache_attr caching attributes if any
525
     *
526
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
527
     * @throws SmartyException              when the plugin tag is invalid
528
     */
529
    public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
530
    {
531
        if (isset($this->smarty->registered_plugins[$type][$tag])) {
532
            throw new SmartyException("Plugin tag \"{$tag}\" already registered");
533
        } elseif (!is_callable($callback)) {
534
            throw new SmartyException("Plugin \"{$tag}\" not callable");
152
        } elseif (is_object($template)) {
153
            if (!isset($template->_objType) || $template->_objType != 2) {
154
                throw new SmartyException($function . '():Template object expected');
535
        } else {
155
            } else {
536
            $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
156
                /* @var Smarty_Internal_Template $template */
157
                $template = clone $template;
537
        }
158
            }
538

  
539
        return $this;
159
        } else {
160
            // get template object
161
            /* @var Smarty_Internal_Template $template */
162
            $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
163
            if ($this->_objType == 1) {
164
                // set caching in template object
165
                $template->caching = $this->caching;
540
    }
166
            }
541

  
542
    /**
543
     * Unregister Plugin
544
     *
545
     * @param  string $type of plugin
546
     * @param  string $tag  name of plugin
547
     *
548
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
549
     */
550
    public function unregisterPlugin($type, $tag)
551
    {
552
        if (isset($this->smarty->registered_plugins[$type][$tag])) {
553
            unset($this->smarty->registered_plugins[$type][$tag]);
554 167
        }
555

  
556
        return $this;
168
        // fetch template content
169
        $level = ob_get_level();
170
        try {
171
            $_smarty_old_error_level =
172
                ($this->_objType == 1 && isset($smarty->error_reporting)) ? error_reporting($smarty->error_reporting) :
173
                    null;
174
            if ($function == 2) {
175
                if ($template->caching) {
176
                    // return cache status of template
177
                    if (!isset($template->cached)) {
178
                        $template->loadCached();
557
    }
179
                    }
180
                    $result = $template->cached->isCached($template);
181
                    $template->smarty->_cache['isCached'][$template->_getTemplateId()] = $template;
182
                } else {
183
                    return false;
184
                }
185
            } else {
186
                ob_start();
187
                $template->_mergeVars();
188
                if (!empty(Smarty::$global_tpl_vars)) {
189
                    $template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
190
                }
191
                $result = $template->render(false, $function);
192
            }
193
            if (isset($_smarty_old_error_level)) {
194
                error_reporting($_smarty_old_error_level);
195
            }
558

  
196
    
559
    /**
560
     * Registers a resource to fetch a template
561
     *
562
     * @param  string                $type     name of resource type
563
     * @param  Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
564
     *
565
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
566
     */
567
    public function registerResource($type, $callback)
568
    {
569
        $this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
197
            $result = $this->_filterSessionIds($result);
570

  
198
            
571
        return $this;
199
            return $result;
572
    }
200
        }
201
        catch (Exception $e) {
202
            while (ob_get_level() > $level) {
203
                ob_end_clean();
204
            }
205
            throw $e;
206
        }
207
    }
573 208

  
574 209
    /**
575
     * Unregisters a resource
210
     * Registers plugin to be used in templates
576 211
     *
577
     * @param  string $type name of resource type
212
     * @api  Smarty::registerPlugin()
213
     * @link http://www.smarty.net/docs/en/api.register.plugin.tpl
578 214
     *
579
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
215
     * @param  string   $type       plugin type
216
     * @param  string   $name       name of template tag
217
     * @param  callback $callback   PHP callback to register
218
     * @param  bool     $cacheable  if true (default) this function is cache able
219
     * @param  mixed    $cache_attr caching attributes if any
220
     *
221
     * @return \Smarty|\Smarty_Internal_Template
222
     * @throws SmartyException              when the plugin tag is invalid
580 223
     */
581
    public function unregisterResource($type)
224
    public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
582 225
    {
583
        if (isset($this->smarty->registered_resources[$type])) {
584
            unset($this->smarty->registered_resources[$type]);
226
        return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr);
585
        }
227
    }
586 228

  
587
        return $this;
588
    }
589

  
590 229
    /**
591
     * Registers a cache resource to cache a template's output
230
     * load a filter of specified type and name
592 231
     *
593
     * @param  string               $type     name of cache resource type
594
     * @param  Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
232
     * @api  Smarty::loadFilter()
233
     * @link http://www.smarty.net/docs/en/api.load.filter.tpl
595 234
     *
596
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
235
     * @param  string $type filter type
236
     * @param  string $name filter name
237
     *
238
     * @return bool
239
     * @throws SmartyException if filter could not be loaded
597 240
     */
598
    public function registerCacheResource($type, Smarty_CacheResource $callback)
241
    public function loadFilter($type, $name)
599 242
    {
600
        $this->smarty->registered_cache_resources[$type] = $callback;
601

  
602
        return $this;
243
        return $this->ext->loadFilter->loadFilter($this, $type, $name);
603 244
    }
604 245

  
605 246
    /**
606
     * Unregisters a cache resource
247
     * Registers a filter function
607 248
     *
608
     * @param  string $type name of cache resource type
249
     * @api  Smarty::registerFilter()
250
     * @link http://www.smarty.net/docs/en/api.register.filter.tpl
609 251
     *
610
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
252
     * @param  string      $type filter type
253
     * @param  callback    $callback
254
     * @param  string|null $name optional filter name
255
     *
256
     * @return \Smarty|\Smarty_Internal_Template
257
     * @throws \SmartyException
611 258
     */
612
    public function unregisterCacheResource($type)
259
    public function registerFilter($type, $callback, $name = null)
613 260
    {
614
        if (isset($this->smarty->registered_cache_resources[$type])) {
615
            unset($this->smarty->registered_cache_resources[$type]);
261
        return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name);
616
        }
262
    }
617 263

  
618
        return $this;
619
    }
620

  
621 264
    /**
622 265
     * Registers object to be used in templates
623 266
     *
624
     * @param          $object_name
625
     * @param  object  $object_impl   the referenced PHP object to register
626
     * @param  array   $allowed       list of allowed methods (empty = all)
627
     * @param  boolean $smarty_args   smarty argument format, else traditional
267
     * @api  Smarty::registerObject()
268
     * @link http://www.smarty.net/docs/en/api.register.object.tpl
269
     *
270
     * @param  string $object_name
271
     * @param  object $object                     the referenced PHP object to register
272
     * @param  array  $allowed_methods_properties list of allowed methods (empty = all)
273
     * @param  bool   $format                     smarty argument format, else traditional
628
     * @param  array   $block_methods list of block-methods
274
     * @param  array  $block_methods              list of block-methods
629 275
     *
630
     * @throws SmartyException
631
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
276
     * @return \Smarty|\Smarty_Internal_Template
277
     * @throws \SmartyException
632 278
     */
633
    public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
279
    public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true,
280
                                   $block_methods = array())
634 281
    {
635
        // test if allowed methods callable
636
        if (!empty($allowed)) {
637
            foreach ((array) $allowed as $method) {
638
                if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
639
                    throw new SmartyException("Undefined method or property '$method' in registered object");
282
        return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties,
283
                                                          $format, $block_methods);
640
                }
284
    }
641
            }
642
        }
643
        // test if block methods callable
644
        if (!empty($block_methods)) {
645
            foreach ((array) $block_methods as $method) {
646
                if (!is_callable(array($object_impl, $method))) {
647
                    throw new SmartyException("Undefined method '$method' in registered object");
648
                }
649
            }
650
        }
651
        // register the object
652
        $this->smarty->registered_objects[$object_name] =
653
            array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
654 285

  
655
        return $this;
656
    }
657

  
658 286
    /**
659
     * return a reference to a registered object
660
     *
661
     * @param  string $name object name
662
     *
663
     * @return object
664
     * @throws SmartyException if no such object is found
287
     * @param boolean $caching
665 288
     */
666
    public function getRegisteredObject($name)
289
    public function setCaching($caching)
667 290
    {
668
        if (!isset($this->smarty->registered_objects[$name])) {
669
            throw new SmartyException("'$name' is not a registered object");
291
        $this->caching = $caching;
670
        }
292
    }
671
        if (!is_object($this->smarty->registered_objects[$name][0])) {
672
            throw new SmartyException("registered '$name' is not an object");
673
        }
674 293

  
675
        return $this->smarty->registered_objects[$name][0];
676
    }
677

  
678 294
    /**
679
     * unregister an object
680
     *
681
     * @param  string $name object name
682
     *
683
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
295
     * @param int $cache_lifetime
684 296
     */
685
    public function unregisterObject($name)
297
    public function setCacheLifetime($cache_lifetime)
686 298
    {
687
        if (isset($this->smarty->registered_objects[$name])) {
688
            unset($this->smarty->registered_objects[$name]);
299
        $this->cache_lifetime = $cache_lifetime;
689
        }
300
    }
690 301

  
691
        return $this;
692
    }
693

  
694 302
    /**
695
     * Registers static classes to be used in templates
696
     *
697
     * @param         $class_name
698
     * @param  string $class_impl the referenced PHP class to register
699
     *
700
     * @throws SmartyException
701
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
303
     * @param string $compile_id
702 304
     */
703
    public function registerClass($class_name, $class_impl)
305
    public function setCompileId($compile_id)
704 306
    {
705
        // test if exists
706
        if (!class_exists($class_impl)) {
707
            throw new SmartyException("Undefined class '$class_impl' in register template class");
307
        $this->compile_id = $compile_id;
708
        }
308
    }
709
        // register the class
710
        $this->smarty->registered_classes[$class_name] = $class_impl;
711 309

  
712
        return $this;
713
    }
714

  
715 310
    /**
716
     * Registers a default plugin handler
717
     *
718
     * @param  callable $callback class/method name
719
     *
720
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
721
     * @throws SmartyException              if $callback is not callable
311
     * @param string $cache_id
722 312
     */
723
    public function registerDefaultPluginHandler($callback)
313
    public function setCacheId($cache_id)
724 314
    {
725
        if (is_callable($callback)) {
726
            $this->smarty->default_plugin_handler_func = $callback;
727
        } else {
728
            throw new SmartyException("Default plugin handler '$callback' not callable");
315
        $this->cache_id = $cache_id;
729
        }
730

  
316
    }
317
    
731
        return $this;
732
    }
733

  
734 318
    /**
735
     * Registers a default template handler
319
     * Checks if the SessionID in a HTML-Element (e.g. a link) matches the current SessionID.
320
     * If not it will replace it with the current SessionID to avoid security problems.
736 321
     *
737
     * @param  callable $callback class/method name
738
     *
739
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
740
     * @throws SmartyException              if $callback is not callable
322
     * @param string $p_output
323
     * @return string
741 324
     */
742
    public function registerDefaultTemplateHandler($callback)
325
    protected function _filterSessionIds($p_output)
743 326
    {
744
        if (is_callable($callback)) {
745
            $this->smarty->default_template_handler_func = $callback;
746
        } else {
747
            throw new SmartyException("Default template handler '$callback' not callable");
748
        }
327
        $newSid	= xtc_session_id();
328
        $sessStr = 'XTCsid';
329
        $sessLength = strlen($newSid);
330
        $agent = false;
749

  
331
        
750
        return $this;
332
        if(function_exists('xtc_check_agent'))
333
        {
334
            $agent = xtc_check_agent();
751
    }
752

  
335
        }
336
        
753
    /**
754
     * Registers a default template handler
755
     *
756
     * @param  callable $callback class/method name
757
     *
758
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
759
     * @throws SmartyException              if $callback is not callable
760
     */
761
    public function registerDefaultConfigHandler($callback)
337
        $pattern  = '/&(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}/s';
338
        $replace = '';
339
        if(!$agent)
762
    {
340
        {
763
        if (is_callable($callback)) {
764
            $this->smarty->default_config_handler_func = $callback;
765
        } else {
766
            throw new SmartyException("Default config handler '$callback' not callable");
341
            $replace  = '&$1=' . $newSid;
767 342
        }
768

  
343
        
769
        return $this;
770
    }
344
        $output = preg_replace($pattern, $replace, $p_output);
771

  
345
        
772
    /**
773
     * Registers a filter function
774
     *
775
     * @param  string   $type filter type
776
     * @param  callback $callback
777
     *
778
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
779
     */
780
    public function registerFilter($type, $callback)
346
        $pattern  = '/&amp;(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}/s';
347
        $replace = '';
348
        if(!$agent)
781
    {
349
        {
782
        $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
783

  
784
        return $this;
350
            $replace  = '&amp;$1=' . $newSid;
785
    }
786

  
351
        }
352
        
787
    /**
788
     * Unregisters a filter function
789
     *
790
     * @param  string   $type filter type
791
     * @param  callback $callback
792
     *
793
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
794
     */
795
    public function unregisterFilter($type, $callback)
353
        $output = preg_replace($pattern, $replace, $output);
354
        
355
        $pattern  = '/\?(' . $sessStr . ')=[a-zA-Z0-9,-]{' . $sessLength . '}([^&])/s';
356
        $replace = '$2';
357
        if(!$agent)
796
    {
358
        {
797
        $name = $this->_get_filter_name($callback);
798
        if (isset($this->smarty->registered_filters[$type][$name])) {
799
            unset($this->smarty->registered_filters[$type][$name]);
359
            $replace  = '?$1=' . $newSid . '$2';
800 360
        }
801

  
361
        
802
        return $this;
803
    }
362
        $output = preg_replace($pattern, $replace, $output);
804

  
363
        
805
    /**
806
     * Return internal filter name
807
     *
808
     * @param  callback $function_name
809
     *
810
     * @return string   internal filter name
811
     */
812
    public function _get_filter_name($function_name)
364
        $pattern  = '/\?(' . $sessStr . ')=([a-zA-Z0-9,-]{' . $sessLength . '})&amp;/s';
365
        $replace = '?';
366
        if(!$agent)
813
    {
367
        {
814
        if (is_array($function_name)) {
815
            $_class_name = (is_object($function_name[0]) ?
816
                get_class($function_name[0]) : $function_name[0]);
817

  
818
            return $_class_name . '_' . $function_name[1];
819
        } else {
820
            return $function_name;
368
            $replace  = '?$1=' . $newSid . '&amp;';
821 369
        }
822
    }
823

  
370
        
824
    /**
825
     * load a filter of specified type and name
826
     *
827
     * @param  string $type filter type
828
     * @param  string $name filter name
829
     *
830
     * @throws SmartyException if filter could not be loaded
831
     */
832
    public function loadFilter($type, $name)
833
    {
834
        $_plugin = "smarty_{$type}filter_{$name}";
835
        $_filter_name = $_plugin;
836
        if ($this->smarty->loadPlugin($_plugin)) {
837
            if (class_exists($_plugin, false)) {
838
                $_plugin = array($_plugin, 'execute');
839
            }
840
            if (is_callable($_plugin)) {
841
                $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;
371
        $output = preg_replace($pattern, $replace, $output);
842

  
372
        
843
                return true;
844
            }
845
        }
846
        throw new SmartyException("{$type}filter \"{$name}\" not callable");
847
    }
848

  
849
    /**
850
     * unload a filter of specified type and name
851
     *
852
     * @param  string $type filter type
853
     * @param  string $name filter name
854
     *
855
     * @return Smarty_Internal_Templatebase current Smarty_Internal_Templatebase (or Smarty or Smarty_Internal_Template) instance for chaining
856
     */
857
    public function unloadFilter($type, $name)
373
        $pattern  = '/\?(' . $sessStr . ')=([a-zA-Z0-9,-]{' . $sessLength . '})&/s';
374
        $replace = '?';
375
        if(!$agent)
858
    {
376
        {
859
        $_filter_name = "smarty_{$type}filter_{$name}";
860
        if (isset($this->smarty->registered_filters[$type][$_filter_name])) {
861
            unset ($this->smarty->registered_filters[$type][$_filter_name]);
377
            $replace  = '?$1=' . $newSid . '&';
862 378
        }
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.
(1-1/2)