PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/kyphp/kycmd/cmd.php

https://github.com/dlimuratdj/kyphp2.0
PHP | 590 lines | 494 code | 65 blank | 31 comment | 53 complexity | d29c22fbe2bf3e6b95b4171659a5e1b3 MD5 | raw file
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // 最便捷的php框架
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.ky53.net All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.ky53.net )
  8. // +----------------------------------------------------------------------
  9. /**
  10. * @author qq:974005652(zhx626@126.com) by老顽童
  11. * @version 1.0
  12. +------------------------------------------------------------------------------
  13. */
  14. function key_hash($str,$m='khash'){
  15. if($m=='khash')$str=substr(md5(md5($str)),0,16).substr(md5($str),16,32);
  16. if($m=='md5')$str=md5($str);
  17. return $str;
  18. }
  19. function _pvolist($name,$nid,$id,$content){
  20. global $volist,$lable,$list;
  21. if($list[$name][$nid]){
  22. foreach($list[$name][$nid] as $key=>$k){
  23. if(!strstr($content,$id.'.')){
  24. $content1.=preg_replace("/[{][$](\w+)[}]/eis",'$k[\\1]',$content);
  25. }else{
  26. //echo $id;
  27. $content1.=preg_replace("/[{][$]$id\.(\w+)[}]/eis",'$k[\\1]',$content);
  28. }
  29. }
  30. }
  31. return $content1;
  32. }
  33. function _if($value1,$condition,$value2,$result){
  34. if($condition=="=="){
  35. if($value1==$value2)return $result;
  36. }
  37. if($condition=="<"){
  38. if($value1<$value2)return $result;
  39. }
  40. if($condition=="<="){
  41. if($value1<=$value2)return $result;
  42. }
  43. if($condition==">"){
  44. if($value1>$value2)return $result;
  45. }
  46. if($condition==">="){
  47. if($value1>=$value2)return $result;
  48. }
  49. }
  50. function _volist($name,$id,$content){
  51. global $volist,$lable,$list,$$id;
  52. $content1='';
  53. foreach($volist[$name] as $key=>$k){
  54. $$id=$k;
  55. $content2=preg_replace("/[{][$](\w+)[}]/eis",'$k[\'\\1\']',$content);
  56. $content1.=preg_replace("/[{][$]$id\.(\w+)[}]/eis",'$k[\'\\1\']',$content2);
  57. }
  58. $content1=preg_replace("/<list\s+name=[\\\][\"|\'|](\w+)\[(.*?)\][\\\][\"|\'|]\s+id=[\\\][\"|\'|](\w+)[\\\][\"|\'|]>(.*?)<\/list>/eis","_pvolist('\\1','\\2','\\3','\\4')",$content1);
  59. $content1=str_replace('\"','"',$content1);
  60. return $content1;
  61. }
  62. function include_file($file){
  63. return require_once($file);
  64. }
  65. function label($key,$key0=''){
  66. global $lable;
  67. if($key0&&isset($lable[$key][$key0]))return $lable[$key][$key0];
  68. if(isset($lable[$key]))return $lable[$key];
  69. }
  70. function make_html($content,$path){
  71. global $lable,$list,$KYPHP,$volist,$datalist;
  72. $templetedir=DEFAULT_TPL_PATH.'/'.DEFAULT_TPL;
  73. $templetedir=str_replace('\\','/',$templetedir);
  74. $content=preg_replace("/<include\s+file=\"(\w+):(\w+)\">/eis",'include_file("'.$templetedir.'/\\1/\\2.htm")',$content);
  75. $content=str_replace('__URL__',__URL__,$content);
  76. $content=str_replace('__ROOT__',__ROOT__,$content);
  77. $content=str_replace('__APP__',__APP__,$content);
  78. if(defined('__WEBURL__'))$content=str_replace('__WEBURL__',__WEBURL__,$content);
  79. $content=str_replace('{$','{--|',$content);
  80. $content=preg_replace("/\{\-\-\|([\w\d\_\-]+)\;\}/eis",'label(\'\\1\')',$content);
  81. $content=str_replace('{--|','{$',$content);
  82. $content=preg_replace("/<lable[ \f\r\t\n]+name=(\"|\'|)(\w+)(\"|\'|)>/eis",'label(\'\\2\')',$content);
  83. $content=preg_replace('/\$lable\[(\"|\'|)(\w+)(\"|\'|)\]\[(\"|\'|)(\w+)(\"|\'|)\]/eis','label(\'\\2\',\'\\5\')',$content);
  84. $content=preg_replace('/\$lable\[(\"|\'|)(\w+)(\"|\'|)\]/eis','label(\'\\2\')',$content);
  85. $content=preg_replace('/\$volist\[(\"|\'|)(\w+)(\"|\'|)\]/eis','$volist[\'\\2\']',$content);
  86. $content=preg_replace("/<volist\s+name=(\"|\'|)(\w+)(\"|\'|)\s+id=(\"|\'|)(\w+)(\"|\'|)>(.*?)<\/volist>/eis","_volist('\\2','\\5','\\7')",$content);
  87. $content=preg_replace("/<if\s+condition=[(](\w+)(==|<|>|>=|<=)(\w+)[)]>(\w+)<\/if>/eis","_if('\\1','\\2','\\3','\\4')",$content);
  88. $content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\')(.*?)(\"|\')\s+manage=(\"|\')(.*?)(\"|\')\s+edit=(\"|\'|)(\w+|)(\"|\'|)\s+title=(\"|\'|)(\w+|)(\"|\'|)\s+page=(\"|\'|)(\w+|)(\"|\'|)\s+table=(\"|\')(.*?)(\"|\')\s+list=(\"|\')(\w+|)(\"|\')(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','\\17','\\20','\\23','\\26','\\29')",$content);
  89. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'edit=')&&strstr($content,'title=')&&strstr($content,'page=')&&strstr($content,'table=')&&!strstr($content,'list='))$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+edit=(\"|\'|)(\w+|)(\"|\'|)\s+title=(\"|\'|)(\w+|)(\"|\'|)\s+page=(\"|\'|)(\w+|)(\"|\'|)\s+table=(\"|\')(.*?)(\"|\')(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','\\17','\\20','\\23','\\26')",$content);
  90. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'edit=')&&strstr($content,'title=')&&strstr($content,'page=')&&!strstr($content,'list=')&&!strstr($content,'table='))$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+edit=(\"|\'|)(\w+|)(\"|\'|)\s+title=(\"|\'|)(\w+|)(\"|\'|)\s+page=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','\\17','\\20','\\23')",$content);
  91. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'edit=')&&strstr($content,'title=')&&!strstr($content,'list=')&&!strstr($content,'page=')&&!strstr($content,'table=')) $content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+edit=(\"|\'|)(\w+|)(\"|\'|)\s+title=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','\\17','\\20')",$content);
  92. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'edit=')&&!strstr($content,'list=')&&!strstr($content,'page=')&&!strstr($content,'table=')&&!strstr($content,'title=')){$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+edit=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','\\17')",$content);}
  93. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'list=')&&!strstr($content,'edit=')&&!strstr($content,'page=')&&!strstr($content,'table=')&&!strstr($content,'title=')){$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+list=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','false','true','false','','\\17')",$content);}
  94. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'table=')&&!strstr($content,'edit=')&&!strstr($content,'page=')&&!strstr($content,'list=')&&!strstr($content,'title=')){$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+table=(\"|\'|)(.*?|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','false','true','false','\\17','table')",$content);}
  95. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'title=')&&!strstr($content,'edit=')&&!strstr($content,'page=')&&!strstr($content,'table=')&&!strstr($content,'list=')){$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+title=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','false','\\17','false','','table')",$content);}
  96. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&strstr($content,'page=')&&!strstr($content,'edit=')&&!strstr($content,'title=')&&!strstr($content,'table=')&&!strstr($content,'list=')){$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)\s+page=(\"|\'|)(\w+|)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14','false','true','\\17','','table')",$content);}
  97. if(strstr($content,'row=')&&strstr($content,'field=')&&strstr($content,'manage=')&&!strstr($content,'list=')&&!strstr($content,'page=')&&!strstr($content,'table=')&&!strstr($content,'title=')&&!strstr($content,'edit='))$content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)\s+manage=(\"|\'|)(.*?)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11','\\14')",$content);
  98. if(strstr($content,'row=')&&strstr($content,'field=')&&!strstr($content,'list=')&&!strstr($content,'page=')&&!strstr($content,'table=')&&!strstr($content,'title=')&&!strstr($content,'edit=')&&!strstr($content,'manage=')) $content=preg_replace("/<datalist\s+name=(\"|\'|)(\w+|)(\"|\'|)\s+id=(\"|\'|)(\w+|)(\"|\'|)\s+row=(\"|\'|)(\w+|)(\"|\'|)\s+field=(\"|\'|)(.*?)(\"|\'|)(\s+|)>/eis","_datalist('\\2','\\5','\\8','\\11')",$content);
  99. if(preg_replace('/<datalist(.*?)>/eis','',$content)!=$content){
  100. global $datafieldname;
  101. if(strstr($content,'name='))preg_replace('/name=(\"|\'|)(\w+|)(\"|\'|)/eis','$name="\\2"',$content);
  102. if(strstr($content,'id='))preg_replace('/id=(\"|\'|)(\w+|)(\"|\'|)/eis','$id="\\2"',$content);
  103. if(strstr($content,'row='))preg_replace('/row=(\"|\'|)(\w+|)(\"|\'|)/eis','$row=\\2',$content);
  104. if(strstr($content,'field=')){//preg_replace('/field=(\"|\')(.*?|)(\"|\')/eis','$field="\\2"',$content);
  105. preg_replace('/field=(\"|\')(.*?|)(\"|\')/eis',"getfieldname('field','\\2')",$content);
  106. $field=$datafieldname['field'];
  107. }
  108. if(strstr($content,'manage=')){preg_replace('/manage=(\"|\')(.*?|)(\"|\')/eis',"getfieldname('manage','\\2')",$content);
  109. $manage=$datafieldname['manage'];
  110. }
  111. if(strstr($content,'edit='))preg_replace('/edit=(\"|\'|)(\w+|)(\"|\'|)/eis','$edit="\\2"',$content);
  112. if(strstr($content,'title='))preg_replace('/title=(\"|\'|)(\w+|)(\"|\'|)/eis','$title="\\2"',$content);
  113. if(strstr($content,'page='))preg_replace('/page=(\"|\'|)(\w+|)(\"|\'|)/eis','$page="\\2"',$content);
  114. if(strstr($content,'table='))preg_replace('/table=(\"|\')(.*?|)(\"|\')/eis','$table="\\2"',$content);
  115. if(strstr($content,'list='))preg_replace('/list=(\"|\')(\w+|)(\"|\')/eis','$islist="\\2"',$content);
  116. $edit=isset($edit)?$edit:'';
  117. $title=isset($title)?$title:'';
  118. $page=isset($page)?$page:'';
  119. $table=isset($table)?$table:'';
  120. $list=isset($list)?$list:'';
  121. $name=isset($name)?$name:'';
  122. $id=isset($id)?$id:'';
  123. $row=isset($row)?$row:'';
  124. $field=isset($field)?$field:'';
  125. $manage=isset($manage)?$manage:'';
  126. $islist=isset($islist)?$islist:'';
  127. $table=isset($table)?$table:'';
  128. $content=preg_replace('/<datalist(.*?)>/eis','_datalist($name,$id,$row,$field,$manage,$edit,$title,$page,$table,$islist)',$content);
  129. $name='';$id='';$row='';$field='';$manage='';$edit='';$title='';$page='';$table='';$islist='';
  130. }
  131. return $content;
  132. }
  133. function getfieldname($name,$str){
  134. global $datafieldname;
  135. $datafieldname[$name]=$str;
  136. return $str;
  137. }
  138. function _datalist($name,$id,$row='',$field,$manage='',$edit='false',$title='true',$page='false',$table='',$islist='table'){
  139. global $datalist;
  140. $fieldarr=explode(',',$field);
  141. $managearr=explode(',',$manage);
  142. $wname='';
  143. $str='<table '.$table.' class='.$name.' id='.$id.'>';
  144. $strli='<ul class='.$name.' id='.$id.'>';
  145. if($title=='true'){
  146. $str.='<tr class=title>';
  147. $strli.='<li class=title>';
  148. foreach($fieldarr as $key=>$kt){
  149. $vpos=strpos($kt,'|');
  150. $vname=substr($kt,0,$vpos);
  151. $tpos=strpos($kt,':');
  152. $wpos=strpos($kt,'%');
  153. if($wpos)$wname=substr($kt,$wpos+1);
  154. $wname=str_replace('=',':',$wname);
  155. if(!$tpos)$tpos=strlen($kt);
  156. $tname=substr($kt,$vpos+1,$tpos-$vpos-1);
  157. if(strstr($tname,'%')) $tname=substr($kt,$vpos+1,$wpos-$vpos-1);
  158. $str.='<td style="'.$wname.'">'.$tname.'</td>';
  159. $strli.='<span style="'.$wname.'">'.$tname.'</span>';
  160. $wname='';
  161. $vname='';
  162. $tname='';
  163. }
  164. if($manage){
  165. foreach($managearr as $key=>$kt){
  166. $vpos=strpos($kt,'|');
  167. $vname=substr($kt,0,$vpos);
  168. $tpos=strpos($kt,':');
  169. $wpos=strpos($kt,'%');
  170. if($wpos)$wname=substr($kt,$wpos+1);
  171. $wname=str_replace('=',':',$wname);
  172. if(!$tpos)$tpos=strlen($kt);
  173. $tname=substr($kt,$vpos+1,$tpos-$vpos-1);
  174. if(strstr($tname,'%')) $tname=substr($kt,$vpos+1,$wpos-$vpos-1);
  175. $str.='<td style="'.$wname.'">'.$tname.'</td>';
  176. $strli.='<span style="'.$wname.'">'.$tname.'</span>';
  177. $wname='';
  178. }
  179. }
  180. $str.='</tr>';
  181. $strli.='</li>';
  182. }
  183. $dataarr=$datalist[$name];
  184. $count=count($dataarr);
  185. if($row&&$row<count($dataarr)&&$row>0){
  186. if($page=='true'){
  187. $pagestr='<div class="page">';
  188. $pa=ceil($count/$row);
  189. $locpa=!empty($_GET['pa'])?$_GET['pa']:'';
  190. if(!$locpa)$locpa=1;
  191. $return=debug_backtrace();
  192. $funame=$return[4]['function'];
  193. $gstr='';
  194. if(!empty($_GET['key']))$gstr='/key/'.$_GET['key'];
  195. if(!empty($_POST['key']))$gstr='/key/'.$_POST['key'];
  196. if($locpa>$pa)$locpa=$pa;
  197. $pagestr='<div class=page>共'.$pa.'页 当前'.$locpa.' 页 <a href='.__URL__.'/'.$funame.'/pa/1'.$gstr.'>首页</a> <a href='.__URL__.'/'.$funame.'/pa/'.($locpa-1).$gstr.'>上一页</a> <a href='.__URL__.'/'.$funame.'/pa/'.($locpa+1).$gstr.'>下一页</a> <a href='.__URL__.'/'.$funame.'/pa/'.$pa.$gstr.'>尾页</a>';
  198. $pagestr.='</div>';
  199. }else{
  200. $locpa=1;
  201. }
  202. unset($dataarr);
  203. $rowend=$row+($locpa-1)*$row;
  204. if($rowend>$count)$rowend=$count;
  205. for($i=($locpa-1)*$row;$i<$rowend;$i++){
  206. $dataarr[]=$datalist[$name][$i];
  207. }
  208. }
  209. foreach($dataarr as $key=>$k){
  210. $str.='<tr>';
  211. $strli.='<li>';
  212. foreach($fieldarr as $key=>$kt){
  213. $vpos=strpos($kt,'|');
  214. $vname=substr($kt,0,$vpos);
  215. $tpos=strpos($kt,':');
  216. $wpos=strpos($kt,'%');
  217. if($wpos)$wname=substr($kt,$wpos+1);
  218. $wname=str_replace('=',':',$wname);
  219. $jname='';
  220. if($tpos)$jname=substr($kt,$tpos+1);
  221. $jname=preg_replace('/[{][$](\w+)[}]/eis','$k[\'\\1\']',$jname);
  222. if(strstr($jname,'%')) $jname=substr($kt,$tpos+1,$wpos-$tpos-1);
  223. $sname=isset($k[$vname])?$k[$vname]:'';
  224. if(strstr($vname,'(')&&strstr($vname,')')){$sname=$vname;
  225. $sname=preg_replace('/[{][$](\w+)[}]/eis','$k[\'\\1\']',$sname);
  226. $sname=preg_replace('/(\w+)[(](.*?)[)]/eis','\\1(\\2)',$sname);
  227. }
  228. $str.='<td style="'.$wname.'"><a href=# onclick="'.$jname.'">'.$sname.'</a></td>';
  229. $strli.='<span style="'.$wname.'"><a href=# onclick="'.$jname.'">'.$sname.'</a></span>';
  230. $wname='';
  231. $jname='';
  232. $sname='';
  233. }
  234. if($manage){
  235. foreach($managearr as $key=>$kt){
  236. $vpos=strpos($kt,'|');
  237. $vname=substr($kt,0,$vpos);
  238. $tpos=strpos($kt,':');
  239. $wpos=strpos($kt,'%');
  240. if($wpos) $wname=substr($kt,$wpos+1);
  241. $wname=str_replace('=',':',$wname);
  242. if(!$tpos)$tpos=strlen($kt);
  243. $tname=substr($kt,$vpos+1,$tpos-$vpos-1);
  244. if(strstr($tname,'%')) $tname=substr($kt,$vpos+1,$wpos-$vpos-1);
  245. $vname=preg_replace('/[{][$](\w+)[}]/eis','$k[\'\\1\']',$vname);
  246. if($tpos)$jname=substr($kt,$tpos+1);
  247. if(strstr($jname,'%')) $jname=substr($kt,$tpos+1,$wpos-$tpos-1);
  248. $jname=preg_replace('/[{][$](\w+)[}]/eis','$k[\'\\1\']',$jname);
  249. $str.='<td style="'.$wname.'"><a href='.$vname.' onclick="'.$jname.'">'.$tname.'</a></td>';
  250. $strli.='<span style="'.$wname.'"><a href='.$vname.' onclick="'.$jname.'">'.$tname.'</a></span>';
  251. $wname='';
  252. $jname='';
  253. $tname='';
  254. }
  255. }
  256. $str.='</tr>';
  257. $strli.='</li>';
  258. }
  259. $strli.='</ul>';
  260. $str.='</table>';
  261. $pagestr=isset($pagestr)?$pagestr:'';
  262. $str.=$pagestr;
  263. $strli.=$pagestr;
  264. if($islist=='li')$str=$strli;
  265. return $str;
  266. }
  267. function dump($n){
  268. print_r($n);
  269. }
  270. function __autoload($class)
  271. {
  272. $auto=array();
  273. $dirs=array();
  274. $custom=APP_PATH.'/custom';
  275. $dirs[]=$custom;
  276. $locdirs=array();
  277. if(!empty($_GET['k'])){
  278. $locdirs=explode('/',$_GET['k']);
  279. $dirs[]=$custom.'/'.$locdirs[0];
  280. $extdirs=readSubDir($custom.'/'.$locdirs[0]);
  281. }else{
  282. $extdirs=readSubDir($custom);
  283. }
  284. $dirs=array_merge($dirs,$extdirs);
  285. $dirs[]=KYPHP_PATH.'kyclass/kyphp_base';
  286. foreach($dirs as $extdir){
  287. $file =$extdir.'/'.$class . '.php';
  288. if (is_file($file)) {
  289. require_once($file);
  290. }
  291. }
  292. KYPHP::autoload_APP($class,$locdirs);
  293. }
  294. spl_autoload_register("__autoload");
  295. require_once(KYPHP_PATH.'kyclass/kyphp_base/Action.php');
  296. require_once(KYPHP_PATH.'kyclass/kyphp_base/Cache.php');
  297. require_once(KYPHP_PATH.'kyclass/kyphp_base/Config.php');
  298. require_once(KYPHP_PATH.'kyclass/kyphp_base/Cookie.php');
  299. require_once(KYPHP_PATH.'kyclass/kyphp_base/DB.php');
  300. require_once(KYPHP_PATH.'kyclass/kyphp_base/front.php');
  301. require_once(KYPHP_PATH.'kyclass/kyphp_base/Image.php');
  302. require_once(KYPHP_PATH.'kyclass/kyphp_base/Json.php');
  303. require_once(KYPHP_PATH.'kyclass/kyphp_base/Language.php');
  304. require_once(KYPHP_PATH.'kyclass/kyphp_base/Language.php');
  305. require_once(KYPHP_PATH.'kyclass/kyphp_base/Log.php');
  306. require_once(KYPHP_PATH.'kyclass/kyphp_base/Pagination.php');
  307. require_once(KYPHP_PATH.'kyclass/kyphp_base/Request.php');
  308. require_once(KYPHP_PATH.'kyclass/kyphp_base/Response.php');
  309. require_once(KYPHP_PATH.'kyclass/kyphp_base/runtime.php');
  310. require_once(KYPHP_PATH.'kyclass/kyphp_base/Session.php');
  311. require_once(KYPHP_PATH.'kyclass/kyphp_base/templete.php');
  312. require_once(KYPHP_PATH.'kyclass/kyphp_base/Url.php');
  313. function readSubDir($path){
  314. $arr=array();
  315. if(is_dir($path)){
  316. $ext1=glob($path.'/*');
  317. if($ext1){
  318. foreach($ext1 as $ext1dir){
  319. if(is_dir($ext1dir)){
  320. $arr[]=$ext1dir;
  321. $sub=readSubDir($ext1dir);
  322. $arr=array_merge($arr,$sub);
  323. }
  324. }
  325. }
  326. }
  327. return $arr;
  328. }
  329. function getfunname($fun){
  330. $return=debug_backtrace();
  331. $file= $return[2]['function'];
  332. $clas= $return[2]['class'];
  333. if($fun=='2')return @$return[2]['object']->class;
  334. if($fun=='1')return $file;
  335. if($fun=='0')return $clas;
  336. if($fun=='')return $return;
  337. }
  338. function verify($cookname){
  339. Header("Content-type: image/gif");
  340. /*
  341. * 初始化
  342. */
  343. $border = 0; //是否要边框 1要:0不要
  344. $how = 4; //验证码位数
  345. $w = $how*15; //图片宽度
  346. $h = 20; //图片高度
  347. $fontsize = 5; //字体大小
  348. $alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容1:字母
  349. $number = "023456789"; //验证码内容2:数字
  350. $randcode = ""; //验证码字符串初始化
  351. srand((double)microtime()*1000000); //初始化随机数种子
  352. $im = ImageCreate($w, $h); //创建验证图片
  353. /*
  354. * 绘制基本框架
  355. */
  356. $bgcolor = ImageColorAllocate($im, 255, 255, 255); //设置背景颜色
  357. ImageFill($im, 0, 0, $bgcolor); //填充背景色
  358. if($border)
  359. {
  360. $black = ImageColorAllocate($im, 0, 0, 0); //设置边框颜色
  361. ImageRectangle($im, 0, 0, $w-1, $h-1, $black);//绘制边框
  362. }
  363. /*
  364. * 逐位产生随机字符
  365. */
  366. for($i=0; $i<$how; $i++)
  367. {
  368. $alpha_or_number = mt_rand(0, 1); //字母还是数字
  369. $str = $alpha_or_number ? $alpha : $number;
  370. $which = mt_rand(0, strlen($str)-1); //取哪个字符
  371. $code = substr($str, $which, 1); //取字符
  372. $j = !$i ? 4 : $j+15; //绘字符位置
  373. $color3 = ImageColorAllocate($im, mt_rand(0,100), mt_rand(0,100), mt_rand(0,100)); //字符随即颜色
  374. ImageChar($im, $fontsize, $j, 3, $code, $color3); //绘字符
  375. $randcode .= $code; //逐位加入验证码字符串
  376. }
  377. /*
  378. * 添加干扰
  379. */
  380. for($i=0; $i<5; $i++)//绘背景干扰线
  381. {
  382. $color1 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //干扰线颜色
  383. ImageArc($im, mt_rand(-5,$w), mt_rand(-5,$h), mt_rand(20,300), mt_rand(20,200), 55, 44, $color1); //干扰线
  384. }
  385. for($i=0; $i<$how*40; $i++)//绘背景干扰点
  386. {
  387. $color2 = ImageColorAllocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); //干扰点颜色
  388. ImageSetPixel($im, mt_rand(0,$w), mt_rand(0,$h), $color2); //干扰点
  389. }
  390. //把验证码字符串写入session
  391. setcookie($cookname,$randcode);
  392. /*绘图结束*/
  393. Imagegif($im);
  394. ImageDestroy($im);
  395. /*绘图结束*/
  396. }
  397. function D($form,$db=null){
  398. global $KYPHP;
  399. if(!$db){
  400. $mysql=$KYPHP->db;
  401. }else{
  402. $mysql=$db;
  403. }
  404. $mysql->table=$form;
  405. $mysql->where='';
  406. $mysql->order='';
  407. $mysql->group='';
  408. $mysql->field='';
  409. $mysql->sql='';
  410. $mysql->limit='';
  411. return $mysql;
  412. }
  413. function M($form,$db=null){
  414. global $KYPHP;
  415. if(!$db){
  416. $mysql=$KYPHP->db;
  417. }else{
  418. $mysql=$db;
  419. }
  420. $mysql->table=$form;
  421. $mysql->where='';
  422. $mysql->order='';
  423. $mysql->group='';
  424. $mysql->field='';
  425. $mysql->sql='';
  426. $mysql->limit='';
  427. return $mysql;
  428. }
  429. function curl_file_get_contents($durl,$time=0.5){
  430. $ch = curl_init();
  431. curl_setopt($ch, CURLOPT_URL, $durl);
  432. curl_setopt($ch, CURLOPT_TIMEOUT, $time);
  433. curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
  434. curl_setopt($ch, CURLOPT_REFERER,_REFERER_);
  435. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  436. $r = curl_exec($ch);
  437. curl_close($ch);
  438. return $r;
  439. }
  440. function curl_get_url_status($url){
  441. $curl = curl_init();
  442. curl_setopt($curl, CURLOPT_URL, $url);
  443. curl_setopt($curl, CURLOPT_HEADER, 1);
  444. curl_setopt($curl,CURLOPT_NOBODY,true);
  445. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  446. $data = curl_exec($curl);
  447. $str= curl_getinfo($curl,CURLINFO_HTTP_CODE);
  448. curl_close($curl);
  449. return $str;
  450. }
  451. function check_utf8($str) {
  452. $len = strlen($str);
  453. for($i = 0; $i < $len; $i++){
  454. $c = ord($str[$i]);
  455. if ($c > 128) {
  456. if (($c > 247)) return false;
  457. elseif ($c > 239) $bytes = 4;
  458. elseif ($c > 223) $bytes = 3;
  459. elseif ($c > 191) $bytes = 2;
  460. else return false;
  461. if (($i + $bytes) > $len) return false;
  462. while ($bytes > 1) {
  463. $i++;
  464. $b = ord($str[$i]);
  465. if ($b < 128 || $b > 191) return false;
  466. $bytes--;
  467. }
  468. }
  469. }
  470. return true;
  471. } // end of chec
  472. function get_url_contents($url)
  473. {
  474. //if (ini_get("allow_url_fopen") == "1")
  475. // return file_get_contents($url);
  476. $ch = curl_init();
  477. curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  478. curl_setopt($ch, CURLOPT_URL, $url);
  479. $result = curl_exec($ch);
  480. curl_close($ch);
  481. return $result;
  482. }
  483. function is_utf8($liehuo_net){
  484. if(preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$liehuo_net) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$liehuo_net) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$liehuo_net) == true)
  485. {
  486. return true;
  487. }
  488. else
  489. {
  490. return false;
  491. }
  492. }
  493. ?>