core.write_compiled_include.php
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:3k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7. /**
  8.  * Extract non-cacheable parts out of compiled template and write it
  9.  *
  10.  * @param string $compile_path
  11.  * @param string $template_compiled
  12.  * @return boolean
  13.  */
  14. function smarty_core_write_compiled_include($params, &$smarty)
  15. {
  16.     $_tag_start = 'if ($this->caching && !$this->_cache_including) { echo '{nocache:('.$params['cache_serial'].')#(d+)}';}';
  17.     $_tag_end   = 'if ($this->caching && !$this->_cache_including) { 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 /* Smarty version ".$smarty->_version.", created on ".strftime("%Y-%m-%d %H:%M:%S")."n";
  24.     $_include_compiled .= "         compiled from " . strtr(urlencode($params['resource_name']), array('%2F'=>'/', '%3A'=>':')) . " */nn";
  25.     $_compile_path = $params['include_file_path'];
  26.     $smarty->_cache_serials[$_compile_path] = $params['cache_serial'];
  27.     $_include_compiled .= "$this->_cache_serials['".$_compile_path."'] = '".$params['cache_serial']."';nn?>";
  28.     $_include_compiled .= $params['plugins_code'];
  29.     $_include_compiled .= "<?php";
  30.     $this_varname = ((double)phpversion() >= 5.0) ? '_smarty' : 'this';
  31.     for ($_i = 0, $_for_max = count($_match_source); $_i < $_for_max; $_i++) {
  32.         $_match =& $_match_source[$_i];
  33.         $source = $_match[4];
  34.         if ($this_varname == '_smarty') {
  35.             /* rename $this to $_smarty in the sourcecode */
  36.             $tokens = token_get_all('<?php ' . $_match[4]);
  37.             array_shift($tokens); /* remove the opening <.?.php */
  38.             for ($i=0, $count = count($tokens); $i < $count; $i++) {
  39.                 if (is_array($tokens[$i])) {
  40.                     if ($tokens[$i][0] == T_VARIABLE && $tokens[$i][1] == '$this') {
  41.                         $tokens[$i] = '$' . $this_varname;
  42.                     } else {
  43.                         $tokens[$i] = $tokens[$i][1];
  44.                     }                   
  45.                 }
  46.             }
  47.             $source = implode('', $tokens);
  48.         }
  49.         /* add function to compiled include */
  50.         $_include_compiled .= "
  51. function _smarty_tplfunc_$_match[2]_$_match[3](&$$this_varname)
  52. {
  53. $source
  54. }
  55. ";
  56.     }
  57.     $_include_compiled .= "nn?>n";
  58.     $_params = array('filename' => $_compile_path,
  59.                      'contents' => $_include_compiled, 'create_dirs' => true);
  60.     require_once(SMARTY_CORE_DIR . 'core.write_file.php');
  61.     smarty_core_write_file($_params, $smarty);
  62.     return true;
  63. }
  64. ?>