rockClass.php 18 KB

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