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

/bblog/libs/core/core.process_cached_inserts.php

https://github.com/escherlat/loquacity
PHP | 74 lines | 47 code | 13 blank | 14 comment | 10 complexity | 92f1ae031fb6b582df6aac39cc247334 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. * Replace cached inserts with the actual results
  10. *
  11. * @param unknown $params
  12. * @param unknown $smarty (reference)
  13. * @return string
  14. */
  15. function smarty_core_process_cached_inserts($params, &$smarty) {
  16. preg_match_all('!'.$smarty->_smarty_md5.'{insert_cache (.*)}'.$smarty->_smarty_md5.'!Uis',
  17. $params['results'], $match);
  18. list($cached_inserts, $insert_args) = $match;
  19. for ($i = 0, $for_max = count($cached_inserts); $i < $for_max; $i++) {
  20. if ($smarty->debugging) {
  21. $_params = array();
  22. require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php';
  23. $debug_start_time = smarty_core_get_microtime($_params, $smarty);
  24. }
  25. $args = unserialize($insert_args[$i]);
  26. $name = $args['name'];
  27. if (isset($args['script'])) {
  28. $_params = array('resource_name' => $smarty->_dequote($args['script']));
  29. require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_php_resource.php';
  30. if (!smarty_core_get_php_resource($_params, $smarty)) {
  31. return false;
  32. }
  33. $resource_type = $_params['resource_type'];
  34. $php_resource = $_params['php_resource'];
  35. if ($resource_type == 'file') {
  36. $smarty->_include($php_resource, true);
  37. } else {
  38. $smarty->_eval($php_resource);
  39. }
  40. }
  41. $function_name = $smarty->_plugins['insert'][$name][0];
  42. if (empty($args['assign'])) {
  43. $replace = $function_name($args, $smarty);
  44. } else {
  45. $smarty->assign($args['assign'], $function_name($args, $smarty));
  46. $replace = '';
  47. }
  48. $params['results'] = str_replace($cached_inserts[$i], $replace, $params['results']);
  49. if ($smarty->debugging) {
  50. $_params = array();
  51. require_once SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.get_microtime.php';
  52. $smarty->_smarty_debug_info[] = array('type' => 'insert',
  53. 'filename' => 'insert_'.$name,
  54. 'depth' => $smarty->_inclusion_depth,
  55. 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $debug_start_time);
  56. }
  57. }
  58. return $params['results'];
  59. }
  60. /* vim: set expandtab: */
  61. ?>