smarty_internal_compile_private_special_variable.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. *
  14. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase {
  18. /**
  19. * Compiles code for the speical $smarty variables
  20. *
  21. * @param array $args array with attributes from parser
  22. * @param object $compiler compiler object
  23. * @return string compiled code
  24. */
  25. public function compile($args, $compiler, $parameter)
  26. {
  27. $_index = preg_split("/\]\[/",substr($parameter, 1, strlen($parameter)-2));
  28. $compiled_ref = ' ';
  29. $variable = trim($_index[0], "'");
  30. switch ($variable) {
  31. case 'foreach':
  32. return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
  33. case 'section':
  34. return "\$_smarty_tpl->getVariable('smarty')->value$parameter";
  35. case 'capture':
  36. return "Smarty::\$_smarty_vars$parameter";
  37. case 'now':
  38. return 'time()';
  39. case 'cookies':
  40. if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
  41. $compiler->trigger_template_error("(secure mode) super globals not permitted");
  42. break;
  43. }
  44. $compiled_ref = '$_COOKIE';
  45. break;
  46. case 'get':
  47. case 'post':
  48. case 'env':
  49. case 'server':
  50. case 'session':
  51. case 'request':
  52. if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_super_globals) {
  53. $compiler->trigger_template_error("(secure mode) super globals not permitted");
  54. break;
  55. }
  56. $compiled_ref = '$_'.strtoupper($variable);
  57. break;
  58. case 'template':
  59. return 'basename($_smarty_tpl->source->filepath)';
  60. case 'template_object':
  61. return '$_smarty_tpl';
  62. case 'current_dir':
  63. return 'dirname($_smarty_tpl->source->filepath)';
  64. case 'version':
  65. $_version = Smarty::SMARTY_VERSION;
  66. return "'$_version'";
  67. case 'const':
  68. if (isset($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->allow_constants) {
  69. $compiler->trigger_template_error("(secure mode) constants not permitted");
  70. break;
  71. }
  72. return '@' . trim($_index[1], "'");
  73. case 'config':
  74. return "\$_smarty_tpl->getConfigVariable($_index[1])";
  75. case 'ldelim':
  76. $_ldelim = $compiler->smarty->left_delimiter;
  77. return "'$_ldelim'";
  78. case 'rdelim':
  79. $_rdelim = $compiler->smarty->right_delimiter;
  80. return "'$_rdelim'";
  81. default:
  82. $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
  83. break;
  84. }
  85. if (isset($_index[1])) {
  86. array_shift($_index);
  87. foreach ($_index as $_ind) {
  88. $compiled_ref = $compiled_ref . "[$_ind]";
  89. }
  90. }
  91. return $compiled_ref;
  92. }
  93. }
  94. ?>