| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: |
|
| 10: |
|
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: |
|
| 17: | class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase
|
| 18: | {
|
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: |
|
| 29: | public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
| 30: | {
|
| 31: | $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
|
| 32: | $variable = strtolower($compiler->getId($_index[ 0 ]));
|
| 33: | if ($variable === false) {
|
| 34: | $compiler->trigger_template_error("special \$Smarty variable name index can not be variable", null, true);
|
| 35: | }
|
| 36: | if (!isset($compiler->smarty->security_policy)
|
| 37: | || $compiler->smarty->security_policy->isTrustedSpecialSmartyVar($variable, $compiler)
|
| 38: | ) {
|
| 39: | switch ($variable) {
|
| 40: | case 'foreach':
|
| 41: | case 'section':
|
| 42: | if (!isset(Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ])) {
|
| 43: | $class = 'Smarty_Internal_Compile_' . ucfirst($variable);
|
| 44: | Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ] = new $class;
|
| 45: | }
|
| 46: | return Smarty_Internal_TemplateCompilerBase::$_tag_objects[ $variable ]->compileSpecialVariable(
|
| 47: | array(),
|
| 48: | $compiler,
|
| 49: | $_index
|
| 50: | );
|
| 51: | case 'capture':
|
| 52: | if (class_exists('Smarty_Internal_Compile_Capture')) {
|
| 53: | return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
|
| 54: | }
|
| 55: | return '';
|
| 56: | case 'now':
|
| 57: | return 'time()';
|
| 58: | case 'cookies':
|
| 59: | if (isset($compiler->smarty->security_policy)
|
| 60: | && !$compiler->smarty->security_policy->allow_super_globals
|
| 61: | ) {
|
| 62: | $compiler->trigger_template_error("(secure mode) super globals not permitted");
|
| 63: | break;
|
| 64: | }
|
| 65: | $compiled_ref = '$_COOKIE';
|
| 66: | break;
|
| 67: | case 'get':
|
| 68: | case 'post':
|
| 69: | case 'env':
|
| 70: | case 'server':
|
| 71: | case 'session':
|
| 72: | case 'request':
|
| 73: | if (isset($compiler->smarty->security_policy)
|
| 74: | && !$compiler->smarty->security_policy->allow_super_globals
|
| 75: | ) {
|
| 76: | $compiler->trigger_template_error("(secure mode) super globals not permitted");
|
| 77: | break;
|
| 78: | }
|
| 79: | $compiled_ref = '$_' . strtoupper($variable);
|
| 80: | break;
|
| 81: | case 'template':
|
| 82: | return 'basename($_smarty_tpl->source->filepath)';
|
| 83: | case 'template_object':
|
| 84: | if (isset($compiler->smarty->security_policy)) {
|
| 85: | $compiler->trigger_template_error("(secure mode) template_object not permitted");
|
| 86: | break;
|
| 87: | }
|
| 88: | return '$_smarty_tpl';
|
| 89: | case 'current_dir':
|
| 90: | return 'dirname($_smarty_tpl->source->filepath)';
|
| 91: | case 'version':
|
| 92: | return "Smarty::SMARTY_VERSION";
|
| 93: | case 'const':
|
| 94: | if (isset($compiler->smarty->security_policy)
|
| 95: | && !$compiler->smarty->security_policy->allow_constants
|
| 96: | ) {
|
| 97: | $compiler->trigger_template_error("(secure mode) constants not permitted");
|
| 98: | break;
|
| 99: | }
|
| 100: | if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) {
|
| 101: | return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)";
|
| 102: | } else {
|
| 103: | return "(defined({$_index[1]}) ? constant({$_index[1]}) : null)";
|
| 104: | }
|
| 105: |
|
| 106: | case 'config':
|
| 107: | if (isset($_index[ 2 ])) {
|
| 108: | return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)";
|
| 109: | } else {
|
| 110: | return "\$_smarty_tpl->smarty->ext->configload->_getConfigVariable(\$_smarty_tpl, $_index[1])";
|
| 111: | }
|
| 112: |
|
| 113: | case 'ldelim':
|
| 114: | return "\$_smarty_tpl->smarty->left_delimiter";
|
| 115: | case 'rdelim':
|
| 116: | return "\$_smarty_tpl->smarty->right_delimiter";
|
| 117: | default:
|
| 118: | $compiler->trigger_template_error('$smarty.' . trim($_index[ 0 ], "'") . ' is not defined');
|
| 119: | break;
|
| 120: | }
|
| 121: | if (isset($_index[ 1 ])) {
|
| 122: | array_shift($_index);
|
| 123: | foreach ($_index as $_ind) {
|
| 124: | $compiled_ref = $compiled_ref . "[$_ind]";
|
| 125: | }
|
| 126: | }
|
| 127: | return $compiled_ref;
|
| 128: | }
|
| 129: | }
|
| 130: | }
|
| 131: | |