/sop/2.0beta1/ThinkPHP/Mode/Compat/compat.php
PHP | 267 lines | 158 code | 17 blank | 92 comment | 31 complexity | 11d71a2c832fd7f737134c6bcf79cab4 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, LGPL-2.1
- <?php
- // +----------------------------------------------------------------------
- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: liu21st <liu21st@gmail.com>
- // +----------------------------------------------------------------------
- // $Id$
-
- define('WEB_LOG_ERROR',0);
- define('WEB_LOG_DEBUG',1);
- define('SQL_LOG_DEBUG',2);
-
- define('SYSTEM_LOG',0);
- define('MAIL_LOG',1);
- define('TCP_LOG',2);
- define('FILE_LOG',3);
-
- define('DATA_TYPE_OBJ',1);
- define('DATA_TYPE_ARRAY',0);
-
- function get_client_ip(){
- if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
- $ip = getenv("HTTP_CLIENT_IP");
- else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
- $ip = getenv("HTTP_X_FORWARDED_FOR");
- else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
- $ip = getenv("REMOTE_ADDR");
- else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
- $ip = $_SERVER['REMOTE_ADDR'];
- else
- $ip = "unknown";
- return($ip);
- }
-
- /**
- +----------------------------------------------------------
- * URL?? ?????????
- +----------------------------------------------------------
- * @param string $action ???
- * @param string $module ???
- * @param string $app ???
- * @param string $route ???
- * @param array $params ??URL??
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- */
- function url($action=ACTION_NAME,$module=MODULE_NAME,$route='',$app=APP_NAME,$params=array()) {
- if(C('DISPATCH_ON') && C('URL_MODEL')>0) {
- $depr = C('PATH_MODEL')==2?C('PATH_DEPR'):'/';
- if(!empty($route)) {
- $url = str_replace(APP_NAME,$app,__APP__).'/'.$route.$depr.implode($depr,$params);
- }else{
- $str = $depr;
- foreach ($params as $var=>$val)
- $str .= $var.$depr.$val.$depr;
- $url = str_replace(APP_NAME,$app,__APP__).'/'.$module.$depr.$action.substr($str,0,-1);
- }
- if(C('HTML_URL_SUFFIX')) {
- $url .= C('HTML_URL_SUFFIX');
- }
- }else{
- $params = http_build_query($params);
- if(!empty($route)) {
- $url = str_replace(APP_NAME,$app,__APP__).'?'.C('VAR_ROUTER').'='.$route.'&'.$params;
- }else{
- $url = str_replace(APP_NAME,$app,__APP__).'?'.C('VAR_MODULE').'='.$module.'&'.C('VAR_ACTION').'='.$action.'&'.$params;
- }
- }
- return $url;
- }
-
- /**
- +----------------------------------------------------------
- * ?????? Log::record ???????
- +----------------------------------------------------------
- * @param string $msg ????
- +----------------------------------------------------------
- * @return void
- +----------------------------------------------------------
- */
- function system_out($msg)
- {
- if(!empty($msg))
- Log::record($msg,Log::DEBUG);
- }
-
-
- /**
- +----------------------------------------------------------
- * ?????????
- +----------------------------------------------------------
- * @param mixed $object ????
- * @param mixed $className ???
- +----------------------------------------------------------
- * @return boolean
- +----------------------------------------------------------
- */
- function is_instance_of($object, $className)
- {
- if (!is_object($object) && !is_string($object)) {
- return false;
- }
- return $object instanceof $className;
- }
-
- /**
- +----------------------------------------------------------
- * ???????????????
- +----------------------------------------------------------
- * @static
- * @access public
- +----------------------------------------------------------
- * @param string $str ????????
- * @param string $start ????
- * @param string $length ????
- * @param string $charset ????
- * @param string $suffix ??????
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- */
- function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
- {
- if($suffix)
- $suffixStr = "
";
- else
- $suffixStr = "";
-
- if(function_exists("mb_substr"))
- return mb_substr($str, $start, $length, $charset).$suffixStr;
- elseif(function_exists('iconv_substr')) {
- return iconv_substr($str,$start,$length,$charset).$suffixStr;
- }
- $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
- $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
- $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
- $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
- preg_match_all($re[$charset], $str, $match);
- $slice = join("",array_slice($match[0], $start, $length));
- return $slice.$suffixStr;
- }
-
- /**
- +----------------------------------------------------------
- * ???????????????? ????6? ???????
- +----------------------------------------------------------
- * @param string $len ??
- * @param string $type ????
- * 0 ?? 1 ?? ?? ??
- * @param string $addChars ????
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- */
- function rand_string($len=6,$type='',$addChars='') {
- $str ='';
- switch($type) {
- case 0:
- $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars;
- break;
- case 1:
- $chars= str_repeat('0123456789',3);
- break;
- case 2:
- $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars;
- break;
- case 3:
- $chars='abcdefghijklmnopqrstuvwxyz'.$addChars;
- break;
- default :
- // ????????????oOLl???01???????addChars??
- $chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
- break;
- }
- if($len>10 ) {//?????????????
- $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5);
- }
- if($type!=4) {
- $chars = str_shuffle($chars);
- $str = substr($chars,0,$len);
- }else{
- // ?????
- for($i=0;$i<$len;$i++){
- $str.= msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1);
- }
- }
- return $str;
- }
-
- /**
- +----------------------------------------------------------
- * ??????? ???4???
- +----------------------------------------------------------
- * @param string $fmode ???
- +----------------------------------------------------------
- * @return string
- +----------------------------------------------------------
- */
- function build_verify ($length=4,$mode=1) {
- return rand_string($length,$mode);
- }
-
- /**
- +----------------------------------------------------------
- * stripslashes?? ?????
- +----------------------------------------------------------
- * @param mixed $value ??
- +----------------------------------------------------------
- * @return mixed
- +----------------------------------------------------------
- */
- if(!function_exists('stripslashes_deep')) {
- function stripslashes_deep($value) {
- $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
- return $value;
- }
- }
-
-
- // ??????????
- function I($class,$baseUrl = '',$ext='.class.php') {
- static $_class = array();
- if(isset($_class[$baseUrl.$class])) {
- return $_class[$baseUrl.$class];
- }
- $class_strut = explode(".",$class);
- $className = array_pop($class_strut);
- if($className != '*') {
- import($class,$baseUrl,$ext,false);
- if(class_exists($className)) {
- $_class[$baseUrl.$class] = new $className();
- return $_class[$baseUrl.$class];
- }else{
- return false;
- }
- }else {
- return false;
- }
- }
-
-
- // ??????
- function clearCache($type=0,$path=NULL) {
- if(is_null($path)) {
- switch($type) {
- case 0:// ??????
- $path = CACHE_PATH;
- break;
- case 1:// ??????
- $path = TEMP_PATH;
- break;
- case 2:// ????
- $path = LOG_PATH;
- break;
- case 3:// ????
- $path = DATA_PATH;
- }
- }
- import("ORG.Io.Dir");
- Dir::del($path);
- }
- ?>