smarty_internal_compile_private_print_expression.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Print Expression
  4. *
  5. * Compiles any tag which will output an expression or variable
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Print Expression Class
  13. */
  14. class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for gererting output from any expression
  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. $this->compiler = $compiler;
  25. $this->required_attributes = array('value');
  26. $this->optional_attributes = array('assign', 'nocache', 'filter', 'nofilter');
  27. // check and get attributes
  28. $_attr = $this->_get_attributes($args);
  29. if (isset($_attr['nocache'])) {
  30. if ($_attr['nocache'] == 'true') {
  31. $this->compiler->tag_nocache = true;
  32. }
  33. }
  34. if (!isset($_attr['filter'])) {
  35. $_attr['filter'] = 'null';
  36. }
  37. if (isset($_attr['nofilter'])) {
  38. if ($_attr['nofilter'] == 'true') {
  39. $_attr['filter'] = 'false';
  40. }
  41. }
  42. if (isset($_attr['assign'])) {
  43. // assign output to variable
  44. $output = '<?php $_smarty_tpl->assign(' . $_attr['assign'] . ',' . $_attr['value'] . ');?>';
  45. } else {
  46. // display value
  47. $this->compiler->has_output = true;
  48. if (isset($this->compiler->smarty->registered_filters['variable'])) {
  49. $output = 'Smarty_Internal_Filter_Handler::runFilter(\'variable\', ' . $_attr['value'] . ',$_smarty_tpl->smarty, $_smarty_tpl, ' . $_attr['filter'] . ')';
  50. } else {
  51. $output = $_attr['value'];
  52. }
  53. if (!isset($_attr['nofilter']) && isset($this->compiler->smarty->default_modifiers)) {
  54. foreach ($this->compiler->smarty->default_modifiers as $default_modifier) {
  55. $mod_array = explode (':', $default_modifier);
  56. $modifier = $mod_array[0];
  57. $mod_array[0] = $output;
  58. $output = $this->compiler->compileTag('private_modifier', array('modifier' => $modifier, 'params' => implode(", ", $mod_array)));
  59. }
  60. }
  61. $output = '<?php echo ' . $output . ';?>';
  62. }
  63. return $output;
  64. }
  65. }
  66. ?>