0) $content=fread($fp, $filesize); fclose($fp); return $content; } /* #################### writeFile #################### */ static function writeFile($filename, $content) //写文件。 { if($filename) { $fp=@fopen($filename, "w"); if($fp) { fwrite($fp, $content); fclose($fp); return true; }else return false; } else { return false; } } /* #################### go2 #################### */ static function go2($url, $msg='') //页面跳转。 { $url = strip_tags($url); $url = str_replace('', '(', $url); echo ""; echo ''; exit; } static function alert($msg) { echo "\n "; exit; } /* ################# getHistoryBack getUrlBack getCloseBack ################# */ static function getHistoryBack($pReason) { echo "\n "; exit; } static function getUrlBack($pReason, $pUrl) { $pUrl = strip_tags($pUrl); $pUrl = str_replace('', '(', $pUrl); echo "\n "; exit; } static function getErrorBack($strError) { //todo exit; } static function script($query) { echo "\n "; exit; } /* #################### postContent #################### */ static function postContent($host, $target, $content, $port=80, $timeout=10) //socket方式 http1.1请求 post方式发送数据 { $host=trim($host); $port=trim($port); $content=trim($content); if(!$host || !$port) return false; $fp=fsockopen($host, $port, $errno, $errstr, $timeout); if($fp) { $post_str="POST ".$target." HTTP/1.1\r\n"; $post_str.="HOST: ".$host."\r\n"; $post_str.="Content-type: application/x-www-form-urlencoded\r\n"; $post_str.="Content-length: ".strlen($content)."\r\n"; $post_str.="User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\r\n"; $post_str.="\r\n".$content."\r\n\r\n"; fwrite($fp, $post_str); $start = 0; $get_str=""; while(!feof($fp)) { $buf=fgets($fp,2048); $get_str .= $buf; } fclose($fp); return trim($get_str); } return false; } /* #################### getContent #################### */ static function getContent($host, $target, $port=80, $timeout=30) //get方式发送数据 { $errno=0; $errstr=""; $result=""; if(!$host || !$target || !$port) return false; $fp=@fsockopen($host, $port, $error, $errstr, $timeout); if(!$fp) { $error="errno:$errno,error:$errstr"; return false; } fwrite($fp, "GET ".$target." HTTP/1.1\r\nHOST: ".$host."\r\n\r\n"); fflush($fp); $buf=fread($fp, 2048); $start=0; while(!feof($fp)) { $buf=fread($fp, 2048); $buf=rtrim($buf); if(ereg("^$",$buf)) { $start=1; continue; } if ( $start == 1 ) { $result.= $buf; } } fclose($fp); return $result; } /* ################# date ################# */ static function makeTimeStamp($year="",$month="",$day="",$hour=0,$minute=0,$second=0) {// 2004-11-22 将html_select_date接收的时间转换成UNIX时间戳记 if(empty($year)) $year = strftime("%Y"); if(empty($month)) $month = strftime("%m"); if(empty($day)) $day = strftime("%d"); if(empty($hour)) $hour = strftime("%H"); if(empty($minute)) $minute = strftime("%i"); if(empty($second)) $second = strftime("%s"); return mktime($hour,$minute,$second,$month,$day,$year); } /* ################# 生成log debug ################# */ static function writeLog($pcontent,$filepath) { exec("echo '".$pcontent."\t".date("Y-m-d H:i:s")."' >> ".$filepath." &"); } /* ################# 获得用户ip ################# */ static function getUserIP() { return $_SERVER['REMOTE_ADDR']; } static function ip2num($ip) { $ip = trim($ip); if($ip==''){ return false; } $ip = split('\.', $ip); return $ip[0]*255*255*255 + $ip[1]*255*255 + $ip[2]*255 + $ip[3]; } /* #################### 内容转换为js输出 #################### */ static function getContentToJS($content, $display=1) { $header="document.writeln('"; $footer="');\n"; $content=eregi_replace("(\r\n|\n|\r)", "\n", $content); $content=addslashes($content); $content=$header.eregi_replace("\n", $footer.$header, $content).$footer; if($display==1) echo $content; else return $content; } /* ################# 获得一个随即串 ################# */ static function makeRandomStr($plength) { $salt = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789"; $len = strlen($salt); $makepass=""; mt_srand(10000000*(double)microtime()); for ($i = 0; $i < $plength; $i++) $makepass .= $salt[mt_rand(0,$len - 1)]; return $makepass; } /* ################# 获得一个微秒时间戳 ################# */ function getMicrotime() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } /* ################# 处理变量 ################# */ static function getParam( &$arr, $name, $def=null) { if (isset( $arr[$name] )) { if (is_string( $arr[$name] )) { $arr[$name] = trim( $arr[$name] ); if (!get_magic_quotes_gpc()) { $arr[$name] = addslashes( $arr[$name] ); } } return $arr[$name]; } else { return $def; } } static function getParams($pParams, $def=null) { if(!get_magic_quotes_gpc()) { STD::addslashes_deep($pParams); }else STD::trim_deep($pParams); return $pParams; } static function addslashes_deep(&$pParam) { if(is_array($pParam)) { foreach ($pParam as $key=>$value) { $pParam[$key] = STD::addslashes_deep($value); } return $pParam; }else return trim(addslashes($pParam)); } static function trim_deep(&$pParam) { if(is_array($pParam)) { foreach ($pParam as $key=>$value) { $pParam[$key] = STD::trim_deep($value); } return $pParam; }else return trim($pParam); } /* ################# 生成php文件 ################# */ static function writePHPFile($pfilename,$pcontent,$version="") { $str = ""; $handle = fopen($pfilename, "w"); if($handle) { fwrite($handle, $str); fclose($handle); return true; }else return false; } /* ################# 图片重设定大小 ################# */ static function resizePic($source,$objective,$setw="",$seth="",$rflag=1)//源,目标,宽,高 rflag 0:按照比例缩放 1:强制缩放为 { $data = GetImageSize($source,$error); switch ($data[2]) { case 1: $s_im = ImageCreateFromGIF($source); break; case 2: $s_im = imagecreatefromjpeg($source); break; case 3: $s_im = ImageCreateFromPNG($source); break; default: return false; } if (!$s_im) { /* See if it failed */ return false; } $pic_x = imagesx($s_im); $pic_y = imagesy($s_im); if($rflag==0&&($data[0]>$setw||$data[1]>$seth)) { if(round($setw*$data[1]/$data[0])>$seth) { $d_h = $seth; $d_w = round($seth*$data[0]/$data[1]); } else { $d_w = $setw; $d_h = round($setw*$data[1]/$data[0]); } }elseif($rflag==0) { $d_h = $data[1]; $d_w = $data[0]; }elseif($rflag==1) { if($setw&&$seth) { $d_w = $setw; $d_h = $seth; }elseif($setw) { $d_w = $setw; $temps = $setw*$pic_y/$pic_x; $d_h = round($temps); }elseif($seth) { $d_h = $seth; $temps = $seth*$pic_x/$pic_y; $d_w = round($temps); }else { $d_w = 90; $d_h = 90; } } $d_im = imagecreatetruecolor($d_w, $d_h); imagecopyresampled($d_im, $s_im, 0, 0, 0, 0, $d_w, $d_h, $pic_x, $pic_y); imagejpeg($d_im,$objective); imagedestroy($s_im); imagedestroy($d_im); return true; } /* ################# 图片重设定大小,比例切图 ################# */ static function cutPic($source,$objective,$setw="",$seth="") { $data = GetImageSize($source,$error); switch ($data[2]) { case 1: $s_im = ImageCreateFromGIF($source); break; case 2: $s_im = ImageCreateFromJpeg($source); break; case 3: $s_im = ImageCreateFromPNG($source); break; default: return false; } if (!$s_im) { /* See if it failed */ return false; } $pic_x = imagesx($s_im); $pic_y = imagesy($s_im); $src_proportion = $pic_x/$pic_y; $dst_proportion = $setw/$seth; if($src_proportion > $dst_proportion) { $ought_width = $pic_y*$dst_proportion; $ought_height = $pic_y; $ought_x = ($pic_x - $ought_width)/2; $ought_y = 0; }elseif($src_proportion < $dst_proportion) { $ought_width = $pic_x; $ought_height = $pic_x/$dst_proportion; $ought_x = 0; $ought_y = ($pic_y - $ought_height)/2; }else { $ought_width = $pic_x; $ought_height = $pic_y; $ought_x = 0; $ought_y = 0; } $d_im = imagecreatetruecolor($setw, $seth); imagecopyresampled($d_im, $s_im, 0, 0, $ought_x, $ought_y, $setw, $seth, $ought_width, $ought_height); imagejpeg($d_im,$objective,92); imagedestroy($s_im); imagedestroy($d_im); return true; } /* ################# hash目录结构 ################# */ static function setPath ($rootpath,$this_id,$pyear="") { if($pyear) { $rootpath .= $pyear; if(!is_dir($rootpath)) mkdir ($rootpath, 0777); $rootpath .= "/"; } $num_path = floor ($this_id/1000); if(!is_dir($rootpath.$num_path )) mkdir ($rootpath.$num_path, 0777); $result_path = $rootpath.$num_path."/"; return $result_path; } static function getPath ($rootpath,$this_id,$pyear="") { if($pyear) { $rootpath .= $pyear."/"; } $num_path = floor ($this_id/1000); $result_path = $rootpath.$num_path."/"; return $result_path; } static function titlecmp( $row1,$row2 ) { return strcmp($row1['title'], $row2['title']) ; } /* ################# 页面定向 ################# */ static function redirect ($url, $status = null) { $pos = strpos($url, '://'); if ($pos === false) { if(strpos($url, '/') !== 0) { $url = '/'.$url; } $url = _URL_ROOT_ . $url; } session_write_close(); if ($status != null) { $codes = array ( 100 => "HTTP/1.1 100 Continue", 101 => "HTTP/1.1 101 Switching Protocols", 200 => "HTTP/1.1 200 OK", 201 => "HTTP/1.1 201 Created", 202 => "HTTP/1.1 202 Accepted", 203 => "HTTP/1.1 203 Non-Authoritative Information", 204 => "HTTP/1.1 204 No Content", 205 => "HTTP/1.1 205 Reset Content", 206 => "HTTP/1.1 206 Partial Content", 300 => "HTTP/1.1 300 Multiple Choices", 301 => "HTTP/1.1 301 Moved Permanently", 302 => "HTTP/1.1 302 Found", 303 => "HTTP/1.1 303 See Other", 304 => "HTTP/1.1 304 Not Modified", 305 => "HTTP/1.1 305 Use Proxy", 307 => "HTTP/1.1 307 Temporary Redirect", 400 => "HTTP/1.1 400 Bad Request", 401 => "HTTP/1.1 401 Unauthorized", 402 => "HTTP/1.1 402 Payment Required", 403 => "HTTP/1.1 403 Forbidden", 404 => "HTTP/1.1 404 Not Found", 405 => "HTTP/1.1 405 Method Not Allowed", 406 => "HTTP/1.1 406 Not Acceptable", 407 => "HTTP/1.1 407 Proxy Authentication Required", 408 => "HTTP/1.1 408 Request Time-out", 409 => "HTTP/1.1 409 Conflict", 410 => "HTTP/1.1 410 Gone", 411 => "HTTP/1.1 411 Length Required", 412 => "HTTP/1.1 412 Precondition Failed", 413 => "HTTP/1.1 413 Request Entity Too Large", 414 => "HTTP/1.1 414 Request-URI Too Large", 415 => "HTTP/1.1 415 Unsupported Media Type", 416 => "HTTP/1.1 416 Requested range not satisfiable", 417 => "HTTP/1.1 417 Expectation Failed", 500 => "HTTP/1.1 500 Internal Server Error", 501 => "HTTP/1.1 501 Not Implemented", 502 => "HTTP/1.1 502 Bad Gateway", 503 => "HTTP/1.1 503 Service Unavailable", 504 => "HTTP/1.1 504 Gateway Time-out" ); if (isset($codes[$status])) { header($codes[$status]); } } //echo $url; std::go2($url); //header ('Location: '.$url); exit(); } static function parsePhoto($address) { $address=trim($address); $ary_header = get_headers($address, 1); $filesize = $ary_header['Content-Length']; Header("Content-type: application/file"); Header( "Pragma: public" ); Header( "Expires: 0" ); // set expiration time Header( "Cache-Component: must-revalidate, post-check=0, pre-check=0" ); Header("Content-type: image/jpeg"); if(_VIEW_TYPE_ == 1) { Header( "Content-Length: " . $filesize ); readfile( $address ); exit; } elseif(_VIEW_TYPE_ == 2) { require_once(_FS_ADDRESS_); $truePath = ''; $path = substr(dirname($address),1); $name = basename($address); $iRet=FS_FileGet($path,$name,$truePath); if ($iRet == FS_RET_OK) { Header( "Content-Length: " . $filesize ); readfile( $truePath ); exit; } } } //tail -n //fopen with ‘r‘ static function tailread($fp, $n) { $out = ""; $i = -2; fseek($fp, -2, SEEK_END); for( ; $n >= 0 ; $n--) { while ("\n" != fgetc($fp)) { $i--; if ( -1 == fseek($fp, $i, SEEK_END)) { rewind($fp); $out .= fgets($fp); return $out; } } $out .= fgets($fp); } return $out; } static function findflvImg($p_id,$type="large",$path) { if(!isset($p_id)) return false; /** * get picture */ $dir_1 = floor($p_id/1000000); $p_path = $dir_1."/"; $dir_2 = floor($p_id/1000); $p_path = $p_path.$dir_2."/"; return $p_path = $path.$p_path.$type.$p_id.".jpg"; } /* 字串长度判断 */ static function checkUtf8Len($string, $short = null, $long = null) { if ((null === $short) && (null === $long)) { return true; } else if ($long <= $short) { return false; } else if (null === $short) { $length = strlen($string); if ($long < $length) { return false; } } else { $length = strlen($string); } $newlength = 0; for($i=0;$i<$length;$i++) { $newlength++; $a = base_convert(ord($string{$i}), 10, 2); $a = substr('00000000'.$a, -8); if (substr($a, 0, 1) == 0) { continue; } elseif (substr($a, 0, 3) == 110) { $newlength++; $i++; } elseif (substr($a, 0, 4) == 1110) { $newlength++; //$length++; $i++; } else { $newlength--; } } if (null !== $long) { if ($long < $newlength) { return false; } else if (null === $short) { return true; } } if (null !== $short) { if ($short > $newlength) { return false; } else { return true; } } return false; } /* ################# 字符串按长度截字 ################# */ static function truncateUtf8($string, $length = 80, $etc = '...') { if ($length == 0) return ''; $newlength = 0; if (strlen($string) > $length) { for($i=0;$i<$length;$i++) { $newlength++; $a = base_convert(ord($string{$i}), 10, 2); $a = substr('00000000'.$a, -8); if (substr($a, 0, 1) == 0) { continue; }elseif (substr($a, 0, 3) == 110) { $newlength++; $i++; }elseif (substr($a, 0, 4) == 1110) { $newlength += 2; $length++; $i++; }else { $newlength--; } } $length = $newlength; return substr($string, 0, $length).$etc; } else { return $string; } } /* ################# 字符串加密 ################# */ static function stringEncode($pString, $pSecretKey='') { require_once _LIBS_PATH_ . 'HCEMD5.php'; $hcemd5 = new Crypt_HCEMD5($pSecretKey); return $hcemd5->encodeMimeSelfRand($pString); } /* ################# 字符串解密 ################# */ static function stringDecode($pKey, $pSecretKey='') { require_once _LIBS_PATH_ . 'HCEMD5.php'; $hcemd5 = new Crypt_HCEMD5($pSecretKey); return $hcemd5->decodeMimeSelfRand($pKey); } /* ################# 过滤字符串中的 & < > ' " ################# */ static function escapeHTMLentities($pStr) { return str_replace(array('&', '<', '>', "'", '"'), array('', '', '', '', ''), $pStr); } //分页代码1 static function dvPage2($curPage, $total, $pageSize, $url) { !preg_match("/^[1-9]{1}[0-9]{0,7}$/", $curPage) && $curPage = 1; $arr = array(); $arr['total'] = $total; $arr['curPage'] = $curPage; $arr['maxPage'] = ceil($total/$pageSize); $arr['upPage'] = $curPage - 1>0?$curPage-1:1; $arr['nextPage'] = $curPage+1>$arr['maxPage']?$arr['maxPage']:$curPage+1; $arr['startPage'] = $curPage-4>0?$curPage-4:1; $arr['endPage'] = $arr['startPage']+8>$arr['maxPage']?$arr['maxPage']:$arr['startPage']+8; $arr['code'] = '
首页上一页'; for ($i=$arr['startPage']; $i<=$arr['endPage']; $i++) { if($i==$curPage)$arr['code'] .= ''.$i.''; else $arr['code'] .= ''.$i.''; } $arr['code'] .= '下一页末页
'; return $arr; } static function dvPage1($curPage, $total, $pageSize, $url, $pnames) { !preg_match("/^[1-9]{1}[0-9]{0,7}$/", $curPage) && $curPage = 1; $arr = array(); $arr['total'] = $total; $arr['curPage'] = $curPage; $arr['maxPage'] = ceil($total/$pageSize); $arr['upPage'] = $curPage - 1>0?$curPage-1:1; $arr['nextPage'] = $curPage+1>$arr['maxPage']?$arr['maxPage']:$curPage+1; $arr['startPage'] = $curPage-4>0?$curPage-4:1; $arr['endPage'] = $arr['startPage']+8>$arr['maxPage']?$arr['maxPage']:$arr['startPage']+8; $arr['code'] = '
共'.$total.'条'.$arr['curPage'].'/'.$arr['maxPage'].'<<<'; for ($i=$arr['startPage']; $i<=$arr['endPage']; $i++) { if($i==$curPage)$arr['code'] .= ''.$i.''; else $arr['code'] .= ''.$i.''; } $arr['code'] .= '>>>
'; return $arr; } #数字加密 static function func_idencode($id){ $newid=$id*123; $newid=str_replace(array('1','2','3','4','5','6','7','8','9','0'),array('w','s','d','f','g','y','u','i','o','k'),$newid); $newid=urlencode(base64_encode($newid)); return $newid; } #数字解密 static function func_iddecode($id){ $id=base64_decode(urldecode($id)); $id=str_replace(array('w','s','d','f','g','y','u','i','o','k'),array('1','2','3','4','5','6','7','8','9','0'),$id); $newid=$id/123; return $newid; } static function rc4encode() { include_once("Crypt/Rc4.php"); $now = time(); $rc4 = new Crypt_RC4; $message = (string)$now; $key = "isnefifensi"; $rc4->setkey($key); $rc4->crypt($message); $enstring = base64_encode($message); $ret = str_replace("/", "_", $enstring); $ret = str_replace("+", "-", $ret); $ret = str_replace("=", "", $ret); return($ret); } ########################## static function hash_dir($root_path, $id) { $id = intval($id); if($id=='')return false; $tmp = array(); while (1) { if(strlen($id)>3){ $tmp[] = substr($id, 0, 3); $id = substr($id, 3); }else{ $tmp[] = $id; break; } if($id=='')break; } $dir = $root_path; foreach ($tmp as $name) { $dir .= $name; if(!is_dir($dir)){ @mkdir($dir, 0777); system("chmod 777 $dir"); } $dir .= DS; } return join(DS, $tmp); } /* $type is icon or group */ static function seekResource($id, $name, $type, $sex = 1) { $dir = _APP_PATH_.'webroot'.DS.'resource'.DS.$type.DS; $hash_dir = self::hash_dir($dir, $id); if(file_exists($dir.$hash_dir.DS.$name.'.jpg')){ return _URL_ROOT_.'resource/'.$type.'/'.$hash_dir.'/'.$name.'.jpg'; }elseif(file_exists($dir.$hash_dir.DS.$name.'.gif')){ return _URL_ROOT_.'resource/'.$type.'/'.$hash_dir.'/'.$name.'.gif'; }elseif(file_exists($dir.$hash_dir.DS.$name.'.png')){ return _URL_ROOT_.'resource/'.$type.'/'.$hash_dir.'/'.$name.'.png'; }else{ if($sex) { return _URL_ROOT_.'resource/'.$type.'/'.$name.'.gif'; } else { return _URL_ROOT_.'resource/'.$type.'/'.$name.$sex.'.gif'; } } } static function sToT($time) { $tmp = split(' ', $time); $tmp[0] = split('-', $tmp[0]); $tmp[1] = split(':', $tmp[1]); $year = $tmp[0][0]; $month = $tmp[0][1]; $day = $tmp[0][2]; $hour = $tmp[1][0]; $minute = $tmp[1][1]; $second = $tmp[1][2]; $time = mktime($hour,$minute,$second,$month,$day,$year); $s = time() - $time; $s = (int)$s; $day = floor($s/(24*3600)); $s %= 24*3600; $hour = floor($s/3600); $s %= 3600; $minute = floor($s/60); $s %= 60; $secnod = $s; $str = ''; if($day){ $str = $day.'天'; }elseif($hour){ $str = $hour.'小时'; }elseif($minute){ $str = $minute.'分钟'; }elseif($secnod){ $str = $secnod.'秒钟'; }else{ $str = '1秒钟'; } return $str; } static function cache_check($cacheid,$expire=3600) { ob_start(); if (!@file_exists($cacheid)) return false; if (!($mtime=@filemtime($cacheid))) return false; $nowtime=mktime(); if (($mtime+$expire)<$nowtime) { return false; }else{ return true; } } static function cache_write($cacheid,$cachecontent='') { !$cachecontent && $cachecontent = @ob_get_contents(); $dir = split(DS, $cacheid); array_pop($dir); unset($dir[0]); $dir = join(DS, $dir); self::createCacheDir($dir); $fp=@fopen($cacheid, 'w'); $tmp=@fwrite($fp,$cachecontent); @fclose($fp); @chmod($cacheid, 0777); @chgrp($cacheid, 'apache'); @chown($cacheid, 'apache'); return true; } static function cache_read($cacheid) { if(@file_exists($cacheid))return @file_get_contents($cacheid); else return false; } static function createCacheDir($dir) { $aDir = split(DS, $dir); $tmp=DS; foreach($aDir as $sDir) { $tmp .= $sDir; if(!is_dir($tmp)) { @mkdir($tmp); @chmod($tmp, 0777); @chgrp($tmp, 'apache'); @chown($tmp, 'apache'); } $tmp .= DS; } } /** +---------------------------------------------------------- * 产生随机字串,可用来自动生成密码 默认长度6位 字母和数字混合 +---------------------------------------------------------- * @param string $len 长度 * @param string $type 字串类型 * 0 字母 1 数字 其它 混合 * @param string $addChars 额外字符 +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ static function rand_string($len=6,$type='',$addChars='') { $str =''; switch($type) { case 0: $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars; break; case 1: $chars= str_repeat('0123456789',3); break; case 2: $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars; break; case 3: $chars='abcdefghijklmnopqrstuvwxyz'.$addChars; break; case 4: $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借".$addChars; break; default : // 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数 $chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars; break; } if($len>10 ) {//位数过长重复字符串一定次数 $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5); } if($type!=4) { $chars = str_shuffle($chars); $str = substr($chars,0,$len); }else{ // 中文随机字 for($i=0;$i<$len;$i++){ $str.= msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1); } } return $str; } static function getUserInfo() { include_once(_LIBS_PATH_."ifensilib/class.ifensiuser.php" ); $ifensiuser = new IfensiUser(); if($ifensiuser->check()){ $userInfo['uid'] = $ifensiuser->getUserId(); $userInfo['nickname'] = $ifensiuser->getNickName(); $userInfo['nickname'] = iconv("gbk", "utf-8", $userInfo['nickname']); }else{ $userInfo = array(); } return $userInfo; } static function upload_file($files,$folder,$pic,$jb=1) { $file_tyle = $files['type']; if($jb=="1"){ $file_type_arr = array('image/gif','image/x-png','image/jpg','image/pjpeg'); if( !in_array($file_tyle,$file_type_arr) ) { exit('上传的文件类型只能为:png,jpeg,jpg,gif'); } } $knamearray = explode( "." , $files["name"] ); $kname = $knamearray[count($knamearray)-1]; //$rand_str = random_filename(); $file_name =$pic.".".$kname; $savepath = $folder; if( !is_dir($savepath) ) mkdir($savepath); $upfile = $savepath.$file_name; if( !move_uploaded_file($files['tmp_name'],$upfile) ) { exit('上传文件失败,请确认你上传的文件类型为png,jpeg,jpg,gif'); } return $file_name;//不要回传值此行可注释掉 } static function GetClientNetWorkInfo() { //$NetWork["ip"] = ""; // $NetWork["mac"] = ""; if(PHP_OS=="WINNT"){ @exec("ipconfig /all",$array); for($Tmpa;$TmpaSmarty(); $this->template_dir = _TEMPLATE_PATH_; $this->compile_dir = _TMP_PATH_."templates_c".DS; $this->config_dir = _VIEWS_PATH_."configs".DS; $this->cache_dir = _TMP_PATH_."cache".DS; $this->caching = false; //echo $this->cache_dir ; $this->compile_check = true; $this->debugging = false; } } ?>$val){ $value = $this->parseValue($val); if(is_scalar($value)) // 过滤非标量数据 $set[] = $this->addSpecialChar($key).'='.$value; } return ' SET '.implode(',',$set); } /** +---------------------------------------------------------- * value分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $value +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseValue(&$value) { if(is_string($value)) { $value = '\''.$this->escape_string($value).'\''; }elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){ $value = $this->escape_string($value[1]); }elseif(is_null($value)){ $value = 'null'; } return $value; } /** +---------------------------------------------------------- * table分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $table +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseTable($tables) { if(is_string($tables))return $tables; } /** +---------------------------------------------------------- * limit分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $lmit +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseLimit($limit) { return !empty($limit)? ' LIMIT '.$limit.' ':''; } /** +---------------------------------------------------------- * order分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $order +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseOrder($order) { if(is_array($order)) { $array = array(); foreach ($order as $key=>$val){ if(is_numeric($key)) { $array[] = $this->addSpecialChar($val); }else{ $array[] = $this->addSpecialChar($key).' '.$val; } } $order = implode(',',$array); } return !empty($order)? ' ORDER BY '.$order:''; } /** +---------------------------------------------------------- * group分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $group +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseGroup($group) { return !empty($group)? ' GROUP BY '.$group:''; } /** +---------------------------------------------------------- * having分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param string $having +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseHaving($having) { return !empty($having)? ' HAVING '.$having:''; } /** +---------------------------------------------------------- * distinct分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $distinct +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseDistinct($distinct) { return !empty($distinct)? ' DISTINCT ' :''; } /** +---------------------------------------------------------- * field分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $fields +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseField($fields) { if(is_array($fields)) { // 完善数组方式传字段名的支持 // 支持 'field1'=>'field2' 这样的字段别名定义 $array = array(); foreach ($fields as $key=>$field){ if(!is_numeric($key)) $array[] = $this->addSpecialChar($key).' AS '.$this->addSpecialChar($field); else $array[] = $this->addSpecialChar($field); } $fieldsStr = implode(',', $array); }elseif(is_string($fields) && !empty($fields)) { $fieldsStr = $this->addSpecialChar($fields); }else{ $fieldsStr = '*'; } return $fieldsStr; } /** +---------------------------------------------------------- * join分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $join +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseJoin($join) { $joinStr = ''; if(!empty($join)) { if(is_array($join)) { foreach ($join as $key=>$_join){ if(false !== stripos($_join,'JOIN')) $joinStr .= ' '.$_join; else $joinStr .= ' LEFT JOIN ' .$_join; } }else{ $joinStr .= ' LEFT JOIN ' .$join; } } return $joinStr; } /** +---------------------------------------------------------- * where分析 +---------------------------------------------------------- * @access protected +---------------------------------------------------------- * @param mixed $where +---------------------------------------------------------- * @return string +---------------------------------------------------------- */ protected function parseWhere($where) { $whereStr = ''; if(is_string($where)) { // 直接使用字符串条件 $whereStr = $where; } else { STD::throw_exception("where参数暂不支持这种类型"); } return empty($whereStr)?'':' WHERE '.$whereStr; } /** +---------------------------------------------------------- * 获取一条记录的某个字段值 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $field 字段名 * @param mixed $condition 查询条件 * @param string $spea 字段数据间隔符号 +---------------------------------------------------------- * @return mixed +---------------------------------------------------------- */ public function getField($field,$condition='',$sepa=' ') { if(empty($condition) && isset($this->options['where'])) $condition = $this->options['where']; $options['where'] = $condition; $options['field'] = $field; $options = $this->_parseOptions($options); if(strpos($field,',')) { // 多字段 $this->select($options); $resultSet = $this->fetch_all(); if(!empty($resultSet)) { $field = explode(',',$field); $key = array_shift($field); $cols = array(); foreach ($resultSet as $result){ $name = $result[$key]; $cols[$name] = ''; foreach ($field as $val) $cols[$name] .= $result[$val].$sepa; $cols[$name] = substr($cols[$name],0,-strlen($sepa)); } return $cols; } }else{ // 查找一条记录 $options['limit'] = 1; $result = $this->selectone($options); if(!empty($result)) { return reset($result); } } return null; } /** +---------------------------------------------------------- * 分析表达式 +---------------------------------------------------------- * @access private +---------------------------------------------------------- * @param array $options 表达式参数 +---------------------------------------------------------- * @return array +---------------------------------------------------------- */ private function _parseOptions($options=array()) { if(is_array($options)) $options = array_merge($this->options,$options); // 查询过后清空sql表达式组装 避免影响下次查询 $this->options = array(); return $options; } /** +---------------------------------------------------------- * 插入记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param mixed $data 数据 * @param array $options 参数表达式 +---------------------------------------------------------- * @return false | integer +---------------------------------------------------------- */ public function insert($data,$options=array(),$return=false) { foreach ($data as $key=>$val){ $value = $this->parseValue($val); if(is_scalar($value)) { // 过滤非标量数据 $values[] = $value; $fields[] = $this->addSpecialChar($key); } } $options= $this->_parseOptions($options); $sql = 'INSERT INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')'; if( $this->query($sql)) { if($return){return $this->lastInsID;}else{ return true;} } else {return false; } } /** +---------------------------------------------------------- * 唯一记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param mixed $data 数据 * @param array $options 参数表达式 +---------------------------------------------------------- * @return false | integer +---------------------------------------------------------- */ public function replace($data,$options=array(),$return=false) { foreach ($data as $key=>$val){ $value = $this->parseValue($val); if(is_scalar($value)) { // 过滤非标量数据 $values[] = $value; $fields[] = $this->addSpecialChar($key); } } $options= $this->_parseOptions($options); $sql = 'REPLACE INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')'; if( $this->query($sql)) { if($return){return $this->lastInsID;}else{ return true;} } else {return false; } } /** +---------------------------------------------------------- * 更新记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param mixed $data 数据 * @param array $options 表达式 +---------------------------------------------------------- * @return false | integer +---------------------------------------------------------- */ public function update($data,$options=array(),$aa=false) { $options= $this->_parseOptions($options); $sql = 'UPDATE ' .$this->parseTable($options['table']) .$this->parseSet($data) .$this->parseWhere(isset($options['where'])?$options['where']:'') .$this->parseOrder(isset($options['order'])?$options['order']:'') .$this->parseLimit(isset($options['limit'])?$options['limit']:''); return $this->query($sql); } public function select($options=array()) { if(count($options)==0) $options=$this->options; if(isset($options['page'])&&$options['page']!='') { // 根据页数计算limit if(strpos($options['page'],",")>0) list($page,$listRows) = explode(',',$options['page']); else $page=$options['page']; $listRows = isset($listRows)?$listRows:((isset($options['limit']) && is_numeric($options['limit']))?$options['limit']:20); $offset = $listRows*((int)$page-1); $options['limit'] = $offset.','.$listRows; } $this->_parseOptions($options); $sql = str_replace( array('%TABLE%','%DISTINCT%','%FIELDS%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), $this->parseField(isset($options['field'])?$options['field']:'*'), $this->parseJoin(isset($options['join'])?$options['join']:''), $this->parseWhere(isset($options['where'])?$options['where']:''), $this->parseGroup(isset($options['group'])?$options['group']:''), $this->parseHaving(isset($options['having'])?$options['having']:''), $this->parseOrder(isset($options['order'])?$options['order']:''), $this->parseLimit(isset($options['limit'])?$options['limit']:'') ),$this->selectSql); if(isset($options['master'])) { $this->query($sql,1); } else { $this->query($sql); } return $this->fetch_all(); } public function selectone($options=array()) { if(count($options)==0) $options=$this->options; if(isset($options['page'])&&$options['page']!='') { // 根据页数计算limit if(strpos($options['page'],",")>0) list($page,$listRows) = explode(',',$options['page']); else $page=$options['page']; $listRows = isset($listRows)?$listRows:((isset($options['limit']) && is_numeric($options['limit']))?$options['limit']:20); $offset = $listRows*((int)$page-1); $options['limit'] = $offset.','.$listRows; } $this->_parseOptions($options); $sql = str_replace( array('%TABLE%','%DISTINCT%','%FIELDS%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), $this->parseField(isset($options['field'])?$options['field']:'*'), $this->parseJoin(isset($options['join'])?$options['join']:''), $this->parseWhere(isset($options['where'])?$options['where']:''), $this->parseGroup(isset($options['group'])?$options['group']:''), $this->parseHaving(isset($options['having'])?$options['having']:''), $this->parseOrder(isset($options['order'])?$options['order']:''), $this->parseLimit(isset($options['limit'])?$options['limit']:'') ),$this->selectSql); if(isset($options['master'])) { return $this->query_first($sql,1); } else { return $this->query_first($sql); } } /** +---------------------------------------------------------- * 通过Select方式插入记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $fields 要插入的数据表字段名 * @param string $table 要插入的数据表名 * @param array $option 查询数据参数 +---------------------------------------------------------- * @return false | integer +---------------------------------------------------------- */ public function selectInsert($fields,$table,$options=array()) { if(is_string($fields)) $fields = explode(',',$fields); array_walk($fields, array($this, 'addSpecialChar')); $options= $this->_parseOptions($options); $sql = 'INSERT INTO '.$this->parseTable($table).' ('.implode(',', $fields).') '; $sql .= str_replace( array('%TABLE%','%DISTINCT%','%FIELDS%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), $this->parseField(isset($options['field'])?$options['field']:'*'), $this->parseJoin(isset($options['join'])?$options['join']:''), $this->parseWhere(isset($options['where'])?$options['where']:''), $this->parseGroup(isset($options['group'])?$options['group']:''), $this->parseHaving(isset($options['having'])?$options['having']:''), $this->parseOrder(isset($options['order'])?$options['order']:''), $this->parseLimit(isset($options['limit'])?$options['limit']:'') ),$this->selectSql); return $this->query($sql,1); } /** +---------------------------------------------------------- * 删除记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param array $options 表达式 +---------------------------------------------------------- * @return false | integer +---------------------------------------------------------- */ public function delete($options=array(),$aa=false) { $options= $this->_parseOptions($options); $sql = 'DELETE FROM ' .$this->parseTable($options['table']) .$this->parseWhere(isset($options['where'])?$options['where']:'') .$this->parseOrder(isset($options['order'])?$options['order']:'') .$this->parseLimit(isset($options['limit'])?$options['limit']:''); return $this->query($sql); } public function selectpage($options=array()) { require_once _LIBS_PATH_."Page.class.php"; $oarray=false; if(count($options)==0) $options=$this->options; if(isset($options['page'])&&$options['page']!='') { // 根据页数计算limit if(strpos($options['page'],",")>0) list($page,$listRows) = explode(',',$options['page']); else $page=$options['page']; $page=is_numeric($page)?$page:1; $listRows = isset($listRows)?$listRows:((isset($options['limit']) && is_numeric($options['limit']))?$options['limit']:20); $offset = $listRows*((int)$page-1); $options['limit'] = $offset.','.$listRows; } $this->_parseOptions($options); $sql = str_replace( array('%TABLE%','%DISTINCT%','%FIELDS%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), 'count(*) as tp_num', $this->parseJoin(isset($options['join'])?$options['join']:''), $this->parseWhere(isset($options['where'])?$options['where']:''), $this->parseGroup(isset($options['group'])?$options['group']:''), $this->parseHaving(isset($options['having'])?$options['having']:''), $this->parseOrder(isset($options['order'])?$options['order']:'') ),$this->selectSql); if(isset($options['group'])) { $sql="select count(*) as tp_num from (" .$sql.") a"; } if(isset($options['master'])) { $r=$this->query_first($sql,1); } else { $r=$this->query_first($sql); } $Pmax=isset($options['pmax'])?$options['pmax']:10; $model=new Page($r['tp_num'],$listRows,$page,$Pmax,$options); $oarray['page']=std_class_object_to_array($model); if($page>$options['page']){ $page=$options['page']; $page=is_numeric($page)?$page:1; $offset = $listRows*((int)$page-1); $options['limit'] = $offset.','.$listRows; } $sql = str_replace( array('%TABLE%','%DISTINCT%','%FIELDS%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%'), array( $this->parseTable($options['table']), $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), $this->parseField(isset($options['field'])?$options['field']:'*'), $this->parseJoin(isset($options['join'])?$options['join']:''), $this->parseWhere(isset($options['where'])?$options['where']:''), $this->parseGroup(isset($options['group'])?$options['group']:''), $this->parseHaving(isset($options['having'])?$options['having']:''), $this->parseOrder(isset($options['order'])?$options['order']:''), $this->parseLimit(isset($options['limit'])?$options['limit']:'') ),$this->selectSql); if(isset($options['master'])) { $this->query($sql,1); } else { $this->query($sql); } $oarray["data"]=$this->fetch_all(); return $oarray; } } ?> // +---------------------------------------------------------------------- // $Id$ /** +------------------------------------------------------------------------------ * 系统异常基类 * @author peaceflash * @version $Id$ +------------------------------------------------------------------------------ */ class SException extends Exception {//类定义开始 /** +---------------------------------------------------------- * 异常类型 +---------------------------------------------------------- * @var string * @access private +---------------------------------------------------------- */ private $type; // 是否存在多余调试信息 private $extra; /** +---------------------------------------------------------- * 架构函数 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $message 异常信息 +---------------------------------------------------------- */ public function __construct($message,$code=0,$extra=false) { parent::__construct($message,$code); $this->type = get_class($this); $this->extra = $extra; } /** +---------------------------------------------------------- * 异常输出 所有异常处理类均通过__toString方法输出错误 * 每次异常都会写入系统日志 * 该方法可以被子类重载 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @return array +---------------------------------------------------------- */ public function __toString() { $trace = $this->getTrace(); if($this->extra) { // 通过throw_exception抛出的异常要去掉多余的调试信息 array_shift($trace); } $this->class = $trace[0]['class']; $this->function = $trace[0]['function']; $this->file = $trace[0]['file']; $this->line = $trace[0]['line']; $file = file($this->file); $traceInfo=''; $time = date("y-m-d H:i:m"); foreach($trace as $t) { $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') '; $traceInfo .= $t['class'].$t['type'].$t['function'].'('; $traceInfo .= implode(', ', $t['args']); $traceInfo .=")\n"; } $error['message'] = $this->message; $error['type'] = $this->type; $error['detail'] = '模块名['.MODULE_NAME.']方法名['.ACTION_NAME.']'."\n"; $error['detail'] .= ($this->line-2).': '.$file[$this->line-3]; $error['detail'] .= ($this->line-1).': '.$file[$this->line-2]; $error['detail'] .= ''.($this->line).': '.$file[$this->line-1].''; $error['detail'] .= ($this->line+1).': '.$file[$this->line]; $error['detail'] .= ($this->line+2).': '.$file[$this->line+1]; $error['class'] = $this->class; $error['function'] = $this->function; $error['file'] = $this->file; $error['line'] = $this->line; $error['trace'] = $traceInfo; //记录系统日志 //$errorStr = "\n错误信息。[ ".APP_NAME.' '.MODULE_NAME.' '.ACTION_NAME.' ]'.$this->message."\n"; $errorStr = "\n错误信息".'模块名['.MODULE_NAME.']方法名['.ACTION_NAME.']'.$this->message."\n"; $errorStr .= "错误的URL".$_SERVER["PHP_SELF"]."\n"; $errorStr .= "错误类型".$this->type."\n"; $errorStr .= "TRACE"."\n".$traceInfo; Log::Write($errorStr); return $error ; } }//类定义结束 ?> options[strtolower($method)] = isset($args[0])?$args[0]:''; return $this; } elseif(strtolower($method)==='tableindex') { if(!isset($this->mTableName[$args[0]])) STD::throw_exception("mTableName变量里没有找到表名"); $this->options["table"] = $this->mTableName[$args[0]]; return $this; } elseif(in_array(strtolower($method),array('count','sum','min','max','avg'),true)){ // 统计查询的实现 $field = isset($args[0])?$args[0]:'*'; return $this->getField(strtoupper($method).'('.$field.') AS tp_'.$method); } elseif(strtolower(substr($method,0,3))=='top'){ // 获取前N条记录 $count = substr($method,3); array_unshift($args,$count); return call_user_func_array(array(&$this, 'topN'), $args); } else { echo "没有找到".$method."函数"; } return; } /** +---------------------------------------------------------- * 查找前N个记录 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param integer $count 记录个数 * @param array $options 查询表达式 +---------------------------------------------------------- * @return array +---------------------------------------------------------- */ public function topN($count,$options=array()) { $options['limit'] = $count; return $this->select($options); } } ?>ViewEngine = new useSmarty(); } public function index() { $this->initController(); STD::go2('/');exit; $this->ViewEngine->display("index.tpl"); } public function debug() { $this->initController(); $this->ViewEngine->display("debug.tpl"); } protected function loadModel($className, $name='') { return $this->loadClass(_MODELS_PATH_, $className, $name); } protected function loadLib($className, $name='') { return $this->loadClass(_LIBS_PATH_, $className, $name); } private function loadClass($path, $className, $name) { if(empty($className))return false; $path .= $className; $className = split('/', $className); $className = $className[count($className)-1]; if(empty($name))$name = $className; if(isset($this->$name))return true; if(file_exists($path.'.class.php')){ require_once($path.'.class.php'); if(class_exists($className)){ $this->$name = new $className(); return true; }else{ die("class $className not exists"); } }else{ die("file ".$path.'.class.php not exists'); } } } ?>"","controller"=>"","action"=>"","pass"=>""); public $url = null; public $recordhit = false; public function piontTo($pUrl) { $this->url = $pUrl; $this->parseParams($pUrl); $this->loadController(); } public function parseParams($pUrl) { if ($pUrl && ('/' != $pUrl[0])) { $pUrl = '/'.$pUrl; } $blockArray = explode ( '/', $pUrl ,3); if (isset($blockArray[1])&&($blockArray[1]==_APP_CGI_)) { return; } elseif(isset($blockArray[1])&&($blockArray[1]==_APP_MANAGE_||$blockArray[1]==_APP_ADMIN_||$blockArray[1]==_APP_INTERFACE_||$blockArray[1]==_APP_XML_)) { $regexp = '/^(?:\/(?:('.$blockArray[1].')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:[\\/\\?](.*))?)?)?))[\/]*$/'; preg_match($regexp, $pUrl, $r); $this->params["basedir"] = $blockArray[1]; if(isset($r[2])) { $this->params["controller"] = trim($r[2]); if(isset($r[3])) { $this->params["action"] = $this->params["basedir"]."_".trim($r[3]); if(isset($r[4])) $this->params["pass"] = explode("/",$r[4]); }else $this->params["action"] = $this->params["basedir"]."_index"; } } elseif(isset($blockArray[1])&&$blockArray[1]==_APP_PLUGIN_) { $regexp = '/^(?:\/(?:('.$blockArray[1].')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:[\\/\\?](.*))?)?))[\/]*$/'; preg_match($regexp, $pUrl, $r); $this->params["basedir"] = $blockArray[1]; if(isset($r[2])) { $this->params["controller"] = trim($r[2]); if(isset($r[3])) { $this->params["pass"] = explode("/",$r[3]); } } } else { $regexp = '/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:[\\/\\?](.*))?)?))[\\/]*$/'; preg_match($regexp, $pUrl, $r); if(isset($r[1])) { $this->params["controller"] = trim($r[1]); if(isset($r[2])) { $this->params["action"] = trim($r[2]); $subblockArray = explode ( '_', $this->params["action"] ,2); if(isset($subblockArray[0])&&($subblockArray[0]==_APP_ADMIN_||$subblockArray[0]==_APP_INTERFACE_||$subblockArray[0]==_APP_XML_)) { $this->params["basedir"] = $subblockArray[0]; } if(isset($r[3])) $this->params["pass"] = explode("/",$r[3]); }else $this->params["action"] = "index"; }else $this->params['action'] = 'index'; if ($this->params["controller"] != "sa") $this->recordhit = true; } $this->params['form'] = STD::getParams($_POST); if (isset($this->params['form']['data'])) { $this->params['data'] = $this->params['form']['data']; } $this->params['url'] = STD::getParams($_GET); foreach ($_FILES as $name => $data) { $this->params['form'][$name] = $data; } if (isset($this->params['form']['xajax'])) { $this->params['xajax'] = $this->params['form']['xajax']; $this->recordhit = false; } if (isset($_SERVER["HTTP_USER_AGENT"])&&$_SERVER["HTTP_USER_AGENT"]=="xmlrpc-php") { $this->params['xmlrpc'] = 1; $this->recordhit = false; } if(isset($this->params['form']['backurl']) && ""!=$this->params['form']['backurl']) $this->params['backurl'] = $this->params['form']['backurl']; elseif (isset($this->params['url']['backurl']) && ""!=$this->params['url']['backurl']) $this->params['backurl'] = $this->params['url']['backurl']; else $this->params['backurl'] = ""; if(isset($this->params['form']['backurl']))$this->params['form']['backurl'] = htmlspecialchars(strip_tags($this->params['form']['backurl'])); if(isset($this->params['url']['backurl']))$this->params['url']['backurl'] = htmlspecialchars(strip_tags($this->params['url']['backurl'])); if(isset($this->params['backurl']))$this->params['backurl'] = htmlspecialchars(strip_tags($this->params['backurl'])); } public function loadController() { if($this->params["basedir"]==_APP_PLUGIN_) { if(file_exists(_PLUGIN_PATH_.$this->params["controller"].".php")) require_once _PLUGIN_PATH_.$this->params["controller"].".php"; elseif(DEBUG<2) STD::redirect($this->url,404); else{ $controller = new Controller(); $controller->debug(); } return; } if(!$this->params["controller"]) { $this->params["controller"] = "index"; } if($this->params["controller"]&&file_exists(_CONTROL_PATH_.$this->params["controller"].".php")) { require_once _CONTROL_PATH_.$this->params["controller"].".php"; if(class_exists(ucfirst($this->params["controller"])."Controller")) { $className = ucfirst($this->params["controller"])."Controller"; $controller = new $className($this->params); if (method_exists($controller,$this->params["action"])) { $controller->{$this->params["action"]}($this->params["pass"]); }else { $controller->index(); } } }elseif(""!=$this->params["basedir"]&&file_exists(_CONTROL_PATH_.$this->params["basedir"].".php")) { $this->recordhit = false; require_once _CONTROL_PATH_.$this->params["basedir"].".php"; if(class_exists(ucfirst($this->params["basedir"])."Controller")) { $className = ucfirst($this->params["basedir"])."Controller"; $controller = new $className($this->params); $controller->index(); } else { if(DEBUG<2) STD::redirect($this->url,404); else{ $controller = new Controller(); $controller->debug(); } } }else { $controller = new Controller(); $this->params['controller'] = 'index'; $this->params['action'] = 'index'; $controller->index(); } } } ?>
( ! ) Fatal error: Class 'STD' not found in D:\web\webroot\index.php on line 13
Call Stack
#TimeMemoryFunctionLocation
10.0000240440{main}( )...\index.php:0