PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_private_special_variable.php

http://zoop.googlecode.com/
PHP | 100 lines | 78 code | 3 blank | 19 comment | 0 complexity | 34d275bf205169ccfdc715d86d8a88fd MD5 | raw file
  1<?php
  2/**
  3* Smarty Internal Plugin Compile Special Smarty Variable
  4* 
  5* Compiles the special $smarty variables
  6* 
  7* @package Smarty
  8* @subpackage Compiler
  9* @author Uwe Tews 
 10*/
 11/**
 12* Smarty Internal Plugin Compile special Smarty Variable Class
 13*/
 14class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase {
 15    /**
 16    * Compiles code for the speical $smarty variables
 17    * 
 18    * @param array $args array with attributes from parser
 19    * @param object $compiler compiler object
 20    * @return string compiled code
 21    */
 22    public function compile($args, $compiler)
 23    {
 24        $_index = explode(',', str_replace(array(']['), array(','), substr($args, 1, strlen($args)-2)));
 25        $compiled_ref = ' ';
 26        $variable = trim($_index[0], "'");
 27        switch ($variable) {
 28            case 'foreach':
 29                return "\$_smarty_tpl->getVariable('smarty')->value$args";
 30            case 'section':
 31                return "\$_smarty_tpl->getVariable('smarty')->value$args";
 32            case 'capture':
 33                return "\$_smarty_tpl->smarty->_smarty_vars$args";
 34            case 'now':
 35                return 'time()';
 36            case 'cookies':
 37                if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
 38                    $compiler->trigger_template_error("(secure mode) super globals not permitted");
 39                    break;
 40                } 
 41                $compiled_ref = '$_COOKIE';
 42                break;
 43
 44            case 'get':
 45            case 'post':
 46            case 'env':
 47            case 'server':
 48            case 'session':
 49            case 'request':
 50                if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
 51                    $compiler->trigger_template_error("(secure mode) super globals not permitted");
 52                    break;
 53                } 
 54                $compiled_ref = '$_'.strtoupper($variable);
 55                break;
 56
 57            case 'template':
 58                $_template_name = basename($compiler->template->getTemplateFilepath());
 59                return "'$_template_name'";
 60
 61            case 'current_dir':
 62                $_template_dir_name = dirname($compiler->template->getTemplateFilepath());
 63                return "'$_template_dir_name'";
 64
 65            case 'version':
 66                $_version = Smarty::SMARTY_VERSION;
 67                return "'$_version'";
 68
 69            case 'const':
 70                if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
 71                    $compiler->trigger_template_error("(secure mode) constants not permitted");
 72                    break;
 73                } 
 74                return '@' . trim($_index[1], "'");
 75
 76            case 'config':
 77                return "\$_smarty_tpl->getConfigVariable($_index[1])";
 78            case 'ldelim':
 79                $_ldelim = $compiler->smarty->left_delimiter;
 80                return "'$_ldelim'";
 81
 82            case 'rdelim':
 83                $_rdelim = $compiler->smarty->right_delimiter;
 84                return "'$_rdelim'";
 85
 86            default:
 87                $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
 88                break;
 89        } 
 90        if (isset($_index[1])) {
 91            array_shift($_index);
 92            foreach ($_index as $_ind) {
 93                $compiled_ref = $compiled_ref . "[$_ind]";
 94            } 
 95        } 
 96        return $compiled_ref;
 97    } 
 98} 
 99
100?>