smarty_internal_compile_private_special_variable.php 3.8 KB

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