f (0 === strpos($name, '@/')) { $baseUrl = MODULE_PATH.'Common/'; $name = substr($name, 2); } else { $array = explode('/', $name); $baseUrl = APP_PATH . array_shift($array).'/Common/'; $name = implode('/',$array); } } if (substr($baseUrl, -1) != '/') $baseUrl .= '/'; require_cache($baseUrl . $name . $ext); } function vendor($class, $baseUrl = '', $ext='.php') { if (empty($baseUrl)) $baseUrl = VENDOR_PATH; return import($class, $baseUrl, $ext); } function D($name='',$layer='') { if(empty($name)) return new Think\Model; static $_model = array(); $layer = $layer? : C('DEFAULT_M_LAYER'); if(isset($_model[$name.$layer])) return $_model[$name.$layer]; $class = parse_res_name($name,$layer); if(class_exists($class)) { $model = new $class(basename($name)); }elseif(false === strpos($name,'/')){ if(!C('APP_USE_NAMESPACE')){ import('Common/'.$layer.'/'.$class); }else{ $class = '\\Common\\'.$layer.'\\'.$name.$layer; } $model = class_exists($class)? new $class($name) : new Think\Model($name); }else { Think\Log::record('D方法实例化没找到模型类'.$class,Think\Log::NOTICE); $model = new Think\Model(basename($name)); } $_model[$name.$layer] = $model; return $model; } function M($name='', $tablePrefix='',$connection='') { static $_model = array(); if(strpos($name,':')) { list($class,$name) = explode(':',$name); }else{ $class = 'Think\\Model'; } $guid = (is_array($connection)?implode('',$connection):$connection).$tablePrefix . $name . '_' . $class; if (!isset($_model[$guid])) $_model[$guid] = new $class($name,$tablePrefix,$connection); return $_model[$guid]; } function parse_res_name($name,$layer,$level=1){ if(strpos($name,'://')) { list($extend,$name) = explode('://',$name); }else{ $extend = ''; } if(strpos($name,'/') && substr_count($name, '/')>=$level){ list($module,$name) = explode('/',$name,2); }else{ $module = defined('MODULE_NAME') ? MODULE_NAME : '' ; } $array = explode('/',$name); if(!C('APP_USE_NAMESPACE')){ $class = parse_name($name, 1); import($module.'/'.$layer.'/'.$class.$layer); }else{ $class = $module.'\\'.$layer; foreach($array as $name){ $class .= '\\'.parse_name($name, 1); } if($extend){ $class = $extend.'\\'.$class; } } return $class.$layer; } function controller($name,$path=''){ $layer = C('DEFAULT_C_LAYER'); if(!C('APP_USE_NAMESPACE')){ $class = parse_name($name, 1).$layer; import(MODULE_NAME.'/'.$layer.'/'.$class); }else{ $class = ( $path ? basename(ADDON_PATH).'\\'.$path : MODULE_NAME ).'\\'.$layer; $array = explode('/',$name); foreach($array as $name){ $class .= '\\'.parse_name($name, 1); } $class .= $layer; } if(class_exists($class)) { return new $class(); }else { return false; } } function A($name,$layer='',$level=0) { static $_action = array(); $layer = $layer? : C('DEFAULT_C_LAYER'); $level = $level? : ($layer == C('DEFAULT_C_LAYER')?C('CONTROLLER_LEVEL'):1); if(isset($_action[$name.$layer])) return $_action[$name.$layer]; $class = parse_res_name($name,$layer,$level); if(class_exists($class)) { $action = new $class(); $_action[$name.$layer] = $action; return $action; }else { return false; } } function R($url,$vars=array(),$layer='') { $info = pathinfo($url); $action = $info['basename']; $module = $info['dirname']; $class = A($module,$layer); if($class){ if(is_string($vars)) { parse_str($vars,$vars); } return call_user_func_array(array(&$class,$action.C('ACTION_SUFFIX')),$vars); }else{ return false; } } function tag($tag, &$params=NULL) { \Think\Hook::listen($tag,$params); } function B($name, $tag='',&$params=NULL) { if(''==$tag){ $name .= 'Behavior'; } \Think\Hook::exec($name,$tag,$params); } 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 .= "<< '; } 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 layout($layout) { if(false !== $layout) { C('LAYOUT_ON',true); if(is_string($layout)) { C('LAYOUT_NAME',$layout); } }else{ C('LAYOUT_ON',false); } } function U($url='',$vars='',$suffix=true,$domain=false) { $info = parse_url($url); $url = !empty($info['path'])?$info['path']:ACTION_NAME; if(isset($info['fragment'])) { $anchor = $info['fragment']; if(false !== strpos($anchor,'?')) { list($anchor,$info['query']) = explode('?',$anchor,2); } if(false !== strpos($anchor,'@')) { list($anchor,$host) = explode('@',$anchor, 2); } }elseif(false !== strpos($url,'@')) { list($url,$host) = explode('@',$info['path'], 2); } if(isset($host)) { $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.')); }elseif($domain===true){ $domain = $_SERVER['HTTP_HOST']; if(C('APP_SUB_DOMAIN_DEPLOY') ) { $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { $rule = is_array($rule)?$rule[0]:$rule; if(false === strpos($key,'*') && 0=== strpos($url,$rule)) { $domain = $key.strstr($domain,'.'); $url = substr_replace($url,'',0,strlen($rule)); break; } } } } if(is_string($vars)) { parse_str($vars,$vars); }elseif(!is_array($vars)){ $vars = array(); } if(isset($info['query'])) { parse_str($info['query'],$params); $vars = array_merge($params,$vars); } $depr = C('URL_PATHINFO_DEPR'); $urlCase = C('URL_CASE_INSENSITIVE'); if($url) { if(0=== strpos($url,'/')) { $route = true; $url = substr($url,1); if('/' != $depr) { $url = str_replace('/',$depr,$url); } }else{ if('/' != $depr) { $url = str_replace('/',$depr,$url); } $url = trim($url,$depr); $path = explode($depr,$url); $var = array(); $varModule = C('VAR_MODULE'); $varController = C('VAR_CONTROLLER'); $varAction = C('VAR_ACTION'); $var[$varAction] = !empty($path)?array_pop($path):ACTION_NAME; $var[$varController] = !empty($path)?array_pop($path):CONTROLLER_NAME; if($maps = C('URL_ACTION_MAP')) { if(isset($maps[strtolower($var[$varController])])) { $maps = $maps[strtolower($var[$varController])]; if($action = array_search(strtolower($var[$varAction]),$maps)){ $var[$varAction] = $action; } } } if($maps = C('URL_CONTROLLER_MAP')) { if($controller = array_search(strtolower($var[$varController]),$maps)){ $var[$varController] = $controller; } } if($urlCase) { $var[$varController] = parse_name($var[$varController]); } $module = ''; if(!empty($path)) { $var[$varModule] = implode($depr,$path); }else{ if(C('MULTI_MODULE')) { if(MODULE_NAME != C('DEFAULT_MODULE') || !C('MODULE_ALLOW_LIST')){ $var[$varModule]= MODULE_NAME; } } } if($maps = C('URL_MODULE_MAP')) { if($_module = array_search(strtolower($var[$varModule]),$maps)){ $var[$varModule] = $_module; } } if(isset($var[$varModule])){ $module = $var[$varModule]; unset($var[$varModule]); } } } if(C('URL_MODEL') == 0) { $url = __APP__.'?'.C('VAR_MODULE')."={$module}&".http_build_query(array_reverse($var)); if($urlCase){ $url = strtolower($url); } if(!empty($vars)) { $vars = http_build