Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

smarty_internal_compile_private_print_expression.php 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Print Expression
  4. * Compiles any tag which will output an expression or variable
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Print Expression Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $optional_attributes = array('assign');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $option_flags = array('nocache', 'nofilter');
  32. /**
  33. * Compiles code for generating output from any expression
  34. *
  35. * @param array $args array with attributes from parser
  36. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. *
  39. * @return string
  40. * @throws \SmartyException
  41. */
  42. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
  43. {
  44. // check and get attributes
  45. $_attr = $this->getAttributes($compiler, $args);
  46. // nocache option
  47. if ($_attr['nocache'] === true) {
  48. $compiler->tag_nocache = true;
  49. }
  50. if (isset($_attr['assign'])) {
  51. // assign output to variable
  52. $output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
  53. } else {
  54. // display value
  55. $output = $parameter['value'];
  56. // tag modifier
  57. if (!empty($parameter['modifierlist'])) {
  58. $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'],
  59. 'value' => $output));
  60. }
  61. if (!$_attr['nofilter']) {
  62. // default modifier
  63. if (!empty($compiler->smarty->default_modifiers)) {
  64. if (empty($compiler->default_modifier_list)) {
  65. $modifierlist = array();
  66. foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
  67. preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $single_default_modifier, $mod_array);
  68. for ($i = 0, $count = count($mod_array[0]); $i < $count; $i ++) {
  69. if ($mod_array[0][$i] != ':') {
  70. $modifierlist[$key][] = $mod_array[0][$i];
  71. }
  72. }
  73. }
  74. $compiler->default_modifier_list = $modifierlist;
  75. }
  76. $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $compiler->default_modifier_list,
  77. 'value' => $output));
  78. }
  79. // autoescape html
  80. if ($compiler->template->smarty->escape_html) {
  81. $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
  82. }
  83. // loop over registered filters
  84. if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
  85. foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key =>
  86. $function) {
  87. if (!is_array($function)) {
  88. $output = "{$function}({$output},\$_smarty_tpl)";
  89. } elseif (is_object($function[0])) {
  90. $output = "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)";
  91. } else {
  92. $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
  93. }
  94. }
  95. }
  96. // auto loaded filters
  97. if (isset($compiler->smarty->autoload_filters[Smarty::FILTER_VARIABLE])) {
  98. foreach ((array) $compiler->template->smarty->autoload_filters[Smarty::FILTER_VARIABLE] as $name) {
  99. $result = $this->compile_output_filter($compiler, $name, $output);
  100. if ($result !== false) {
  101. $output = $result;
  102. } else {
  103. // not found, throw exception
  104. throw new SmartyException("Unable to load filter '{$name}'");
  105. }
  106. }
  107. }
  108. foreach ($compiler->variable_filters as $filter) {
  109. if (count($filter) == 1 &&
  110. ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false
  111. ) {
  112. $output = $result;
  113. } else {
  114. $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter),
  115. 'value' => $output));
  116. }
  117. }
  118. }
  119. $compiler->has_output = true;
  120. $output = "<?php echo {$output};?>";
  121. }
  122. return $output;
  123. }
  124. /**
  125. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  126. * @param string $name name of variable filter
  127. * @param string $output embedded output
  128. *
  129. * @return string
  130. */
  131. private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
  132. {
  133. $plugin_name = "smarty_variablefilter_{$name}";
  134. $path = $compiler->smarty->loadPlugin($plugin_name, false);
  135. if ($path) {
  136. if ($compiler->template->caching) {
  137. $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
  138. $compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
  139. } else {
  140. $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
  141. $compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
  142. }
  143. } else {
  144. // not found
  145. return false;
  146. }
  147. return "{$plugin_name}({$output},\$_smarty_tpl)";
  148. }
  149. }