You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_nocache_insert.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Nocache Insert
  4. * Compiles the {insert} tag into the cache file
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Insert Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Nocache_Insert
  17. {
  18. /**
  19. * Compiles code for the {insert} tag into cache file
  20. *
  21. * @param string $_function insert function name
  22. * @param array $_attr array with parameter
  23. * @param Smarty_Internal_Template $_template template object
  24. * @param string $_script script name to load or 'null'
  25. * @param string $_assign optional variable name
  26. *
  27. * @return string compiled code
  28. */
  29. public static function compile($_function, $_attr, $_template, $_script, $_assign = null)
  30. {
  31. $_output = '<?php ';
  32. if ($_script !== 'null') {
  33. // script which must be included
  34. // code for script file loading
  35. $_output .= "require_once '{$_script}';";
  36. }
  37. // call insert
  38. if (isset($_assign)) {
  39. $_output .= "\$_smarty_tpl->assign('{$_assign}' , {$_function} (" . var_export($_attr, true) .
  40. ',\$_smarty_tpl), true);?>';
  41. } else {
  42. $_output .= "echo {$_function}(" . var_export($_attr, true) . ',$_smarty_tpl);?>';
  43. }
  44. $_tpl = $_template;
  45. while ($_tpl->_isSubTpl()) {
  46. $_tpl = $_tpl->parent;
  47. }
  48. return "/*%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$_tpl->compiled->nocache_hash}%%*/";
  49. }
  50. }