/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_call.php

http://zoop.googlecode.com/ · PHP · 63 lines · 33 code · 2 blank · 28 comment · 7 complexity · 69f707442629a55136c6ded7527e7bcc MD5 · raw file

  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Function_Call
  4. *
  5. * Compiles the calls of user defined tags defined by {function}
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Function_Call Class
  13. */
  14. class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles the calls of user defined tags defined by {function}
  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('name');
  26. $this->optional_attributes = array('_any');
  27. // check and get attributes
  28. $_attr = $this->_get_attributes($args);
  29. // save posible attributes
  30. if (isset($_attr['assign'])) {
  31. // output will be stored in a smarty variable instead of beind displayed
  32. $_assign = $_attr['assign'];
  33. }
  34. // set flag (compiled code of {function} must be included in cache file
  35. if ($this->compiler->nocache || $this->compiler->tag_nocache) {
  36. $nocache = 'true';
  37. } else {
  38. $nocache = 'false';
  39. }
  40. // create template object
  41. $_output = "<?php \$_template = new Smarty_Internal_Function_Call_Handler ({$_attr['name']}, \$_smarty_tpl->smarty, \$_smarty_tpl, {$nocache});\n";
  42. // delete {include} standard attributes
  43. unset($_attr['name'], $_attr['assign']);
  44. // remaining attributes must be assigned as smarty variable
  45. if (!empty($_attr)) {
  46. // create variables
  47. foreach ($_attr as $_key => $_value) {
  48. $_output .= "\$_template->assign('$_key',$_value);\n";
  49. }
  50. }
  51. // was there an assign attribute
  52. if (isset($_assign)) {
  53. $_output .= "\$_smarty_tpl->assign({$_assign},\$_template->getRenderedTemplate());\n";
  54. } else {
  55. $_output .= "echo \$_template->getRenderedTemplate();\n";
  56. }
  57. $_output .= 'unset($_template);?>';
  58. return $_output;
  59. }
  60. }
  61. ?>