name)); } return null; } function tag($tag, &$params=NULL) { $extends = C('extends.' . $tag); $tags = C('tags.' . $tag); if (!empty($tags)) { if(empty($tags['_overlay']) && !empty($extends)) { $tags = array_unique(array_merge($extends,$tags)); }elseif(isset($tags['_overlay'])){ unset($tags['_overlay']); } }elseif(!empty($extends)) { $tags = $extends; } if($tags) { if(APP_DEBUG) { G($tag.'Start'); Log::record('Tag[ '.$tag.' ] --START--',Log::INFO); } foreach ($tags as $key=>$name) { if(!is_int($key)) { $name = $key; } B($name, $params); } if(APP_DEBUG) { Log::record('Tag[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]',Log::INFO); } }else{ return false; } } function add_tag_behavior($tag,$behavior,$path='') { $array = C('tags.'.$tag); if(!$array) { $array = array(); } if($path) { $array[$behavior] = $path; }else{ $array[] = $behavior; } C('tags.'.$tag,$array); } function filter($name, &$content) { $class = $name . 'Filter'; require_cache(LIB_PATH . 'Filter/' . $class . '.class.php'); $filter = new $class(); $content = $filter->run($content); } function B($name, &$params=NULL) { $class = $name.'Behavior'; G('behaviorStart'); $behavior = new $class(); $behavior->run($params); if(APP_DEBUG) { G('behaviorEnd'); Log::record('Run '.$name.' Behavior [ RunTime:'.G('behaviorStart','behaviorEnd',6).'s ]',Log::INFO); } } function W($name, $data=array(), $return=false) { $class = $name . 'Widget'; require_cache(LIB_PATH . 'Widget/' . $class . '.class.php'); if (!class_exists($class)) throw_exception(L('_CLASS_NOT_EXIST_') . ':' . $class); $widget = Think::instance($class); $content = $widget->render($data); if ($return) return $content; else echo $content; } function strip_whitespace($content) { $stripStr = ''; $tokens = token_get_all($content); $last_space = false; for ($i = 0, $j = count($tokens); $i < $j; $i++) { if (is_string($tokens[$i])) { $last_space = false; $stripStr .= $tokens[$i]; } else { switch ($tokens[$i][0]) { case T_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$last_space) { $stripStr .= ' '; $last_space = true; } break; case T_START_HEREDOC: $stripStr .= "<<__toString()); } static public function appError($errno, $errstr, $errfile, $errline) { switch ($errno) { case E_ERROR: case E_USER_ERROR: $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行."; if(C('LOG_RECORD')) Log::write($errorStr,Log::ERR); halt($errorStr); break; case E_STRICT: case E_USER_WARNING: case E_USER_NOTICE: default: $errorStr = "[$errno] $errstr ".basename($errfile)." 第 $errline 行."; Log::record($errorStr,Log::NOTICE); break; } } public function __set($name ,$value) { if(property_exists($this,$name)) $this->$name = $value; } public function __get($name) { return isset($this->$name)?$this->$name:null; } } class ThinkException extends Exception { private $type; private $extra; public function __construct($message,$code=0,$extra=false) { parent::__construct($message,$code); $this->type = get_class($this); $this->extra = $extra; } public function __toString() { $trace = $this->getTrace(); if($this->extra) array_shift($trace); $this->class = $trace[0]['class']; $this->function = $trace[0]['function']; $this->file = $trace[0]['file']; $this->line = $trace[0]['line']; $file = file($this->file); $traceInfo=''; $time = date('y-m-d H:i:m'); foreach($trace as $t) { $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') '; $traceInfo .= $t['class'].$t['type'].$t['function'].'('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=")\n"; } $error['message'] = $this->message; $error['type'] = $this->type; $error['detail'] = L('_MODULE_').'['.MODULE_NAME.'] '.L('_ACTION_').'['.ACTION_NAME.']'."\n"; $error['detail'] .= ($this->line-2).': '.$file[$this->line-3]; $error['detail'] .= ($this->line-1).': '.$file[$this->line-2]; $error['detail'] .= ''.($this->line).': '.$file[$this->line-1].''; $error['detail'] .= ($this->line+1).': '.$file[$this->line]; $error['detail'] .= ($this->line+2).': '.$file[$this->line+1]; $error['class'] = $this->class; $error['function'] = $this->function; $error['file'] = $this->file; $error['line'] = $this->line; $error['trace'] = $traceInfo; if(C('LOG_EXCEPTION_RECORD')) { Log::Write('('.$this->type.') '.$this->message); } return $error ; } } abstract class Behavior { protected $options = array(); public function __construct() { if(!empty($this->options)) { foreach ($this->options as $name=>$val){ if(NULL !== C($name)) { $this->options[$name] = C($name); }else{ C($name,$val); } } array_change_key_case($this->options); } } public function __get($name){ return $this->options[strtolower($name)]; } abstract public function run(&$params); } class ReadHtmlCacheBehavior extends Behavior { protected $options = array( 'HTML_CACHE_ON'=>false, 'HTML_CACHE_TIME'=>60, 'HTML_CACHE_RULES'=>array(), 'HTML_FILE_SUFFIX'=>'.html', ); public function run(&$params){ if(C('HTML_CACHE_ON')) { if(($cacheTime = $this->requireHtmlCache()) && $this->checkHTMLCache(HTML_FILE_NAME,$cacheTime)) { readfile(HTML_FILE_NAME); exit(); } } } static private function requireHtmlCache() { $htmls = C('HTML_CACHE_RULES'); if(!empty($htmls)) { $moduleName = strtolower(MODULE_NAME); if(isset($htmls[$moduleName.':'.ACTION_NAME])) { $html = $htmls[$moduleName.':'.ACTION_NAME]; }elseif(isset($htmls[$moduleName.':'])){ $html = $htmls[$moduleName.':']; }elseif(isset($htmls[ACTION_NAME])){ $html = $htmls[ACTION_NAME]; }elseif(isset($htmls['*'])){ $html = $htmls['*']; }elseif(isset($htmls['empty:index']) && !class_exists(MODULE_NAME.'Action')){ $html = $htmls['empty:index']; }elseif(isset($htmls[$moduleName.':_empty']) && $this->isEmptyAction(MODULE_NAME,ACTION_NAME)){ $html = $htmls[$moduleName.':_empty']; } if(!empty($html)) { $rule = $html[0]; $rule = preg_replace('/{\$(_\w+)\.(\w+)\|(\w+)}/e',"\\3(\$\\1['\\2'])",$rule); $rule = preg_replace('/{\$(_\w+)\.(\w+)}/e',"\$\\1['\\2']",$rule); $rule = preg_replace('/{(\w+)\|(\w+)}/e',"\\2(\$_GET['\\1'])",$rule); $rule = preg_replace('/{(\w+)}/e',"\$_GET['\\1']",$rule); $rule = str_ireplace( array('{:app}','{:module}','{:action}','{:group}'), array(APP_NAME,MODULE_NAME,ACTION_NAME,defined('GROUP_NAME')?GROUP_NAME:''), $rule); $rule = preg_replace('/{|(\w+)}/e',"\\1()",$rule); if(!empty($html[2])) $rule = $html[2]($rule); $cacheTime = isset($html[1])?$html[1]:C('HTML_CACHE_TIME'); define('HTML_FILE_NAME',HTML_PATH . $rule.C('HTML_FILE_SUFFIX')); return $cacheTime; } } return false; } static public function checkHTMLCache($cacheFile='',$cacheTime='') { if(!is_file($cacheFile)){ return false; }elseif (filemtime(C('TEMPLATE_NAME')) > filemtime($cacheFile)) { return false; }elseif(!is_numeric($cacheTime) && function_exists($cacheTime)){ return $cacheTime($cacheFile); }elseif ($cacheTime != 0 && time() > filemtime($cacheFile)+$cacheTime) { return false; } return true; } static private function isEmptyAction($module,$action) { $className = $module.'Action'; $class=new $className; return !method_exists($class,$action); } } class CheckRouteBehavior extends Behavior { protected $options = array( 'URL_ROUTER_ON' => false, 'URL_ROUTE_RULES' => array(), ); public function run(&$return){ $regx = trim($_SERVER['PATH_INFO'],'/'); if(empty($regx)) return $return = true; if(!C('URL_ROUTER_ON')) return $return = false; $routes = C('URL_ROUTE_RULES'); if(!empty($routes)) { $Group_name = substr($_SERVER['PATH_INFO'],1,5); $depr = ($Group_name =='Admin'||strpos(C('MOBILE_URL'),$_SERVER['HTTP_HOST'])!==false)?C('URL_PATHINFO_DEPR_ADMIN'):C('URL_PATHINFO_DEPR'); $regx = str_replace($depr,'/',$regx); foreach ($routes as $rule=>$route){ if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { return $return = $this->parseRegex($matches,$route,$regx); }else{ $len1= substr_count($regx,'/'); $len2 = substr_count($rule,'/'); if($len1>=$len2) { if('$' == substr($rule,-1,1)) { if($len1 != $len2) { continue; }else{ $rule = substr($rule,0,-1); } } $match = $this->checkUrlMatch($regx,$rule); if($match) return $return = $this->parseRule($rule,$route,$regx); } } } } $return = false; } private function checkUrlMatch($regx,$rule) { $m1 = explode('/',$regx); $m2 = explode('/',$rule); $match = true; foreach ($m2 as $key=>$val){ if(':' == substr($val,0,1)) { if(strpos($val,'\\')) { $type = substr($val,-1); if('d'==$type && !is_numeric($m1[$key])) { $match = false; break; } }elseif(strpos($val,'^')){ $array = explode('|',substr(strstr($val,'^'),1)); if(in_array($m1[$key],$array)) { $match = false; break; } } }elseif(0 !== strcasecmp($val,$m1[$key])){ $match = false; break; } } return $match; } private function parseUrl($url) { $var = array(); if(false !== strpos($url,'?')) { $info = parse_url($url); $path = explode('/',$info['path']); parse_str($info['query'],$var); }elseif(strpos($url,'/')){ $path = explode('/',$url); }else{ parse_str($url,$var); } if(isset($path)) { $var[C('VAR_ACTION')] = array_pop($path); if(!empty($path)) { $var[C('VAR_MODULE')] = array_pop($path); } if(!empty($path)) { $var[C('VAR_GROUP')] = array_pop($path); } } return $var; } private function parseRule($rule,$route,$regx) { $url = is_array($route)?$route[0]:$route; $paths = explode('/',$regx); $matches = array(); $rule = explode('/',$rule); foreach ($rule as $item){ if(0===strpos($item,':')) { if($pos = strpos($item,'^') ) { $var = substr($item,1,$pos-1); }elseif(strpos($item,'\\')){ $var = substr($item,1,-2); }else{ $var = substr($item,1); } $matches[$var] = array_shift($paths); }else{ array_shift($paths); } } if(0=== strpos($url,'/') || 0===strpos($url,'http')) { if(strpos($url,':')) { $values = array_values($matches); $url = preg_replace('/:(\d)/e','$values[\\1-1]',$url); } header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $values = array_values($matches); foreach ($var as $key=>$val){ if(0===strpos($val,':')) { $var[$key] = $values[substr($val,1)-1]; } } $var = array_merge($matches,$var); if($paths) { preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', implode('/',$paths)); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } private function parseRegex($matches,$route,$regx) { $url = is_array($route)?$route[0]:$route; $url = preg_replace('/:(\d)/e','$matches[\\1]',$url); if(0=== strpos($url,'/') || 0===strpos($url,'http')) { header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); exit; }else{ $var = $this->parseUrl($url); $regx = substr_replace($regx,'',0,strlen($matches[0])); if($regx) { preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', $regx); } if(is_array($route) && isset($route[1])) { parse_str($route[1],$params); $var = array_merge($var,$params); } $_GET = array_merge($var,$_GET); } return true; } } class LocationTemplateBehavior extends Behavior { public function run(&$templateFile){ if(!file_exists_case($templateFile)) $templateFile = $this->parseTemplateFile($templateFile); } private function parseTemplateFile($templateFile) { if(''==$templateFile) { $templateFile = C('TEMPLATE_NAME'); }elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){ $path = explode(':',$templateFile); $action = array_pop($path); $module = !empty($path)?array_pop($path):MODULE_NAME; if(!empty($path)) { $path = dirname(THEME_PATH).'/'.array_pop($path).'/'; }else{ $path = THEME_PATH; } $depr = defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/'; $templateFile = $path.$module.$depr.$action.C('TMPL_TEMPLATE_SUFFIX'); } if(!file_exists_case($templateFile)) throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']'); return $templateFile; } } class ParseTemplateBehavior extends Behavior { protected $options = array( 'TMPL_ENGINE_TYPE' => 'Think', 'TMPL_CACHFILE_SUFFIX' => '.php', 'TMPL_DENY_FUNC_LIST' => 'echo,exit', 'TMPL_DENY_PHP' =>false, 'TMPL_L_DELIM' => '{', 'TMPL_R_DELIM' => '}', 'TMPL_VAR_IDENTIFY' => 'array', 'TMPL_STRIP_SPACE' => true, 'TMPL_CACHE_ON' => true, 'TMPL_CACHE_TIME' => 0, 'TMPL_LAYOUT_ITEM' => '{__CONTENT__}', 'LAYOUT_ON' => false, 'LAYOUT_NAME' => 'layout', 'TAGLIB_BEGIN' => '<', 'TAGLIB_END' => '>', 'TAGLIB_LOAD' => true, 'TAGLIB_BUILD_IN' => 'cx', 'TAGLIB_PRE_LOAD' => '', ); public function run(&$_data){ $engine = strtolower(C('TMPL_ENGINE_TYPE')); if('think'==$engine){ if($this->checkCache($_data['file'])) { extract($_data['var'], EXTR_OVERWRITE); include C('CACHE_PATH').md5($_data['file']).C('TMPL_CACHFILE_SUFFIX'); }else{ $tpl = Think::instance('ThinkTemplate'); $tpl->fetch($_data['file'],$_data['var']); } }else{ $class = 'Template'.ucwords($engine); if(is_file(CORE_PATH.'Driver/Template/'.$class.'.class.php')) { $path = CORE_PATH; }else{ $path = EXTEND_PATH; } if(require_cache($path.'Driver/Template/'.$class.'.class.php')) { $tpl = new $class; $tpl->fetch($_data['file'],$_data['var']); }else { throw_exception(L('_NOT_SUPPERT_').': ' . $class); } } } protected function checkCache($tmplTemplateFile) { if (!C('TMPL_CACHE_ON')) return false; $tmplCacheFile = C('CACHE_PATH').md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); if(!is_file($tmplCacheFile)){ return false; }elseif (filemtime($tmplTemplateFile) > filemtime($tmplCacheFile)) { return false; }elseif (C('TMPL_CACHE_TIME') != 0 && time() > filemtime($tmplCacheFile)+C('TMPL_CACHE_TIME')) { return false; } if(C('LAYOUT_ON')) { $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); if(filemtime($layoutFile) > filemtime($tmplCacheFile)) { return false; } } return true; } } class ContentReplaceBehavior extends Behavior { protected $options = array( 'TMPL_PARSE_STRING'=>array(), ); public function run(&$content){ $content = $this->templateContentReplace($content); } protected function templateContentReplace($content) { $replace = array( '__TMPL__' => APP_TMPL_PATH, '__ROOT__' => __ROOT__, '__APP__' => __APP__, '__GROUP__' => defined('GROUP_NAME')?__GROUP__:__APP__, '__ACTION__' => __ACTION__, '__SELF__' => __SELF__, '__URL__' => __URL__, '../Public' => APP_TMPL_PATH.'Public', '__PUBLIC__' => __ROOT__.'/Public', '__MODULE__' => MODULE_NAME, ); if(is_array(C('TMPL_PARSE_STRING')) ) $replace = array_merge($replace,C('TMPL_PARSE_STRING')); $content = str_replace(array_keys($replace),array_values($replace),$content); return $content; } } class TokenBuildBehavior extends Behavior { protected $options = array( 'TOKEN_ON' => true, 'TOKEN_NAME' => '__hash__', 'TOKEN_TYPE' => 'md5', 'TOKEN_RESET' => true, ); public function run(&$content){ if(C('TOKEN_ON')) { if(strpos($content,'{__TOKEN__}')) { $content = str_replace('{__TOKEN__}',$this->buildToken(),$content); }elseif(preg_match('/<\/form(\s*)>/is',$content,$match)) { $content = str_replace($match[0],$this->buildToken().$match[0],$content); } } } private function buildToken() { $tokenName = C('TOKEN_NAME'); $tokenType = C('TOKEN_TYPE'); if(!isset($_SESSION[$tokenName])) { $_SESSION[$tokenName] = array(); } $tokenKey = md5($_SERVER['REQUEST_URI']); if(isset($_SESSION[$tokenName][$tokenKey])) { $tokenValue = $_SESSION[$tokenName][$tokenKey]; }else{ $tokenValue = $tokenType(microtime(TRUE)); $_SESSION[$tokenName][$tokenKey] = $tokenValue; } if($action = C('TOKEN_ACTION')){ $_SESSION[$action($tokenKey)] = true; } $token = ''; return $token; } } class WriteHtmlCacheBehavior extends Behavior { public function run(&$content){ if(C('HTML_CACHE_ON') && defined('HTML_FILE_NAME')) { if(!is_dir(dirname(HTML_FILE_NAME))) mk_dir(dirname(HTML_FILE_NAME)); if( false === file_put_contents( HTML_FILE_NAME , $content )) throw_exception(L('_CACHE_WRITE_ERROR_').':'.HTML_FILE_NAME); } } } class ShowRuntimeBehavior extends Behavior { protected $options = array( 'SHOW_RUN_TIME' => false, 'SHOW_ADV_TIME' => false, 'SHOW_DB_TIMES' => false, 'SHOW_CACHE_TIMES' => false, 'SHOW_USE_MEM' => false, 'SHOW_LOAD_FILE' => false, 'SHOW_FUN_TIMES' => false , ); public function run(&$content){ if(C('SHOW_RUN_TIME')){ if(false !== strpos($content,'{__NORUNTIME__}')) { $content = str_replace('{__NORUNTIME__}','',$content); }else{ $runtime = $this->showTime(); if(strpos($content,'{__RUNTIME__}')) $content = str_replace('{__RUNTIME__}',$runtime,$content); else $content .= $runtime; } }else{ $content = str_replace(array('{__NORUNTIME__}','{__RUNTIME__}'),'',$content); } } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; if(C('SHOW_ADV_TIME')) { $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; } if(C('SHOW_DB_TIMES') && class_exists('Db',false) ) { $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; } if(C('SHOW_CACHE_TIMES') && class_exists('Cache',false)) { $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; } if(MEMORY_LIMIT_ON && C('SHOW_USE_MEM')) { $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; } if(C('SHOW_LOAD_FILE')) { $showTime .= ' | LoadFile:'.count(get_included_files()); } if(C('SHOW_FUN_TIMES')) { $fun = get_defined_functions(); $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); } return $showTime; } } class ShowPageTraceBehavior extends Behavior { protected $options = array( 'SHOW_PAGE_TRACE' => false, ); public function run(&$params){ if(C('SHOW_PAGE_TRACE')) { echo $this->showTrace(); } } private function showTrace() { $log = Log::$log; $files = get_included_files(); $trace = array( '请求时间'=> date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']), '当前页面'=> __SELF__, '请求协议'=> $_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'], '运行信息'=> $this->showTime(), '会话ID' => session_id(), '日志记录'=> count($log)?count($log).'条日志
'.implode('
',$log):'无日志记录', '加载文件'=> count($files).str_replace("\n",'
',substr(substr(print_r($files,true),7),0,-2)), ); $traceFile = CONF_PATH.'trace.php'; if(is_file($traceFile)) { $trace = array_merge(include $traceFile,$trace); } trace($trace); ob_start(); include C('TMPL_TRACE_FILE')?C('TMPL_TRACE_FILE'):THINK_PATH.'Tpl/page_trace.tpl'; return ob_get_clean(); } private function showTime() { G('beginTime',$GLOBALS['_beginTime']); G('viewEndTime'); $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; if(class_exists('Db',false) ) { $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; } if( class_exists('Cache',false)) { $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; } if(MEMORY_LIMIT_ON ) { $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; } $showTime .= ' | LoadFile:'.count(get_included_files()); $fun = get_defined_functions(); $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); return $showTime; } }alias_import(array ( 'Model' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Core/Model.class.php', 'Db' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Core/Db.class.php', 'Log' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Core/Log.class.php', 'ThinkTemplate' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Template/ThinkTemplate.class.php', 'TagLib' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Template/TagLib.class.php', 'Cache' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Core/Cache.class.php', 'Widget' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Core/Widget.class.php', 'TagLibCx' => '/data/webroot/k886.net/mh/ThinkPHP/Lib/Driver/TagLib/TagLibCx.class.php', )); function halt($error) { $e = array(); if (APP_DEBUG) { if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['class'] = $trace[0]['class']; $e['function'] = $trace[0]['function']; $e['line'] = $trace[0]['line']; $traceInfo = ''; $time = date('y-m-d H:i:m'); foreach ($trace as $t) { $traceInfo .= '[' . $time . '] ' . $t['file'] . ' (' . $t['line'] . ') '; $traceInfo .= $t['class'] . $t['type'] . $t['function'] . '('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=')
'; } $e['trace'] = $traceInfo; } else { $e = $error; } include C('TMPL_EXCEPTION_FILE'); } else { $error_page = C('ERROR_PAGE'); if (!empty($error_page)) { redirect($error_page); } else { if (C('SHOW_ERROR_MSG')) $e['message'] = is_array($error) ? $error['message'] : $error; else $e['message'] = C('ERROR_MESSAGE'); include C('TMPL_EXCEPTION_FILE'); } } exit; } function throw_exception($msg, $type='ThinkException', $code=0) { if (class_exists($type, false)) throw new $type($msg, $code, true); else halt($msg); } function dump($var, $echo=true, $label=null, $strict=true) { $label = ($label === null) ? '' : rtrim($label) . ' '; if (!$strict) { if (ini_get('html_errors')) { $output = print_r($var, true); $output = '
' . $label . htmlspecialchars($output, ENT_QUOTES) . '
'; } else { $output = $label . print_r($var, true); } } else { ob_start(); var_dump($var); $output = ob_get_clean(); if (!extension_loaded('xdebug')) { $output = preg_replace("/\]\=\>\n(\s+)/m", '] => ', $output); $output = '
' . $label . htmlspecialchars($output, ENT_QUOTES) . '
'; } } if ($echo) { echo($output); return null; }else return $output; } function debug_start($label='') { $GLOBALS[$label]['_beginTime'] = microtime(TRUE); if (MEMORY_LIMIT_ON) $GLOBALS[$label]['_beginMem'] = memory_get_usage(); } function debug_end($label='') { $GLOBALS[$label]['_endTime'] = microtime(TRUE); echo '
Process ' . $label . ': Times ' . number_format($GLOBALS[$label]['_endTime'] - $GLOBALS[$label]['_beginTime'], 6) . 's '; if (MEMORY_LIMIT_ON) { $GLOBALS[$label]['_endMem'] = memory_get_usage(); echo ' Memories ' . number_format(($GLOBALS[$label]['_endMem'] - $GLOBALS[$label]['_beginMem']) / 1024) . ' k'; } echo '
'; } function trace($title='',$value='') { if(!C('SHOW_PAGE_TRACE')) return; static $_trace = array(); if(is_array($title)) { $_trace = array_merge($_trace