Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

smarty_internal_compile_private_modifier.php 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Modifier
  4. * Compiles code for modifier execution
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Modifier Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Compiles code for modifier execution
  20. *
  21. * @param array $args array with attributes from parser
  22. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  23. * @param array $parameter array with compilation parameter
  24. *
  25. * @return string compiled code
  26. * @throws \SmartyCompilerException
  27. */
  28. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
  29. {
  30. // check and get attributes
  31. $_attr = $this->getAttributes($compiler, $args);
  32. $output = $parameter['value'];
  33. // loop over list of modifiers
  34. foreach ($parameter['modifierlist'] as $single_modifier) {
  35. $modifier = $single_modifier[0];
  36. $single_modifier[0] = $output;
  37. $params = implode(',', $single_modifier);
  38. // check if we know already the type of modifier
  39. if (isset($compiler->known_modifier_type[$modifier])) {
  40. $modifier_types = array($compiler->known_modifier_type[$modifier]);
  41. } else {
  42. $modifier_types = array(1, 2, 3, 4, 5, 6);
  43. }
  44. foreach ($modifier_types as $type) {
  45. switch ($type) {
  46. case 1:
  47. // registered modifier
  48. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
  49. $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
  50. if (!is_array($function)) {
  51. $output = "{$function}({$params})";
  52. } else {
  53. if (is_object($function[0])) {
  54. $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
  55. $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
  56. } else {
  57. $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
  58. }
  59. }
  60. $compiler->known_modifier_type[$modifier] = $type;
  61. break 2;
  62. }
  63. break;
  64. case 2:
  65. // registered modifier compiler
  66. if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
  67. $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
  68. $compiler->known_modifier_type[$modifier] = $type;
  69. break 2;
  70. }
  71. break;
  72. case 3:
  73. // modifiercompiler plugin
  74. if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
  75. // check if modifier allowed
  76. if (!is_object($compiler->smarty->security_policy) ||
  77. $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
  78. ) {
  79. $plugin = 'smarty_modifiercompiler_' . $modifier;
  80. $output = $plugin($single_modifier, $compiler);
  81. }
  82. $compiler->known_modifier_type[$modifier] = $type;
  83. break 2;
  84. }
  85. break;
  86. case 4:
  87. // modifier plugin
  88. if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
  89. // check if modifier allowed
  90. if (!is_object($compiler->smarty->security_policy) ||
  91. $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
  92. ) {
  93. $output = "{$function}({$params})";
  94. }
  95. $compiler->known_modifier_type[$modifier] = $type;
  96. break 2;
  97. }
  98. break;
  99. case 5:
  100. // PHP function
  101. if (is_callable($modifier)) {
  102. // check if modifier allowed
  103. if (!is_object($compiler->smarty->security_policy) ||
  104. $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)
  105. ) {
  106. $output = "{$modifier}({$params})";
  107. }
  108. $compiler->known_modifier_type[$modifier] = $type;
  109. break 2;
  110. }
  111. break;
  112. case 6:
  113. // default plugin handler
  114. if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) ||
  115. (is_callable($compiler->smarty->default_plugin_handler_func) &&
  116. $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))
  117. ) {
  118. $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
  119. // check if modifier allowed
  120. if (!is_object($compiler->smarty->security_policy) ||
  121. $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)
  122. ) {
  123. if (!is_array($function)) {
  124. $output = "{$function}({$params})";
  125. } else {
  126. if (is_object($function[0])) {
  127. $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
  128. $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
  129. } else {
  130. $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
  131. }
  132. }
  133. }
  134. if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
  135. isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
  136. ) {
  137. // was a plugin
  138. $compiler->known_modifier_type[$modifier] = 4;
  139. } else {
  140. $compiler->known_modifier_type[$modifier] = $type;
  141. }
  142. break 2;
  143. }
  144. }
  145. }
  146. if (!isset($compiler->known_modifier_type[$modifier])) {
  147. $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", null, true);
  148. }
  149. }
  150. return $output;
  151. }
  152. }