Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

smarty_internal_compile_private_special_variable.php 5.2KB

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