PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/librerias/smarty/libs/sysplugins/smarty_internal_compile_call.php

https://bitbucket.org/ferjmendozap/siace
PHP | 130 lines | 83 code | 3 blank | 44 comment | 2 complexity | a8a35fde56c83013b1ac0fc9c39c08e7 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, GPL-3.0, LGPL-2.0, LGPL-2.1, LGPL-3.0, Apache-2.0, MPL-2.0-no-copyleft-exception
  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. * @package Smarty
  15. * @subpackage Compiler
  16. */
  17. class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $required_attributes = array('name');
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $shorttag_order = array('name');
  32. /**
  33. * Attribute definition: Overwrites base class.
  34. *
  35. * @var array
  36. * @see Smarty_Internal_CompileBase
  37. */
  38. public $optional_attributes = array('_any');
  39. /**
  40. * Compiles the calls of user defined tags defined by {function}
  41. *
  42. * @param array $args array with attributes from parser
  43. * @param object $compiler compiler object
  44. * @param array $parameter array with compilation parameter
  45. * @return string compiled code
  46. */
  47. public function compile($args, $compiler)
  48. {
  49. // check and get attributes
  50. $_attr = $this->getAttributes($compiler, $args);
  51. // save possible attributes
  52. if (isset($_attr['assign'])) {
  53. // output will be stored in a smarty variable instead of beind displayed
  54. $_assign = $_attr['assign'];
  55. }
  56. $_name = $_attr['name'];
  57. if ($compiler->compiles_template_function) {
  58. $compiler->called_functions[] = trim($_name, "'\"");
  59. }
  60. unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
  61. // set flag (compiled code of {function} must be included in cache file
  62. if ($compiler->nocache || $compiler->tag_nocache) {
  63. $_nocache = 'true';
  64. } else {
  65. $_nocache = 'false';
  66. }
  67. $_ParametrosArray = array();
  68. foreach ($_attr as $_key => $_value) {
  69. if (is_int($_key)) {
  70. $_ParametrosArray[] = "$_key=>$_value";
  71. } else {
  72. $_ParametrosArray[] = "'$_key'=>$_value";
  73. }
  74. }
  75. if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
  76. foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
  77. if (!isset($_attr[$_key])) {
  78. if (is_int($_key)) {
  79. $_ParametrosArray[] = "$_key=>$_value";
  80. } else {
  81. $_ParametrosArray[] = "'$_key'=>$_value";
  82. }
  83. }
  84. }
  85. } elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
  86. foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
  87. if (!isset($_attr[$_key])) {
  88. if (is_int($_key)) {
  89. $_ParametrosArray[] = "$_key=>$_value";
  90. } else {
  91. $_ParametrosArray[] = "'$_key'=>$_value";
  92. }
  93. }
  94. }
  95. }
  96. //varibale name?
  97. if (!(strpos($_name, '$') === false)) {
  98. $call_cache = $_name;
  99. $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
  100. } else {
  101. $_name = trim($_name, "'\"");
  102. $call_cache = "'{$_name}'";
  103. $call_function = 'smarty_template_function_' . $_name;
  104. }
  105. $_Parametros = 'array(' . implode(",", $_ParametrosArray) . ')';
  106. $_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
  107. // was there an assign attribute
  108. if (isset($_assign)) {
  109. if ($compiler->template->caching) {
  110. $_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_Parametros},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
  111. } else {
  112. $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_Parametros}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
  113. }
  114. } else {
  115. if ($compiler->template->caching) {
  116. $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_Parametros},'{$_hash}',{$_nocache});?>\n";
  117. } else {
  118. $_output = "<?php {$call_function}(\$_smarty_tpl,{$_Parametros});?>\n";
  119. }
  120. }
  121. return $_output;
  122. }
  123. }
  124. ?>