smarty_internal_compile_private_special_variable.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. class 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. case 'get':
  44. case 'post':
  45. case 'env':
  46. case 'server':
  47. case 'session':
  48. case 'request':
  49. if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_super_globals) {
  50. $compiler->trigger_template_error("(secure mode) super globals not permitted");
  51. break;
  52. }
  53. $compiled_ref = '$_'.strtoupper($variable);
  54. break;
  55. case 'template':
  56. $_template_name = basename($compiler->template->getTemplateFilepath());
  57. return "'$_template_name'";
  58. case 'current_dir':
  59. $_template_dir_name = dirname($compiler->template->getTemplateFilepath());
  60. return "'$_template_dir_name'";
  61. case 'version':
  62. $_version = Smarty::SMARTY_VERSION;
  63. return "'$_version'";
  64. case 'const':
  65. if ($compiler->smarty->security && !$compiler->smarty->security_policy->allow_constants) {
  66. $compiler->trigger_template_error("(secure mode) constants not permitted");
  67. break;
  68. }
  69. return '@' . trim($_index[1], "'");
  70. case 'config':
  71. return "\$_smarty_tpl->getConfigVariable($_index[1])";
  72. case 'ldelim':
  73. $_ldelim = $compiler->smarty->left_delimiter;
  74. return "'$_ldelim'";
  75. case 'rdelim':
  76. $_rdelim = $compiler->smarty->right_delimiter;
  77. return "'$_rdelim'";
  78. default:
  79. $compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
  80. break;
  81. }
  82. if (isset($_index[1])) {
  83. array_shift($_index);
  84. foreach ($_index as $_ind) {
  85. $compiled_ref = $compiled_ref . "[$_ind]";
  86. }
  87. }
  88. return $compiled_ref;
  89. }
  90. }
  91. ?>