PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/bblog/libs/core/core.write_compiled_include.php

https://github.com/escherlat/loquacity
PHP | 58 lines | 30 code | 13 blank | 15 comment | 2 complexity | c2f4cac1849bead2586ede8920d9c7ba MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * Smarty plugin
  4. *
  5. * @subpackage plugins
  6. * @package Smarty
  7. */
  8. /**
  9. * Extract non-cacheable parts out of compiled template and write it
  10. *
  11. * @param unknown $params
  12. * @param unknown $smarty (reference)
  13. * @return boolean
  14. */
  15. function smarty_core_write_compiled_include($params, &$smarty) {
  16. $_tag_start = 'if \(\$this->caching\) \{ echo \'\{nocache\:('.$params['cache_serial'].')#(\d+)\}\';\}';
  17. $_tag_end = 'if \(\$this->caching\) \{ echo \'\{/nocache\:(\\2)#(\\3)\}\';\}';
  18. preg_match_all('!('.$_tag_start.'(.*)'.$_tag_end.')!Us',
  19. $params['compiled_content'], $_match_source, PREG_SET_ORDER);
  20. // no nocache-parts found: done
  21. if (count($_match_source)==0) return;
  22. // convert the matched php-code to functions
  23. $_include_compiled = "<?php /* funky header here */\n\n";
  24. $_compile_path = $params['include_file_path'];
  25. $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
  26. $_include_compiled .= "\$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';\n\n?>";
  27. $_include_compiled .= $params['plugins_code'];
  28. $_include_compiled .= "<?php";
  29. for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
  30. $_match =& $_match_source[$_i];
  31. $_include_compiled .= "
  32. function _smarty_tplfunc_$_match[2]_$_match[3](&\$this)
  33. {
  34. $_match[4]
  35. }
  36. ";
  37. }
  38. $_include_compiled .= "\n\n?>\n";
  39. $_params = array('filename' => $_compile_path,
  40. 'contents' => $_include_compiled, 'create_dirs' => true);
  41. require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.write_file.php';
  42. smarty_core_write_file($_params, $smarty);
  43. return true;
  44. }
  45. ?>