core.run_insert_handler.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Handle insert tags
  9. *
  10. * @param array $args
  11. * @return string
  12. */
  13. function smarty_core_run_insert_handler($params, &$smarty)
  14. {
  15. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  16. if ($smarty->debugging) {
  17. $_params = array();
  18. $_debug_start_time = smarty_core_get_microtime($_params, $smarty);
  19. }
  20. if ($smarty->caching) {
  21. $_arg_string = serialize($params['args']);
  22. $_name = $params['args']['name'];
  23. if (!isset($smarty->_cache_info['insert_tags'][$_name])) {
  24. $smarty->_cache_info['insert_tags'][$_name] = array('insert',
  25. $_name,
  26. $smarty->_plugins['insert'][$_name][1],
  27. $smarty->_plugins['insert'][$_name][2],
  28. !empty($params['args']['script']) ? true : false);
  29. }
  30. return $smarty->_smarty_md5."{insert_cache $_arg_string}".$smarty->_smarty_md5;
  31. } else {
  32. if (isset($params['args']['script'])) {
  33. $_params = array('resource_name' => $smarty->_dequote($params['args']['script']));
  34. require_once(SMARTY_CORE_DIR . 'core.get_php_resource.php');
  35. if(!smarty_core_get_php_resource($_params, $smarty)) {
  36. return false;
  37. }
  38. if ($_params['resource_type'] == 'file') {
  39. $smarty->_include($_params['php_resource'], true);
  40. } else {
  41. $smarty->_eval($_params['php_resource']);
  42. }
  43. unset($params['args']['script']);
  44. }
  45. $_funcname = $smarty->_plugins['insert'][$params['args']['name']][0];
  46. $_content = $_funcname($params['args'], $smarty);
  47. if ($smarty->debugging) {
  48. $_params = array();
  49. require_once(SMARTY_CORE_DIR . 'core.get_microtime.php');
  50. $smarty->_smarty_debug_info[] = array('type' => 'insert',
  51. 'filename' => 'insert_'.$params['args']['name'],
  52. 'depth' => $smarty->_inclusion_depth,
  53. 'exec_time' => smarty_core_get_microtime($_params, $smarty) - $_debug_start_time);
  54. }
  55. if (!empty($params['args']["assign"])) {
  56. $smarty->assign($params['args']["assign"], $_content);
  57. } else {
  58. return $_content;
  59. }
  60. }
  61. }
  62. /* vim: set expandtab: */
  63. ?>