Exemple #1
0
 function fetch($file, $display = false)
 {
     if ($this->debugging) {
         $this->_templatelite_debug_info[] = array('type' => 'template', 'filename' => $file, 'depth' => 0, 'exec_time' => array_sum(explode(' ', microtime())));
         $included_tpls_idx = count($this->_templatelite_debug_info) - 1;
     }
     if ($display) {
         $this->_fetch_compile($file);
         $this->debugging && ($this->_templatelite_debug_info[$included_tpls_idx]['exec_time'] = array_sum(explode(' ', microtime())) - $this->_templatelite_debug_info[$included_tpls_idx]['exec_time']);
         if ($this->debugging && !$this->_templatelite_debug_loop) {
             $this->debugging = false;
             $this->internal('template_generate_debug_output');
             template_generate_debug_output($this);
             $this->debugging = true;
         }
     } else {
         return $this->_fetch_compile($file, true);
     }
 }
Exemple #2
0
 function fetch($file, $cache_id = null, $display = false)
 {
     $file = $this->_get_resource($file);
     if ($this->debugging) {
         $this->_templatelite_debug_info[] = array('type' => 'template', 'filename' => $file, 'depth' => 0, 'exec_time' => array_sum(explode(' ', microtime())));
         $included_tpls_idx = count($this->_templatelite_debug_info) - 1;
     }
     $this->_cache_id = $cache_id;
     $this->template_dir = $this->_get_dir($this->template_dir);
     $this->compile_dir = $this->_get_dir($this->compile_dir);
     if ($this->cache) {
         $this->_cache_dir = $this->_build_dir($this->cache_dir, $this->_cache_id);
     }
     $name = $this->encode_file_name ? md5($this->_resource_type == 1 ? $this->template_dir . $file : $this->_resource_type . "_" . $file) . '.php' : str_replace(".", "_", str_replace("/", "_", $this->_resource_type . "_" . $file)) . '.php';
     $this->_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
     //		$this->_error_level = error_reporting(E_ALL);
     if (!$this->force_compile && $this->cache && $this->_is_cached($file, $cache_id)) {
         ob_start();
         include $this->_cache_dir . $name;
         $output = ob_get_contents();
         ob_end_clean();
         $output = substr($output, strpos($output, "\n") + 1);
     } else {
         $output = $this->_fetch_compile($file, $cache_id);
         if ($this->cache) {
             $f = fopen($this->_cache_dir . $name, "w");
             fwrite($f, serialize($this->_cache_info) . "\n{$output}");
             fclose($f);
         }
     }
     if (strpos($output, $this->_sl_md5) !== false) {
         preg_match_all('!' . $this->_sl_md5 . '{_run_insert (.*)}' . $this->_sl_md5 . '!U', $output, $_match);
         foreach ($_match[1] as $value) {
             $arguments = unserialize($value);
             $output = str_replace($this->_sl_md5 . '{_run_insert ' . $value . '}' . $this->_sl_md5, call_user_func_array('insert_' . $arguments['name'], array((array) $arguments, $this)), $output);
         }
     }
     foreach ($this->_plugins['outputfilter'] as $function) {
         $output = $function($output, $this);
     }
     error_reporting($this->_error_level);
     if ($this->debugging) {
         $this->_templatelite_debug_info[$included_tpls_idx]['exec_time'] = array_sum(explode(' ', microtime())) - $this->_templatelite_debug_info[$included_tpls_idx]['exec_time'];
     }
     if ($display) {
         echo $output;
         if ($this->debugging && !$this->_templatelite_debug_loop) {
             $this->debugging = false;
             if (!function_exists("template_generate_debug_output")) {
                 require_once TEMPLATE_LITE_DIR . "internal/template.generate_debug_output.php";
             }
             $debug_output = template_generate_debug_output($this);
             $this->debugging = true;
             echo $debug_output;
         }
     } else {
         return $output;
     }
 }
Exemple #3
0
 function fetch($file, $cache_id = null, $display = false)
 {
     $file = $this->_get_resource($file);
     if ($this->debugging) {
         $this->_templatelite_debug_info[] = array('type' => 'template', 'filename' => $file, 'depth' => 0, 'exec_time' => array_sum(explode(' ', microtime())));
         $included_tpls_idx = count($this->_templatelite_debug_info) - 1;
     }
     $this->_cache_id = $cache_id;
     $this->template_dir = $this->_get_dir($this->template_dir);
     $this->compile_dir = $this->_get_dir($this->compile_dir);
     if ($this->cache) {
         $this->_cache_dir = $this->_build_dir($this->cache_dir, $this->_cache_id);
     }
     $name = $this->encode_file_name ? md5($this->_resource_type == 1 ? $this->template_dir . $file : $this->_resource_type . "_" . $file) . '.php' : str_replace(".", "_", str_replace("/", "_", $this->_resource_type . "_" . $file)) . '.php';
     $this->_error_level = $this->debugging ? error_reporting() : error_reporting(error_reporting() & ~E_NOTICE);
     //		$this->_error_level = error_reporting(E_ALL);
     if (!$this->force_compile && $this->cache && $this->_is_cached($file, $cache_id)) {
         ob_start();
         include $this->_cache_dir . $name;
         $output = ob_get_contents();
         ob_end_clean();
         $output = substr($output, strpos($output, "\n") + 1);
     } else {
         $output = $this->_fetch_compile($file, $cache_id, true);
         if ($this->cache) {
             $f = fopen($this->_cache_dir . $name, "w");
             fwrite($f, serialize($this->_cache_info) . "\n{$output}");
             fclose($f);
         }
     }
     if (strpos($output, $this->_sl_md5) !== false) {
         preg_match_all('!' . $this->_sl_md5 . '{_run_DreamCMS (.*)}' . $this->_sl_md5 . '!U', $output, $_match);
         foreach ($_match[1] as $value) {
             $arguments = unserialize($value);
             $output = str_replace($this->_sl_md5 . '{_run_DreamCMS ' . $value . '}' . $this->_sl_md5, call_user_func_array('DreamCMS_' . $arguments['module'], array((array) $arguments, $this)), $output);
         }
     }
     foreach ($this->_plugins['outputfilter'] as $function) {
         $output = $function($output, $this);
     }
     error_reporting($this->_error_level);
     if ($this->debugging) {
         $this->_templatelite_debug_info[$included_tpls_idx]['exec_time'] = array_sum(explode(' ', microtime())) - $this->_templatelite_debug_info[$included_tpls_idx]['exec_time'];
     }
     //		2007-11-27 ADD mod_rewrite url BY 枯木
     $this->error && ($output = str_replace("<?php error_reporting(0);!defined('DCPATH') && exit('What are you doing?');?>", '', $output));
     if ($this->rewrite) {
         $output = preg_replace("/\\<a(\\s*[^\\>]+\\s*)href\\=([\"|\\'|\\s]?)([^\"\\'>\\s]+\\.php\\?[^\"\\'>\\s]+)\\2/ies", "rewrite('\\3','<a\\1href=\\2','\\2')", $output);
         $output = preg_replace("/\\<iframe(\\s*[^\\>]+\\s*)src\\=([\"|\\'|\\s]?)([^\"\\'>\\s]+\\.php\\?[^\"\\'>\\s]+)\\2/ies", "rewrite('\\3','<iframe\\1src=\\2','\\2')", $output);
     }
     $output = $this->_replace_path($output, $file);
     if ($display) {
         echo $output;
         if ($this->debugging && !$this->_templatelite_debug_loop) {
             $this->debugging = false;
             if (!function_exists("template_generate_debug_output")) {
                 require_once TEMPLATE_LITE_DIR . "internal/template.generate_debug_output.php";
             }
             $debug_output = template_generate_debug_output($this);
             $this->debugging = true;
             echo $debug_output;
         }
     } else {
         return $output;
     }
 }