rockClass.php 18 KB

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