source: trunk/include/smarty/libs/sysplugins/smarty_internal_nocache_insert.php @ 23384

Last change on this file since 23384 was 23384, checked in by rvelices, 11 years ago

smarty 3 - first pass for tests

File size: 1.7 KB
Line 
1<?php
2/**
3 * Smarty Internal Plugin Nocache Insert
4 *
5 * Compiles the {insert} tag into the cache file
6 *
7 * @package Smarty
8 * @subpackage Compiler
9 * @author Uwe Tews
10 */
11
12/**
13 * Smarty Internal Plugin Compile Insert Class
14 *
15 * @package Smarty
16 * @subpackage Compiler
17 */
18class Smarty_Internal_Nocache_Insert {
19
20    /**
21     * Compiles code for the {insert} tag into cache file
22     *
23     * @param string                   $_function insert function name
24     * @param array                    $_attr     array with parameter
25     * @param Smarty_Internal_Template $_template template object
26     * @param string                   $_script   script name to load or 'null'
27     * @param string                   $_assign   optional variable name
28     * @return string compiled code
29     */
30    public static function compile($_function, $_attr, $_template, $_script, $_assign = null)
31    {
32        $_output = '<?php ';
33        if ($_script != 'null') {
34            // script which must be included
35            // code for script file loading
36            $_output .= "require_once '{$_script}';";
37        }
38        // call insert
39        if (isset($_assign)) {
40            $_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) . ",\$_smarty_tpl), true);?>";
41        } else {
42            $_output .= "echo {$_function}(" . var_export($_attr, true) . ",\$_smarty_tpl);?>";
43        }
44        $_tpl = $_template;
45        while ($_tpl->parent instanceof Smarty_Internal_Template) {
46            $_tpl = $_tpl->parent;
47        }
48        return "/*%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/" . $_output . "/*/%%SmartyNocache:{$_tpl->properties['nocache_hash']}%%*/";
49    }
50
51}
52
53?>
Note: See TracBrowser for help on using the repository browser.