信呼OA版本v2.3.8
This commit is contained in:
759
include/class/mysql.php
Normal file
759
include/class/mysql.php
Normal file
@@ -0,0 +1,759 @@
|
||||
<?php
|
||||
/**
|
||||
*****************************************************************
|
||||
* 联系QQ: 290802026 *
|
||||
* 版 本: V2.0 *
|
||||
* 开发者:雨中磐石工作室 *
|
||||
* 网 址: http://www.rockoa.com/ *
|
||||
* 说 明: 数据库核心类 *
|
||||
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
|
||||
*****************************************************************
|
||||
*/
|
||||
if(!defined('HOST'))exit('not access');
|
||||
abstract class mysql{
|
||||
|
||||
public $conn = null;
|
||||
public $iudcount = 0;
|
||||
public $iudarr = array();
|
||||
public $tran = false;
|
||||
public $rock;
|
||||
|
||||
public $nowsql;
|
||||
public $countsql = 0;
|
||||
public $sqlarr = array();
|
||||
public $total = 0;
|
||||
public $count = 0;
|
||||
public $perfix = PREFIX;
|
||||
public $errorbool = false;
|
||||
public $errormsg = '';
|
||||
public $errorlast = '';
|
||||
public $nowerror = false;
|
||||
public $basename;
|
||||
|
||||
protected $db_host;
|
||||
protected $db_user;
|
||||
protected $db_pass;
|
||||
protected $db_base;
|
||||
|
||||
protected $exparray = array(
|
||||
'eq' => "='?0'", 'neq' => "<>'?0'", 'eqi' => '=?0', 'neqi' => '<>?0', 'lt' => "<'?0'", 'elt' => "<='?0'",
|
||||
'gt' => ">'?0'", 'egt' => ">='?0'", 'lti' => '<?0', 'elti' => '<=?0', 'gti' => '>?0', 'egti' => '>=?0',
|
||||
'like' => "LIKE '%?0%'", 'notlike' => "NOT LIKE '%?0%'", 'leftlike' => "LIKE '%?0'", 'rightlike' => "LIKE '?0%'",
|
||||
'in' => "IN(?0)", 'notin' => "NOT IN(?0)",
|
||||
'between' => "BETWEEN '?0' AND '?1'", 'notbetween' => "NOT BETWEEN '?0' AND '?1'",
|
||||
'betweeni' => "BETWEEN ?0 AND ?1", 'notbetweeni' => "NOT BETWEEN ?0 AND ?1"
|
||||
);
|
||||
|
||||
//sql中禁用方法
|
||||
protected $disabledfua = array('dumpfile','outfile','load_file','system_user');
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->rock = $GLOBALS['rock'];
|
||||
$this->errorbool = false;
|
||||
$this->errormsg = '';
|
||||
if(getconfig('dbencrypt')){
|
||||
$this->db_host = $this->rock->jm->uncrypt(DB_HOST);
|
||||
$this->db_user = $this->rock->jm->uncrypt(DB_USER);
|
||||
$this->db_pass = $this->rock->jm->uncrypt(DB_PASS);
|
||||
$this->db_base = $this->rock->jm->uncrypt(DB_BASE);
|
||||
}else{
|
||||
$this->db_host = DB_HOST;
|
||||
$this->db_user = DB_USER;
|
||||
$this->db_pass = DB_PASS;
|
||||
$this->db_base = DB_BASE;
|
||||
}
|
||||
$this->basename = $this->db_base;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if($this->conn){
|
||||
$this->tranend();
|
||||
$this->close();
|
||||
}
|
||||
//记录访问sql日志
|
||||
if(getconfig('sqllog')){
|
||||
$sql = '';
|
||||
$filstr = 'sqllog_'.date('Y.m.d.H.i.s').'_'.$this->rock->adminid.'_'.str_shuffle('abcdefghijklmn').'.log';
|
||||
foreach($this->sqlarr as $sql1)$sql.="\n\n$sql1;";
|
||||
if($sql!='')$this->rock->createtxt(''.UPDIR.'/sqllog/'.date('Y-m-d').'/'.$filstr.'', "时间[".$this->rock->now."],用户[".$this->rock->adminid.".".$this->rock->adminname."],IP[".$this->rock->ip."],WEB[".$this->rock->web."],URL[".$this->rock->nowurl()."]".$sql);
|
||||
}
|
||||
}
|
||||
|
||||
protected function connect(){}
|
||||
protected function selectdb($name)
|
||||
{
|
||||
$this->basename = $name;
|
||||
}
|
||||
|
||||
protected function querysql($sql){return false;}
|
||||
|
||||
protected function starttran(){}
|
||||
protected function endtran($bo){}
|
||||
|
||||
public function fetch_array($res, $type=0){return false;}
|
||||
public function insert_id(){return 0;}
|
||||
|
||||
public function error(){return '';}
|
||||
public function close(){}
|
||||
|
||||
|
||||
public function changeattr($host, $user, $pass, $base)
|
||||
{
|
||||
$this->db_host = $host;
|
||||
$this->db_user = $user;
|
||||
$this->db_pass = $pass;
|
||||
$this->db_base = $base;
|
||||
}
|
||||
|
||||
public function connectdb()
|
||||
{
|
||||
$this->errormsg = '';
|
||||
$this->connect();
|
||||
return $this->conn;
|
||||
}
|
||||
|
||||
public function query($sql, $ebo=true)
|
||||
{
|
||||
if($this->conn == null)$this->connect();
|
||||
if($this->conn == null)exit('数据库的帐号/密码有错误!'.$this->errormsg.'');
|
||||
$sql = trim($sql);
|
||||
$sql = str_replace(array('[Q]','[q]','{asqom}'), array($this->perfix, $this->perfix,''), $sql);
|
||||
$sqls = strtolower($sql);
|
||||
foreach($this->disabledfua as $fus)if(contain($sqls,$fus))exit('禁止包含'.$fus.'字符串');
|
||||
|
||||
$this->countsql++;
|
||||
$this->sqlarr[] = $sql;
|
||||
$this->nowsql = $sql;
|
||||
$this->count = 0;
|
||||
try {
|
||||
$rsbool = $this->querysql($sql);
|
||||
} catch (Exception $e) {
|
||||
$rsbool = false;
|
||||
$this->errormsg = $e->getMessage();
|
||||
}
|
||||
|
||||
$this->nowerror = false;
|
||||
if(!$rsbool)$this->nowerror = true;
|
||||
|
||||
$stabs = ''.$this->perfix.'log';
|
||||
if(!contain($sql, $stabs) && !$rsbool)$this->errorlast = $this->error(); //最后错误信息
|
||||
|
||||
//记录错误sql
|
||||
if(!$rsbool && $ebo){
|
||||
$txt = '[ERROR SQL]'.chr(10).''.$sql.''.chr(10).''.chr(10).'[Reason]'.chr(10).''.$this->error().''.chr(10).'';
|
||||
$efile = $this->rock->debug($txt,''.DB_DRIVE.'_sqlerr', true);
|
||||
$errmsg = str_replace("'",''', $this->error());
|
||||
if(!contain($sql, $stabs)){
|
||||
m('log')->addlogs('错误SQL',''.$errmsg.'', 2, array(
|
||||
'url' => $efile
|
||||
));
|
||||
}
|
||||
}
|
||||
return $rsbool;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回最后错误信息
|
||||
*/
|
||||
public function lasterror()
|
||||
{
|
||||
$err = $this->errorlast;
|
||||
if($err=='')$err = $this->error();
|
||||
return $err;
|
||||
}
|
||||
|
||||
public function execsql($sql)
|
||||
{
|
||||
$rsa = $this->query($sql);
|
||||
$this->iudarr[]=$rsa;
|
||||
return $rsa;
|
||||
}
|
||||
|
||||
public function getLastSql()
|
||||
{
|
||||
return $this->nowsql;
|
||||
}
|
||||
|
||||
public function getsyscount($lx='')
|
||||
{
|
||||
$to = 0;
|
||||
if($lx=='')return $to;
|
||||
$lx = strtoupper($lx);
|
||||
$rsa = $this->getall('SELECT '.$lx.'() as total');
|
||||
$to = $rsa[0]['total'];
|
||||
return $to;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回使用SQL_CALC_FOUND_ROWS,统计总记录数
|
||||
*/
|
||||
public function found_rows()
|
||||
{
|
||||
return $this->getsyscount('found_rows');
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回update,insert,delete上所影响的条数
|
||||
*/
|
||||
public function row_count()
|
||||
{
|
||||
return $this->getsyscount('row_count');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取select的sql
|
||||
*/
|
||||
public function getsql($arr=array())
|
||||
{
|
||||
$where = $table = $order = $limit = $group = '';
|
||||
$fields = '*';
|
||||
if(isset($arr['table']))$table=$arr['table'];
|
||||
if(isset($arr['where']))$where=$arr['where'];
|
||||
if(isset($arr['order']))$order=$arr['order'];
|
||||
if(isset($arr['limit']))$limit=$arr['limit'];
|
||||
if(isset($arr['group']))$group=$arr['group'];
|
||||
if(isset($arr['fields']))$fields=$arr['fields'];
|
||||
$where = $this->getwhere($where);
|
||||
$table = $this->gettable($table);
|
||||
$sql = "SELECT $fields FROM $table";
|
||||
if($where!=''){
|
||||
//$where = $this->filterstr($where);
|
||||
$sql.=" WHERE $where";
|
||||
}
|
||||
if($order!='')$sql.=" ORDER BY $order";
|
||||
if($group!='')$sql.=" GROUP BY $group";
|
||||
if($limit!='')$sql.=" LIMIT $limit";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
//弃用过滤
|
||||
public function filterstr($str)
|
||||
{
|
||||
$str = strtolower($str);
|
||||
$file= explode(',','delete,drop,update,union,exec,insert,declare,master,truncate,create,alter,database');
|
||||
$res = array();
|
||||
foreach($file as $fid)$res[]='';
|
||||
$str = str_replace($file, $res, $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function getone($table,$where,$fields='*',$order='')
|
||||
{
|
||||
$rows = $this->getrows($table,$where,$fields,$order,'1');
|
||||
$row = false;
|
||||
if($this->count>0)$row=$rows[0];
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function getrows($table,$where,$fields='*',$order='', $limit='',$group='')
|
||||
{
|
||||
$sql = $this->getsql(array(
|
||||
'table' => $table,
|
||||
'where' => $where,
|
||||
'fields'=> $fields,
|
||||
'order' => $order,
|
||||
'limit' => $limit,
|
||||
'group' => $group
|
||||
));
|
||||
return $this->getall($sql);
|
||||
}
|
||||
|
||||
public function getall($sql)
|
||||
{
|
||||
$res=$this->query($sql);
|
||||
$arr=array();
|
||||
if($res){
|
||||
while($row=$this->fetch_array($res)){
|
||||
$arr[] = $row;
|
||||
$this->count++;
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
string table1 a left JOIN table2 b on b.uid=a.id
|
||||
array(table=>$table,join=>'left')
|
||||
*/
|
||||
public function gettable($arr)
|
||||
{
|
||||
if(is_array($arr)){
|
||||
$s = '';$oi=0;
|
||||
foreach($arr as $k=>$v){
|
||||
if($oi==0){
|
||||
$s=''.$v.' a';
|
||||
}else{
|
||||
if($k=='join')$s.=' '.$v.' JOIN';
|
||||
if($k=='table1')$s.=' '.$v.' b';
|
||||
if($k=='where')$s.=' ON '.$v.'';
|
||||
if($k=='where1')$s.=' AND '.$v.'';
|
||||
}
|
||||
$oi++;
|
||||
}
|
||||
$arr = $s;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
条件的
|
||||
$arrs = array(
|
||||
'id|eqi|a' => '0',
|
||||
'name|like' => '我',
|
||||
'id|notin' => '0,12',
|
||||
'enddt|rightlike' => '2015-10',
|
||||
'startdt|between' => '2015-10-01@@@2015-10-31',
|
||||
'price|notbetweeni' => '1@@@10',
|
||||
'sid > ?0 and <?1' => '0@@@2'
|
||||
);
|
||||
*/
|
||||
public function getwhere($where='')
|
||||
{
|
||||
$len = func_num_args();
|
||||
$arr = array();
|
||||
$sfh1 = '';
|
||||
for($i=0; $i<$len; $i++){
|
||||
$sfh = func_get_arg($i);
|
||||
if(is_numeric($sfh)){
|
||||
$arr[] = "`id`='$sfh'";
|
||||
}else if($sfh=='AND' || $sfh=='OR' || $sfh=='and' || $sfh=='or'){
|
||||
$sfh1 = $sfh;
|
||||
}else{
|
||||
$arr[] = $this->_getwhere($sfh);
|
||||
}
|
||||
}
|
||||
$joins = ') AND (';
|
||||
if($sfh1!='')$joins = ') '.$sfh1.' (';
|
||||
$where = join($joins, $arr);
|
||||
if($sfh1!='')$where = "($where)";
|
||||
|
||||
return $where;
|
||||
}
|
||||
private function _getwhere($where='')
|
||||
{
|
||||
if($where=='')return '';
|
||||
if(is_numeric($where)){
|
||||
$where = "`id`='$where'";
|
||||
}else if(is_array($where)){
|
||||
$sarr = array();
|
||||
foreach($where as $fid=>$val){
|
||||
$qz = '';
|
||||
$farr = explode('|', $fid);
|
||||
$fid = $farr[0];
|
||||
$_fhs = "='?0'";
|
||||
if(isset($farr[1])){
|
||||
$_fh = $farr[1];
|
||||
if(isset($this->exparray[$_fh]))$_fhs=$this->exparray[$_fh];
|
||||
}
|
||||
if(isset($farr[2]))$qz=''.$farr[2].'.';
|
||||
$vala = explode('@@@', $val);
|
||||
$val1 = $vala[0];$val2='';
|
||||
if(isset($vala[1]))$val2=$vala[1];
|
||||
$_bo1 = $this->contain($fid,'?0');
|
||||
if($_bo1)$_fhs = $fid;
|
||||
$_fhs = str_replace(array('?0','?1'), array($val1,$val2), $_fhs);
|
||||
$s = $_fhs;
|
||||
if(!$_bo1)$s = ''.$qz.'`'.$fid.'` '.$_fhs.'';
|
||||
$sarr[]=$s;
|
||||
}
|
||||
$where = join(' AND ', $sarr);
|
||||
}
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以$kfied作为主键返回数组
|
||||
*/
|
||||
public function getarr($table, $where='', $fields='*', $kfied='id')
|
||||
{
|
||||
$sql = $this->getsql(array(
|
||||
'table' => $table,
|
||||
'where' => $where,
|
||||
'fields'=> "`$kfied`,$fields"
|
||||
));
|
||||
$res = $this->query($sql);
|
||||
$arr = array();
|
||||
if($res){
|
||||
while($row=$this->fetch_array($res)){
|
||||
$arr[$row[$kfied]] = $row;
|
||||
$this->count++;
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
读取全部同时将第一个字段作为主键(读取的数据存在数组里)
|
||||
*/
|
||||
public function getkeyall($table,$fields,$where='')
|
||||
{
|
||||
$sql = $this->getsql(array(
|
||||
'table' => $table,
|
||||
'where' => $where,
|
||||
'fields'=> $fields
|
||||
));
|
||||
$res=$this->query($sql);
|
||||
$arr=array();
|
||||
if($res){
|
||||
while(list($ka,$ab) = $this->fetch_array($res, 1)){
|
||||
$arr[$ka]=$ab;
|
||||
$this->count++;
|
||||
}
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
读取一条sql语句用规定字符连接起来
|
||||
*/
|
||||
public function getjoinval($table,$fields,$where='',$join=',')
|
||||
{
|
||||
$sql = $this->getsql(array(
|
||||
'table' => $table,
|
||||
'where' => $where,
|
||||
'fields'=> $fields
|
||||
));
|
||||
$res=$this->query($sql);
|
||||
$arr=array();
|
||||
if($res){
|
||||
while(list($kv) = $this->fetch_array($res, 1)){
|
||||
$arr[]=$kv;
|
||||
$this->count++;
|
||||
}
|
||||
}
|
||||
return join($join,$arr);
|
||||
}
|
||||
|
||||
/**
|
||||
读取某行某字段的
|
||||
*/
|
||||
public function getmou($table,$fields,$where,$order='')
|
||||
{
|
||||
$sql = $this->getsql(array(
|
||||
'table' => $table,
|
||||
'where' => $where,
|
||||
'fields'=> $fields,
|
||||
'order' => $order
|
||||
));
|
||||
$res=$this->query($sql);
|
||||
if($res){
|
||||
$row = $this->fetch_array($res, 1);
|
||||
if($row){
|
||||
$this->count = 1;
|
||||
return $row[0];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启事务
|
||||
*/
|
||||
public function routinestart()
|
||||
{
|
||||
$this->starttran();
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交/回滚事务
|
||||
* $bo=null 自动 true 提交,false 回滚
|
||||
*/
|
||||
public function routineend($bo=null)
|
||||
{
|
||||
if(!is_bool($bo))$bo = $this->backsql();
|
||||
$this->endtran($bo);
|
||||
return $bo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 启用事务,没有事务
|
||||
*/
|
||||
private function tranbegin($sql)
|
||||
{
|
||||
//if($this->errorbool)return false;
|
||||
if($this->conn == null)$this->connect();
|
||||
$this->iudcount++;
|
||||
if(!$this->tran){
|
||||
//$this->starttran();
|
||||
//$this->tran=true;
|
||||
}
|
||||
$rsa = $this->query($sql);
|
||||
$this->iudarr[]=$rsa;
|
||||
if(!$rsa)$this->errorbool = true;
|
||||
return $rsa;
|
||||
}
|
||||
|
||||
/**
|
||||
事务结束
|
||||
*/
|
||||
private function tranend()
|
||||
{
|
||||
if($this->tran){
|
||||
//$this->endtran($this->backsql());
|
||||
}
|
||||
$this->tran=false;
|
||||
}
|
||||
|
||||
/**
|
||||
判断插入更新删除sql语句是否有错
|
||||
*/
|
||||
public function backsql()
|
||||
{
|
||||
$subt=true;
|
||||
foreach($this->iudarr as $tra){
|
||||
if(!$tra){
|
||||
$subt=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $subt;
|
||||
}
|
||||
|
||||
public function insert($table,$name,$values,$sel=false)
|
||||
{
|
||||
$sql="insert into `$table` ($name) ";
|
||||
if(!$sel){
|
||||
$sql.="values($values)";
|
||||
}else{
|
||||
$sql.=$values;
|
||||
}
|
||||
return $this->tranbegin($sql);
|
||||
}
|
||||
|
||||
public function update($table,$content,$where)
|
||||
{
|
||||
$where = $this->getwhere($where);
|
||||
$sql="update `$table` set $content where $where ";
|
||||
return $this->tranbegin($sql);
|
||||
}
|
||||
|
||||
public function delete($table,$where)
|
||||
{
|
||||
$where = $this->getwhere($where);
|
||||
$sql="delete from `$table` where $where ";
|
||||
return $this->tranbegin($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
记录添加修改
|
||||
*/
|
||||
public function record($table,$array,$where='')
|
||||
{
|
||||
$addbool = true;
|
||||
if(!$this->isempt($where))$addbool=false;
|
||||
$cont = '';
|
||||
if(is_array($array)){
|
||||
foreach($array as $key=>$val){
|
||||
$cont.=",`$key`=".$this->toaddval($val)."";
|
||||
}
|
||||
$cont = substr($cont,1);
|
||||
}else{
|
||||
$cont = $array;
|
||||
}
|
||||
if($addbool){
|
||||
$sql="insert into `$table` set $cont";
|
||||
}else{
|
||||
$where = $this->getwhere($where);
|
||||
$sql="update `$table` set $cont where $where";
|
||||
}
|
||||
return $this->tranbegin($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
返回总条数
|
||||
*/
|
||||
public function rows($table,$where,$rowtype='count(1)'){
|
||||
return (int)$this->getmou($table,$rowtype,$where);
|
||||
}
|
||||
|
||||
/**
|
||||
返回所有数据库的表
|
||||
*/
|
||||
public function getalltable($base='')
|
||||
{
|
||||
if($base=='')$base = $this->basename;
|
||||
$sql = "select `TABLE_NAME` from information_schema.`TABLES` where `TABLE_SCHEMA`='$base'";
|
||||
$arr = $this->getall($sql);
|
||||
$rows= array();
|
||||
foreach($arr as $k=>$rs)$rows[] = $rs['TABLE_NAME'];
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
返回表所有字段
|
||||
*/
|
||||
public function getallfields($table)
|
||||
{
|
||||
$finfo = $this->gettablefields($table);
|
||||
foreach ($finfo as $val) {
|
||||
$arr[] = $val['name'];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function getfields($table)
|
||||
{
|
||||
$f = $this->getallfields($table);
|
||||
foreach($f as $f1)$arr[$f1]='';
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function gettablefields($table, $base='',$whe='')
|
||||
{
|
||||
if($base=='')$base = $this->db_base;
|
||||
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,`COLUMN_DEFAULT` as dev,`IS_NULLABLE` as isnull,`CHARACTER_MAXIMUM_LENGTH` as lens,`NUMERIC_PRECISION` as xslen1,`NUMERIC_SCALE` as xslen2 from information_schema.COLUMNS where `TABLE_NAME`='$table' and `TABLE_SCHEMA` ='$base' $whe order by `ORDINAL_POSITION`";
|
||||
return $this->getall($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
读取表结构
|
||||
*/
|
||||
public function gettablecolumn($table, $fields='')
|
||||
{
|
||||
$where = '';
|
||||
if($fields!='')$where = "and `COLUMN_NAME`='$fields'";
|
||||
$sql = "select COLUMN_NAME as `name`,DATA_TYPE as `type`,COLUMN_COMMENT as `explain`,COLUMN_TYPE as `types`,COLUMN_DEFAULT as 'defval' from information_schema.COLUMNS where `TABLE_NAME`='$table' and `TABLE_SCHEMA` ='$this->db_base' $where order by `ORDINAL_POSITION`";
|
||||
$arr = $this->getall($sql);
|
||||
$rows = array();
|
||||
foreach($arr as $k=>$rs){
|
||||
$dev = 'NULL';
|
||||
if(!$this->isempt($rs['defval']))$dev=$rs['defval'];
|
||||
$str = "`".$rs['name']."` ".$rs['types']." DEFAULT ".$dev."";
|
||||
|
||||
if(!$this->isempt($rs['explain']))$str.=" COMMENT '".$rs['explain']."'";
|
||||
$rows[] = $str;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function showcreatetable($table)
|
||||
{
|
||||
$sql = "show create table `$table`";
|
||||
$res= $this->query($sql);
|
||||
list($ka,$nr) = $this->fetch_array($res, 1);
|
||||
return $nr;
|
||||
}
|
||||
|
||||
/**
|
||||
判断变量是否为空
|
||||
*/
|
||||
public function isempt($str)
|
||||
{
|
||||
return isempt($str);
|
||||
}
|
||||
|
||||
public function contain($str,$a)
|
||||
{
|
||||
$bool=false;
|
||||
if(!$this->isempt($a) && !$this->isempt($str)){
|
||||
$ad=strpos($str,$a);
|
||||
if($ad>0||!is_bool($ad))$bool=true;
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
转换数据库可插入的对象
|
||||
*/
|
||||
public function toaddval($str)
|
||||
{
|
||||
$adstr="'$str'";
|
||||
if($this->isempt($str)){
|
||||
$adstr='null';
|
||||
}else{
|
||||
if(substr($str,0,4)=='(&;)')$adstr=substr($str,4);
|
||||
}
|
||||
return $adstr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换特殊符合'
|
||||
*/
|
||||
public function tocovexec($str, $lx=0)
|
||||
{
|
||||
$str = str_replace('\'', ''',$str);
|
||||
if($lx==1){
|
||||
$str = str_replace("\n", '',$str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
创建随机编号
|
||||
*/
|
||||
public function ranknum($table,$field='num',$n=6, $dx=0)
|
||||
{
|
||||
$arr = 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');
|
||||
$num = '';
|
||||
for($i=1;$i<=$n;$i++)$num.=$arr[rand(0,count($arr)-1)];
|
||||
if($dx==1)$num = strtoupper($num);//转换成大写
|
||||
$rsnum = $this->getmou($table,$field,"`$field`='$num'");
|
||||
return ($rsnum)?$this->ranknum($table,$field,$n, $dx):$num;
|
||||
}
|
||||
|
||||
/**
|
||||
流水编号
|
||||
*/
|
||||
public function sericnum($num, $table,$fields='sericnum', $ws=4, $whe='')
|
||||
{
|
||||
$dts = explode('-', date('Y-m-d'));
|
||||
$ymd = $dts[0].$dts[1].$dts[2];
|
||||
$ym = $dts[0].$dts[1];
|
||||
$num = str_replace('Ymd', $ymd, $num);
|
||||
$num = str_replace('Ym', $ym, $num);
|
||||
$num = str_replace('Year', $dts[0], $num);
|
||||
$num = str_replace('Day', $dts[2], $num);
|
||||
$num = str_replace('Month', $dts[1], $num);
|
||||
$where = "`$fields` like '".$num."%' $whe";
|
||||
$max = (int)$this->getmou($table, "max(cast(replace(`$fields`,'$num','') as decimal(10)))", $where);
|
||||
$max++;
|
||||
$wsnum = ''.$max.'';
|
||||
$len = strlen($wsnum);
|
||||
$oix = $ws - $len;
|
||||
for($i=1;$i<=$oix;$i++)$wsnum='0'.$wsnum;
|
||||
$num .= $wsnum;
|
||||
return $num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有顶级信息连接起来
|
||||
* @param $table 表名
|
||||
* @param $pfields 上级字段 $jfield 要连接的字段名 $afid = 值
|
||||
*/
|
||||
private $joinarr=array();
|
||||
public function getpval($table,$pfields,$jfield,$afid,$plit='/',$afield='id',$maxlen=8)
|
||||
{
|
||||
$this->joinarr = array();
|
||||
$this->joinlen = 0;
|
||||
$this->getpvala($table,$pfields,$jfield,$afid,$afield,$maxlen);
|
||||
return join($plit,array_reverse($this->joinarr));
|
||||
}
|
||||
private function getpvala($table,$pfields,$jfield,$afid,$afield,$maxlen)
|
||||
{
|
||||
if(count($this->joinarr)>=$maxlen)return;
|
||||
$rsa = $this->getone($table,"`$afield`='$afid'","`id`,`$pfields`,`$jfield`");
|
||||
if($rsa){
|
||||
$this->joinarr[]=$rsa[$jfield];
|
||||
$pid = $rsa[$pfields];
|
||||
if($pid!=$afid)if($this->rows($table,"`$afield`='$pid'")>0)$this->getpvala($table,$pfields,$jfield,$pid,$afield,$maxlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
class DB{
|
||||
|
||||
public static $tablename;
|
||||
|
||||
public static function table($tab)
|
||||
{
|
||||
self::$tablename = ''.getconfig('.perfix.').$tab.'';
|
||||
return m($tab);
|
||||
}
|
||||
|
||||
public static function where($f, $v)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
90
include/class/mysqlClass.php
Normal file
90
include/class/mysqlClass.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
include_once('mysql.php');
|
||||
class mysqlClass extends mysql{
|
||||
|
||||
|
||||
protected function connect()
|
||||
{
|
||||
$this->errormsg = '';
|
||||
if(!function_exists('mysql_connect'))exit('不支持mysql_connect的php扩展');
|
||||
$this->conn = @mysql_connect($this->db_host,$this->db_user, $this->db_pass);
|
||||
$msg = $this->error();
|
||||
if($msg){
|
||||
$this->conn = null;
|
||||
$this->errormsg = $msg;
|
||||
}else{
|
||||
$this->selectdb($this->db_base);
|
||||
$this->query("SET NAMES 'utf8'");
|
||||
}
|
||||
}
|
||||
|
||||
protected function selectdb($name)
|
||||
{
|
||||
$this->basename = $name;
|
||||
@mysql_select_db($name, $this->conn);
|
||||
$msg = $this->error();
|
||||
if($msg){
|
||||
$this->errormsg = $msg;
|
||||
}
|
||||
}
|
||||
|
||||
protected function querysql($sql)
|
||||
{
|
||||
return mysql_query($sql,$this->conn);
|
||||
}
|
||||
|
||||
public function fetch_array($result, $type = 0)
|
||||
{
|
||||
$result_type = ($type==0)?MYSQL_ASSOC:MYSQL_NUM;
|
||||
return mysql_fetch_array($result, $result_type);
|
||||
}
|
||||
|
||||
public function insert_id()
|
||||
{
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
protected function starttran()
|
||||
{
|
||||
$this->query('BEGIN');
|
||||
}
|
||||
|
||||
protected function endtran($bo)
|
||||
{
|
||||
if(!$bo){
|
||||
$this->query('ROLLBACK');
|
||||
}else{
|
||||
$this->query('COMMIT');
|
||||
}
|
||||
}
|
||||
|
||||
public function getalltable_old()
|
||||
{
|
||||
@$result = mysql_list_tables($this->basename);
|
||||
while($row = mysql_fetch_row($result)) {
|
||||
$arr[]=$row[0];
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function getallfields($table)
|
||||
{
|
||||
$sql = 'select * from '.$table.' limit 0,0';
|
||||
$row = $this->query($sql);
|
||||
$scount = mysql_num_fields($row);
|
||||
for($i=0; $i<$scount; $i++){
|
||||
$arr[] = mysql_field_name($row, $i);
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function error()
|
||||
{
|
||||
return mysql_error();
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
return @mysql_close($this->conn);
|
||||
}
|
||||
}
|
||||
71
include/class/mysqliClass.php
Normal file
71
include/class/mysqliClass.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
include_once('mysql.php');
|
||||
class mysqliClass extends mysql{
|
||||
|
||||
|
||||
protected function connect()
|
||||
{
|
||||
$this->errormsg = '';
|
||||
$this->conn = @new mysqli($this->db_host,$this->db_user, $this->db_pass, $this->db_base);
|
||||
if (mysqli_connect_errno()) {
|
||||
$this->conn = null;
|
||||
$this->errormsg = mysqli_connect_error();
|
||||
}else{
|
||||
$this->selectdb($this->db_base);
|
||||
$this->conn->query("SET NAMES 'utf8'");
|
||||
}
|
||||
}
|
||||
|
||||
protected function querysql($sql)
|
||||
{
|
||||
return $this->conn->query($sql);
|
||||
}
|
||||
|
||||
public function fetch_array($result, $type = 0)
|
||||
{
|
||||
$result_type = ($type==0)?MYSQLI_ASSOC:MYSQLI_NUM;
|
||||
return $result->fetch_array($result_type);
|
||||
}
|
||||
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->conn->insert_id;
|
||||
}
|
||||
|
||||
protected function starttran()
|
||||
{
|
||||
$this->conn->autocommit(FALSE);
|
||||
}
|
||||
|
||||
protected function endtran($bo)
|
||||
{
|
||||
if(!$bo){
|
||||
$this->conn->rollback();
|
||||
}else{
|
||||
$this->conn->commit();
|
||||
}
|
||||
}
|
||||
|
||||
public function getallfields($table)
|
||||
{
|
||||
$sql = 'select * from '.$table.' limit 0,0';
|
||||
$result = $this->query($sql);
|
||||
if(!$result)return array();
|
||||
$finfo = $result->fetch_fields();
|
||||
foreach ($finfo as $val) {
|
||||
$arr[] = $val->name;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function error()
|
||||
{
|
||||
return 'mysqliError:'.$this->conn->error;
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if($this->conn==null)return;
|
||||
return $this->conn->close();
|
||||
}
|
||||
}
|
||||
66
include/class/pdoClass.php
Normal file
66
include/class/pdoClass.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
include_once('mysql.php');
|
||||
class pdoClass extends mysql{
|
||||
|
||||
|
||||
protected function connect()
|
||||
{
|
||||
$this->errormsg = '';
|
||||
try {
|
||||
$this->conn = @new PDO('mysql:host='.$this->db_host.';dbname='.$this->db_base.'', $this->db_user, $this->db_pass);
|
||||
$this->conn->query("SET NAMES 'utf8'");
|
||||
$this->selectdb($this->db_base);
|
||||
} catch (PDOException $e) {
|
||||
$this->conn = null;
|
||||
$this->errormsg = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
protected function querysql($sql)
|
||||
{
|
||||
try {
|
||||
$bo = $this->conn->query($sql);
|
||||
} catch (PDOException $e) {
|
||||
$bo = false;
|
||||
$this->errormsg = $e->getMessage();
|
||||
}
|
||||
return $bo;
|
||||
}
|
||||
|
||||
public function fetch_array($result, $type = 0)
|
||||
{
|
||||
$result_type = ($type==0)? PDO::FETCH_ASSOC : PDO::FETCH_NUM;
|
||||
return $result->fetch($result_type);
|
||||
}
|
||||
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->conn->lastInsertId();
|
||||
}
|
||||
|
||||
protected function starttran()
|
||||
{
|
||||
$this->conn->beginTransaction();
|
||||
}
|
||||
|
||||
protected function endtran($bo)
|
||||
{
|
||||
if(!$bo){
|
||||
$this->conn->rollBack();
|
||||
}else{
|
||||
$this->conn->commit();
|
||||
}
|
||||
}
|
||||
|
||||
public function error()
|
||||
{
|
||||
$str = $this->conn->errorInfo();
|
||||
return 'pdoError('.$str[0].'):'.$str[2].''.$this->errormsg.'';
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
if($this->conn==null)return;
|
||||
return $this->conn=null;
|
||||
}
|
||||
}
|
||||
681
include/class/rockClass.php
Normal file
681
include/class/rockClass.php
Normal file
@@ -0,0 +1,681 @@
|
||||
<?php
|
||||
/**
|
||||
*****************************************************************
|
||||
* 联系QQ: 290802026 *
|
||||
* 版 本: V2.0 *
|
||||
* 开发者:雨中磐石(rainrock) *
|
||||
* 邮 箱: admin@rockoa.com *
|
||||
* 说 明: 基础操作类方法 *
|
||||
* 备 注: 未经允许不得商业出售,代码欢迎参考纠正 *
|
||||
*****************************************************************
|
||||
*/
|
||||
final class rockClass
|
||||
{
|
||||
public $ip;
|
||||
public $host;
|
||||
public $url;
|
||||
public $win;
|
||||
public $web;
|
||||
public $unarr;
|
||||
public $now;
|
||||
public $date;
|
||||
public $jm;
|
||||
|
||||
|
||||
public $adminid;
|
||||
public $adminuser;
|
||||
public $adminname;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ip = $this->getclientip();
|
||||
$this->host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '' ;
|
||||
$this->url = '';
|
||||
$this->isqywx = false;
|
||||
$this->win = php_uname();
|
||||
$this->HTTPweb = isset($_SERVER['HTTP_USER_AGENT'])? $_SERVER['HTTP_USER_AGENT'] : '' ;
|
||||
$this->web = $this->getbrowser();
|
||||
$this->unarr = explode(',','1,2');
|
||||
$this->now = $this->now();
|
||||
$this->date = date('Y-m-d');
|
||||
$this->lvlaras = explode(',','select ,
|
||||
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');
|
||||
$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*');
|
||||
$this->lvlarab = array();
|
||||
foreach($this->lvlaraa as $_i)$this->lvlarab[]='';
|
||||
}
|
||||
|
||||
/**
|
||||
* 特殊字符过滤
|
||||
*/
|
||||
public function xssrepstr($str)
|
||||
{
|
||||
$xpd = explode(',','(,), , ,<,>,\\,*,&,%,$,^,[,],{,},!,@,#,",+,?,;\'');
|
||||
$xpd[]= "\n";
|
||||
return str_ireplace($xpd, '', $str);
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取IP
|
||||
*/
|
||||
public function getclientip()
|
||||
{
|
||||
$ip = '';
|
||||
if(isset($_SERVER['HTTP_CLIENT_IP'])){
|
||||
$ip = $_SERVER['HTTP_CLIENT_IP'];
|
||||
}else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||
}else if(isset($_SERVER['REMOTE_ADDR'])){
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
$ip= htmlspecialchars($this->xssrepstr($ip));
|
||||
if($ip){$ipar = explode('.', $ip);foreach($ipar as $ip1)if(!is_numeric($ip1))$ip='';}
|
||||
if(!$ip)$ip = 'unknow';
|
||||
return $ip;
|
||||
}
|
||||
|
||||
public function initRock()
|
||||
{
|
||||
$this->jm = c('jm', true);
|
||||
$this->adminid = (int)$this->session('adminid',0);
|
||||
$this->adminname= $this->session('adminname');
|
||||
$this->adminuser= $this->session('adminuser');
|
||||
}
|
||||
|
||||
public function iconvsql($str,$lx=0)
|
||||
{
|
||||
$str = str_ireplace($this->lvlaraa,$this->lvlarab,$str);
|
||||
$str = str_replace("\n",'', $str);
|
||||
if($lx==1)$str = str_replace(array(' ',' ',' '),array('','',''),$str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
private function unstr($str)
|
||||
{
|
||||
$ystr = '';
|
||||
for($i=0;$i<count($this->unarr);$i++){
|
||||
if($this->contain($str,$this->unarr[$i])){
|
||||
$ystr = $this->unarr[$i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $ystr;
|
||||
}
|
||||
|
||||
public function get($name,$dev='', $lx=0)
|
||||
{
|
||||
$val=$dev;
|
||||
if(isset($_GET[$name]))$val=$_GET[$name];
|
||||
if($this->isempt($val))$val=$dev;
|
||||
return $this->jmuncode($val, $lx, $name);
|
||||
}
|
||||
|
||||
public function post($name,$dev='', $lx=0)
|
||||
{
|
||||
$val = '';
|
||||
if(isset($_POST[$name])){$val=$_POST[$name];}else{if(isset($_GET[$name]))$val=$_GET[$name];}
|
||||
if($this->isempt($val))$val=$dev;
|
||||
return $this->jmuncode($val, $lx, $name);
|
||||
}
|
||||
|
||||
public function request($name,$dev='', $lx=0)
|
||||
{
|
||||
return $this->post($name,$dev,$lx);
|
||||
}
|
||||
|
||||
//get和post参数处理$lx=1:rockjm,6:basejm, 3:判断是否rockjm
|
||||
public function jmuncode($s, $lx=0, $na='')
|
||||
{
|
||||
$jmbo = false;
|
||||
if($lx==3)$jmbo = $this->isjm($s);
|
||||
if(substr($s, 0, 7)=='rockjm_' || $lx == 1 || $jmbo){
|
||||
$s = str_replace('rockjm_', '', $s);
|
||||
$s = $this->jm->uncrypt($s);
|
||||
if($lx==1){
|
||||
$jmbo = $this->isjm($s);
|
||||
if($jmbo)$s = $this->jm->uncrypt($s);
|
||||
}
|
||||
}
|
||||
if(substr($s, 0, 7)=='basejm_' || $lx==5){
|
||||
$s = str_replace('basejm_', '', $s);
|
||||
$s = $this->jm->base64decode($s);
|
||||
}
|
||||
$s=str_replace("'", ''', $s);
|
||||
$s=str_replace('%20', '', $s);
|
||||
if($lx==2)$s=str_replace(array('{','}'), array('[H1]','[H2]'), $s);
|
||||
$str = strtolower($s);
|
||||
foreach($this->lvlaras as $v1)if($this->contain($str, $v1)){
|
||||
$this->debug(''.$na.'《'.$s.'》error:包含非法字符《'.$v1.'》','params_err');
|
||||
$s = $this->lvlarrep($str, $v1);
|
||||
$str = $s;
|
||||
}
|
||||
$cslv = array('m','a','p','d','ip','web','host','ajaxbool','token','adminid');
|
||||
if(in_array($na, $cslv))$s = $this->xssrepstr($s);
|
||||
return $this->reteistrs($s);
|
||||
}
|
||||
//参数里面禁用/*,*/
|
||||
private function reteistrs($s){
|
||||
$lvlaras = array('/*','*/');
|
||||
$bo = false;
|
||||
foreach($lvlaras as $v1)if($this->contain($s, $v1)){
|
||||
$s = str_replace($v1,'', $s);
|
||||
$bo = true;
|
||||
}
|
||||
if($bo)$s = $this->reteistrs($s);
|
||||
return $s;
|
||||
}
|
||||
private function lvlarrep($str, $v1){
|
||||
$s = str_ireplace($v1,'', $str);
|
||||
if(contain($s, $v1))$s = $this->lvlarrep($s, $v1);
|
||||
return $s;
|
||||
}
|
||||
public function debug($txt, $lx, $dabo=false)
|
||||
{
|
||||
if(!DEBUG && !$dabo)return;
|
||||
$txt = ''.$txt.''.chr(10).'[URL]'.chr(10).''.$this->nowurl().'';
|
||||
if($_POST){
|
||||
$pstr = '';
|
||||
foreach($_POST as $k=>$v)$pstr.=''.chr(10).'['.$k.']:'.$v.'';
|
||||
$txt.=''.chr(10).''.chr(10).'[POST]'.$pstr.'';
|
||||
}
|
||||
$txt.=''.chr(10).''.chr(10).'[IP]'.chr(10).''.$this->ip.'';
|
||||
$txt.=''.chr(10).''.chr(10).'[datetime]'.chr(10).''.$this->now().'';
|
||||
$txt.=''.chr(10).''.chr(10).'[Browser]'.chr(10).''.$this->HTTPweb.'';
|
||||
|
||||
$file = ''.UPDIR.'/logs/'.date('Y-m').'/'.$lx.''.date('YmdHis').'_'.str_shuffle('abcdefghijklmn').'.txt';
|
||||
$this->createtxt($file, $txt);
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否加密的字符串
|
||||
*/
|
||||
public function isjm($s)
|
||||
{
|
||||
$bo = false;
|
||||
if(!$s)return $bo;
|
||||
$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);
|
||||
return $bo;
|
||||
$a = explode('0', $s);
|
||||
$len= count($a);
|
||||
if($len>1){
|
||||
$ls=(int)$a[$len-1];
|
||||
if($ls>=1&&$ls<=14)$bo=true;
|
||||
}
|
||||
return $bo;
|
||||
}
|
||||
|
||||
public function savesession($arr)
|
||||
{
|
||||
foreach($arr as $kv=>$vv)$this->setsession($kv,$vv);
|
||||
}
|
||||
|
||||
public function setsession($kv,$vv)
|
||||
{
|
||||
$_SESSION[QOM.$kv]=$vv;
|
||||
}
|
||||
|
||||
public function session($name,$dev='')
|
||||
{
|
||||
$val = '';
|
||||
$name = QOM.$name;
|
||||
if(isset($_SESSION[$name]))$val=$_SESSION[$name];
|
||||
if($this->isempt($val))$val=$dev;
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function clearsession($name)
|
||||
{
|
||||
$arrn=explode(',',$name);
|
||||
for($i=0;$i<count($arrn);$i++){
|
||||
@$_SESSION[QOM.$arrn[$i]]='';
|
||||
}
|
||||
}
|
||||
|
||||
public function clearallsession()
|
||||
{
|
||||
foreach($_SESSION as $key=>$value){
|
||||
$this->clearsession($key);
|
||||
}
|
||||
}
|
||||
|
||||
//保存cookie,默认是7天
|
||||
public function savecookie($namarr,$valarr,$expire=360,$path='/',$domain='')
|
||||
{
|
||||
$time = time()+$expire*3600*24;
|
||||
$arrn = explode(',',$namarr);
|
||||
$valn = $valarr;
|
||||
if(!is_array($valarr))$valn=explode(',',$valarr);
|
||||
for($i=0;$i<count($arrn);$i++){
|
||||
setcookie(QOM.$arrn[$i],$valn[$i], $time, $path,'');
|
||||
}
|
||||
}
|
||||
|
||||
//获取cookie
|
||||
public function cookie($name,$dev='')
|
||||
{
|
||||
$val = '';
|
||||
$name = QOM.$name;
|
||||
if(isset($_COOKIE[$name]))$val=$_COOKIE[$name];
|
||||
if($this->isempt($val))$val=$dev;
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function getcookie($namarr)
|
||||
{
|
||||
$arrn=explode(',',$namarr);
|
||||
for($i=0;$i<count($arrn);$i++){
|
||||
$val[$arrn[$i]]=$this->cookie($arrn[$i]);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
//删除cookie
|
||||
public function clearcookie($name,$path='/',$domain='')
|
||||
{
|
||||
//$domain=(empty($domain))?$this->host:$domain;
|
||||
$arr=explode(',',$name);
|
||||
for($i=0;$i<count($arr);$i++){
|
||||
setcookie(QOM.$arr[$i],'',time()-1,$path,$domain);
|
||||
@$_COOKIE[$arr[$i]]='';
|
||||
}
|
||||
}
|
||||
|
||||
//删除所有cookie
|
||||
public function clearallcookie()
|
||||
{
|
||||
foreach($_COOKIE as $key=>$value){
|
||||
$this->clearcookie($key);
|
||||
}
|
||||
}
|
||||
|
||||
//跳转
|
||||
public function location($url)
|
||||
{
|
||||
header('location:'.$url.'');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function now($type='Y-m-d H:i:s',$kmti='')
|
||||
{
|
||||
if($kmti=='')$kmti=time();
|
||||
return date($type,$kmti);
|
||||
}
|
||||
|
||||
public function cnweek($date)
|
||||
{
|
||||
$arr = array('日','一','二','三','四','五','六');
|
||||
return $arr[date('w', strtotime($date))];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断类型0微信,1钉钉,2安卓原生app,3企业微信,4华为welink,5苹果,6QQ,7REIM平台
|
||||
*/
|
||||
public function iswebbro($lx=0)
|
||||
{
|
||||
$lxar = array('micromessenger','dingtalk','xinhuapp','wxwork','huawei-anyoffice','iphone','mqqbrowser','reimplat');
|
||||
return contain(strtolower($this->HTTPweb), $lxar[$lx]);
|
||||
}
|
||||
|
||||
public function getbrowser()
|
||||
{
|
||||
$web = $this->HTTPweb;
|
||||
$val = 'IE';
|
||||
$parr = array(
|
||||
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'),
|
||||
array('MSIE 13'),array('Firefox'),array('OPR/','Opera'),array('Edge'),array('MQQBrowser','mqq'),array('Chrome'),array('Safari'),array('Android'),array('iPhone')
|
||||
);
|
||||
foreach($parr as $wp){
|
||||
if(contain($web, $wp[0])){
|
||||
$val = $wp[0];
|
||||
if(isset($wp[1]))$val = $wp[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$web = strtolower($web);
|
||||
if(contain($web,'micromessenger'))$val='wxbro';//微信浏览器
|
||||
if(contain($web,'dingtalk'))$val='ding';//钉钉浏览器
|
||||
if($val=='wxbro' && contain($web, 'wxwork'))$this->isqywx = true;
|
||||
return $val;
|
||||
}
|
||||
|
||||
public function ismobile()
|
||||
{
|
||||
$web = strtolower($this->HTTPweb);
|
||||
$bo = false;
|
||||
$strar = explode(',','micromessenger,android,mobile,iphone');
|
||||
foreach($strar as $str){
|
||||
if(contain($web, $str))return true;
|
||||
}
|
||||
return $bo;
|
||||
}
|
||||
|
||||
public function script($daima)
|
||||
{
|
||||
echo '<script type="text/javascript">
|
||||
'.$daima.'
|
||||
</script>';
|
||||
}
|
||||
|
||||
/**
|
||||
全角半角转换
|
||||
*/
|
||||
public function replace($str,$quantoban=true)
|
||||
{
|
||||
$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');
|
||||
$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');
|
||||
if($quantoban){
|
||||
$str=str_replace($replace,$search,$str);
|
||||
}else{
|
||||
$str=str_replace($search,$replace,$str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
过滤特殊符合
|
||||
*/
|
||||
public function repmark($str)
|
||||
{
|
||||
$search=array('select','delete','join','inner','outer');
|
||||
$str=strtolower($str);//转为小写
|
||||
$str=str_replace($search,'',$str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
html编码
|
||||
*/
|
||||
public function htmlescape($str)
|
||||
{
|
||||
$str = htmlspecialchars($str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
小数点位数
|
||||
*/
|
||||
public function number($num,$w=2)
|
||||
{
|
||||
if(!$num)$num='0';
|
||||
return number_format($num,$w,'.','');
|
||||
}
|
||||
|
||||
/**
|
||||
是否包含返回bool
|
||||
*/
|
||||
public function contain($str,$a)
|
||||
{
|
||||
$bool=false;
|
||||
if(!$this->isempt($a) && !$this->isempt($str)){
|
||||
$ad=strpos($str,$a);
|
||||
if($ad>0||!is_bool($ad))$bool=true;
|
||||
}
|
||||
return $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
将'转换'
|
||||
*/
|
||||
public function covexec($str)
|
||||
{
|
||||
$dt = date('Y-m-d');
|
||||
$str = str_replace(
|
||||
array(''', ''','[F]', '[X]', '[K]', '[A]', '[D]', '[adminid]', '[date]', '{adminid}', '{date}','[H1]','[H2]','&#xing;'),
|
||||
array('\'', '\'', '\'', '\\', ' ', 'and', '=', $this->adminid, $dt, $this->adminid, $dt,'{','}','*'),
|
||||
$str
|
||||
);
|
||||
return $str;
|
||||
}
|
||||
|
||||
//判断是否为空
|
||||
public function isempt($str)
|
||||
{
|
||||
$bool=false;
|
||||
if( ($str==''||$str==NULL||empty($str)) && (!is_numeric($str)) )$bool=true;
|
||||
return $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
地址
|
||||
*/
|
||||
public function rewrite($m,$a,$s)
|
||||
{
|
||||
$url = '';
|
||||
if(REWRITE=='true'){
|
||||
$url = ''.$m.'';
|
||||
if($a == '' && $s == ''){
|
||||
$url = ''.$url.'.html';
|
||||
}elseif($a == ''){
|
||||
$url = ''.$url.'_'.$s.'.html';
|
||||
}else{
|
||||
$url = ''.$url.'_'.$a.'_'.$s.'_a.html';
|
||||
}
|
||||
}else{
|
||||
$url = 'index.php?m='.$m.'';
|
||||
if($a != '')$url.='&a='.$a.'';
|
||||
if($s != '')$url.='&s='.$s.'';
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
//设置所有的GET方法
|
||||
public function setallcan($rep=4)
|
||||
{
|
||||
foreach($_GET as $key=>$val)$GLOBALS['get_'.$key]=$this->get($key,'',0);
|
||||
foreach($_POST as $key=>$val)$GLOBALS['post_'.$key]=$this->post($key,'',0);
|
||||
}
|
||||
|
||||
/**
|
||||
如果字符为空,使用默认的
|
||||
*/
|
||||
public function repempt($str,$dev='')
|
||||
{
|
||||
$s = $str;
|
||||
if($this->isempt($s))$s=$dev;
|
||||
return $s;
|
||||
}
|
||||
|
||||
//返回文件大小
|
||||
public function formatsize($size)
|
||||
{
|
||||
$arr = array('Byte', 'KB', 'MB', 'GB', 'TB', 'PB');
|
||||
if($size == 0)return '0';
|
||||
$e = floor(log($size)/log(1024));
|
||||
return number_format(($size/pow(1024,floor($e))),2,'.','').' '.$arr[$e];
|
||||
}
|
||||
|
||||
/**
|
||||
采集字符串截取
|
||||
*/
|
||||
public function getcai($content,$start,$end)
|
||||
{
|
||||
$geju = strpos($content,$start);
|
||||
if($geju===false){
|
||||
$cont1='';
|
||||
}else{
|
||||
$stard = $geju+strlen($start);
|
||||
$cont1 = substr($content,$stard);
|
||||
$endd = strpos($cont1,$end);
|
||||
$cont1 = substr($cont1,0,$endd);
|
||||
$cont1 = trim($cont1);
|
||||
}
|
||||
return $cont1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入文件
|
||||
*/
|
||||
public function createtxt($path, $txt)
|
||||
{
|
||||
$this->createdir($path);
|
||||
$path = ''.ROOT_PATH.'/'.$path.'';
|
||||
@$file = fopen($path,'w');
|
||||
$bo = false;
|
||||
if($file){
|
||||
$bo = true;
|
||||
if($txt)$bo = fwrite($file,$txt);
|
||||
fclose($file);
|
||||
}
|
||||
return $bo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
*/
|
||||
public function createdir($path, $oi=1)
|
||||
{
|
||||
$zpath = explode('/', $path);
|
||||
$len = count($zpath);
|
||||
$mkdir = '';
|
||||
for($i=0; $i<$len-$oi; $i++){
|
||||
if(!isempt($zpath[$i])){
|
||||
$mkdir.='/'.$zpath[$i].'';
|
||||
$wzdir = ROOT_PATH.''.$mkdir;
|
||||
if(!is_dir($wzdir)){
|
||||
mkdir($wzdir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function stringformat($str, $arr=array())
|
||||
{
|
||||
$s = $str;
|
||||
for($i=0; $i<count($arr); $i++){
|
||||
$s=str_replace('?'.$i.'', $arr[$i], $s);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function strformat($str)
|
||||
{
|
||||
$len = func_num_args();
|
||||
$arr = array();
|
||||
for($i=1; $i<$len; $i++)$arr[] = func_get_arg($i);
|
||||
$s = $this->stringformat($str, $arr);
|
||||
return $s;
|
||||
}
|
||||
|
||||
public function T($n)
|
||||
{
|
||||
return PREFIX.''.$n;
|
||||
}
|
||||
|
||||
public function reparr($str, $arr=array())
|
||||
{
|
||||
if($this->isempt($str))return '';
|
||||
preg_match_all('/\{(.*?)\}/', $str, $list);
|
||||
$s = $str;
|
||||
foreach($list[1] as $k=>$nrs){
|
||||
$nts = '';
|
||||
if(isset($arr[$nrs]))$nts = $arr[$nrs];
|
||||
$s = str_replace('{'.$nrs.'}', $nts, $s);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
字段中包含
|
||||
*/
|
||||
public function dbinstr($fiekd, $str, $spl1=',', $spl2=',')
|
||||
{
|
||||
return "instr(concat('$spl1', $fiekd, '$spl2'), '".$spl1.$str.$spl2."')>0";
|
||||
}
|
||||
|
||||
public function debugs($str, $lxs='')
|
||||
{
|
||||
if(!DEBUG)return;
|
||||
if(is_array($str))$str = json_encode($str, JSON_UNESCAPED_UNICODE);
|
||||
$msg = '['.$this->now.']:'.$this->nowurl().''.chr(10).''.$str.'';
|
||||
$mkdir = ''.UPDIR.'/logs/'.date('Y-m').'';
|
||||
$this->createtxt(''.$mkdir.'/'.$lxs.''.date('Y-m-d.H.i.s').'_'.str_shuffle('abcdefghijklmn').'.log', $msg);
|
||||
}
|
||||
|
||||
public function arrvalue($arr, $k, $dev='')
|
||||
{
|
||||
$val = $dev;
|
||||
if(isset($arr[$k]))$val= $arr[$k];
|
||||
return $val;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取当前访问全部url
|
||||
*/
|
||||
public function nowurl()
|
||||
{
|
||||
if(!isset($_SERVER['HTTP_HOST']))return '';
|
||||
$qz = 'http';
|
||||
if($_SERVER['SERVER_PORT']==443)$qz='https';
|
||||
$url = ''.$qz.'://'.$_SERVER['HTTP_HOST'];
|
||||
if(isset($_SERVER['REQUEST_URI']))$url.= $_SERVER['REQUEST_URI'];
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前访问URL地址
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
$url = $this->nowurl();
|
||||
$wz = strrpos($url,'/');
|
||||
return substr($url,0, $wz+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配
|
||||
*/
|
||||
public function matcharr($str, $lx=0)
|
||||
{
|
||||
$match = '/\{(.*?)\}/';
|
||||
if($lx==1)$match = '/\[(.*?)\]/';
|
||||
if($lx==2)$match = '/\`(.*?)\`/';
|
||||
if($lx==3)$match = '/\#(.*?)\#/';
|
||||
preg_match_all($match, $str, $list);
|
||||
$barr = array();
|
||||
foreach($list[1] as $k=>$nrs){
|
||||
$barr[] = $nrs;
|
||||
}
|
||||
return $barr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 函数参数转为key
|
||||
*/
|
||||
public function getfunkey($arr=array(),$qz='a')
|
||||
{
|
||||
$s = '';
|
||||
foreach($arr as $k=>$v)$s.='_'.$v.'';
|
||||
$s = ''.$qz.''.$s.'';
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取外网地址
|
||||
*/
|
||||
public function getouturl($dz='')
|
||||
{
|
||||
if($dz=='')$dz = URL;
|
||||
$xurl = URL;
|
||||
$xurl1 = getconfig('outurl');
|
||||
if(!isempt($xurl1))$xurl = $xurl1;
|
||||
if(substr($xurl,-1)!='/')$xurl.='/';
|
||||
return $xurl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个完整绝对路径
|
||||
*/
|
||||
public function gethttppath($path, $url='', $dev='')
|
||||
{
|
||||
if($url=='')$url = URL;
|
||||
if(isempt($path))return $dev;
|
||||
if(contain($path, '{FILEURL}')){
|
||||
$platurl = getconfig('rockfile_url');
|
||||
if(substr($platurl,-1)!='/')$platurl.='/';
|
||||
$path = str_replace('{FILEURL}',$platurl,$path);
|
||||
}
|
||||
if(substr($path,0,4)!='http')$path = ''.$url.''.$path.'';
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user