| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: |
|
| 10: |
|
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
| 18: | {
|
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: |
|
| 25: | public $required_attributes = array('name');
|
| 26: |
|
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: |
|
| 33: | public $shorttag_order = array('name');
|
| 34: |
|
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: |
|
| 41: | public $optional_attributes = array('_any');
|
| 42: |
|
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: |
|
| 53: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
| 54: | {
|
| 55: |
|
| 56: | $_attr = $this->getAttributes($compiler, $args);
|
| 57: | $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
|
| 58: | if (!$nocacheParam) {
|
| 59: |
|
| 60: | $compiler->suppressNocacheProcessing = true;
|
| 61: | }
|
| 62: | $compiler->tag_nocache = true;
|
| 63: | $_smarty_tpl = $compiler->template;
|
| 64: | $_name = null;
|
| 65: | $_script = null;
|
| 66: | $_output = '<?php ';
|
| 67: |
|
| 68: | eval('$_name = @' . $_attr[ 'name' ] . ';');
|
| 69: | if (isset($_attr[ 'assign' ])) {
|
| 70: |
|
| 71: | $_assign = $_attr[ 'assign' ];
|
| 72: |
|
| 73: | $var = trim($_attr[ 'assign' ], '\'');
|
| 74: | if (isset($compiler->template->tpl_vars[ $var ])) {
|
| 75: | $compiler->template->tpl_vars[ $var ]->nocache = true;
|
| 76: | } else {
|
| 77: | $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true);
|
| 78: | }
|
| 79: | }
|
| 80: | if (isset($_attr[ 'script' ])) {
|
| 81: |
|
| 82: | $_function = "smarty_insert_{$_name}";
|
| 83: | $_smarty_tpl = $compiler->template;
|
| 84: | $_filepath = false;
|
| 85: | eval('$_script = @' . $_attr[ 'script' ] . ';');
|
| 86: | if (!isset($compiler->smarty->security_policy) && file_exists($_script)) {
|
| 87: | $_filepath = $_script;
|
| 88: | } else {
|
| 89: | if (isset($compiler->smarty->security_policy)) {
|
| 90: | $_dir = $compiler->smarty->security_policy->trusted_dir;
|
| 91: | } else {
|
| 92: | $_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null;
|
| 93: | }
|
| 94: | if (!empty($_dir)) {
|
| 95: | foreach ((array)$_dir as $_script_dir) {
|
| 96: | $_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;
|
| 97: | if (file_exists($_script_dir . $_script)) {
|
| 98: | $_filepath = $_script_dir . $_script;
|
| 99: | break;
|
| 100: | }
|
| 101: | }
|
| 102: | }
|
| 103: | }
|
| 104: | if ($_filepath === false) {
|
| 105: | $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true);
|
| 106: | }
|
| 107: |
|
| 108: | $_output .= "require_once '{$_filepath}' ;";
|
| 109: | include_once $_filepath;
|
| 110: | if (!is_callable($_function)) {
|
| 111: | $compiler->trigger_template_error(
|
| 112: | " {insert} function '{$_function}' is not callable in script file '{$_script}'",
|
| 113: | null,
|
| 114: | true
|
| 115: | );
|
| 116: | }
|
| 117: | } else {
|
| 118: | $_filepath = 'null';
|
| 119: | $_function = "insert_{$_name}";
|
| 120: |
|
| 121: | if (!is_callable($_function)) {
|
| 122: |
|
| 123: | if (!$_function = $compiler->getPlugin($_name, 'insert')) {
|
| 124: | $compiler->trigger_template_error(
|
| 125: | "{insert} no function or plugin found for '{$_name}'",
|
| 126: | null,
|
| 127: | true
|
| 128: | );
|
| 129: | }
|
| 130: | }
|
| 131: | }
|
| 132: |
|
| 133: | unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]);
|
| 134: |
|
| 135: | $_paramsArray = array();
|
| 136: | foreach ($_attr as $_key => $_value) {
|
| 137: | $_paramsArray[] = "'$_key' => $_value";
|
| 138: | }
|
| 139: | $_params = 'array(' . implode(", ", $_paramsArray) . ')';
|
| 140: |
|
| 141: | if (isset($_assign)) {
|
| 142: | if ($_smarty_tpl->caching && !$nocacheParam) {
|
| 143: | $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>";
|
| 144: | } else {
|
| 145: | $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>";
|
| 146: | }
|
| 147: | } else {
|
| 148: | if ($_smarty_tpl->caching && !$nocacheParam) {
|
| 149: | $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>";
|
| 150: | } else {
|
| 151: | $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
|
| 152: | }
|
| 153: | }
|
| 154: | $compiler->template->compiled->has_nocache_code = true;
|
| 155: | return $_output;
|
| 156: | }
|
| 157: | }
|
| 158: | |