rockClass.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <?php
  2. /**
  3. *****************************************************************
  4. * 联系QQ: 290802026 *
  5. * 版 本: V2.0 *
  6. * 开发者:雨中磐石(rainrock) *
  7. * 邮 箱: admin@rockoa.com *
  8. * 说 明: 基础操作类方法 *
  9. * 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
  10. *****************************************************************
  11. */
  12. final class rockClass
  13. {
  14. public $ip;
  15. public $host;
  16. public $url;
  17. public $win;
  18. public $web;
  19. public $unarr;
  20. public $now;
  21. public $date;
  22. public $jm;
  23. public $adminid;
  24. public $adminuser;
  25. public $adminname;
  26. public $HTTPweb,$isqywx,$lvlaras,$lvlaraa,$lvlarab;
  27. public function __construct()
  28. {
  29. $this->ip = $this->getclientip();
  30. $this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '' ;
  31. if($this->host && substr($this->host,-3)==':80')$this->host = str_replace(':80', '', $this->host);
  32. $this->url = '';
  33. $this->isqywx = false;
  34. $this->win = php_uname();
  35. $this->HTTPweb = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : '' ;
  36. $this->web = $this->getbrowser();
  37. $this->unarr = explode(',','1,2');
  38. $this->now = $this->now();
  39. $this->date = date('Y-m-d');
  40. $this->lvlaras = explode(',','select ,
  41. alter table,delete ,drop ,update ,insert into,load_file,/*,*/,union,<script,</script,sleep(,outfile,eval(,user(,phpinfo(),select*,union%20,sleep%20,select%20,delete%20,drop%20,and%20');
  42. $this->lvlaraa = explode(',','select,alter,delete,drop,update,/*,*/,insert,from,time_so_sec,convert,from_unixtime,unix_timestamp,curtime,time_format,union,concat,information_schema,group_concat,length,load_file,outfile,database,system_user,current_user,user(),found_rows,declare,master,exec,(),select*from,select*');
  43. $this->lvlarab = array();
  44. foreach($this->lvlaraa as $_i)$this->lvlarab[]='';
  45. }
  46. /**
  47. * 特殊字符过滤
  48. */
  49. public function xssrepstr($str)
  50. {
  51. $xpd = explode(',','(,), , ,<,>,\\,*,&,%,$,^,[,],{,},!,@,#,",+,?,;\'');
  52. $xpd[]= "\n";
  53. return str_ireplace($xpd, '', $str);
  54. }
  55. /*
  56. * 获取IP
  57. */
  58. public function getclientip()
  59. {
  60. $ip = '';
  61. $trusta = array(
  62. 'HTTP_CF_CONNECTING_IP', // Cloudflare
  63. 'HTTP_ALI_CDN_REAL_IP', // 阿里云
  64. 'HTTP_X_REAL_IP', // 腾讯云/nginx
  65. 'HTTP_X_TRUE_IP', // 宝塔/反向代理
  66. 'HTTP_CLIENT_IP', // 百度/360
  67. 'HTTP_X_FORWARDED_FOR',
  68. 'REMOTE_ADDR'
  69. );
  70. foreach($trusta as $k)if(isset($_SERVER[$k])){
  71. $ip = $_SERVER[$k];
  72. break;
  73. }
  74. //可能是ipv6
  75. if($ip && !is_numeric(str_replace('.','', $ip))){
  76. $ip = str_replace(':','.', $ip);
  77. $sip = preg_replace("/[a-zA-Z0-9.]/",'', $ip);
  78. if($sip)$ip = '';
  79. if($ip){$ipar = explode('.', $ip);foreach($ipar as $ip1)if(strlen($ip1)>4)$ip='';}
  80. if(strlen($ip)>40)$ip='';
  81. }
  82. if(!$ip)$ip = 'unknow';
  83. return $ip;
  84. }
  85. public function initRock()
  86. {
  87. $this->jm = c('jm', true);
  88. $this->adminid = (int)$this->session('adminid',0);
  89. $this->adminname= $this->session('adminname');
  90. $this->adminuser= $this->session('adminuser');
  91. $apptheme = $this->get('apptheme');
  92. if(strlen($apptheme)==6)$this->savecookie('apptheme', $apptheme);
  93. if(!$apptheme)$apptheme = $this->cookie('apptheme');
  94. if(strlen($apptheme)==6)$GLOBALS['config']['apptheme']='#'.$apptheme.'';
  95. }
  96. public function iconvsql($str,$lx=0)
  97. {
  98. $str = str_ireplace($this->lvlaraa,$this->lvlarab,$str);
  99. $str = str_replace("\n",'', $str);
  100. if($lx==1)$str = str_replace(array(' ',' ',' '),array('','',''),$str);
  101. return $str;
  102. }
  103. private function unstr($str)
  104. {
  105. $ystr = '';
  106. for($i=0;$i<count($this->unarr);$i++){
  107. if($this->contain($str,$this->unarr[$i])){
  108. $ystr = $this->unarr[$i];
  109. break;
  110. }
  111. }
  112. return $ystr;
  113. }
  114. public function get($name,$dev='', $lx=0)
  115. {
  116. $val=$dev;
  117. if(isset($_GET[$name]))$val=$_GET[$name];
  118. if($this->isempt($val))$val=$dev;
  119. return $this->jmuncode($val, $lx, $name);
  120. }
  121. public function post($name,$dev='', $lx=0)
  122. {
  123. $val = '';
  124. if(isset($_POST[$name])){$val=$_POST[$name];}else{if(isset($_GET[$name]))$val=$_GET[$name];}
  125. if($this->isempt($val))$val=$dev;
  126. return $this->jmuncode($val, $lx, $name);
  127. }
  128. public function request($name,$dev='', $lx=0)
  129. {
  130. return $this->post($name,$dev,$lx);
  131. }
  132. //get和post参数处理$lx=1:rockjm,6:basejm, 3:判断是否rockjm
  133. public function jmuncode($s, $lx=0, $na='')
  134. {
  135. $jmbo = false;$s = (string)$s;
  136. if($lx==3)$jmbo = $this->isjm($s);
  137. if(substr($s, 0, 7)=='rockjm_' || $lx == 1 || $jmbo){
  138. $s = str_replace('rockjm_', '', $s);
  139. $s = $this->jm->uncrypt($s);
  140. if($lx==1){
  141. $jmbo = $this->isjm($s);
  142. if($jmbo)$s = $this->jm->uncrypt($s);
  143. }
  144. }
  145. if(substr($s, 0, 7)=='basejm_' || $lx==5){
  146. $s = str_replace('basejm_', '', $s);
  147. $s = $this->jm->base64decode($s);
  148. }
  149. $s=str_replace("'", '&#39', $s);
  150. $s=str_replace('%20', '', $s);
  151. if($lx==2)$s=str_replace(array('{','}'), array('[H1]','[H2]'), $s);
  152. $str = strtolower($s);
  153. foreach($this->lvlaras as $v1)if($this->contain($str, $v1)){
  154. $this->debug(''.$na.'《'.$s.'》error:包含非法字符《'.$v1.'》','params_err');
  155. $s = $this->lvlarrep($str, $v1);
  156. $str = $s;
  157. }
  158. $cslv = array('m','a','p','d','ip','web','host','ajaxbool','token','adminid');
  159. if(in_array($na, $cslv))$s = $this->xssrepstr($s);
  160. return $this->reteistrs($s);
  161. }
  162. //参数里面禁用/*,*/
  163. private function reteistrs($s){
  164. $lvlaras = array('/*','*/');
  165. $bo = false;
  166. foreach($lvlaras as $v1)if($this->contain($s, $v1)){
  167. $s = str_replace($v1,'', $s);
  168. $bo = true;
  169. }
  170. if($bo)$s = $this->reteistrs($s);
  171. return $s;
  172. }
  173. private function lvlarrep($str, $v1){
  174. $s = str_ireplace($v1,'', $str);
  175. if(contain($s, $v1))$s = $this->lvlarrep($s, $v1);
  176. return $s;
  177. }
  178. public function debug($txt, $lx, $dabo=false)
  179. {
  180. if(!DEBUG && !$dabo)return;
  181. $txt = ''.$txt.''.chr(10).'[URL]'.chr(10).''.$this->nowurl().'';
  182. if($_POST){
  183. $pstr = '';
  184. foreach($_POST as $k=>$v)$pstr.=''.chr(10).'['.$k.']:'.$v.'';
  185. $txt.=''.chr(10).''.chr(10).'[POST]'.$pstr.'';
  186. }
  187. $txt.=''.chr(10).''.chr(10).'[IP]'.chr(10).''.$this->ip.'';
  188. $txt.=''.chr(10).''.chr(10).'[datetime]'.chr(10).''.$this->now().'';
  189. $txt.=''.chr(10).''.chr(10).'[Browser]'.chr(10).''.$this->HTTPweb.'';
  190. if(contain(HOST,'rockoa.com') && getconfig('systype') != 'demo')
  191. foreach($_SERVER as $k=>$v)$txt.=''.chr(10).''.chr(10).'['.$k.']'.chr(10).''.$v.'';
  192. $file = ''.UPDIR.'/logs/'.date('Y-m').'/'.$lx.''.date('YmdHis').'_'.str_shuffle('abcdefghijklmn').'.txt';
  193. $this->createtxt($file, $txt);
  194. return $file;
  195. }
  196. /**
  197. * 是否加密的字符串
  198. */
  199. public function isjm($s)
  200. {
  201. $bo = false;
  202. if(!$s)return $bo;
  203. $bo = preg_match("/^([a-z]{2,3})0([a-z]{2,3})0([a-z]{2,3})0([a-z0])*([1-9]{1,2})$/", $s);
  204. return $bo;
  205. $a = explode('0', $s);
  206. $len= count($a);
  207. if($len>1){
  208. $ls=(int)$a[$len-1];
  209. if($ls>=1&&$ls<=14)$bo=true;
  210. }
  211. return $bo;
  212. }
  213. public function savesession($arr)
  214. {
  215. foreach($arr as $kv=>$vv)$this->setsession($kv,$vv);
  216. }
  217. public function setsession($kv,$vv)
  218. {
  219. $_SESSION[QOM.$kv]=$vv;
  220. }
  221. public function session($name,$dev='')
  222. {
  223. $val = '';
  224. $name = QOM.$name;
  225. if(isset($_SESSION[$name]))$val=$_SESSION[$name];
  226. if($this->isempt($val))$val=$dev;
  227. return $val;
  228. }
  229. public function clearsession($name)
  230. {
  231. $arrn=explode(',',$name);
  232. for($i=0;$i<count($arrn);$i++){
  233. @$_SESSION[QOM.$arrn[$i]]='';
  234. }
  235. }
  236. public function clearallsession()
  237. {
  238. foreach($_SESSION as $key=>$value){
  239. $this->clearsession($key);
  240. }
  241. }
  242. //保存cookie,默认是7天
  243. public function savecookie($namarr,$valarr,$expire=360,$path='/',$domain='')
  244. {
  245. $time = time()+$expire*3600*24;
  246. $arrn = explode(',',$namarr);
  247. $valn = $valarr;
  248. if(!is_array($valarr))$valn=explode(',',$valarr);
  249. for($i=0;$i<count($arrn);$i++){
  250. @setcookie(QOM.$arrn[$i],$valn[$i], $time, $path,'');
  251. }
  252. }
  253. //获取cookie
  254. public function cookie($name,$dev='')
  255. {
  256. $val = '';
  257. $name = QOM.$name;
  258. if(isset($_COOKIE[$name]))$val=$_COOKIE[$name];
  259. if($this->isempt($val))$val=$dev;
  260. return $val;
  261. }
  262. public function getcookie($namarr)
  263. {
  264. $arrn=explode(',',$namarr);
  265. for($i=0;$i<count($arrn);$i++){
  266. $val[$arrn[$i]]=$this->cookie($arrn[$i]);
  267. }
  268. return $val;
  269. }
  270. //删除cookie
  271. public function clearcookie($name,$path='/',$domain='')
  272. {
  273. //$domain=(empty($domain))?$this->host:$domain;
  274. $arr=explode(',',$name);
  275. for($i=0;$i<count($arr);$i++){
  276. setcookie(QOM.$arr[$i],'',time()-1,$path,$domain);
  277. @$_COOKIE[$arr[$i]]='';
  278. }
  279. }
  280. //删除所有cookie
  281. public function clearallcookie()
  282. {
  283. foreach($_COOKIE as $key=>$value){
  284. $this->clearcookie($key);
  285. }
  286. }
  287. //跳转
  288. public function location($url)
  289. {
  290. header('location:'.$url.'');
  291. exit;
  292. }
  293. public function now($type='Y-m-d H:i:s',$kmti='')
  294. {
  295. if($kmti=='')$kmti=time();
  296. return date($type,$kmti);
  297. }
  298. public function cnweek($date)
  299. {
  300. $arr = array('日','一','二','三','四','五','六');
  301. return $arr[date('w', strtotime($date))];
  302. }
  303. /**
  304. * 判断类型0微信,1钉钉,2安卓原生app,3企业微信,4华为welink,5苹果,6QQ,7REIM平台
  305. */
  306. public function iswebbro($lx=0)
  307. {
  308. $lxar = array('micromessenger','dingtalk','xinhuapp','wxwork','huawei-anyoffice','iphone','mqqbrowser','reimplat');
  309. return contain(strtolower($this->HTTPweb), $lxar[$lx]);
  310. }
  311. public function getbrowser()
  312. {
  313. $web = $this->HTTPweb;
  314. $val = 'IE';
  315. $parr = array(
  316. array('MSIE 5'),array('MSIE 6'),array('XIAOMI','xiaomi'),array('HUAWEI','huawei'),array('XINHUAPP','xinhu'),array('DingTalk','ding'),array('MSIE 7'),array('MSIE 8'),array('MSIE 9'),array('MSIE 10'),array('MSIE 11'),array('rv:11','MSIE 11'),array('MSIE 12'),array('HuaWei-AnyOffice','welink'),array('MicroMessenger','wxbro'),
  317. array('MSIE 13'),array('Firefox'),array('OPR/','Opera'),array('Edge'),array('MQQBrowser','mqq'),array('Chrome'),array('Safari'),array('Android'),array('iPhone')
  318. );
  319. foreach($parr as $wp){
  320. if(contain($web, $wp[0])){
  321. $val = $wp[0];
  322. if(isset($wp[1]))$val = $wp[1];
  323. break;
  324. }
  325. }
  326. $web = strtolower($web);
  327. if(contain($web,'micromessenger'))$val='wxbro';//微信浏览器
  328. if(contain($web,'dingtalk'))$val='ding';//钉钉浏览器
  329. if($val=='wxbro' && contain($web, 'wxwork'))$this->isqywx = true;
  330. return $val;
  331. }
  332. public function ismobile()
  333. {
  334. $web = strtolower($this->HTTPweb);
  335. $bo = false;
  336. $strar = explode(',','micromessenger,android,mobile,iphone');
  337. foreach($strar as $str){
  338. if(contain($web, $str))return true;
  339. }
  340. return $bo;
  341. }
  342. public function script($daima)
  343. {
  344. echo '<script type="text/javascript">
  345. '.$daima.'
  346. </script>';
  347. }
  348. /**
  349. 全角半角转换
  350. */
  351. public function replace($str,$quantoban=true)
  352. {
  353. $search=array('0','1','2','3','4','5','6','7','8','9',',','.','?','\'','(',')',';','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  354. $replace=array('0','1','2','3','4','5','6','7','8','9',',','。','?','’','(',')',';','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','Z','Y','Z');
  355. if($quantoban){
  356. $str=str_replace($replace,$search,$str);
  357. }else{
  358. $str=str_replace($search,$replace,$str);
  359. }
  360. return $str;
  361. }
  362. /**
  363. 过滤特殊符合
  364. */
  365. public function repmark($str)
  366. {
  367. $search=array('select','delete','join','inner','outer');
  368. $str=strtolower($str);//转为小写
  369. $str=str_replace($search,'',$str);
  370. return $str;
  371. }
  372. /**
  373. html编码
  374. */
  375. public function htmlescape($str)
  376. {
  377. $str = htmlspecialchars($str);
  378. return $str;
  379. }
  380. /**
  381. 小数点位数
  382. */
  383. public function number($num,$w=2)
  384. {
  385. if(!$num)$num='0';
  386. return number_format($num,$w,'.','');
  387. }
  388. /**
  389. 是否包含返回bool
  390. */
  391. public function contain($str,$a)
  392. {
  393. $bool=false;
  394. if(!$this->isempt($a) && !$this->isempt($str)){
  395. $ad=strpos($str,$a);
  396. if($ad>0||!is_bool($ad))$bool=true;
  397. }
  398. return $bool;
  399. }
  400. /**
  401. 将&#39;转换'
  402. */
  403. public function covexec($str)
  404. {
  405. $dt = date('Y-m-d');
  406. $str = str_replace(
  407. array('&#39;', '&#39','[F]', '[X]', '[K]', '[A]', '[D]', '[adminid]', '[date]', '{adminid}', '{date}','[H1]','[H2]','&#xing;'),
  408. array('\'', '\'', '\'', '\\', ' ', 'and', '=', $this->adminid, $dt, $this->adminid, $dt,'{','}','*'),
  409. $str
  410. );
  411. return $str;
  412. }
  413. //判断是否为空
  414. public function isempt($str)
  415. {
  416. $bool=false;
  417. if( ($str==''||$str==NULL||empty($str)) && (!is_numeric($str)) )$bool=true;
  418. return $bool;
  419. }
  420. /**
  421. 地址
  422. */
  423. public function rewrite($m,$a,$s)
  424. {
  425. $url = '';
  426. if(REWRITE=='true'){
  427. $url = ''.$m.'';
  428. if($a == '' && $s == ''){
  429. $url = ''.$url.'.html';
  430. }elseif($a == ''){
  431. $url = ''.$url.'_'.$s.'.html';
  432. }else{
  433. $url = ''.$url.'_'.$a.'_'.$s.'_a.html';
  434. }
  435. }else{
  436. $url = 'index.php?m='.$m.'';
  437. if($a != '')$url.='&a='.$a.'';
  438. if($s != '')$url.='&s='.$s.'';
  439. }
  440. return $url;
  441. }
  442. //设置所有的GET方法
  443. public function setallcan($rep=4)
  444. {
  445. foreach($_GET as $key=>$val)$GLOBALS['get_'.$key]=$this->get($key,'',0);
  446. foreach($_POST as $key=>$val)$GLOBALS['post_'.$key]=$this->post($key,'',0);
  447. }
  448. /**
  449. 如果字符为空,使用默认的
  450. */
  451. public function repempt($str,$dev='')
  452. {
  453. $s = $str;
  454. if($this->isempt($s))$s=$dev;
  455. return $s;
  456. }
  457. //返回文件大小
  458. public function formatsize($size)
  459. {
  460. $arr = array('Byte', 'KB', 'MB', 'GB', 'TB', 'PB');
  461. if($size == 0)return '0';
  462. $e = floor(log($size)/log(1024));
  463. return number_format(($size/pow(1024,floor($e))),2,'.','').' '.$arr[$e];
  464. }
  465. /**
  466. 采集字符串截取
  467. */
  468. public function getcai($content,$start,$end)
  469. {
  470. $geju = strpos($content,$start);
  471. if($geju===false){
  472. $cont1='';
  473. }else{
  474. $stard = $geju+strlen($start);
  475. $cont1 = substr($content,$stard);
  476. $endd = strpos($cont1,$end);
  477. $cont1 = substr($cont1,0,$endd);
  478. $cont1 = trim($cont1);
  479. }
  480. return $cont1;
  481. }
  482. /**
  483. * 写入文件
  484. */
  485. public function createtxt($path, $txt)
  486. {
  487. $this->createdir($path);
  488. $path = ''.ROOT_PATH.'/'.$path.'';
  489. @$file = fopen($path,'w');
  490. $bo = false;
  491. if($file){
  492. $bo = true;
  493. if($txt)$bo = fwrite($file,$txt);
  494. fclose($file);
  495. }
  496. return $bo;
  497. }
  498. /**
  499. * 创建文件夹
  500. */
  501. public function createdir($path, $oi=1)
  502. {
  503. $zpath = explode('/', $path);
  504. $len = count($zpath);
  505. $mkdir = '';
  506. for($i=0; $i<$len-$oi; $i++){
  507. if(!isempt($zpath[$i])){
  508. $mkdir.='/'.$zpath[$i].'';
  509. $wzdir = ROOT_PATH.''.$mkdir;
  510. if(!is_dir($wzdir)){
  511. mkdir($wzdir);
  512. }
  513. }
  514. }
  515. }
  516. public function stringformat($str, $arr=array())
  517. {
  518. $s = $str;
  519. for($i=0; $i<count($arr); $i++){
  520. $s=str_replace('?'.$i.'', $arr[$i], $s);
  521. }
  522. return $s;
  523. }
  524. public function strformat($str)
  525. {
  526. $len = func_num_args();
  527. $arr = array();
  528. for($i=1; $i<$len; $i++)$arr[] = func_get_arg($i);
  529. $s = $this->stringformat($str, $arr);
  530. return $s;
  531. }
  532. public function T($n)
  533. {
  534. return PREFIX.''.$n;
  535. }
  536. public function reparr($str, $arr=array())
  537. {
  538. if($this->isempt($str))return '';
  539. preg_match_all('/\{(.*?)\}/', $str, $list);
  540. $s = $str;
  541. foreach($list[1] as $k=>$nrs){
  542. $nts = '';
  543. if(isset($arr[$nrs]))$nts = $arr[$nrs];
  544. $s = str_replace('{'.$nrs.'}', $nts, $s);
  545. }
  546. return $s;
  547. }
  548. /**
  549. 字段中包含
  550. */
  551. public function dbinstr($fiekd, $str, $spl1=',', $spl2=',')
  552. {
  553. return "instr(concat('$spl1', $fiekd, '$spl2'), '".$spl1.$str.$spl2."')>0";
  554. }
  555. public function debugs($str, $lxs='')
  556. {
  557. if(!DEBUG)return;
  558. if(is_array($str))$str = json_encode($str, JSON_UNESCAPED_UNICODE);
  559. $msg = '['.$this->now.']:'.$this->nowurl().''.chr(10).''.$str.'';
  560. $mkdir = ''.UPDIR.'/logs/'.date('Y-m').'';
  561. $this->createtxt(''.$mkdir.'/'.$lxs.''.date('Y-m-d.H.i.s').'_'.str_shuffle('abcdefghijklmn').'.log', $msg);
  562. }
  563. public function arrvalue($arr, $k, $dev='')
  564. {
  565. $val = $dev;
  566. if(isset($arr[$k]))$val= $arr[$k];
  567. return $val;
  568. }
  569. /*
  570. * 获取当前访问全部url
  571. */
  572. public function nowurl()
  573. {
  574. if(!isset($_SERVER['HTTP_HOST']))return '';
  575. $qz = 'http';
  576. if($_SERVER['SERVER_PORT']==443)$qz='https';
  577. $url = ''.$qz.'://'.$_SERVER['HTTP_HOST'];
  578. if(isset($_SERVER['REQUEST_URI']))$url.= $_SERVER['REQUEST_URI'];
  579. return $url;
  580. }
  581. /**
  582. * 获取当前访问URL地址
  583. */
  584. public function url()
  585. {
  586. $url = $this->nowurl();
  587. $wz = strrpos($url,'/');
  588. return substr($url,0, $wz+1);
  589. }
  590. /**
  591. * 匹配
  592. */
  593. public function matcharr($str, $lx=0)
  594. {
  595. $match = '/\{(.*?)\}/';
  596. if($lx==1)$match = '/\[(.*?)\]/';
  597. if($lx==2)$match = '/\`(.*?)\`/';
  598. if($lx==3)$match = '/\#(.*?)\#/';
  599. preg_match_all($match, $str, $list);
  600. $barr = array();
  601. foreach($list[1] as $k=>$nrs){
  602. $barr[] = $nrs;
  603. }
  604. return $barr;
  605. }
  606. /**
  607. * 函数参数转为key
  608. */
  609. public function getfunkey($arr=array(),$qz='a')
  610. {
  611. $s = '';
  612. foreach($arr as $k=>$v)$s.='_'.$v.'';
  613. $s = ''.$qz.''.$s.'';
  614. return $s;
  615. }
  616. /**
  617. * 获取外网地址
  618. */
  619. public function getouturl($dz='')
  620. {
  621. if($dz=='')$dz = URL;
  622. $xurl = URL;
  623. $xurl1 = getconfig('outurl');
  624. if(!isempt($xurl1))$xurl = $xurl1;
  625. if(substr($xurl,-1)!='/')$xurl.='/';
  626. return $xurl;
  627. }
  628. /**
  629. * 一个完整绝对路径
  630. */
  631. public function gethttppath($path, $url='', $dev='')
  632. {
  633. if($url=='')$url = URL;
  634. if(isempt($path))return $dev;
  635. if(contain($path, '{FILEURL}')){
  636. $platurl = getconfig('rockfile_url');
  637. if(substr($platurl,-1)!='/')$platurl.='/';
  638. $path = str_replace('{FILEURL}',$platurl,$path);
  639. }
  640. if(substr($path,0,4)!='http')$path = ''.$url.''.$path.'';
  641. return $path;
  642. }
  643. /**
  644. * 根据value获取name
  645. */
  646. public function valtoname($arr, $val, $fid1='',$fid2='')
  647. {
  648. if($fid1=='')$fid1='value';
  649. if($fid2=='')$fid2='name';
  650. $nval = $val;
  651. foreach($arr as $k=>$rs){
  652. if($rs[$fid1]==$val){
  653. $nval = $rs[$fid2];
  654. break;
  655. }
  656. }
  657. return $nval;
  658. }
  659. }
粤ICP备19079148号