PageRenderTime 39ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/sop/2.0beta1/ThinkPHP/Mode/Compat/compat.php

http://iiccms.googlecode.com/
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
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // $Id$
  12. define('WEB_LOG_ERROR',0);
  13. define('WEB_LOG_DEBUG',1);
  14. define('SQL_LOG_DEBUG',2);
  15. define('SYSTEM_LOG',0);
  16. define('MAIL_LOG',1);
  17. define('TCP_LOG',2);
  18. define('FILE_LOG',3);
  19. define('DATA_TYPE_OBJ',1);
  20. define('DATA_TYPE_ARRAY',0);
  21. function get_client_ip(){
  22. if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
  23. $ip = getenv("HTTP_CLIENT_IP");
  24. else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
  25. $ip = getenv("HTTP_X_FORWARDED_FOR");
  26. else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
  27. $ip = getenv("REMOTE_ADDR");
  28. else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
  29. $ip = $_SERVER['REMOTE_ADDR'];
  30. else
  31. $ip = "unknown";
  32. return($ip);
  33. }
  34. /**
  35. +----------------------------------------------------------
  36. * URL?? ?????????
  37. +----------------------------------------------------------
  38. * @param string $action ???
  39. * @param string $module ???
  40. * @param string $app ???
  41. * @param string $route ???
  42. * @param array $params ??URL??
  43. +----------------------------------------------------------
  44. * @return string
  45. +----------------------------------------------------------
  46. */
  47. function url($action=ACTION_NAME,$module=MODULE_NAME,$route='',$app=APP_NAME,$params=array()) {
  48. if(C('DISPATCH_ON') && C('URL_MODEL')>0) {
  49. $depr = C('PATH_MODEL')==2?C('PATH_DEPR'):'/';
  50. if(!empty($route)) {
  51. $url = str_replace(APP_NAME,$app,__APP__).'/'.$route.$depr.implode($depr,$params);
  52. }else{
  53. $str = $depr;
  54. foreach ($params as $var=>$val)
  55. $str .= $var.$depr.$val.$depr;
  56. $url = str_replace(APP_NAME,$app,__APP__).'/'.$module.$depr.$action.substr($str,0,-1);
  57. }
  58. if(C('HTML_URL_SUFFIX')) {
  59. $url .= C('HTML_URL_SUFFIX');
  60. }
  61. }else{
  62. $params = http_build_query($params);
  63. if(!empty($route)) {
  64. $url = str_replace(APP_NAME,$app,__APP__).'?'.C('VAR_ROUTER').'='.$route.'&'.$params;
  65. }else{
  66. $url = str_replace(APP_NAME,$app,__APP__).'?'.C('VAR_MODULE').'='.$module.'&'.C('VAR_ACTION').'='.$action.'&'.$params;
  67. }
  68. }
  69. return $url;
  70. }
  71. /**
  72. +----------------------------------------------------------
  73. * ?????? Log::record ???????
  74. +----------------------------------------------------------
  75. * @param string $msg ????
  76. +----------------------------------------------------------
  77. * @return void
  78. +----------------------------------------------------------
  79. */
  80. function system_out($msg)
  81. {
  82. if(!empty($msg))
  83. Log::record($msg,Log::DEBUG);
  84. }
  85. /**
  86. +----------------------------------------------------------
  87. * ?????????
  88. +----------------------------------------------------------
  89. * @param mixed $object ????
  90. * @param mixed $className ???
  91. +----------------------------------------------------------
  92. * @return boolean
  93. +----------------------------------------------------------
  94. */
  95. function is_instance_of($object, $className)
  96. {
  97. if (!is_object($object) && !is_string($object)) {
  98. return false;
  99. }
  100. return $object instanceof $className;
  101. }
  102. /**
  103. +----------------------------------------------------------
  104. * ???????????????
  105. +----------------------------------------------------------
  106. * @static
  107. * @access public
  108. +----------------------------------------------------------
  109. * @param string $str ????????
  110. * @param string $start ????
  111. * @param string $length ????
  112. * @param string $charset ????
  113. * @param string $suffix ??????
  114. +----------------------------------------------------------
  115. * @return string
  116. +----------------------------------------------------------
  117. */
  118. function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
  119. {
  120. if($suffix)
  121. $suffixStr = "…";
  122. else
  123. $suffixStr = "";
  124. if(function_exists("mb_substr"))
  125. return mb_substr($str, $start, $length, $charset).$suffixStr;
  126. elseif(function_exists('iconv_substr')) {
  127. return iconv_substr($str,$start,$length,$charset).$suffixStr;
  128. }
  129. $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
  130. $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
  131. $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
  132. $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
  133. preg_match_all($re[$charset], $str, $match);
  134. $slice = join("",array_slice($match[0], $start, $length));
  135. return $slice.$suffixStr;
  136. }
  137. /**
  138. +----------------------------------------------------------
  139. * ???????????????? ????6? ???????
  140. +----------------------------------------------------------
  141. * @param string $len ??
  142. * @param string $type ????
  143. * 0 ?? 1 ?? ?? ??
  144. * @param string $addChars ????
  145. +----------------------------------------------------------
  146. * @return string
  147. +----------------------------------------------------------
  148. */
  149. function rand_string($len=6,$type='',$addChars='') {
  150. $str ='';
  151. switch($type) {
  152. case 0:
  153. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars;
  154. break;
  155. case 1:
  156. $chars= str_repeat('0123456789',3);
  157. break;
  158. case 2:
  159. $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars;
  160. break;
  161. case 3:
  162. $chars='abcdefghijklmnopqrstuvwxyz'.$addChars;
  163. break;
  164. default :
  165. // ????????????oOLl???01???????addChars??
  166. $chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars;
  167. break;
  168. }
  169. if($len>10 ) {//?????????????
  170. $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5);
  171. }
  172. if($type!=4) {
  173. $chars = str_shuffle($chars);
  174. $str = substr($chars,0,$len);
  175. }else{
  176. // ?????
  177. for($i=0;$i<$len;$i++){
  178. $str.= msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1);
  179. }
  180. }
  181. return $str;
  182. }
  183. /**
  184. +----------------------------------------------------------
  185. * ??????? ???4???
  186. +----------------------------------------------------------
  187. * @param string $fmode ???
  188. +----------------------------------------------------------
  189. * @return string
  190. +----------------------------------------------------------
  191. */
  192. function build_verify ($length=4,$mode=1) {
  193. return rand_string($length,$mode);
  194. }
  195. /**
  196. +----------------------------------------------------------
  197. * stripslashes?? ?????
  198. +----------------------------------------------------------
  199. * @param mixed $value ??
  200. +----------------------------------------------------------
  201. * @return mixed
  202. +----------------------------------------------------------
  203. */
  204. if(!function_exists('stripslashes_deep')) {
  205. function stripslashes_deep($value) {
  206. $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
  207. return $value;
  208. }
  209. }
  210. // ??????????
  211. function I($class,$baseUrl = '',$ext='.class.php') {
  212. static $_class = array();
  213. if(isset($_class[$baseUrl.$class])) {
  214. return $_class[$baseUrl.$class];
  215. }
  216. $class_strut = explode(".",$class);
  217. $className = array_pop($class_strut);
  218. if($className != '*') {
  219. import($class,$baseUrl,$ext,false);
  220. if(class_exists($className)) {
  221. $_class[$baseUrl.$class] = new $className();
  222. return $_class[$baseUrl.$class];
  223. }else{
  224. return false;
  225. }
  226. }else {
  227. return false;
  228. }
  229. }
  230. // ??????
  231. function clearCache($type=0,$path=NULL) {
  232. if(is_null($path)) {
  233. switch($type) {
  234. case 0:// ??????
  235. $path = CACHE_PATH;
  236. break;
  237. case 1:// ??????
  238. $path = TEMP_PATH;
  239. break;
  240. case 2:// ????
  241. $path = LOG_PATH;
  242. break;
  243. case 3:// ????
  244. $path = DATA_PATH;
  245. }
  246. }
  247. import("ORG.Io.Dir");
  248. Dir::del($path);
  249. }
  250. ?>