技术支持:KUOQPS@163.com
-

助手方法一览

更新时间:2020-07-31 10:54:16 | 简介:幻冰kuoqiPHP使用核心助手方法一览
/**
    *input int $code 状态code
    *input string $message 状态描述
    *input auto $info 输入数据
    *output array
    */
if(!function_exists('ajaxShow')){
    function ajaxShow($code,$message,$info)
    {
    $config = array('code'=>$code,'message'=>$message,'info'=>$info);
    return library('error')->showAjax($config);
    }
}
/**
    *input int $code 状态code
    *input string $message 状态描述
    *input auto $data 输入数据
    */
if(!function_exists('ajaxReturn')){
function    ajaxReturn($status = 1,$message = NULL,$data = array())
{
    return \kuoqi\app\request::ajaxReturn($status,$message,$data);
}    
}
/**
    *input int $code 状态code
    *input string $message 状态描述
    *input auto $data 输入数据
    */
if(!function_exists('arrReturn')){
function    arrReturn($status = 1,$message = 'OK',$data = array())
{
    $output = array('status'=>$status,'message'=>$message);
    if($status){
    if($status==9){
    $output['url'] = $data;
    }else{
    $output['data'] = $data;
    }
    }
    return $output;
}    
}
function    api($useApi,$useNamespace = true)
{
    return \kuoqi\api::useModule($useApi,$useNamespace);
}
//缓存模块
if(!function_exists('cache')){
function    cache($cacheName,$cacheValue = NULL,$cacheLife = '0',$cachePath = '',$isCommon = false){
    $o = new \Kuoqi\Cache\Cache;
    $o::$isCommon = $isCommon;
    if($cacheName){
    if($cacheValue===NULL){
    $o = $o->getCache($cacheName);
    }else{
    $o = $o->setCache($cacheName,$cacheValue,$cacheLife,$cachePath);
    }
    }
    return $o;
}
}
function    config($name,$value = NULL)
{
    $client = new \Kuoqi\Config;
    if($value){
    return $client->set($name,$value);
    }else{
    return $client->get($name);
    }
}
function    setconfig($name,$value)
{
    $client = new \kuoqi\config;
    return $client->set($name,$value);
}
function    getconfig($name)
{
    $client = new \kuoqi\config;
    return $client->get($name);
}
function    conts_decode($text){
    return \Kuoqi\Inputs::conts_decode($text);
}
function    debug_start()
{
    $str = explode(' ',microtime());
    $GLOBALS['debug_stime'] = $str[0]+($str[1]%60);
    echo '
';
}
function    debug_show()
{
    $str = explode(' ',microtime());
    $time = $str[0]+($str[1]%60);
    echo 'running time:'.($time-$GLOBALS['debug_stime']).'秒
';
}
function    debug_end($isDie = false)
{
    $str = explode(' ',microtime());
    $time = $str[0]+($str[1]%60);
    echo 'running end:'.($time-$GLOBALS['debug_stime']).'秒
';
    if($isDie)die();
}
//createby:kuoqi:有格式的打印信息
function    dump($code)
{
    echo '
';
    var_dump($code);
    echo '';
}
//createby:kuoqi:额外加载代码,本函数体代码不会暂用文件返回时间
function    exeed(&$code)
{
    $code();
}
function    extend($path)
{
    $pathObj = new \kuoqi\path;
    $path = $pathObj->getExtend($path);
    $file = new kuoqi\files;
    return $file->loadfile($path);
}
//全局最大的用户使用方法
function    role(){
    return new \Kuoqi\Member();
}
function    ftp()
{
    return new \kuoqi\ftp();
}
if(!function_exists('jsonReturn')){
function    jsonReturn($status = 1,$message = 'OK',$data = array())
{
    $output = array('status'=>$status,'message'=>$message);
    if($status){
    $output['data'] = $data;
    }
    $request = new \kuoqi\app\request;
    $request->jsonReturn($output);
}    
}
function    check_wap()
{
    if(isset($_SERVER['HTTP_VIA'])&&stristr(@$_SERVER['HTTP_VIA'],"wap")){
    return true;
    }
    elseif(isset($_SERVER['HTTP_ACCEPT'])&&strpos(strtoupper(@$_SERVER['HTTP_ACCEPT']),"VND.WAP.WML") > 0){
    return true;
    }
    elseif(preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])){
    if(preg_match('/MicroMessenger/',$_SERVER['HTTP_USER_AGENT'])){
    return 'wx';
    }
    return true;
    }
    else{
    return false;
    }
}
function    checkbaseadmin()
{
    $config = new \kuoqi\config;
    if($config->get('top_admin_id')==admin()->id()){
    return true;
    }else{
    return false;
    }
}
function    curl($curl = '', $type = false, $data = array(), $callback = '')
{
    return \Kuoqi\Curl::send($curl, $type, $data, $callback);
}
//错误模块外部引用
if(!function_exists('E')){
function    E(){
    $object = library('error');
    return $object;
}
}
if(!function_exists('html'))
{
function    html($isBase = false)
{
    return new \Kuoqi\Html;
}    
}
if(!function_exists('I'))
{
function    I($param = '',$default = NULL,$delFunc = NULL,$isOpt = false)
{
    $o = new \kuoqi\app\input;
    return $o->getParam($param,$default,$delFunc,$isOpt);
}
}
function    ignore($timeOut = 30){
    ignore_user_abort(true);
    if(function_exists('fastcgi_finish_request')){
    //Nginx使用 后面输出客户端获取不到
    fastcgi_finish_request();
    }else {
    //apache 使用
    $size = ob_get_length();
    header("Content-length: $size");
    header('Connection:close');
    echo ob_get_flush();
    //ob_end_flush();
    flush();
    }
    ignore_user_abort(true);//忽略浏览器执行
    set_time_limit($timeOut);
    return true;
}
if(!function_exists('ipfClient')){
function    ipfClient()
{
    $IPaddress='';
    if(isset($_SERVER)){
    if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
    $IPaddress = $_SERVER["HTTP_X_FORWARDED_FOR"];
    }else if(isset($_SERVER["HTTP_CLIENT_IP"])){
    $IPaddress = $_SERVER["HTTP_CLIENT_IP"];
    }else{
    $IPaddress = $_SERVER["REMOTE_ADDR"];
    }
    }else{
    if(getenv("HTTP_X_FORWARDED_FOR")){
    $IPaddress = getenv("HTTP_X_FORWARDED_FOR");
    }else if(getenv("HTTP_CLIENT_IP")) {
    $IPaddress = getenv("HTTP_CLIENT_IP");
    }else{
    $IPaddress = getenv("REMOTE_ADDR");
    }
    }
    return $IPaddress;
}
}
function    kong($conts)
{
    return $conts;
}
function    logs($message){
    \Kuoqi\Logs::logs($message);
}
//数据库控制
function    M($isPrefix = '',$dateTable = false)
{
    $object = new \Kuoqi\Database;
    $client = $object->useServer();
    if($dateTable&&$isPrefix){
    $object = $client->table($dateTable,$isPrefix);
    }elseif($isPrefix){
    $object = $client->table($isPrefix);
    }
    return $client;
}
//model
if(!function_exists('model')){
function    model($modelname,$modeltype = 'Model')
{
    return \Kuoqi\Model::useModel($modelname,$modeltype);
}
}
if(!function_exists('notes')){
function    notes($type = '100000')
{
    $type = $type.'000000';
    $type = substr($type,0,6);
    return $type.date('YmdHis').rand(1000,9999);
}    
}
//图书馆控制方法,调用模块下面标识
function    library($library)
{
    $class = '\\kuoqi\\'.$library;
    if(class_exists($class)){
    return new $class();
    }else{
    throw new \kuoqi\error("不存在的模块【{$library}】",'debug');
    }
}
if(!function_exists('jsonpReturn')){
function    jsonpReturn($status,$message,$data = array())
{
    $data = array('status'=>$status,'message'=>$message,'data'=>$data);
    $request = new \kuoqi\app\request;
    $request->jsonpReturn($data);
}    
}
if(!function_exists('priceEncode')){
function    priceEncode($string)
{
    return intval(floatval($string)*100);
}    
}
if(!function_exists('priceDecode')){
function    priceDecode($intval)
{
    return (int)($intval/100).'.'.str_pad($intval%100,2,'0',STR_PAD_LEFT);
}    
}
if(!function_exists('session')){
function    session($sessName,$sessValue = NULL)
{
    $client = new \kuoqi\session;
    if($sessValue){
    return $client->set($sessName,$sessValue);
    }else{
    return $client->get($sessName);
    }
}
}
if(!function_exists('getSession')){
function    getSession($sessName = '')
{
    $client = new \kuoqi\session;
    return $client->get($sessName);
}
}
if(!function_exists('setSession')){
function    setSession($sessName,$sessValue = NULL)
{
    $client = new \kuoqi\session;
    return $client->set($sessName,$sessValue);
}
}
if(!function_exists('delSession')){
function    delSession($sessName)
{
    $client = new \kuoqi\session;
    return $client->del($sessName);
}
}
if(!function_exists('submitcode')){
function    submitcode()
{
    return 1;
}
}
if(!function_exists('submit_encode')){
function    submit_encode()
{
    return 1;
}
}
if(!function_exists('submit_decode')){
function    submit_decode()
{
    return true;
}
}
if(!function_exists('T')){
function    T($link,$param = array())
{
    $link = Kuoqi\package::controllerExplode($link,'/');
    $code = \Kuoqi\App\Request::readPage($link,$params);
    $html = \Kuoqi\Template::execCode($code,$params);
    \Kuoqi\Template::setTemplate($link,$html);
    return \Kuoqi\Template::readTemplate($link,$params);
}    
}
if(!function_exists('template')){
function    template($link,$params = array())
{
    $link = Kuoqi\package::controllerExplode($link,'/');
    $code = \Kuoqi\App\Request::readPage($link,$params);
    $html = \Kuoqi\Template::execCode($code,$params);
    \Kuoqi\Template::setTemplate($link,$html);
    return \Kuoqi\Template::readTemplate($link,$params);
}
}
//时间长度转字符串
if(!function_exists('time2str')){
function    time2str($code){
    //获取秒
    $s = $code%60;
    $code = intval($code/60);
    $m = $code%60;
    $code = intval($code/60);
    $h = $code%60;
    return ($h?($h.'h'):'').($m?($m.'m'):'').$s.'s';
}
}
if(!function_exists('thumb')){
function    thumb($url,$w,$h,$hasimg = false)
{
    $info = \Kuoqi\Cache\Thumb::input($url,$w,$h);
    if($info['status']==1){
    $src = "/".$info['data']['url'];
    }else{$src = '';}
    $src = str_replace('\\','/',$src);
    if($hasimg){
    return '';
    }else{
    return $src;
    }
}
}
if(!function_exists('token_encode')){
function    token_encode($tkData){
    return \Kuoqi\Token::write($tkData);
}    
}
if(!function_exists('token_decode')){
function    token_decode($tkName){
    return \Kuoqi\Token::read($tkName);
}    
}
if(!function_exists('url')){
function    url($link = NULL,$param = array(),$isTruePath = false,$isParamsway = false){
    $client = new \kuoqi\url;
    return $client->getLink($link,$param,$isTruePath,$isParamsway);
}
}
function    ZIP(){
    return \kuoqi\zip::__initialize();
}