smarty_internal_nocache_insert.php 1.6 KB

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