Home > Backend Development > PHP Tutorial > Summary of methods for data filtering in common PHP interfaces

Summary of methods for data filtering in common PHP interfaces

黄舟
Release: 2023-03-15 20:06:02
Original
1402 people have browsed it

php常用接口数据过滤的方法总结

<?php/**
 *  global.func.php 公共函数库
 *//**
 * 返回经addslashes处理过的字符串或数组
 * @param $string 需要处理的字符串或数组
 * @return mixed
 */function new_addslashes($string){
    if(!is_array($string)) return addslashes($string);    
    foreach($string as $key => $val) $string[$key] = new_addslashes($val);    
    return $string;
}/**
 * 返回经stripslashes处理过的字符串或数组
 * @param $string 需要处理的字符串或数组
 * @return mixed
 */function new_stripslashes($string) {
    if(!is_array($string)) return stripslashes($string);    
    foreach($string as $key => $val) $string[$key] = new_stripslashes($val);    
    return $string;
}/**
 * 返回经htmlspecialchars处理过的字符串或数组
 * @param $obj 需要处理的字符串或数组
 * @return mixed
 */function new_html_special_chars($string) {
    $encoding = &#39;utf-8&#39;;    
    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    
    if(!is_array($string)) return htmlspecialchars($string,ENT_QUOTES,$encoding);    
    foreach($string as $key => $val) $string[$key] = new_html_special_chars($val);    
    return $string;
}function new_html_entity_decode($string) {
    $encoding = &#39;utf-8&#39;;    
    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    
    return html_entity_decode($string,ENT_QUOTES,$encoding);
}function new_htmlentities($string) {
    $encoding = &#39;utf-8&#39;;    
    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    
    return htmlentities($string,ENT_QUOTES,$encoding);
}/**
 * 安全过滤函数
 *
 * @param $string
 * @return string
 */function safe_replace($string) {
    $string = str_replace(&#39;%20&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;%27&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;%2527&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;*&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;"&#39;,&#39;"&#39;,$string);    
    $string = str_replace("&#39;",&#39;&#39;,$string);    
    $string = str_replace(&#39;"&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;;&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;<&#39;,&#39;<&#39;,$string);    
    $string = str_replace(&#39;>&#39;,&#39;>&#39;,$string);    
    $string = str_replace("{",&#39;&#39;,$string);    
    $string = str_replace(&#39;}&#39;,&#39;&#39;,$string);    
    $string = str_replace(&#39;\\&#39;,&#39;&#39;,$string);    
    return $string;
}
/**
 * xss过滤函数
 *
 * @param $string
 * @return string
 */function remove_xss($string) { 
    $string = preg_replace(&#39;/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S&#39;, &#39;&#39;, $string);    
    $parm1 = Array(&#39;javascript&#39;, &#39;vbscript&#39;, &#39;expression&#39;, &#39;applet&#39;, &#39;meta&#39;, &#39;xml&#39;, &#39;blink&#39;, &#39;link&#39;, &#39;script&#39;, &#39;embed&#39;, &#39;object&#39;, &#39;iframe&#39;, &#39;frame&#39;, &#39;frameset&#39;, &#39;ilayer&#39;, &#39;layer&#39;, &#39;bgsound&#39;, &#39;title&#39;, &#39;base&#39;);    $parm2 = Array(&#39;onabort&#39;, &#39;onactivate&#39;, &#39;onafterprint&#39;, &#39;onafterupdate&#39;, &#39;onbeforeactivate&#39;, &#39;onbeforecopy&#39;, &#39;onbeforecut&#39;, &#39;onbeforedeactivate&#39;, &#39;onbeforeeditfocus&#39;, &#39;onbeforepaste&#39;, &#39;onbeforeprint&#39;, &#39;onbeforeunload&#39;, &#39;onbeforeupdate&#39;, &#39;onblur&#39;, &#39;onbounce&#39;, &#39;oncellchange&#39;, &#39;onchange&#39;, &#39;onclick&#39;, &#39;oncontextmenu&#39;, &#39;oncontrolselect&#39;, &#39;oncopy&#39;, &#39;oncut&#39;, &#39;ondataavailable&#39;, &#39;ondatasetchanged&#39;, &#39;ondatasetcomplete&#39;, &#39;ondblclick&#39;, &#39;ondeactivate&#39;, &#39;ondrag&#39;, &#39;ondragend&#39;, &#39;ondragenter&#39;, &#39;ondragleave&#39;, &#39;ondragover&#39;, &#39;ondragstart&#39;, &#39;ondrop&#39;, &#39;onerror&#39;, &#39;onerrorupdate&#39;, &#39;onfilterchange&#39;, &#39;onfinish&#39;, &#39;onfocus&#39;, &#39;onfocusin&#39;, &#39;onfocusout&#39;, &#39;onhelp&#39;, &#39;onkeydown&#39;, &#39;onkeypress&#39;, &#39;onkeyup&#39;, &#39;onlayoutcomplete&#39;, &#39;onload&#39;, &#39;onlosecapture&#39;, &#39;onmousedown&#39;, &#39;onmouseenter&#39;, &#39;onmouseleave&#39;, &#39;onmousemove&#39;, &#39;onmouseout&#39;, &#39;onmouseover&#39;, &#39;onmouseup&#39;, &#39;onmousewheel&#39;, &#39;onmove&#39;, &#39;onmoveend&#39;, &#39;onmovestart&#39;, &#39;onpaste&#39;, &#39;onpropertychange&#39;, &#39;onreadystatechange&#39;, &#39;onreset&#39;, &#39;onresize&#39;, &#39;onresizeend&#39;, &#39;onresizestart&#39;, &#39;onrowenter&#39;, &#39;onrowexit&#39;, &#39;onrowsdelete&#39;, &#39;onrowsinserted&#39;, &#39;onscroll&#39;, &#39;onselect&#39;, &#39;onselectionchange&#39;, &#39;onselectstart&#39;, &#39;onstart&#39;, &#39;onstop&#39;, &#39;onsubmit&#39;, &#39;onunload&#39;);    $parm = array_merge($parm1, $parm2); 

    for ($i = 0; $i < sizeof($parm); $i++) { 
        $pattern = &#39;/&#39;; 
        for ($j = 0; $j < strlen($parm[$i]); $j++) { 
            if ($j > 0) { 
                $pattern .= &#39;(&#39;; 
                $pattern .= &#39;(&#[x|X]0([9][a][b]);?)?&#39;; 
                $pattern .= &#39;|(&#0([9][10][13]);?)?&#39;; 
                $pattern .= &#39;)?&#39;; 
            }            $pattern .= $parm[$i][$j]; 
        }        $pattern .= &#39;/i&#39;;        
        $string = preg_replace($pattern, &#39; &#39;, $string); 
    }    return $string;
}/**
 * 过滤ASCII码从0-28的控制字符
 * @return String
 */function trim_unsafe_control_chars($str) {
    $rule = &#39;/[&#39; . chr ( 1 ) . &#39;-&#39; . chr ( 8 ) . chr ( 11 ) . &#39;-&#39; . chr ( 12 ) . chr ( 14 ) . &#39;-&#39; . chr ( 31 ) . &#39;]*/&#39;;    return str_replace ( chr ( 0 ), &#39;&#39;, preg_replace ( $rule, &#39;&#39;, $str ) );
}/**
 * 格式化文本域内容
 *
 * @param $string 文本域内容
 * @return string
 */function trim_textarea($string) {
    $string = nl2br ( str_replace ( &#39; &#39;, &#39; &#39;, $string ) );    return $string;
}/**
 * 将文本格式成适合js输出的字符串
 * @param string $string 需要处理的字符串
 * @param intval $isjs 是否执行字符串格式化,默认为执行
 * @return string 处理后的字符串
 */function format_js($string, $isjs = 1) {
    $string = addslashes(str_replace(array("\r", "\n", "\t"), array(&#39;&#39;, &#39;&#39;, &#39;&#39;), $string));    
    return $isjs ? &#39;document.write("&#39;.$string.&#39;");&#39; : $string;
}/**
 * 转义 javascript 代码标记
 *
 * @param $str
 * @return mixed
 */
 function trim_script($str) {
    if(is_array($str)){        
    foreach ($str as $key => $val){            
    $str[$key] = trim_script($val);
        }
     }else{         
     $str = preg_replace ( &#39;/\<([\/]?)script([^\>]*?)\>/si&#39;, &#39;<\\1script\\2>&#39;, $str );        
     $str = preg_replace ( &#39;/\<([\/]?)iframe([^\>]*?)\>/si&#39;, &#39;<\\1iframe\\2>&#39;, $str );        
     $str = preg_replace ( &#39;/\<([\/]?)frame([^\>]*?)\>/si&#39;, &#39;<\\1frame\\2>&#39;, $str );        
     $str = str_replace ( &#39;javascript:&#39;, &#39;javascript:&#39;, $str );
     }    return $str;
}/**
 * 获取当前页面完整URL地址
 */function get_url() {
    $sys_protocal = isset($_SERVER[&#39;SERVER_PORT&#39;]) && $_SERVER[&#39;SERVER_PORT&#39;] == &#39;443&#39; ? &#39;https://&#39; : &#39;http://&#39;;    
    $php_self = $_SERVER[&#39;PHP_SELF&#39;] ? safe_replace($_SERVER[&#39;PHP_SELF&#39;]) : safe_replace($_SERVER[&#39;SCRIPT_NAME&#39;]);    
    $path_info = isset($_SERVER[&#39;PATH_INFO&#39;]) ? safe_replace($_SERVER[&#39;PATH_INFO&#39;]) : &#39;&#39;;    
    $relate_url = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? safe_replace($_SERVER[&#39;REQUEST_URI&#39;]) : $php_self.(isset($_SERVER[&#39;QUERY_STRING&#39;]) ? &#39;?&#39;.safe_replace($_SERVER[&#39;QUERY_STRING&#39;]) : $path_info);    return $sys_protocal.(isset($_SERVER[&#39;HTTP_HOST&#39;]) ? $_SERVER[&#39;HTTP_HOST&#39;] : &#39;&#39;).$relate_url;
}/**
 * 字符截取 支持UTF8/GBK
 * @param $string
 * @param $length
 * @param $dot
 */function str_cut($string, $length, $dot = &#39;...&#39;) {
    $strlen = strlen($string);    
    if($strlen <= $length) return $string;    
    $string = str_replace(array(&#39; &#39;,&#39; &#39;, &#39;&&#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), array(&#39;∵&#39;,&#39; &#39;, &#39;&&#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), $string);
    $strcut = &#39;&#39;;
    if(strtolower(CHARSET) == &#39;utf-8&#39;) {
        $length = intval($length-strlen($dot)-$length/3);
        $n = $tn = $noc = 0;
        while($n < strlen($string)) {
            $t = ord($string[$n]);
            if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
                $tn = 1; $n++; $noc++;
            } elseif(194 <= $t && $t <= 223) {
                $tn = 2; $n += 2; $noc += 2;
            } elseif(224 <= $t && $t <= 239) {
                $tn = 3; $n += 3; $noc += 2;
            } elseif(240 <= $t && $t <= 247) {
                $tn = 4; $n += 4; $noc += 2;
            } elseif(248 <= $t && $t <= 251) {
                $tn = 5; $n += 5; $noc += 2;
            } elseif($t == 252 || $t == 253) {
                $tn = 6; $n += 6; $noc += 2;
            } else {
                $n++;
            }
            if($noc >= $length) {
                break;
            }
        }
        if($noc > $length) {
            $n -= $tn;
        }
        $strcut = substr($string, 0, $n);
        $strcut = str_replace(array(&#39;∵&#39;, &#39;&&#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), array(&#39; &#39;, &#39;&&#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), $strcut);
    } else {
        $dotlen = strlen($dot);
        $maxi = $length - $dotlen - 1;
        $current_str = &#39;&#39;;
        $search_arr = array(&#39;&&#39;,&#39; &#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;,&#39;∵&#39;);
        $replace_arr = array(&#39;&&#39;,&#39; &#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;,&#39; &#39;);        
        $search_flip = array_flip($search_arr);        for ($i = 0; $i < $maxi; $i++) {            
        $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];            
        if (in_array($current_str, $search_arr)) {                
        $key = $search_flip[$current_str];                
        $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
            }            
            $strcut .= $current_str;
            
        }
    }    return $strcut.$dot;
}/**
 * 获取请求ip
 *
 * @return ip地址
 */function ip() {
    if(getenv(&#39;HTTP_CLIENT_IP&#39;) && strcasecmp(getenv(&#39;HTTP_CLIENT_IP&#39;), &#39;unknown&#39;)) {        
    $ip = getenv(&#39;HTTP_CLIENT_IP&#39;);
    } elseif(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;) && strcasecmp(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;), &#39;unknown&#39;)) {        
    $ip = getenv(&#39;HTTP_X_FORWARDED_FOR&#39;);
    } elseif(getenv(&#39;REMOTE_ADDR&#39;) && strcasecmp(getenv(&#39;REMOTE_ADDR&#39;), &#39;unknown&#39;)) {        
    $ip = getenv(&#39;REMOTE_ADDR&#39;);
    } elseif(isset($_SERVER[&#39;REMOTE_ADDR&#39;]) && $_SERVER[&#39;REMOTE_ADDR&#39;] && strcasecmp($_SERVER[&#39;REMOTE_ADDR&#39;], &#39;unknown&#39;)) {        
    $ip = $_SERVER[&#39;REMOTE_ADDR&#39;];
    }    return preg_match ( &#39;/[\d\.]{7,15}/&#39;, $ip, $matches ) ? $matches [0] : &#39;&#39;;
}function get_cost_time() {
    $microtime = microtime ( TRUE );    
    return $microtime - SYS_START_TIME;
}/**
 * 程序执行时间
 *
 * @return    int    单位ms
 */function execute_time() {
    $stime = explode ( &#39; &#39;, SYS_START_TIME );    
    $etime = explode ( &#39; &#39;, microtime () );    
    return number_format ( ($etime [1] + $etime [0] - $stime [1] - $stime [0]), 6 );
}
/**
* 将字符串转换为数组
*
* @param    string    $data    字符串
* @return    array    返回数组格式,如果,data为空,则返回空数组
*/function string2array($data) {
    if($data == &#39;&#39;) return array();    $data = stripslashes($data);
    @eval("\$array = $data;");    return $array;
}/**
* 将数组转换为字符串
*
* @param    array    $data        数组
* @param    bool    $isformdata    如果为0,则不使用new_stripslashes处理,可选参数,默认为1
* @return    string    返回字符串,如果,data为空,则返回空
*/function array2string($data, $isformdata = 1) {
    if($data == &#39;&#39;) return &#39;&#39;;    
    if($isformdata) $data = new_stripslashes($data);    
    
    return addslashes(var_export($data, TRUE));
}
/**
* 转换字节数为其他单位
*
*
* @param    string    $filesize    字节大小
* @return    string    返回大小
*/function sizecount($filesize) {
    if ($filesize >= 1073741824) {        $filesize = round($filesize / 1073741824 * 100) / 100 .&#39; GB&#39;;
    } elseif ($filesize >= 1048576) {        $filesize = round($filesize / 1048576 * 100) / 100 .&#39; MB&#39;;
    } elseif($filesize >= 1024) {        $filesize = round($filesize / 1024 * 100) / 100 . &#39; KB&#39;;
    } else {        $filesize = $filesize.&#39; Bytes&#39;;
    }    return $filesize;
}/**
* 字符串加密、解密函数
*
*
* @param    string    $txt        字符串
* @param    string    $operation    ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,
* @param    string    $key        密钥:数字、字母、下划线
* @param    string    $expiry        过期时间
* @return    string
*/function sys_auth($string, $operation = &#39;ENCODE&#39;, $key = &#39;&#39;, $expiry = 0) {
    $key_length = 4;    $key = md5($key != &#39;&#39; ? $key : app_base::load_config(&#39;system&#39;, &#39;auth_key&#39;));    $fixedkey = md5($key);    $egiskeys = md5(substr($fixedkey, 16, 16));    $runtokey = $key_length ? ($operation == &#39;ENCODE&#39; ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : &#39;&#39;;    $keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));    $string = $operation == &#39;ENCODE&#39; ? sprintf(&#39;%010d&#39;, $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));    $i = 0; $result = &#39;&#39;;    $string_length = strlen($string);    for ($i = 0; $i < $string_length; $i++){        $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
    }    if($operation == &#39;ENCODE&#39;) {        return $runtokey . str_replace(&#39;=&#39;, &#39;&#39;, base64_encode($result));
    } else {        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {            return substr($result, 26);
        } else {            return &#39;&#39;;
        }
    }
}/**
* 语言文件处理
*
* @param    string        $language    标示符
* @param    array        $pars    转义的数组,二维数组 ,&#39;key1&#39;=>&#39;value1&#39;,&#39;key2&#39;=>&#39;value2&#39;,
* @param    string        $modules 多个模块之间用半角逗号隔开,如:member,guestbook
* @return    string        语言字符
*/function L($language = &#39;no_language&#39;,$pars = array(), $modules = &#39;&#39;) {
    static $LANG = array();    static $LANG_MODULES = array();    static $lang = &#39;&#39;;    if(defined(&#39;IN_ADMIN&#39;)) {        $lang = SYS_STYLE ? SYS_STYLE : &#39;zh-cn&#39;;
    } else {        $lang = app_base::load_config(&#39;system&#39;,&#39;lang&#39;);
    }    if(!$LANG) {        require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.&#39;system.lang.php&#39;;        if(defined(&#39;IN_ADMIN&#39;)) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.&#39;system_menu.lang.php&#39;;        if(file_exists(CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.&#39;.lang.php&#39;)) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.&#39;.lang.php&#39;;
    }    if(!empty($modules)) {        $modules = explode(&#39;,&#39;,$modules);        foreach($modules AS $m) {            if(!isset($LANG_MODULES[$m])) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$m.&#39;.lang.php&#39;;
        }
    }    if(!array_key_exists($language,$LANG)) {        return $language;
    } else {        $language = $LANG[$language];        if($pars) {            foreach($pars AS $_k=>$_v) {                $language = str_replace(&#39;{&#39;.$_k.&#39;}&#39;,$_v,$language);
            }
        }        return $language;
    }
}/**
 * 模板调用
 *
 * @param $module
 * @param $template
 * @param $istag
 * @return unknown_type
 */function template($module = &#39;content&#39;, $template = &#39;index&#39;, $style = &#39;&#39;) {

    if(strpos($module, &#39;plugin/&#39;)!== false) {        $plugin = str_replace(&#39;plugin/&#39;, &#39;&#39;, $module);        return p_template($plugin, $template,$style);
    }    $module = str_replace(&#39;/&#39;, DIRECTORY_SEPARATOR, $module);    if(!empty($style) && preg_match(&#39;/([a-z0-9\-_]+)/is&#39;,$style)) {
    } elseif (empty($style) && !defined(&#39;STYLE&#39;)) {        if(defined(&#39;SITEID&#39;)) {            $siteid = SITEID;
        } else {            $siteid = param::get_cookie(&#39;siteid&#39;);
        }        if (!$siteid) $siteid = 1;        $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);        if(!empty($siteid)) {            $style = $sitelist[$siteid][&#39;default_style&#39;];
        }
    } elseif (empty($style) && defined(&#39;STYLE&#39;)) {        $style = STYLE;
    } else {        $style = &#39;default&#39;;
    }    if(!$style) $style = &#39;default&#39;;    $template_cache = app_base::load_sys_class(&#39;template_cache&#39;);    $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;    if(file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {        if(!file_exists($compiledtplfile) || (@filemtime(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > @filemtime($compiledtplfile))) {            $template_cache->template_compile($module, $template, $style);
        }
    } else {        $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;        if(!file_exists($compiledtplfile) || (file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) && filemtime(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > filemtime($compiledtplfile))) {            $template_cache->template_compile($module, $template, &#39;default&#39;);
        } elseif (!file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {
            showmessage(&#39;Template does not exist.&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;);
        }
    }    return $compiledtplfile;
}/**
 * 输出自定义错误
 *
 * @param $errno 错误号
 * @param $errstr 错误描述
 * @param $errfile 报错文件地址
 * @param $errline 错误行号
 * @return string 错误提示
 */function my_error_handler($errno, $errstr, $errfile, $errline) {
    if($errno==8) return &#39;&#39;;    $errfile = str_replace(ROOT_PATH,&#39;&#39;,$errfile);    if(app_base::load_config(&#39;system&#39;,&#39;errorlog&#39;)) {
        error_log(&#39;<?php exit;?>&#39;.date(&#39;m-d H:i:s&#39;,SYS_TIME).&#39; | &#39;.$errno.&#39; | &#39;.str_pad($errstr,30).&#39; | &#39;.$errfile.&#39; | &#39;.$errline."\r\n", 3, CACHE_PATH.&#39;error_log.php&#39;);
    } else {        $str = &#39;<p style="font-size:12px;text-align:left; border-bottom:1px solid #9cc9e0; border-right:1px solid #9cc9e0;padding:1px 4px;color:#000000;font-family:Arial, Helvetica,sans-serif;"><span>errorno:&#39; . $errno . &#39;,str:&#39; . $errstr . &#39;,file:<font color="blue">&#39; . $errfile . &#39;</font>,line&#39; . $errline .&#39;<br />Need Help?</span></p>&#39;;        echo $str;
    }
}/**
 * 提示信息页面跳转,跳转地址如果传入数组,页面会提示多个地址供用户选择,默认跳转地址为数组的第一个值,时间为5秒。
 * showmessage(&#39;登录成功&#39;, array(&#39;默认跳转地址&#39;=>&#39;http://www.baidu.com&#39;));
 * @param string $msg 提示信息
 * @param mixed(string/array) $url_forward 跳转地址
 * @param int $ms 跳转等待时间
 */function showmessage($msg, $url_forward = &#39;goback&#39;, $ms = 1250, $dialog = &#39;&#39;, $returnjs = &#39;&#39;) {
    if(defined(&#39;IN_ADMIN&#39;)) {        include(admin::admin_tpl(&#39;showmessage&#39;, &#39;admin&#39;));
    } else {        include(template(&#39;content&#39;, &#39;message&#39;));
    }    exit;
}/**
 * 查询字符是否存在于某字符串
 *
 * @param $haystack 字符串
 * @param $needle 要查找的字符
 * @return bool
 */function str_exists($haystack, $needle){
    return !(strpos($haystack, $needle) === FALSE);
}/**
 * 取得文件扩展
 *
 * @param $filename 文件名
 * @return 扩展名
 */function fileext($filename) {
    return strtolower(trim(substr(strrchr($filename, &#39;.&#39;), 1, 10)));
}/**
 * 加载模板标签缓存
 * @param string $name 缓存名
 * @param integer $times 缓存时间
 */function tpl_cache($name,$times = 0) {
    $filepath = &#39;tpl_data&#39;;    $info = getcacheinfo($name, $filepath);    if (SYS_TIME - $info[&#39;filemtime&#39;] >= $times) {        return false;
    } else {        return getcache($name,$filepath);
    }
}/**
 * 写入缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $data 缓存数据
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 * @param $timeout 过期时间
 */function setcache($name, $data, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;, $timeout=0) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->set($name, $data, $timeout, &#39;&#39;, $filepath);
}/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */function getcache($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->get($name, &#39;&#39;, &#39;&#39;, $filepath);
}//根据行政区划数字获取对应名称名称  如 110101 得到 北京市东城区function get_p($p=&#39;&#39;){
    if(empty($p)){        return false;
    }    $regioncode = getcache(&#39;1&#39;,&#39;linkage&#39;);    if($regioncode)
    {        $l1=substr($p,0,2).&#39;0000&#39;;        $L1_n=$regioncode[&#39;data&#39;][$l1][&#39;name&#39;];        $tb=array(&#39;110000&#39;,&#39;120000&#39;,&#39;310000&#39;,&#39;500000&#39;);        if(in_array($l1,$tb)){            $l2 = $l1=substr($p,0,2)."0000-r";
        }else{            $l2 = substr($p,0,4)."00";
        }        $L2_n =  $regioncode[&#39;data&#39;][$l2][&#39;name&#39;];        $L3_n =  $regioncode[&#39;data&#39;][$p][&#39;name&#39;];        if($L2_n===$L1_n){            $res_p = $L1_n.$L3_n;
        }else{            $res_p = $L1_n.$L2_n.$L3_n;
        }        return $res_p;
    }else{        return &#39;无行政区划地址&#39;;
    }
}//根据行业类型数字获取对应名称名称  如 $trade=‘1A0112’ 得到 农、林、牧、渔业-农业-谷物及其他作物的种植-薯类的种植function get_trade_category($trade=&#39;&#39;){
    if(empty($trade)){        return false;
    }    $trade_category = getcache(&#39;3&#39;,&#39;linkage&#39;);    if($trade_category){        $t1=substr($trade,0,2);        $T_1=$trade_category[&#39;data&#39;][$t1][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t1][&#39;name&#39;]:&#39;&#39;;        $t2=substr($trade,0,4);        $T_2=$trade_category[&#39;data&#39;][$t2][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t2][&#39;name&#39;]:&#39;&#39;;        $t3=substr($trade,0,5);        $T_3=$trade_category[&#39;data&#39;][$t3][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t3][&#39;name&#39;]:&#39;&#39;;        $T_4=$trade_category[&#39;data&#39;][$trade][&#39;name&#39;]?$trade_category[&#39;data&#39;][$trade][&#39;name&#39;]:&#39;&#39;;        if($T_3===$T_4){            $res_trade = $T_1.&#39;-&#39;.$T_2.&#39;-&#39;.$T_3;
        }else{            $res_trade = $T_1.&#39;-&#39;.$T_2.&#39;-&#39;.$T_3.&#39;-&#39;.$T_4;
        }        if(empty($res_trade)){            return &#39;行业类型数据不存在&#39;;
        }        return $res_trade;

    }else{        return &#39;行业类型数据不存在&#39;;
    }
}/**
 * 删除缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 */function delcache($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->delete($name, &#39;&#39;, &#39;&#39;, $filepath);
}/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */function getcacheinfo($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->cacheinfo($name, &#39;&#39;, &#39;&#39;, $filepath);
}/**
 * 生成sql语句,如果传入$in_cloumn 生成格式为 IN(&#39;a&#39;, &#39;b&#39;, &#39;c&#39;)
 * @param $data 条件数组或者字符串
 * @param $front 连接符
 * @param $in_column 字段名称
 * @return string
 */function to_sqls($data, $front = &#39; AND &#39;, $in_column = false) {
    if($in_column && is_array($data)) {        $ids = &#39;\&#39;&#39;.implode(&#39;\&#39;,\&#39;&#39;, $data).&#39;\&#39;&#39;;        $sql = "$in_column IN ($ids)";        return $sql;
    } else {        if ($front == &#39;&#39;) {            $front = &#39; AND &#39;;
        }        if(is_array($data) && count($data) > 0) {            $sql = &#39;&#39;;            foreach ($data as $key => $val) {                $sql .= $sql ? " $front $key = &#39;$val&#39; " : " $key = &#39;$val&#39; ";
            }            return $sql;
        } else {            return $data;
        }
    }
}/**
 * 分页函数
 *
 * @param $num 信息总数
 * @param $curr_page 当前分页
 * @param $perpage 每页显示数
 * @param $urlrule URL规则
 * @param $array 需要传递的数组,用于增加额外的方法
 * @return 分页
 */function pages($num, $curr_page, $perpage = 20, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($num > $perpage) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        $pages = ceil($num / $perpage);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $curr_page-1, $array).&#39;" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, 1, $array).&#39;">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, 1, $array).&#39;">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $i, $array).&#39;">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="&#39;.pageurl($urlrule, $curr_page, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}function pages1($num, $curr_page, $perpage = 20, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($num > $perpage) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        $pages = ceil($num / $perpage);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page-1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(1);$(\&#39;#pageform\&#39;).submit();">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(1);$(\&#39;#pageform\&#39;).submit();">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$i.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###"  onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$curr_page.&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}function pages2($num, $curr_page, $pages, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($pages > 1) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page-1).&#39;]);" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[1]);">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[1]);">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$i.&#39;]);">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###"  onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}/**
 * 返回分页路径
 *
 * @param $urlrule 分页规则
 * @param $page 当前页
 * @param $array 需要传递的数组,用于增加额外的方法
 * @return 完整的URL路径
 */function pageurl($urlrule, $page, $array = array()) {
    if(strpos($urlrule, &#39;~&#39;)) {        $urlrules = explode(&#39;~&#39;, $urlrule);        $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
    }    $findme = array(&#39;{$page}&#39;);    $replaceme = array($page);    if (is_array($array)) foreach ($array as $k=>$v) {        $findme[] = &#39;{$&#39;.$k.&#39;}&#39;;        $replaceme[] = $v;
    }    $url = str_replace($findme, $replaceme, $urlrule);    $url = str_replace(array(&#39;http://&#39;,&#39;//&#39;,&#39;~&#39;), array(&#39;~&#39;,&#39;/&#39;,&#39;http://&#39;), $url);    return $url;
}/**
 * URL路径解析,pages 函数的辅助函数
 *
 * @param $par 传入需要解析的变量 默认为,page={$page}
 * @param $url URL地址
 * @return URL
 */function url_par($par, $url = &#39;&#39;) {
    if($url == &#39;&#39;) $url = get_url();    $pos = strpos($url, &#39;?&#39;);    if($pos === false) {        $url .= &#39;?&#39;.$par;
    } else {        $querystring = substr(strstr($url, &#39;?&#39;), 1);
        parse_str($querystring, $pars);        $query_array = array();        foreach($pars as $k=>$v) {            if($k != &#39;page&#39;) $query_array[$k] = $v;
        }        $querystring = http_build_query($query_array).&#39;&&#39;.$par;        $url = substr($url, 0, $pos).&#39;?&#39;.$querystring;
    }    return $url;
}/**
 * 判断email格式是否正确
 * @param $email
 */function is_email($email) {
    return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}/**
 * iconv 编辑转换
 */if (!function_exists(&#39;iconv&#39;)) {    function iconv($in_charset, $out_charset, $str) {
        $in_charset = strtoupper($in_charset);        $out_charset = strtoupper($out_charset);        if (function_exists(&#39;mb_convert_encoding&#39;)) {            return mb_convert_encoding($str, $out_charset, $in_charset);
        } else {
            app_base::load_sys_func(&#39;iconv&#39;);            $in_charset = strtoupper($in_charset);            $out_charset = strtoupper($out_charset);            if ($in_charset == &#39;UTF-8&#39; && ($out_charset == &#39;GBK&#39; || $out_charset == &#39;GB2312&#39;)) {                return utf8_to_gbk($str);
            }            if (($in_charset == &#39;GBK&#39; || $in_charset == &#39;GB2312&#39;) && $out_charset == &#39;UTF-8&#39;) {                return gbk_to_utf8($str);
            }            return $str;
        }
    }
}/**
 * 代码广告展示函数
 * @param intval $siteid 所属站点
 * @param intval $id 广告ID
 * @return 返回广告代码
 */function show_ad($siteid, $id) {
    $siteid = intval($siteid);    $id = intval($id);    if(!$id || !$siteid) return false;    $p = app_base::load_model(&#39;poster_model&#39;);    $r = $p->get_one(array(&#39;spaceid&#39;=>$id, &#39;siteid&#39;=>$siteid), &#39;disabled, setting&#39;, &#39;id ASC&#39;);    if ($r[&#39;disabled&#39;]) return &#39;&#39;;    if ($r[&#39;setting&#39;]) {        $c = string2array($r[&#39;setting&#39;]);
    } else {        $r[&#39;code&#39;] = &#39;&#39;;
    }    return $c[&#39;code&#39;];
}/**
 * 获取当前的站点ID
 */function get_siteid() {
    static $siteid;    if (!empty($siteid)) return $siteid;    if (defined(&#39;IN_ADMIN&#39;)) {        if ($d = param::get_cookie(&#39;siteid&#39;)) {            $siteid = $d;
        } else {            return &#39;&#39;;
        }
    } else {        $data = getcache(&#39;sitelist&#39;, &#39;commons&#39;);        if(!is_array($data)) return &#39;1&#39;;        $site_url = SITE_PROTOCOL.SITE_URL;        foreach ($data as $v) {            if ($v[&#39;url&#39;] == $site_url.&#39;/&#39;) $siteid = $v[&#39;siteid&#39;];
        }
    }    if (empty($siteid)) $siteid = 1;    return $siteid;
}/**
 * 获取用户昵称
 * 不传入userid取当前用户nickname,如果nickname为空取username
 * 传入field,取用户$field字段信息
 */function get_nickname($userid=&#39;&#39;, $field=&#39;&#39;) {
    $return = &#39;&#39;;    if(is_numeric($userid)) {        $member_db = app_base::load_model(&#39;member_model&#39;);        $memberinfo = $member_db->get_one(array(&#39;userid&#39;=>$userid));        if(!empty($field) && $field != &#39;nickname&#39; && isset($memberinfo[$field]) &&!empty($memberinfo[$field])) {            $return = $memberinfo[$field];
        } else {            $return = isset($memberinfo[&#39;nickname&#39;]) && !empty($memberinfo[&#39;nickname&#39;]) ? $memberinfo[&#39;nickname&#39;].&#39;(&#39;.$memberinfo[&#39;username&#39;].&#39;)&#39; : $memberinfo[&#39;username&#39;];
        }
    } else {        if (param::get_cookie(&#39;_nickname&#39;)) {            $return .= &#39;(&#39;.param::get_cookie(&#39;_nickname&#39;).&#39;)&#39;;
        } else {            $return .= &#39;(&#39;.param::get_cookie(&#39;_username&#39;).&#39;)&#39;;
        }
    }    return $return;
}/**
 * 获取用户信息
 * 不传入$field返回用户所有信息,
 * 传入field,取用户$field字段信息
 */function get_memberinfo($userid, $field=&#39;&#39;) {
    if(!is_numeric($userid)) {        return false;
    } else {        static $memberinfo;        if (!isset($memberinfo[$userid])) {            $member_db = app_base::load_model(&#39;member_model&#39;);            $memberinfo[$userid] = $member_db->get_one(array(&#39;userid&#39;=>$userid));
        }        if(!empty($field) && !empty($memberinfo[$userid][$field])) {            return $memberinfo[$userid][$field];
        } else {            return $memberinfo[$userid];
        }
    }
}/**
 * 通过 username 值,获取用户所有信息
 * 获取用户信息
 * 不传入$field返回用户所有信息,
 * 传入field,取用户$field字段信息
 */function get_memberinfo_buyusername($username, $field=&#39;&#39;) {
    if(empty($username)){return false;}    static $memberinfo;    if (!isset($memberinfo[$username])) {        $member_db = app_base::load_model(&#39;member_model&#39;);        $memberinfo[$username] = $member_db->get_one(array(&#39;username&#39;=>$username));
    }    if(!empty($field) && !empty($memberinfo[$username][$field])) {        return $memberinfo[$username][$field];
    } else {        return $memberinfo[$username];
    }
}/**
 * 调用关联菜单
 * @param $linkageid 联动菜单id
 * @param $id 生成联动菜单的样式id
 * @param $defaultvalue 默认值
 */function menu_linkage($linkageid = 0, $id = &#39;linkid&#39;, $defaultvalue = 0, $defaultlabel = array()) {
    $linkageid = intval($linkageid);    $datas = array();    $datas = getcache($linkageid,&#39;linkage&#39;);    $infos = $datas[&#39;data&#39;];    if($datas[&#39;style&#39;]==&#39;1&#39;) {        $title = $datas[&#39;title&#39;];        $container = &#39;content&#39;.create_randomnum(100, 999).date(&#39;is&#39;);        if(!defined(&#39;DIALOG_INIT_1&#39;)) {
            define(&#39;DIALOG_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;dialog.js"></script>&#39;;            //TODO $string .= &#39;<link href="&#39;.CSS_PATH.&#39;dialog.css" rel="stylesheet" type="text/css">&#39;;
        }        if(!defined(&#39;LINKAGE_INIT_1&#39;)) {
            define(&#39;LINKAGE_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/pop.js"></script>&#39;;
        }        $var_p = $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39; || ROUTE_A==&#39;orderinfo&#39;) ? menu_linkage_level($defaultvalue,$linkageid,$infos) : $datas[&#39;title&#39;];        $var_input = $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39;) ? &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="&#39;.$defaultvalue.&#39;">&#39; : &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="">&#39;;        $string .= &#39;<p name="&#39;.$id.&#39;" value="" id="&#39;.$id.&#39;" class="ib">&#39;.$var_p.&#39;</p>&#39;.$var_input.&#39; <input type="button" name="btn_&#39;.$id.&#39;" class="button" value="&#39;.L(&#39;linkage_select&#39;).&#39;" onclick="open_linkage(\&#39;&#39;.$id.&#39;\&#39;,\&#39;&#39;.$title.&#39;\&#39;,&#39;.$container.&#39;,\&#39;&#39;.$linkageid.&#39;\&#39;)">&#39;;        $string .= &#39;<script type="text/javascript">&#39;;        $string .= &#39;var returnid_&#39;.$id.&#39;= \&#39;&#39;.$id.&#39;\&#39;;&#39;;        $string .= &#39;var returnkeyid_&#39;.$id.&#39; = \&#39;&#39;.$linkageid.&#39;\&#39;;&#39;;        $string .=  &#39;var &#39;.$container.&#39; = new Array(&#39;;        foreach($infos AS $k=>$v) {            if($v[&#39;parentid&#39;] == 0) {                $s[]=&#39;new Array(\&#39;&#39;.$v[&#39;linkageid&#39;].&#39;\&#39;,\&#39;&#39;.$v[&#39;name&#39;].&#39;\&#39;,\&#39;&#39;.$v[&#39;parentid&#39;].&#39;\&#39;)&#39;;
            } else {                continue;
            }
        }        $s = implode(&#39;,&#39;,$s);        $string .=$s;        $string .= &#39;)&#39;;        $string .= &#39;</script>&#39;;

    } elseif($datas[&#39;style&#39;]==&#39;2&#39;) {        if(!defined(&#39;LINKAGE_INIT_1&#39;)) {
            define(&#39;LINKAGE_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/jquery.ld.js"></script>&#39;;
        }        $default_txt = &#39;&#39;;        if($defaultvalue) {                $default_txt = menu_linkage_level($defaultvalue,$linkageid,$infos);                $default_txt = &#39;["&#39;.str_replace(&#39; > &#39;,&#39;","&#39;,$default_txt).&#39;"]&#39;;
        }        $string .= $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39;) ? &#39;<input type="hidden" name="info[&#39;.$id.&#39;]"  id="&#39;.$id.&#39;" value="&#39;.$defaultvalue.&#39;">&#39; : &#39;<input type="hidden" name="info[&#39;.$id.&#39;]"  id="&#39;.$id.&#39;" value="">&#39;;        for($i=1;$i<=$datas[&#39;setting&#39;][&#39;level&#39;];$i++) {            $txt = isset($defaultlabel[$i]) ? $defaultlabel[$i] : &#39;请选择&#39;;            $string .=&#39;<select class="pc-select-&#39;.$id.&#39;" name="&#39;.$id.&#39;-&#39;.$i.&#39;" id="&#39;.$id.&#39;-&#39;.$i.&#39;" width="100"><option value="">&#39; . $txt . &#39;</option></select> &#39;;
        }        $string .= &#39;<script type="text/javascript">
                    $(function(){
                        var $ld5 = $(".pc-select-&#39;.$id.&#39;");                      
                        $ld5.ld({ajaxOptions : {"url" : "&#39;.APP_PATH.&#39;api.php?op=get_linkage&act=ajax_select&keyid=&#39;.$linkageid.&#39;"},defaultParentId : 0,style : {"width" : 120}})     
                        var ld5_api = $ld5.ld("api");
                        //ld5_api.selected(&#39;.$default_txt.&#39;);
                        $ld5.bind("change",onchange);
                        function onchange(e){
                            var $target = $(e.target);
                            var index = $ld5.index($target);
                            $("#&#39;.$id.&#39;-&#39;.$i.&#39;").remove();
                            $("#&#39;.$id.&#39;").val($ld5.eq(index).show().val());
                            index ++;
                            $ld5.eq(index).show();                                }
                    })
        </script>&#39;;

    } else {        $title = $defaultvalue ? $infos[$defaultvalue][&#39;name&#39;] : $datas[&#39;title&#39;];        $colObj = create_randomnum(100, 999).date(&#39;is&#39;);        $string = &#39;&#39;;        if(!defined(&#39;LINKAGE_INIT&#39;)) {
            define(&#39;LINKAGE_INIT&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/mln.colselect.js"></script>&#39;;            if(defined(&#39;IN_ADMIN&#39;)) {                $string .= &#39;<link href="&#39;.JS_PATH.&#39;linkage/style/admin.css" rel="stylesheet" type="text/css">&#39;;
            } else {                $string .= &#39;<link href="&#39;.JS_PATH.&#39;linkage/style/css.css" rel="stylesheet" type="text/css">&#39;;
            }
        }        $string .= &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="1"><p id="&#39;.$id.&#39;"></p>&#39;;        $string .= &#39;<script type="text/javascript">&#39;;        $string .= &#39;var colObj&#39;.$colObj.&#39; = {"Items":[&#39;;        foreach($infos AS $k=>$v) {            $s .= &#39;{"name":"&#39;.$v[&#39;name&#39;].&#39;","topid":"&#39;.$v[&#39;parentid&#39;].&#39;","colid":"&#39;.$k.&#39;","value":"&#39;.$k.&#39;","fun":function(){}},&#39;;
        }        $string .= substr($s, 0, -1);        $string .= &#39;]};&#39;;        $string .= &#39;$("#&#39;.$id.&#39;").mlnColsel(colObj&#39;.$colObj.&#39;,{&#39;;        $string .= &#39;title:"&#39;.$title.&#39;",&#39;;        $string .= &#39;value:"&#39;.$defaultvalue.&#39;",&#39;;        $string .= &#39;width:100&#39;;        $string .= &#39;});&#39;;        $string .= &#39;</script>&#39;;
    }    return $string;
}/**
 * 联动菜单层级
 */function menu_linkage_level($linkageid,$keyid,$infos,$result=array()) {
    if(array_key_exists($linkageid,$infos)) {        $result[]=$infos[$linkageid][&#39;name&#39;];        return menu_linkage_level($infos[$linkageid][&#39;parentid&#39;],$keyid,$infos,$result);
    }
    krsort($result);    return implode(&#39; > &#39;,$result);
}/**
 * 通过catid获取显示菜单完整结构
 * @param  $menuid 菜单ID
 * @param  $cache_file 菜单缓存文件名称
 * @param  $cache_path 缓存文件目录
 * @param  $key 取得缓存值的键值名称
 * @param  $parentkey 父级的ID
 * @param  $linkstring 链接字符
 */function menu_level($menuid, $cache_file, $cache_path = &#39;commons&#39;, $key = &#39;catname&#39;, $parentkey = &#39;parentid&#39;, $linkstring = &#39; > &#39;, $result=array()) {
    $menu_arr = getcache($cache_file, $cache_path);    if (array_key_exists($menuid, $menu_arr)) {        $result[] = $menu_arr[$menuid][$key];        return menu_level($menu_arr[$menuid][$parentkey], $cache_file, $cache_path, $key, $parentkey, $linkstring, $result);
    }
    krsort($result);    return implode($linkstring, $result);
}/**
 * 通过id获取显示联动菜单
 * @param  $linkageid 联动菜单ID
 * @param  $keyid 菜单keyid
 * @param  $space 菜单间隔符
 * @param  $tyoe 1 返回间隔符链接,完整路径名称 3 返回完整路径数组,2返回当前联动菜单名称,4 直接返回ID
 * @param  $result 递归使用字段1
 * @param  $infos 递归使用字段2
 */function get_linkage($linkageid, $keyid, $space = &#39;>&#39;, $type = 1, $result = array(), $infos = array()) {
    if($space==&#39;&#39; || !isset($space))$space = &#39;>&#39;;    if(!$infos) {        $datas = getcache($keyid,&#39;linkage&#39;);        $infos = $datas[&#39;data&#39;];
    }    if($type == 1 || $type == 3 || $type == 4) {        if(array_key_exists($linkageid,$infos)) {            $result[]= ($type == 1) ? $infos[$linkageid][&#39;name&#39;] : (($type == 4) ? $linkageid :$infos[$linkageid]);            return get_linkage($infos[$linkageid][&#39;parentid&#39;], $keyid, $space, $type, $result, $infos);
        } else {            if(count($result)>0) {
                krsort($result);                if($type == 1 || $type == 4) $result = implode($space,$result);                return $result;
            } else {                return $result;
            }
        }
    } else {        return $infos[$linkageid][&#39;name&#39;];
    }
}/**
 * IE浏览器判断
 */function is_ie() {
    $useragent = strtolower($_SERVER[&#39;HTTP_USER_AGENT&#39;]);    if((strpos($useragent, &#39;opera&#39;) !== false) || (strpos($useragent, &#39;konqueror&#39;) !== false)) return false;    if(strpos($useragent, &#39;msie &#39;) !== false) return true;    return false;
}/**
 * 文件下载
 * @param $filepath 文件路径
 * @param $filename 文件名称
 */function file_down($filepath, $filename = &#39;&#39;) {
    if(!$filename) $filename = basename($filepath);    if(is_ie()) $filename = rawurlencode($filename);    $filetype = fileext($filename);    $filesize = sprintf("%u", filesize($filepath));    if(ob_get_length() !== false) @ob_end_clean();
    header(&#39;Pragma: public&#39;);
    header(&#39;Last-Modified: &#39;.gmdate(&#39;D, d M Y H:i:s&#39;) . &#39; GMT&#39;);
    header(&#39;Cache-Control: no-store, no-cache, must-revalidate&#39;);
    header(&#39;Cache-Control: pre-check=0, post-check=0, max-age=0&#39;);
    header(&#39;Content-Transfer-Encoding: binary&#39;);
    header(&#39;Content-Encoding: none&#39;);
    header(&#39;Content-type: &#39;.$filetype);
    header(&#39;Content-Disposition: attachment; filename="&#39;.$filename.&#39;"&#39;);
    header(&#39;Content-length: &#39;.$filesize);
    readfile($filepath);    exit;
}/**
 * 判断字符串是否为utf8编码,英文和半角字符返回ture
 * @param $string
 * @return bool
 */function is_utf8($string) {
    return preg_match(&#39;%^(?:
                    [\x09\x0A\x0D\x20-\x7E] # ASCII
                    | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
                    | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
                    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
                    | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
                    | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
                    | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
                    | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
                    )*$%xs&#39;, $string);
}/**
 * 组装生成ID号
 * @param $modules 模块名
 * @param $contentid 内容ID
 * @param $siteid 站点ID
 */function id_encode($modules,$contentid, $siteid) {
    return urlencode($modules.&#39;-&#39;.$contentid.&#39;-&#39;.$siteid);
}/**
 * 解析ID
 * @param $id 评论ID
 */function id_decode($id) {
    return explode(&#39;-&#39;, $id);
}/**
 * 对用户的密码进行加密
 * @param $password
 * @param $encrypt //传入加密串,在修改密码时做认证
 * @return array/password
 */function password($password, $encrypt=&#39;&#39;) {
    $pwd = array();    $pwd[&#39;encrypt&#39;] =  $encrypt ? $encrypt : create_randomstr();    $pwd[&#39;password&#39;] = md5(md5(trim($password)).$pwd[&#39;encrypt&#39;]);    return $encrypt ? $pwd[&#39;password&#39;] : $pwd;
}/**
 * 生成随机字符串
 * @param string $lenth 长度
 * @return string 字符串
 */function create_randomstr($lenth = 6) {
    //openssl_random_pseudo_bytes
    $fp = @fopen(&#39;/dev/urandom&#39;,&#39;rb&#39;);    $pr_bits = &#39;&#39;;    if ($fp !== FALSE) {        $pr_bits .= @fread($fp,$lenth/2);
        @fclose($fp);
    }    return bin2hex($pr_bits);    //return random($lenth, &#39;123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&#39;);}/**
 * 生成随机数
 * @param string $lenth 长度
 * @return string 字符串
 */function create_randomnum($min,$max) {
    //openssl_random_pseudo_bytes
    $difference = $max-$min;    $bytesNeeded = ceil($difference/256);    $fp = @fopen(&#39;/dev/urandom&#39;,&#39;rb&#39;);    if ($fp !== FALSE) {        $randomBytes = @fread($fp,$bytesNeeded);
        @fclose($fp);
    }    $sum = 0;    for ($a = 0; $a < $bytesNeeded; $a++){        $sum += ord($randomBytes[$a]);
    }    $sum = $sum % ($difference);    return $sum + $min;    //return random($lenth, &#39;123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&#39;);}/**
 * 检查密码长度是否符合规定
 *
 * @param STRING $password
 * @return     TRUE or FALSE
 */function is_password($password) {
    $strlen = strlen($password);    if($strlen >= 6 && $strlen <= 20) return true;    return false;
} /**
 * 检测输入中是否含有错误字符
 *
 * @param char $string 要检查的字符串名称
 * @return TRUE or FALSE
 */function is_badword($string) {
    $badwords = array("\\",&#39;&&#39;,&#39; &#39;,"&#39;",&#39;"&#39;,&#39;/&#39;,&#39;*&#39;,&#39;,&#39;,&#39;<&#39;,&#39;>&#39;,"\r","\t","\n","#");    foreach($badwords as $value){        if(strpos($string, $value) !== FALSE) {            return TRUE;
        }
    }    return FALSE;
}/**
 * 检查用户名是否符合规定
 *
 * @param STRING $username 要检查的用户名
 * @return     TRUE or FALSE
 */function is_username($username) {
    $strlen = strlen($username);    if(is_badword($username) || !preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/", $username)){        return false;
    } elseif ( 20 < $strlen || $strlen < 2 ) {        return false;
    }    return true;
}/**
 * 检查id是否存在于数组中
 *
 * @param $id
 * @param $ids
 * @param $s
 */function check_in($id, $ids = &#39;&#39;, $s = &#39;,&#39;) {
    if(!$ids) return false;    $ids = explode($s, $ids);    return is_array($id) ? array_intersect($id, $ids) : in_array($id, $ids);
}/**
 * 对数据进行编码转换
 * @param array/string $data       数组
 * @param string $input     需要转换的编码
 * @param string $output    转换后的编码
 */function array_iconv($data, $input = &#39;gbk&#39;, $output = &#39;utf-8&#39;) {
    if (!is_array($data)) {        return iconv($input, $output, $data);
    } else {        foreach ($data as $key=>$val) {            if(is_array($val)) {                $data[$key] = array_iconv($val, $input, $output);
            } else {                $data[$key] = iconv($input, $output, $val);
            }
        }        return $data;
    }
}/**
 * 生成缩略图函数
 * @param  $imgurl 图片路径
 * @param  $width  缩略图宽度
 * @param  $height 缩略图高度
 * @param  $autocut 是否自动裁剪 默认裁剪,当高度或宽度有一个数值为0是,自动关闭
 * @param  $smallpic 无图片是默认图片路径
 */function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = &#39;nopic.gif&#39;) {
    global $image;    $upload_url = app_base::load_config(&#39;system&#39;,&#39;upload_url&#39;);    $upload_path = app_base::load_config(&#39;system&#39;,&#39;upload_path&#39;);    if(empty($imgurl)) return IMG_PATH.$smallpic;    $imgurl_replace= str_replace($upload_url, &#39;&#39;, $imgurl);    if(!extension_loaded(&#39;gd&#39;) || strpos($imgurl_replace, &#39;://&#39;)) return $imgurl;    if(!file_exists($upload_path.$imgurl_replace)) return IMG_PATH.$smallpic;    list($width_t, $height_t, $type, $attr) = getimagesize($upload_path.$imgurl_replace);    if($width>=$width_t || $height>=$height_t) return $imgurl;    $newimgurl = dirname($imgurl_replace).&#39;/thumb_&#39;.$width.&#39;_&#39;.$height.&#39;_&#39;.basename($imgurl_replace);    if(file_exists($upload_path.$newimgurl)) return $upload_url.$newimgurl;    if(!is_object($image)) {
        app_base::load_sys_class(&#39;image&#39;,&#39;&#39;,&#39;0&#39;);        $image = new image(1,0);
    }    return $image->thumb($upload_path.$imgurl_replace, $upload_path.$newimgurl, $width, $height, &#39;&#39;, $autocut) ? $upload_url.$newimgurl : $imgurl;
}/**
 * 水印添加
 * @param $source 原图片路径
 * @param $target 生成水印图片途径,默认为空,覆盖原图
 * @param $siteid 站点id,系统需根据站点id获取水印信息
 */function watermark($source, $target = &#39;&#39;,$siteid) {
    global $image_w;    if(empty($source)) return $source;    if(!extension_loaded(&#39;gd&#39;) || strpos($source, &#39;://&#39;)) return $source;    if(!$target) $target = $source;    if(!is_object($image_w)){
        app_base::load_sys_class(&#39;image&#39;,&#39;&#39;,&#39;0&#39;);        $image_w = new image(0,$siteid);
    }        $image_w->watermark($source, $target);    return $target;
}/**
 * 当前路径
 * 返回指定栏目路径层级
 * @param $catid 栏目id
 * @param $symbol 栏目间隔符
 */function catpos($catid, $symbol=&#39; > &#39;){
    $category_arr = array();    $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);    $siteid = $siteids[$catid];    $category_arr = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);    if(!isset($category_arr[$catid])) return &#39;&#39;;    $pos = &#39;&#39;;    $siteurl = siteurl($category_arr[$catid][&#39;siteid&#39;]);    $arrparentid = array_filter(explode(&#39;,&#39;, $category_arr[$catid][&#39;arrparentid&#39;].&#39;,&#39;.$catid));    foreach($arrparentid as $catid) {        $url = $category_arr[$catid][&#39;url&#39;];    //    if(strpos($url, &#39;://&#39;) === false) $url = $siteurl.$url;
        $pos .= &#39;<a href="&#39;.$url.&#39;">&#39;.$category_arr[$catid][&#39;catname&#39;].&#39;</a>&#39;.$symbol;
    }    return $pos;
}/**
 * 根据catid获取子栏目数据的sql语句
 * @param string $module 缓存文件名
 * @param intval $catid 栏目ID
 */function get_sql_catid($file = &#39;category_content_1&#39;, $catid = 0, $module = &#39;commons&#39;) {
    $category = getcache($file,$module);    $catid = intval($catid);    if(!isset($category[$catid])) return false;    return $category[$catid][&#39;child&#39;] ? " catid IN(".$category[$catid][&#39;arrchildid&#39;].") " : " catid=$catid ";
}/**
 * 获取子栏目
 * @param $parentid 父级id
 * @param $type 栏目类型
 * @param $self 是否包含本身 0为不包含
 * @param $siteid 站点id
 */function subcat($parentid = NULL, $type = NULL,$self = &#39;0&#39;, $siteid = &#39;&#39;) {
    if (empty($siteid)) $siteid = get_siteid();    $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);    foreach($category as $id=>$cat) {        if($cat[&#39;siteid&#39;] == $siteid && ($parentid === NULL || $cat[&#39;parentid&#39;] == $parentid) && ($type === NULL || $cat[&#39;type&#39;] == $type)) $subcat[$id] = $cat;        if($self == 1 && $cat[&#39;catid&#39;] == $parentid && !$cat[&#39;child&#39;])  $subcat[$id] = $cat;
    }    return $subcat;
}/**
 * 获取内容地址
 * @param $catid   栏目ID
 * @param $id      文章ID
 * @param $allurl  是否以绝对路径返回
 */function go($catid,$id, $allurl = 0) {
    static $category;    if(empty($category)) {        $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);        $siteid = $siteids[$catid];        $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);
    }    $id = intval($id);    if(!$id || !isset($category[$catid])) return &#39;&#39;;    $modelid = $category[$catid][&#39;modelid&#39;];    if(!$modelid) return &#39;&#39;;    $db = app_base::load_model(&#39;content_model&#39;);    $db->set_model($modelid);    $r = $db->setCache()->get_one(array(&#39;id&#39;=>$id), &#39;url&#39;);    if (!empty($allurl)) {        if (strpos($r[&#39;url&#39;], &#39;://&#39;)===false) {            if (strpos($category[$catid][&#39;url&#39;], &#39;://&#39;) === FALSE) {                $site = siteinfo($category[$catid][&#39;siteid&#39;]);                $r[&#39;url&#39;] = substr($site[&#39;domain&#39;], 0, -1).$r[&#39;url&#39;];
            } else {                $r[&#39;url&#39;] = $category[$catid][&#39;url&#39;].$r[&#39;url&#39;];
            }
        }
    }    return $r[&#39;url&#39;];
}/**
 * 将附件地址转换为绝对地址
 * @param $path 附件地址
 */function atturl($path) {
    if(strpos($path, &#39;:/&#39;)) {        return $path;
    } else {        $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);        $siteid =  get_siteid();        $siteurl = $sitelist[$siteid][&#39;domain&#39;];        $domainlen = strlen($sitelist[$siteid][&#39;domain&#39;])-1;        $path = $siteurl.$path;        $path = substr_replace($path, &#39;/&#39;, strpos($path, &#39;//&#39;,$domainlen),2);        return     $path;
    }
}/**
 * 判断模块是否安装
 * @param $m    模块名称
 */function module_exists($m = &#39;&#39;) {
    if ($m==&#39;admin&#39;) return true;    $modules = getcache(&#39;modules&#39;, &#39;commons&#39;);    $modules = array_keys($modules);    return in_array($m, $modules);
}/**
 * 生成SEO
 * @param $siteid       站点ID
 * @param $catid        栏目ID
 * @param $title        标题
 * @param $description  描述
 * @param $keyword      关键词
 */function seo($siteid, $catid = &#39;&#39;, $title = &#39;&#39;, $description = &#39;&#39;, $keyword = &#39;&#39;) {
    if (!empty($title))$title = strip_tags($title);    if (!empty($description)) $description = strip_tags($description);    if (!empty($keyword)) $keyword = str_replace(&#39; &#39;, &#39;,&#39;, strip_tags($keyword));    $sites = getcache(&#39;sitelist&#39;, &#39;commons&#39;);    $site = $sites[$siteid];    $cat = array();    if (!empty($catid)) {        $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);        $siteid = $siteids[$catid];        $categorys = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);        $cat = $categorys[$catid];        $cat[&#39;setting&#39;] = string2array($cat[&#39;setting&#39;]);
    }    $seo[&#39;site_title&#39;] =isset($site[&#39;site_title&#39;]) && !empty($site[&#39;site_title&#39;]) ? $site[&#39;site_title&#39;] : $site[&#39;name&#39;];    $seo[&#39;keyword&#39;] = !empty($keyword) ? $keyword : $site[&#39;keywords&#39;];    $seo[&#39;description&#39;] = isset($description) && !empty($description) ? $description : (isset($cat[&#39;setting&#39;][&#39;meta_description&#39;]) && !empty($cat[&#39;setting&#39;][&#39;meta_description&#39;]) ? $cat[&#39;setting&#39;][&#39;meta_description&#39;] : (isset($site[&#39;description&#39;]) && !empty($site[&#39;description&#39;]) ? $site[&#39;description&#39;] : &#39;&#39;));    $seo[&#39;title&#39;] =  (isset($title) && !empty($title) ? $title.&#39; - &#39; : &#39;&#39;).(isset($cat[&#39;setting&#39;][&#39;meta_title&#39;]) && !empty($cat[&#39;setting&#39;][&#39;meta_title&#39;]) ? $cat[&#39;setting&#39;][&#39;meta_title&#39;].&#39; - &#39; : (isset($cat[&#39;catname&#39;]) && !empty($cat[&#39;catname&#39;]) ? $cat[&#39;catname&#39;].&#39; - &#39; : &#39;&#39;));    foreach ($seo as $k=>$v) {        $seo[$k] = str_replace(array("\n","\r"),    &#39;&#39;, $v);
    }    return $seo;
}/**
 * 获取站点的信息
 * @param $siteid   站点ID
 */function siteinfo($siteid) {
    static $sitelist;    if (empty($sitelist)) $sitelist  = getcache(&#39;sitelist&#39;,&#39;commons&#39;);    return isset($sitelist[$siteid]) ? $sitelist[$siteid] : &#39;&#39;;
}/**
 * 生成CNZZ统计代码
 */function tjcode() {
    if(!module_exists(&#39;cnzz&#39;)) return false;    $config = getcache(&#39;cnzz&#39;, &#39;commons&#39;);    if (empty($config)) {        return false;
    } else {        return &#39;<script src=\&#39;http://pw.m.sbmmt.com/c.php?id=&#39;.$config[&#39;siteid&#39;].&#39;&l=2\&#39; language=\&#39;JavaScript\&#39; charset=\&#39;gb2312\&#39;></script>&#39;;
    }
}/**
 * 生成标题样式
 * @param $style   样式
 * @param $html    是否显示完整的STYLE
 */function title_style($style, $html = 1) {
    $str = &#39;&#39;;    if ($html) $str = &#39; style="&#39;;    $style_arr = explode(&#39;;&#39;,$style);    if (!empty($style_arr[0])) $str .= &#39;color:&#39;.$style_arr[0].&#39;;&#39;;    if (!empty($style_arr[1])) $str .= &#39;font-weight:&#39;.$style_arr[1].&#39;;&#39;;    if ($html) $str .= &#39;" &#39;;    return $str;
}/**
 * 获取站点域名
 * @param $siteid   站点id
 */function siteurl($siteid) {
    static $sitelist;    return WEB_PATH;//    if(!$siteid) return WEB_PATH;//    if(empty($sitelist)) $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);//    return substr($sitelist[$siteid][&#39;domain&#39;],0,-1);}/**
 * 生成上传附件验证
 * @param $args   参数
 * @param $operation   操作类型(加密解密)
 */function upload_key($args) {
    $pc_auth_key = md5(app_base::load_config(&#39;system&#39;,&#39;auth_key&#39;).$_SERVER[&#39;HTTP_USER_AGENT&#39;]);    $authkey = md5($args.$pc_auth_key);    return $authkey;
}/**
 * 文本转换为图片
 * @param string $txt 图形化文本内容
 * @param int $fonttype 无外部字体时生成文字大小,取值范围1-5
 * @param int $fontsize 引入外部字体时,字体大小
 * @param string $font 字体名称 字体请放于app\libs\data\font下
 * @param string $fontcolor 字体颜色 十六进制形式 如FFFFFF,FF0000
 */function string2img($txt, $fonttype = 5, $fontsize = 16, $font = &#39;&#39;, $fontcolor = &#39;FF0000&#39;,$transparent = &#39;1&#39;) {
    if(empty($txt)) return false;    if(function_exists("imagepng")) {        $txt = urlencode(sys_auth($txt));        $txt = &#39;<img src="&#39;.APP_PATH.&#39;api.php?op=creatimg&txt=&#39;.$txt.&#39;&fonttype=&#39;.$fonttype.&#39;&fontsize=&#39;.$fontsize.&#39;&font=&#39;.$font.&#39;&fontcolor=&#39;.$fontcolor.&#39;&transparent=&#39;.$transparent.&#39;" align="absmiddle">&#39;;
    }    return $txt;
}/**
 * 获取系统版本号
 */function get_pc_version($type=&#39;&#39;) {
    $version = app_base::load_config(&#39;version&#39;);    if($type==1) {        return $version[&#39;pc_version&#39;];
    } elseif($type==2) {        return $version[&#39;pc_release&#39;];
    } else {        return $version[&#39;pc_version&#39;].&#39; &#39;.$version[&#39;pc_release&#39;];
    }
}/**
 * 运行钩子(插件使用)
 */function runhook($method) {
    $time_start = getmicrotime();    $data  = &#39;&#39;;    $getpclass = FALSE;    $hook_appid = getcache(&#39;hook&#39;,&#39;plugins&#39;);    if(!empty($hook_appid)) {        foreach($hook_appid as $appid => $p) {            $pluginfilepath = CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$p.DIRECTORY_SEPARATOR.&#39;hook.class.php&#39;;            $getpclass = TRUE;            include_once $pluginfilepath;
        }        $hook_appid = array_flip($hook_appid);        if($getpclass) {            $pclass = new ReflectionClass(&#39;hook&#39;);            foreach($pclass->getMethods() as $r) {                $legalmethods[] = $r->getName();
            }
        }        if(in_array($method,$legalmethods)) {            foreach (get_declared_classes() as $class){               $refclass = new ReflectionClass($class);               if($refclass->isSubclassOf(&#39;hook&#39;)){                  if ($_method = $refclass->getMethod($method)) {                          $classname = $refclass->getName();                        if ($_method->isPublic() && $_method->isFinal()) {
                            plugin_stat($hook_appid[$classname]);                            $data .= $_method->invoke(null);
                        }
                    }
               }
            }
        }        return $data;
    }
}function getmicrotime() {
    list($usec, $sec) = explode(" ",microtime());    return ((float)$usec + (float)$sec);
}/**
 * 插件前台模板加载
 * Enter description here ...
 * @param unknown_type $module
 * @param unknown_type $template
 * @param unknown_type $style
 */function p_template($plugin = &#39;content&#39;, $template = &#39;index&#39;,$style=&#39;default&#39;) {
    if(!$style) $style = &#39;default&#39;;    $template_cache = app_base::load_sys_class(&#39;template_cache&#39;);    $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;    if(!file_exists($compiledtplfile) || (file_exists(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) && filemtime(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > filemtime($compiledtplfile))) {        $template_cache->template_compile(&#39;plugin/&#39;.$plugin, $template, &#39;default&#39;);
    } elseif (!file_exists(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {
        showmessage(&#39;Template does not exist.&#39;.DIRECTORY_SEPARATOR.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;);
    }    return $compiledtplfile;
}/**
 * 读取缓存动态页面
 */function cache_page_start() {
    $relate_url = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? safe_replace($_SERVER[&#39;REQUEST_URI&#39;]) : $php_self.(isset($_SERVER[&#39;QUERY_STRING&#39;]) ? &#39;?&#39;.safe_replace($_SERVER[&#39;QUERY_STRING&#39;]) : $path_info);
    define(&#39;CACHE_PAGE_ID&#39;, md5($relate_url));    $contents = getcache(CACHE_PAGE_ID, &#39;page_tmp/&#39;.substr(CACHE_PAGE_ID, 0, 2));    if($contents && intval(substr($contents, 15, 10)) > SYS_TIME) {        echo substr($contents, 29);        exit;
    }    if (!defined(&#39;HTML&#39;)) define(&#39;HTML&#39;,true);    return true;
}/**
 * 写入缓存动态页面
 */function cache_page($ttl = 360, $isjs = 0) {
    if($ttl == 0 || !defined(&#39;CACHE_PAGE_ID&#39;)) return false;    $contents = ob_get_contents();    if($isjs) $contents = format_js($contents);    $contents = "<!--expiretime:".(SYS_TIME + $ttl)."-->\n".$contents;
    setcache(CACHE_PAGE_ID, $contents, &#39;page_tmp/&#39;.substr(CACHE_PAGE_ID, 0, 2));
}/**
 *
 * 获取远程内容
 * @param $url 接口url地址
 * @param $timeout 超时时间
 */function pc_file_get_contents($url, $timeout=30) {
    $stream = stream_context_create(array(&#39;http&#39; => array(&#39;timeout&#39; => $timeout)));    return @file_get_contents($url, 0, $stream);
}/**
 * Function get_vid
 * 获取视频信息
 * @param int $contentid 内容ID 必须
 * @param int $catid 栏目id 取内容里面视频信息时必须
 * @param int $isspecial 是否取专题的视频信息
 */function get_vid($contentid = 0, $catid = 0, $isspecial = 0) {
    static $categorys;    if (!$contentid) return false;    if (!$isspecial) {        if (!$catid) return false;        $contentid = intval($contentid);        $catid = intval($catid);        $siteid = get_siteid();        if (!$categorys) {            $categorys = getcache(&#39;category_content_&#39;.$siteid, &#39;commons&#39;);
        }        $modelid = $categorys[$catid][&#39;modelid&#39;];        $video_content = app_base::load_model(&#39;video_content_model&#39;);        $r = $video_content->get_one(array(&#39;contentid&#39;=>$contentid, &#39;modelid&#39;=>$modelid), &#39;videoid&#39;, &#39;listorder ASC&#39;);        $video_store =app_base::load_model(&#39;video_store_model&#39;);        return $video_store->get_one(array(&#39;videoid&#39;=>$r[&#39;videoid&#39;]));
    } else {        $special_content = app_base::load_model(&#39;special_content_model&#39;);        $contentid = intval($contentid);        $video_store =app_base::load_model(&#39;video_store_model&#39;);        $r = $special_content->get_one(array(&#39;id&#39;=>$contentid), &#39;videoid&#39;);        return $video_store->get_one(array(&#39;videoid&#39;=>$r[&#39;videoid&#39;]));
    }
}/**
 * Function dataformat
 * 时间转换
  * @param $n INT时间
 */
 function dataformat($n) {
    $hours = floor($n/3600);    $minite    = floor($n%3600/60);    $secend = floor($n%3600%60);    $minite = $minite < 10 ? "0".$minite : $minite;    $secend = $secend < 10 ? "0".$secend : $secend;    if($n >= 3600){        return $hours.":".$minite.":".$secend;
    }else{        return $minite.":".$secend;
    }

 } 
 function httpResponse($status, $msg=&#39;&#39;){
     $m = app_base::load_model(&#39;category_model&#39;);     $CATEGORYS = $m->select(array(&#39;parentid&#39;=>0),&#39;*&#39;,&#39;&#39;,&#39;listorder&#39;);     include CODE_PATH . &#39;libs&#39;.DIRECTORY_SEPARATOR.&#39;data&#39;.DIRECTORY_SEPARATOR.&#39;http&#39;.DIRECTORY_SEPARATOR.$status.&#39;.php&#39;;
 } function array_change_key_case_recursive($arr)
 {
     if(! $arr || !is_array($arr))return array(); 
    return array_map(function($item){
        if(is_array($item))            $item = array_change_key_case_recursive($item);        return $item;
    },array_change_key_case($arr));
 } 

 function visitauth(){
     $vtime = time();    $vsign = md5("cuichuande@ideadata.com.cn#$%" . $vtime);    return "tm={$vtime}&sn={$vsign}";
 }?>
Copy after login

最近工作有点忙,更新慢了

<?php/**
 *  global.func.php 公共函数库
 *//**
 * 返回经addslashes处理过的字符串或数组
 * @param $string 需要处理的字符串或数组
 * @return mixed
 */function new_addslashes($string){
    if(!is_array($string)) return addslashes($string);    foreach($string as $key => $val) $string[$key] = new_addslashes($val);    return $string;
}/**
 * 返回经stripslashes处理过的字符串或数组
 * @param $string 需要处理的字符串或数组
 * @return mixed
 */function new_stripslashes($string) {
    if(!is_array($string)) return stripslashes($string);    foreach($string as $key => $val) $string[$key] = new_stripslashes($val);    return $string;
}/**
 * 返回经htmlspecialchars处理过的字符串或数组
 * @param $obj 需要处理的字符串或数组
 * @return mixed
 */function new_html_special_chars($string) {
    $encoding = &#39;utf-8&#39;;    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    if(!is_array($string)) return htmlspecialchars($string,ENT_QUOTES,$encoding);    foreach($string as $key => $val) $string[$key] = new_html_special_chars($val);    return $string;
}function new_html_entity_decode($string) {
    $encoding = &#39;utf-8&#39;;    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    return html_entity_decode($string,ENT_QUOTES,$encoding);
}function new_htmlentities($string) {
    $encoding = &#39;utf-8&#39;;    if(strtolower(CHARSET)==&#39;gbk&#39;) $encoding = &#39;ISO-8859-15&#39;;    return htmlentities($string,ENT_QUOTES,$encoding);
}/**
 * 安全过滤函数
 *
 * @param $string
 * @return string
 */function safe_replace($string) {
    $string = str_replace(&#39;%20&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;%27&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;%2527&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;*&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;"&#39;,&#39;"&#39;,$string);    $string = str_replace("&#39;",&#39;&#39;,$string);    $string = str_replace(&#39;"&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;;&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;<&#39;,&#39;<&#39;,$string);    $string = str_replace(&#39;>&#39;,&#39;>&#39;,$string);    $string = str_replace("{",&#39;&#39;,$string);    $string = str_replace(&#39;}&#39;,&#39;&#39;,$string);    $string = str_replace(&#39;\\&#39;,&#39;&#39;,$string);    return $string;
}/**
 * xss过滤函数
 *
 * @param $string
 * @return string
 */function remove_xss($string) { 
    $string = preg_replace(&#39;/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S&#39;, &#39;&#39;, $string);    $parm1 = Array(&#39;javascript&#39;, &#39;vbscript&#39;, &#39;expression&#39;, &#39;applet&#39;, &#39;meta&#39;, &#39;xml&#39;, &#39;blink&#39;, &#39;link&#39;, &#39;script&#39;, &#39;embed&#39;, &#39;object&#39;, &#39;iframe&#39;, &#39;frame&#39;, &#39;frameset&#39;, &#39;ilayer&#39;, &#39;layer&#39;, &#39;bgsound&#39;, &#39;title&#39;, &#39;base&#39;);    $parm2 = Array(&#39;onabort&#39;, &#39;onactivate&#39;, &#39;onafterprint&#39;, &#39;onafterupdate&#39;, &#39;onbeforeactivate&#39;, &#39;onbeforecopy&#39;, &#39;onbeforecut&#39;, &#39;onbeforedeactivate&#39;, &#39;onbeforeeditfocus&#39;, &#39;onbeforepaste&#39;, &#39;onbeforeprint&#39;, &#39;onbeforeunload&#39;, &#39;onbeforeupdate&#39;, &#39;onblur&#39;, &#39;onbounce&#39;, &#39;oncellchange&#39;, &#39;onchange&#39;, &#39;onclick&#39;, &#39;oncontextmenu&#39;, &#39;oncontrolselect&#39;, &#39;oncopy&#39;, &#39;oncut&#39;, &#39;ondataavailable&#39;, &#39;ondatasetchanged&#39;, &#39;ondatasetcomplete&#39;, &#39;ondblclick&#39;, &#39;ondeactivate&#39;, &#39;ondrag&#39;, &#39;ondragend&#39;, &#39;ondragenter&#39;, &#39;ondragleave&#39;, &#39;ondragover&#39;, &#39;ondragstart&#39;, &#39;ondrop&#39;, &#39;onerror&#39;, &#39;onerrorupdate&#39;, &#39;onfilterchange&#39;, &#39;onfinish&#39;, &#39;onfocus&#39;, &#39;onfocusin&#39;, &#39;onfocusout&#39;, &#39;onhelp&#39;, &#39;onkeydown&#39;, &#39;onkeypress&#39;, &#39;onkeyup&#39;, &#39;onlayoutcomplete&#39;, &#39;onload&#39;, &#39;onlosecapture&#39;, &#39;onmousedown&#39;, &#39;onmouseenter&#39;, &#39;onmouseleave&#39;, &#39;onmousemove&#39;, &#39;onmouseout&#39;, &#39;onmouseover&#39;, &#39;onmouseup&#39;, &#39;onmousewheel&#39;, &#39;onmove&#39;, &#39;onmoveend&#39;, &#39;onmovestart&#39;, &#39;onpaste&#39;, &#39;onpropertychange&#39;, &#39;onreadystatechange&#39;, &#39;onreset&#39;, &#39;onresize&#39;, &#39;onresizeend&#39;, &#39;onresizestart&#39;, &#39;onrowenter&#39;, &#39;onrowexit&#39;, &#39;onrowsdelete&#39;, &#39;onrowsinserted&#39;, &#39;onscroll&#39;, &#39;onselect&#39;, &#39;onselectionchange&#39;, &#39;onselectstart&#39;, &#39;onstart&#39;, &#39;onstop&#39;, &#39;onsubmit&#39;, &#39;onunload&#39;);    $parm = array_merge($parm1, $parm2); 

    for ($i = 0; $i < sizeof($parm); $i++) { 
        $pattern = &#39;/&#39;; 
        for ($j = 0; $j < strlen($parm[$i]); $j++) { 
            if ($j > 0) { 
                $pattern .= &#39;(&#39;; 
                $pattern .= &#39;(&#[x|X]0([9][a][b]);?)?&#39;; 
                $pattern .= &#39;|(&#0([9][10][13]);?)?&#39;; 
                $pattern .= &#39;)?&#39;; 
            }            $pattern .= $parm[$i][$j]; 
        }        $pattern .= &#39;/i&#39;;        $string = preg_replace($pattern, &#39; &#39;, $string); 
    }    return $string;
}/**
 * 过滤ASCII码从0-28的控制字符
 * @return String
 */function trim_unsafe_control_chars($str) {
    $rule = &#39;/[&#39; . chr ( 1 ) . &#39;-&#39; . chr ( 8 ) . chr ( 11 ) . &#39;-&#39; . chr ( 12 ) . chr ( 14 ) . &#39;-&#39; . chr ( 31 ) . &#39;]*/&#39;;    return str_replace ( chr ( 0 ), &#39;&#39;, preg_replace ( $rule, &#39;&#39;, $str ) );
}/**
 * 格式化文本域内容
 *
 * @param $string 文本域内容
 * @return string
 */function trim_textarea($string) {
    $string = nl2br ( str_replace ( &#39; &#39;, &#39; &#39;, $string ) );    return $string;
}/**
 * 将文本格式成适合js输出的字符串
 * @param string $string 需要处理的字符串
 * @param intval $isjs 是否执行字符串格式化,默认为执行
 * @return string 处理后的字符串
 */function format_js($string, $isjs = 1) {
    $string = addslashes(str_replace(array("\r", "\n", "\t"), array(&#39;&#39;, &#39;&#39;, &#39;&#39;), $string));    return $isjs ? &#39;document.write("&#39;.$string.&#39;");&#39; : $string;
}/**
 * 转义 javascript 代码标记
 *
 * @param $str
 * @return mixed
 */
 function trim_script($str) {
    if(is_array($str)){        foreach ($str as $key => $val){            $str[$key] = trim_script($val);
        }
     }else{         $str = preg_replace ( &#39;/\<([\/]?)script([^\>]*?)\>/si&#39;, &#39;<\\1script\\2>&#39;, $str );        $str = preg_replace ( &#39;/\<([\/]?)iframe([^\>]*?)\>/si&#39;, &#39;<\\1iframe\\2>&#39;, $str );        $str = preg_replace ( &#39;/\<([\/]?)frame([^\>]*?)\>/si&#39;, &#39;<\\1frame\\2>&#39;, $str );        $str = str_replace ( &#39;javascript:&#39;, &#39;javascript:&#39;, $str );
     }    return $str;
}/**
 * 获取当前页面完整URL地址
 */function get_url() {
    $sys_protocal = isset($_SERVER[&#39;SERVER_PORT&#39;]) && $_SERVER[&#39;SERVER_PORT&#39;] == &#39;443&#39; ? &#39;https://&#39; : &#39;http://&#39;;    $php_self = $_SERVER[&#39;PHP_SELF&#39;] ? safe_replace($_SERVER[&#39;PHP_SELF&#39;]) : safe_replace($_SERVER[&#39;SCRIPT_NAME&#39;]);    $path_info = isset($_SERVER[&#39;PATH_INFO&#39;]) ? safe_replace($_SERVER[&#39;PATH_INFO&#39;]) : &#39;&#39;;    $relate_url = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? safe_replace($_SERVER[&#39;REQUEST_URI&#39;]) : $php_self.(isset($_SERVER[&#39;QUERY_STRING&#39;]) ? &#39;?&#39;.safe_replace($_SERVER[&#39;QUERY_STRING&#39;]) : $path_info);    return $sys_protocal.(isset($_SERVER[&#39;HTTP_HOST&#39;]) ? $_SERVER[&#39;HTTP_HOST&#39;] : &#39;&#39;).$relate_url;
}/**
 * 字符截取 支持UTF8/GBK
 * @param $string
 * @param $length
 * @param $dot
 */function str_cut($string, $length, $dot = &#39;...&#39;) {
    $strlen = strlen($string);    if($strlen <= $length) return $string;    $string = str_replace(array(&#39; &#39;,&#39; &#39;, &#39;&&#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), array(&#39;∵&#39;,&#39; &#39;, &#39;&&#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), $string);
    $strcut = &#39;&#39;;
    if(strtolower(CHARSET) == &#39;utf-8&#39;) {
        $length = intval($length-strlen($dot)-$length/3);
        $n = $tn = $noc = 0;
        while($n < strlen($string)) {
            $t = ord($string[$n]);
            if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
                $tn = 1; $n++; $noc++;
            } elseif(194 <= $t && $t <= 223) {
                $tn = 2; $n += 2; $noc += 2;
            } elseif(224 <= $t && $t <= 239) {
                $tn = 3; $n += 3; $noc += 2;
            } elseif(240 <= $t && $t <= 247) {
                $tn = 4; $n += 4; $noc += 2;
            } elseif(248 <= $t && $t <= 251) {
                $tn = 5; $n += 5; $noc += 2;
            } elseif($t == 252 || $t == 253) {
                $tn = 6; $n += 6; $noc += 2;
            } else {
                $n++;
            }
            if($noc >= $length) {
                break;
            }
        }
        if($noc > $length) {
            $n -= $tn;
        }
        $strcut = substr($string, 0, $n);
        $strcut = str_replace(array(&#39;∵&#39;, &#39;&&#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), array(&#39; &#39;, &#39;&&#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;), $strcut);
    } else {
        $dotlen = strlen($dot);
        $maxi = $length - $dotlen - 1;
        $current_str = &#39;&#39;;
        $search_arr = array(&#39;&&#39;,&#39; &#39;, &#39;"&#39;, "&#39;", &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;,&#39;∵&#39;);
        $replace_arr = array(&#39;&&#39;,&#39; &#39;, &#39;"&#39;, &#39;&#39;&#39;, &#39;“&#39;, &#39;”&#39;, &#39;—&#39;, &#39;<&#39;, &#39;>&#39;, &#39;·&#39;, &#39;…&#39;,&#39; &#39;);        $search_flip = array_flip($search_arr);        for ($i = 0; $i < $maxi; $i++) {            $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];            if (in_array($current_str, $search_arr)) {                $key = $search_flip[$current_str];                $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
            }            $strcut .= $current_str;
        }
    }    return $strcut.$dot;
}/**
 * 获取请求ip
 *
 * @return ip地址
 */function ip() {
    if(getenv(&#39;HTTP_CLIENT_IP&#39;) && strcasecmp(getenv(&#39;HTTP_CLIENT_IP&#39;), &#39;unknown&#39;)) {        $ip = getenv(&#39;HTTP_CLIENT_IP&#39;);
    } elseif(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;) && strcasecmp(getenv(&#39;HTTP_X_FORWARDED_FOR&#39;), &#39;unknown&#39;)) {        $ip = getenv(&#39;HTTP_X_FORWARDED_FOR&#39;);
    } elseif(getenv(&#39;REMOTE_ADDR&#39;) && strcasecmp(getenv(&#39;REMOTE_ADDR&#39;), &#39;unknown&#39;)) {        $ip = getenv(&#39;REMOTE_ADDR&#39;);
    } elseif(isset($_SERVER[&#39;REMOTE_ADDR&#39;]) && $_SERVER[&#39;REMOTE_ADDR&#39;] && strcasecmp($_SERVER[&#39;REMOTE_ADDR&#39;], &#39;unknown&#39;)) {        $ip = $_SERVER[&#39;REMOTE_ADDR&#39;];
    }    return preg_match ( &#39;/[\d\.]{7,15}/&#39;, $ip, $matches ) ? $matches [0] : &#39;&#39;;
}function get_cost_time() {
    $microtime = microtime ( TRUE );    return $microtime - SYS_START_TIME;
}/**
 * 程序执行时间
 *
 * @return    int    单位ms
 */function execute_time() {
    $stime = explode ( &#39; &#39;, SYS_START_TIME );    $etime = explode ( &#39; &#39;, microtime () );    return number_format ( ($etime [1] + $etime [0] - $stime [1] - $stime [0]), 6 );
}/**
* 将字符串转换为数组
*
* @param    string    $data    字符串
* @return    array    返回数组格式,如果,data为空,则返回空数组
*/function string2array($data) {
    if($data == &#39;&#39;) return array();    $data = stripslashes($data);
    @eval("\$array = $data;");    return $array;
}/**
* 将数组转换为字符串
*
* @param    array    $data        数组
* @param    bool    $isformdata    如果为0,则不使用new_stripslashes处理,可选参数,默认为1
* @return    string    返回字符串,如果,data为空,则返回空
*/function array2string($data, $isformdata = 1) {
    if($data == &#39;&#39;) return &#39;&#39;;    if($isformdata) $data = new_stripslashes($data);    return addslashes(var_export($data, TRUE));
}/**
* 转换字节数为其他单位
*
*
* @param    string    $filesize    字节大小
* @return    string    返回大小
*/function sizecount($filesize) {
    if ($filesize >= 1073741824) {        $filesize = round($filesize / 1073741824 * 100) / 100 .&#39; GB&#39;;
    } elseif ($filesize >= 1048576) {        $filesize = round($filesize / 1048576 * 100) / 100 .&#39; MB&#39;;
    } elseif($filesize >= 1024) {        $filesize = round($filesize / 1024 * 100) / 100 . &#39; KB&#39;;
    } else {        $filesize = $filesize.&#39; Bytes&#39;;
    }    return $filesize;
}/**
* 字符串加密、解密函数
*
*
* @param    string    $txt        字符串
* @param    string    $operation    ENCODE为加密,DECODE为解密,可选参数,默认为ENCODE,
* @param    string    $key        密钥:数字、字母、下划线
* @param    string    $expiry        过期时间
* @return    string
*/function sys_auth($string, $operation = &#39;ENCODE&#39;, $key = &#39;&#39;, $expiry = 0) {
    $key_length = 4;    $key = md5($key != &#39;&#39; ? $key : app_base::load_config(&#39;system&#39;, &#39;auth_key&#39;));    $fixedkey = md5($key);    $egiskeys = md5(substr($fixedkey, 16, 16));    $runtokey = $key_length ? ($operation == &#39;ENCODE&#39; ? substr(md5(microtime(true)), -$key_length) : substr($string, 0, $key_length)) : &#39;&#39;;    $keys = md5(substr($runtokey, 0, 16) . substr($fixedkey, 0, 16) . substr($runtokey, 16) . substr($fixedkey, 16));    $string = $operation == &#39;ENCODE&#39; ? sprintf(&#39;%010d&#39;, $expiry ? $expiry + time() : 0).substr(md5($string.$egiskeys), 0, 16) . $string : base64_decode(substr($string, $key_length));    $i = 0; $result = &#39;&#39;;    $string_length = strlen($string);    for ($i = 0; $i < $string_length; $i++){        $result .= chr(ord($string{$i}) ^ ord($keys{$i % 32}));
    }    if($operation == &#39;ENCODE&#39;) {        return $runtokey . str_replace(&#39;=&#39;, &#39;&#39;, base64_encode($result));
    } else {        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$egiskeys), 0, 16)) {            return substr($result, 26);
        } else {            return &#39;&#39;;
        }
    }
}/**
* 语言文件处理
*
* @param    string        $language    标示符
* @param    array        $pars    转义的数组,二维数组 ,&#39;key1&#39;=>&#39;value1&#39;,&#39;key2&#39;=>&#39;value2&#39;,
* @param    string        $modules 多个模块之间用半角逗号隔开,如:member,guestbook
* @return    string        语言字符
*/function L($language = &#39;no_language&#39;,$pars = array(), $modules = &#39;&#39;) {
    static $LANG = array();    static $LANG_MODULES = array();    static $lang = &#39;&#39;;    if(defined(&#39;IN_ADMIN&#39;)) {        $lang = SYS_STYLE ? SYS_STYLE : &#39;zh-cn&#39;;
    } else {        $lang = app_base::load_config(&#39;system&#39;,&#39;lang&#39;);
    }    if(!$LANG) {        require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.&#39;system.lang.php&#39;;        if(defined(&#39;IN_ADMIN&#39;)) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.&#39;system_menu.lang.php&#39;;        if(file_exists(CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.&#39;.lang.php&#39;)) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.ROUTE_M.&#39;.lang.php&#39;;
    }    if(!empty($modules)) {        $modules = explode(&#39;,&#39;,$modules);        foreach($modules AS $m) {            if(!isset($LANG_MODULES[$m])) require_once CODE_PATH.&#39;languages&#39;.DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR.$m.&#39;.lang.php&#39;;
        }
    }    if(!array_key_exists($language,$LANG)) {        return $language;
    } else {        $language = $LANG[$language];        if($pars) {            foreach($pars AS $_k=>$_v) {                $language = str_replace(&#39;{&#39;.$_k.&#39;}&#39;,$_v,$language);
            }
        }        return $language;
    }
}/**
 * 模板调用
 *
 * @param $module
 * @param $template
 * @param $istag
 * @return unknown_type
 */function template($module = &#39;content&#39;, $template = &#39;index&#39;, $style = &#39;&#39;) {

    if(strpos($module, &#39;plugin/&#39;)!== false) {        $plugin = str_replace(&#39;plugin/&#39;, &#39;&#39;, $module);        return p_template($plugin, $template,$style);
    }    $module = str_replace(&#39;/&#39;, DIRECTORY_SEPARATOR, $module);    if(!empty($style) && preg_match(&#39;/([a-z0-9\-_]+)/is&#39;,$style)) {
    } elseif (empty($style) && !defined(&#39;STYLE&#39;)) {        if(defined(&#39;SITEID&#39;)) {            $siteid = SITEID;
        } else {            $siteid = param::get_cookie(&#39;siteid&#39;);
        }        if (!$siteid) $siteid = 1;        $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);        if(!empty($siteid)) {            $style = $sitelist[$siteid][&#39;default_style&#39;];
        }
    } elseif (empty($style) && defined(&#39;STYLE&#39;)) {        $style = STYLE;
    } else {        $style = &#39;default&#39;;
    }    if(!$style) $style = &#39;default&#39;;    $template_cache = app_base::load_sys_class(&#39;template_cache&#39;);    $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;    if(file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {        if(!file_exists($compiledtplfile) || (@filemtime(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > @filemtime($compiledtplfile))) {            $template_cache->template_compile($module, $template, $style);
        }
    } else {        $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;        if(!file_exists($compiledtplfile) || (file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) && filemtime(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > filemtime($compiledtplfile))) {            $template_cache->template_compile($module, $template, &#39;default&#39;);
        } elseif (!file_exists(CODE_PATH.&#39;templates&#39;.DIRECTORY_SEPARATOR.&#39;default&#39;.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {
            showmessage(&#39;Template does not exist.&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;);
        }
    }    return $compiledtplfile;
}/**
 * 输出自定义错误
 *
 * @param $errno 错误号
 * @param $errstr 错误描述
 * @param $errfile 报错文件地址
 * @param $errline 错误行号
 * @return string 错误提示
 */function my_error_handler($errno, $errstr, $errfile, $errline) {
    if($errno==8) return &#39;&#39;;    $errfile = str_replace(ROOT_PATH,&#39;&#39;,$errfile);    if(app_base::load_config(&#39;system&#39;,&#39;errorlog&#39;)) {
        error_log(&#39;<?php exit;?>&#39;.date(&#39;m-d H:i:s&#39;,SYS_TIME).&#39; | &#39;.$errno.&#39; | &#39;.str_pad($errstr,30).&#39; | &#39;.$errfile.&#39; | &#39;.$errline."\r\n", 3, CACHE_PATH.&#39;error_log.php&#39;);
    } else {        $str = &#39;<p style="font-size:12px;text-align:left; border-bottom:1px solid #9cc9e0; border-right:1px solid #9cc9e0;padding:1px 4px;color:#000000;font-family:Arial, Helvetica,sans-serif;"><span>errorno:&#39; . $errno . &#39;,str:&#39; . $errstr . &#39;,file:<font color="blue">&#39; . $errfile . &#39;</font>,line&#39; . $errline .&#39;<br />Need Help?</span></p>&#39;;        echo $str;
    }
}/**
 * 提示信息页面跳转,跳转地址如果传入数组,页面会提示多个地址供用户选择,默认跳转地址为数组的第一个值,时间为5秒。
 * showmessage(&#39;登录成功&#39;, array(&#39;默认跳转地址&#39;=>&#39;http://www.baidu.com&#39;));
 * @param string $msg 提示信息
 * @param mixed(string/array) $url_forward 跳转地址
 * @param int $ms 跳转等待时间
 */function showmessage($msg, $url_forward = &#39;goback&#39;, $ms = 1250, $dialog = &#39;&#39;, $returnjs = &#39;&#39;) {
    if(defined(&#39;IN_ADMIN&#39;)) {        include(admin::admin_tpl(&#39;showmessage&#39;, &#39;admin&#39;));
    } else {        include(template(&#39;content&#39;, &#39;message&#39;));
    }    exit;
}/**
 * 查询字符是否存在于某字符串
 *
 * @param $haystack 字符串
 * @param $needle 要查找的字符
 * @return bool
 */function str_exists($haystack, $needle){
    return !(strpos($haystack, $needle) === FALSE);
}/**
 * 取得文件扩展
 *
 * @param $filename 文件名
 * @return 扩展名
 */function fileext($filename) {
    return strtolower(trim(substr(strrchr($filename, &#39;.&#39;), 1, 10)));
}/**
 * 加载模板标签缓存
 * @param string $name 缓存名
 * @param integer $times 缓存时间
 */function tpl_cache($name,$times = 0) {
    $filepath = &#39;tpl_data&#39;;    $info = getcacheinfo($name, $filepath);    if (SYS_TIME - $info[&#39;filemtime&#39;] >= $times) {        return false;
    } else {        return getcache($name,$filepath);
    }
}/**
 * 写入缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $data 缓存数据
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 * @param $timeout 过期时间
 */function setcache($name, $data, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;, $timeout=0) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->set($name, $data, $timeout, &#39;&#39;, $filepath);
}/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */function getcache($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->get($name, &#39;&#39;, &#39;&#39;, $filepath);
}//根据行政区划数字获取对应名称名称  如 110101 得到 北京市东城区function get_p($p=&#39;&#39;){
    if(empty($p)){        return false;
    }    $regioncode = getcache(&#39;1&#39;,&#39;linkage&#39;);    if($regioncode)
    {        $l1=substr($p,0,2).&#39;0000&#39;;        $L1_n=$regioncode[&#39;data&#39;][$l1][&#39;name&#39;];        $tb=array(&#39;110000&#39;,&#39;120000&#39;,&#39;310000&#39;,&#39;500000&#39;);        if(in_array($l1,$tb)){            $l2 = $l1=substr($p,0,2)."0000-r";
        }else{            $l2 = substr($p,0,4)."00";
        }        $L2_n =  $regioncode[&#39;data&#39;][$l2][&#39;name&#39;];        $L3_n =  $regioncode[&#39;data&#39;][$p][&#39;name&#39;];        if($L2_n===$L1_n){            $res_p = $L1_n.$L3_n;
        }else{            $res_p = $L1_n.$L2_n.$L3_n;
        }        return $res_p;
    }else{        return &#39;无行政区划地址&#39;;
    }
}//根据行业类型数字获取对应名称名称  如 $trade=‘1A0112’ 得到 农、林、牧、渔业-农业-谷物及其他作物的种植-薯类的种植function get_trade_category($trade=&#39;&#39;){
    if(empty($trade)){        return false;
    }    $trade_category = getcache(&#39;3&#39;,&#39;linkage&#39;);    if($trade_category){        $t1=substr($trade,0,2);        $T_1=$trade_category[&#39;data&#39;][$t1][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t1][&#39;name&#39;]:&#39;&#39;;        $t2=substr($trade,0,4);        $T_2=$trade_category[&#39;data&#39;][$t2][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t2][&#39;name&#39;]:&#39;&#39;;        $t3=substr($trade,0,5);        $T_3=$trade_category[&#39;data&#39;][$t3][&#39;name&#39;]?$trade_category[&#39;data&#39;][$t3][&#39;name&#39;]:&#39;&#39;;        $T_4=$trade_category[&#39;data&#39;][$trade][&#39;name&#39;]?$trade_category[&#39;data&#39;][$trade][&#39;name&#39;]:&#39;&#39;;        if($T_3===$T_4){            $res_trade = $T_1.&#39;-&#39;.$T_2.&#39;-&#39;.$T_3;
        }else{            $res_trade = $T_1.&#39;-&#39;.$T_2.&#39;-&#39;.$T_3.&#39;-&#39;.$T_4;
        }        if(empty($res_trade)){            return &#39;行业类型数据不存在&#39;;
        }        return $res_trade;

    }else{        return &#39;行业类型数据不存在&#39;;
    }
}/**
 * 删除缓存,默认为文件缓存,不加载缓存配置。
 * @param $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param $type 缓存类型[file,memcache,apc]
 * @param $config 配置名称
 */function delcache($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;,&#39;&#39;,0);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->delete($name, &#39;&#39;, &#39;&#39;, $filepath);
}/**
 * 读取缓存,默认为文件缓存,不加载缓存配置。
 * @param string $name 缓存名称
 * @param $filepath 数据路径(模块名称) caches/cache_$filepath/
 * @param string $config 配置名称
 */function getcacheinfo($name, $filepath=&#39;&#39;, $type=&#39;file&#39;, $config=&#39;&#39;) {
    app_base::load_sys_class(&#39;cache_factory&#39;);    if($config) {        $cacheconfig = app_base::load_config(&#39;cache&#39;);        $cache = cache_factory::get_instance($cacheconfig)->get_cache($config);
    } else {        $cache = cache_factory::get_instance()->get_cache($type);
    }    return $cache->cacheinfo($name, &#39;&#39;, &#39;&#39;, $filepath);
}/**
 * 生成sql语句,如果传入$in_cloumn 生成格式为 IN(&#39;a&#39;, &#39;b&#39;, &#39;c&#39;)
 * @param $data 条件数组或者字符串
 * @param $front 连接符
 * @param $in_column 字段名称
 * @return string
 */function to_sqls($data, $front = &#39; AND &#39;, $in_column = false) {
    if($in_column && is_array($data)) {        $ids = &#39;\&#39;&#39;.implode(&#39;\&#39;,\&#39;&#39;, $data).&#39;\&#39;&#39;;        $sql = "$in_column IN ($ids)";        return $sql;
    } else {        if ($front == &#39;&#39;) {            $front = &#39; AND &#39;;
        }        if(is_array($data) && count($data) > 0) {            $sql = &#39;&#39;;            foreach ($data as $key => $val) {                $sql .= $sql ? " $front $key = &#39;$val&#39; " : " $key = &#39;$val&#39; ";
            }            return $sql;
        } else {            return $data;
        }
    }
}/**
 * 分页函数
 *
 * @param $num 信息总数
 * @param $curr_page 当前分页
 * @param $perpage 每页显示数
 * @param $urlrule URL规则
 * @param $array 需要传递的数组,用于增加额外的方法
 * @return 分页
 */function pages($num, $curr_page, $perpage = 20, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($num > $perpage) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        $pages = ceil($num / $perpage);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $curr_page-1, $array).&#39;" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, 1, $array).&#39;">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, 1, $array).&#39;">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $i, $array).&#39;">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="&#39;.pageurl($urlrule, $curr_page, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="&#39;.pageurl($urlrule, $pages, $array).&#39;">&#39;.$pages.&#39;</a> <a href="&#39;.pageurl($urlrule, $curr_page+1, $array).&#39;" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}function pages1($num, $curr_page, $perpage = 20, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($num > $perpage) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        $pages = ceil($num / $perpage);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page-1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(1);$(\&#39;#pageform\&#39;).submit();">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(1);$(\&#39;#pageform\&#39;).submit();">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$i.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###"  onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$curr_page.&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.$pages.&#39;);$(\&#39;#pageform\&#39;).submit();">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#page\&#39;).val(&#39;.($curr_page+1).&#39;);$(\&#39;#pageform\&#39;).submit();" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}function pages2($num, $curr_page, $pages, $urlrule = &#39;&#39;, $array = array(),$setpages = 10) {
    if(defined(&#39;URLRULE&#39;) && $urlrule == &#39;&#39;) {        $urlrule = URLRULE;        $array = $GLOBALS[&#39;URL_ARRAY&#39;];
    } elseif($urlrule == &#39;&#39;) {        $urlrule = url_par(&#39;page={$page}&#39;);
    }    $multipage = &#39;&#39;;    if($pages > 1) {        $page = $setpages+1;        $offset = ceil($setpages/2-1);        if (defined(&#39;IN_ADMIN&#39;) && !defined(&#39;PAGES&#39;)) define(&#39;PAGES&#39;, $pages);        $from = $curr_page - $offset;        $to = $curr_page + $offset;        $more = 0;        if($page >= $pages) {            $from = 2;            $to = $pages-1;
        } else {            if($from <= 1) {                $to = $page-1;                $from = 2;
            }  elseif($to >= $pages) {                $from = $pages-($page-2);                $to = $pages-1;
            }            $more = 1;
        }        //$multipage .= &#39;<a class="a1">&#39;.$num.L(&#39;page_item&#39;).&#39;</a>&#39;;
        if($curr_page>0) {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page-1).&#39;]);" class="a1">&#39;.L(&#39;previous&#39;).&#39;</a>&#39;;            if($curr_page==1) {                $multipage .= &#39; <span>1</span>&#39;;
            } elseif($curr_page>6 && $more) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[1]);">1</a>..&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[1]);">1</a>&#39;;
            }
        }        for($i = $from; $i <= $to; $i++) {            if($i != $curr_page) {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$i.&#39;]);">&#39;.$i.&#39;</a>&#39;;
            } else {                $multipage .= &#39; <span>&#39;.$i.&#39;</span>&#39;;
            }
        }        if($curr_page<$pages) {            if($curr_page<$pages-5 && $more) {                $multipage .= &#39; ..<a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            } else {                $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###"  onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
            }
        } elseif($curr_page==$pages) {            $multipage .= &#39; <span>&#39;.$pages.&#39;</span> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        } else {            $multipage .= &#39; <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.$pages.&#39;]);">&#39;.$pages.&#39;</a> <a href="###" onclick="$(\&#39;#dosearch\&#39;).trigger(\&#39;click\&#39;,[&#39;.($curr_page+1).&#39;]);" class="a1">&#39;.L(&#39;next&#39;).&#39;</a>&#39;;
        }
    }    return $multipage;
}/**
 * 返回分页路径
 *
 * @param $urlrule 分页规则
 * @param $page 当前页
 * @param $array 需要传递的数组,用于增加额外的方法
 * @return 完整的URL路径
 */function pageurl($urlrule, $page, $array = array()) {
    if(strpos($urlrule, &#39;~&#39;)) {        $urlrules = explode(&#39;~&#39;, $urlrule);        $urlrule = $page < 2 ? $urlrules[0] : $urlrules[1];
    }    $findme = array(&#39;{$page}&#39;);    $replaceme = array($page);    if (is_array($array)) foreach ($array as $k=>$v) {        $findme[] = &#39;{$&#39;.$k.&#39;}&#39;;        $replaceme[] = $v;
    }    $url = str_replace($findme, $replaceme, $urlrule);    $url = str_replace(array(&#39;http://&#39;,&#39;//&#39;,&#39;~&#39;), array(&#39;~&#39;,&#39;/&#39;,&#39;http://&#39;), $url);    return $url;
}/**
 * URL路径解析,pages 函数的辅助函数
 *
 * @param $par 传入需要解析的变量 默认为,page={$page}
 * @param $url URL地址
 * @return URL
 */function url_par($par, $url = &#39;&#39;) {
    if($url == &#39;&#39;) $url = get_url();    $pos = strpos($url, &#39;?&#39;);    if($pos === false) {        $url .= &#39;?&#39;.$par;
    } else {        $querystring = substr(strstr($url, &#39;?&#39;), 1);
        parse_str($querystring, $pars);        $query_array = array();        foreach($pars as $k=>$v) {            if($k != &#39;page&#39;) $query_array[$k] = $v;
        }        $querystring = http_build_query($query_array).&#39;&&#39;.$par;        $url = substr($url, 0, $pos).&#39;?&#39;.$querystring;
    }    return $url;
}/**
 * 判断email格式是否正确
 * @param $email
 */function is_email($email) {
    return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
}/**
 * iconv 编辑转换
 */if (!function_exists(&#39;iconv&#39;)) {    function iconv($in_charset, $out_charset, $str) {
        $in_charset = strtoupper($in_charset);        $out_charset = strtoupper($out_charset);        if (function_exists(&#39;mb_convert_encoding&#39;)) {            return mb_convert_encoding($str, $out_charset, $in_charset);
        } else {
            app_base::load_sys_func(&#39;iconv&#39;);            $in_charset = strtoupper($in_charset);            $out_charset = strtoupper($out_charset);            if ($in_charset == &#39;UTF-8&#39; && ($out_charset == &#39;GBK&#39; || $out_charset == &#39;GB2312&#39;)) {                return utf8_to_gbk($str);
            }            if (($in_charset == &#39;GBK&#39; || $in_charset == &#39;GB2312&#39;) && $out_charset == &#39;UTF-8&#39;) {                return gbk_to_utf8($str);
            }            return $str;
        }
    }
}/**
 * 代码广告展示函数
 * @param intval $siteid 所属站点
 * @param intval $id 广告ID
 * @return 返回广告代码
 */function show_ad($siteid, $id) {
    $siteid = intval($siteid);    $id = intval($id);    if(!$id || !$siteid) return false;    $p = app_base::load_model(&#39;poster_model&#39;);    $r = $p->get_one(array(&#39;spaceid&#39;=>$id, &#39;siteid&#39;=>$siteid), &#39;disabled, setting&#39;, &#39;id ASC&#39;);    if ($r[&#39;disabled&#39;]) return &#39;&#39;;    if ($r[&#39;setting&#39;]) {        $c = string2array($r[&#39;setting&#39;]);
    } else {        $r[&#39;code&#39;] = &#39;&#39;;
    }    return $c[&#39;code&#39;];
}/**
 * 获取当前的站点ID
 */function get_siteid() {
    static $siteid;    if (!empty($siteid)) return $siteid;    if (defined(&#39;IN_ADMIN&#39;)) {        if ($d = param::get_cookie(&#39;siteid&#39;)) {            $siteid = $d;
        } else {            return &#39;&#39;;
        }
    } else {        $data = getcache(&#39;sitelist&#39;, &#39;commons&#39;);        if(!is_array($data)) return &#39;1&#39;;        $site_url = SITE_PROTOCOL.SITE_URL;        foreach ($data as $v) {            if ($v[&#39;url&#39;] == $site_url.&#39;/&#39;) $siteid = $v[&#39;siteid&#39;];
        }
    }    if (empty($siteid)) $siteid = 1;    return $siteid;
}/**
 * 获取用户昵称
 * 不传入userid取当前用户nickname,如果nickname为空取username
 * 传入field,取用户$field字段信息
 */function get_nickname($userid=&#39;&#39;, $field=&#39;&#39;) {
    $return = &#39;&#39;;    if(is_numeric($userid)) {        $member_db = app_base::load_model(&#39;member_model&#39;);        $memberinfo = $member_db->get_one(array(&#39;userid&#39;=>$userid));        if(!empty($field) && $field != &#39;nickname&#39; && isset($memberinfo[$field]) &&!empty($memberinfo[$field])) {            $return = $memberinfo[$field];
        } else {            $return = isset($memberinfo[&#39;nickname&#39;]) && !empty($memberinfo[&#39;nickname&#39;]) ? $memberinfo[&#39;nickname&#39;].&#39;(&#39;.$memberinfo[&#39;username&#39;].&#39;)&#39; : $memberinfo[&#39;username&#39;];
        }
    } else {        if (param::get_cookie(&#39;_nickname&#39;)) {            $return .= &#39;(&#39;.param::get_cookie(&#39;_nickname&#39;).&#39;)&#39;;
        } else {            $return .= &#39;(&#39;.param::get_cookie(&#39;_username&#39;).&#39;)&#39;;
        }
    }    return $return;
}/**
 * 获取用户信息
 * 不传入$field返回用户所有信息,
 * 传入field,取用户$field字段信息
 */function get_memberinfo($userid, $field=&#39;&#39;) {
    if(!is_numeric($userid)) {        return false;
    } else {        static $memberinfo;        if (!isset($memberinfo[$userid])) {            $member_db = app_base::load_model(&#39;member_model&#39;);            $memberinfo[$userid] = $member_db->get_one(array(&#39;userid&#39;=>$userid));
        }        if(!empty($field) && !empty($memberinfo[$userid][$field])) {            return $memberinfo[$userid][$field];
        } else {            return $memberinfo[$userid];
        }
    }
}/**
 * 通过 username 值,获取用户所有信息
 * 获取用户信息
 * 不传入$field返回用户所有信息,
 * 传入field,取用户$field字段信息
 */function get_memberinfo_buyusername($username, $field=&#39;&#39;) {
    if(empty($username)){return false;}    static $memberinfo;    if (!isset($memberinfo[$username])) {        $member_db = app_base::load_model(&#39;member_model&#39;);        $memberinfo[$username] = $member_db->get_one(array(&#39;username&#39;=>$username));
    }    if(!empty($field) && !empty($memberinfo[$username][$field])) {        return $memberinfo[$username][$field];
    } else {        return $memberinfo[$username];
    }
}/**
 * 调用关联菜单
 * @param $linkageid 联动菜单id
 * @param $id 生成联动菜单的样式id
 * @param $defaultvalue 默认值
 */function menu_linkage($linkageid = 0, $id = &#39;linkid&#39;, $defaultvalue = 0, $defaultlabel = array()) {
    $linkageid = intval($linkageid);    $datas = array();    $datas = getcache($linkageid,&#39;linkage&#39;);    $infos = $datas[&#39;data&#39;];    if($datas[&#39;style&#39;]==&#39;1&#39;) {        $title = $datas[&#39;title&#39;];        $container = &#39;content&#39;.create_randomnum(100, 999).date(&#39;is&#39;);        if(!defined(&#39;DIALOG_INIT_1&#39;)) {
            define(&#39;DIALOG_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;dialog.js"></script>&#39;;            //TODO $string .= &#39;<link href="&#39;.CSS_PATH.&#39;dialog.css" rel="stylesheet" type="text/css">&#39;;
        }        if(!defined(&#39;LINKAGE_INIT_1&#39;)) {
            define(&#39;LINKAGE_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/pop.js"></script>&#39;;
        }        $var_p = $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39; || ROUTE_A==&#39;orderinfo&#39;) ? menu_linkage_level($defaultvalue,$linkageid,$infos) : $datas[&#39;title&#39;];        $var_input = $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39;) ? &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="&#39;.$defaultvalue.&#39;">&#39; : &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="">&#39;;        $string .= &#39;<p name="&#39;.$id.&#39;" value="" id="&#39;.$id.&#39;" class="ib">&#39;.$var_p.&#39;</p>&#39;.$var_input.&#39; <input type="button" name="btn_&#39;.$id.&#39;" class="button" value="&#39;.L(&#39;linkage_select&#39;).&#39;" onclick="open_linkage(\&#39;&#39;.$id.&#39;\&#39;,\&#39;&#39;.$title.&#39;\&#39;,&#39;.$container.&#39;,\&#39;&#39;.$linkageid.&#39;\&#39;)">&#39;;        $string .= &#39;<script type="text/javascript">&#39;;        $string .= &#39;var returnid_&#39;.$id.&#39;= \&#39;&#39;.$id.&#39;\&#39;;&#39;;        $string .= &#39;var returnkeyid_&#39;.$id.&#39; = \&#39;&#39;.$linkageid.&#39;\&#39;;&#39;;        $string .=  &#39;var &#39;.$container.&#39; = new Array(&#39;;        foreach($infos AS $k=>$v) {            if($v[&#39;parentid&#39;] == 0) {                $s[]=&#39;new Array(\&#39;&#39;.$v[&#39;linkageid&#39;].&#39;\&#39;,\&#39;&#39;.$v[&#39;name&#39;].&#39;\&#39;,\&#39;&#39;.$v[&#39;parentid&#39;].&#39;\&#39;)&#39;;
            } else {                continue;
            }
        }        $s = implode(&#39;,&#39;,$s);        $string .=$s;        $string .= &#39;)&#39;;        $string .= &#39;</script>&#39;;

    } elseif($datas[&#39;style&#39;]==&#39;2&#39;) {        if(!defined(&#39;LINKAGE_INIT_1&#39;)) {
            define(&#39;LINKAGE_INIT_1&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/jquery.ld.js"></script>&#39;;
        }        $default_txt = &#39;&#39;;        if($defaultvalue) {                $default_txt = menu_linkage_level($defaultvalue,$linkageid,$infos);                $default_txt = &#39;["&#39;.str_replace(&#39; > &#39;,&#39;","&#39;,$default_txt).&#39;"]&#39;;
        }        $string .= $defaultvalue && (ROUTE_A==&#39;edit&#39; || ROUTE_A==&#39;account_manage_info&#39;  || ROUTE_A==&#39;info_publish&#39;) ? &#39;<input type="hidden" name="info[&#39;.$id.&#39;]"  id="&#39;.$id.&#39;" value="&#39;.$defaultvalue.&#39;">&#39; : &#39;<input type="hidden" name="info[&#39;.$id.&#39;]"  id="&#39;.$id.&#39;" value="">&#39;;        for($i=1;$i<=$datas[&#39;setting&#39;][&#39;level&#39;];$i++) {            $txt = isset($defaultlabel[$i]) ? $defaultlabel[$i] : &#39;请选择&#39;;            $string .=&#39;<select class="pc-select-&#39;.$id.&#39;" name="&#39;.$id.&#39;-&#39;.$i.&#39;" id="&#39;.$id.&#39;-&#39;.$i.&#39;" width="100"><option value="">&#39; . $txt . &#39;</option></select> &#39;;
        }        $string .= &#39;<script type="text/javascript">
                    $(function(){
                        var $ld5 = $(".pc-select-&#39;.$id.&#39;");                      
                        $ld5.ld({ajaxOptions : {"url" : "&#39;.APP_PATH.&#39;api.php?op=get_linkage&act=ajax_select&keyid=&#39;.$linkageid.&#39;"},defaultParentId : 0,style : {"width" : 120}})     
                        var ld5_api = $ld5.ld("api");
                        //ld5_api.selected(&#39;.$default_txt.&#39;);
                        $ld5.bind("change",onchange);
                        function onchange(e){
                            var $target = $(e.target);
                            var index = $ld5.index($target);
                            $("#&#39;.$id.&#39;-&#39;.$i.&#39;").remove();
                            $("#&#39;.$id.&#39;").val($ld5.eq(index).show().val());
                            index ++;
                            $ld5.eq(index).show();                                }
                    })
        </script>&#39;;

    } else {        $title = $defaultvalue ? $infos[$defaultvalue][&#39;name&#39;] : $datas[&#39;title&#39;];        $colObj = create_randomnum(100, 999).date(&#39;is&#39;);        $string = &#39;&#39;;        if(!defined(&#39;LINKAGE_INIT&#39;)) {
            define(&#39;LINKAGE_INIT&#39;, 1);            $string .= &#39;<script type="text/javascript" src="&#39;.JS_PATH.&#39;linkage/js/mln.colselect.js"></script>&#39;;            if(defined(&#39;IN_ADMIN&#39;)) {                $string .= &#39;<link href="&#39;.JS_PATH.&#39;linkage/style/admin.css" rel="stylesheet" type="text/css">&#39;;
            } else {                $string .= &#39;<link href="&#39;.JS_PATH.&#39;linkage/style/css.css" rel="stylesheet" type="text/css">&#39;;
            }
        }        $string .= &#39;<input type="hidden" name="info[&#39;.$id.&#39;]" value="1"><p id="&#39;.$id.&#39;"></p>&#39;;        $string .= &#39;<script type="text/javascript">&#39;;        $string .= &#39;var colObj&#39;.$colObj.&#39; = {"Items":[&#39;;        foreach($infos AS $k=>$v) {            $s .= &#39;{"name":"&#39;.$v[&#39;name&#39;].&#39;","topid":"&#39;.$v[&#39;parentid&#39;].&#39;","colid":"&#39;.$k.&#39;","value":"&#39;.$k.&#39;","fun":function(){}},&#39;;
        }        $string .= substr($s, 0, -1);        $string .= &#39;]};&#39;;        $string .= &#39;$("#&#39;.$id.&#39;").mlnColsel(colObj&#39;.$colObj.&#39;,{&#39;;        $string .= &#39;title:"&#39;.$title.&#39;",&#39;;        $string .= &#39;value:"&#39;.$defaultvalue.&#39;",&#39;;        $string .= &#39;width:100&#39;;        $string .= &#39;});&#39;;        $string .= &#39;</script>&#39;;
    }    return $string;
}/**
 * 联动菜单层级
 */function menu_linkage_level($linkageid,$keyid,$infos,$result=array()) {
    if(array_key_exists($linkageid,$infos)) {        $result[]=$infos[$linkageid][&#39;name&#39;];        return menu_linkage_level($infos[$linkageid][&#39;parentid&#39;],$keyid,$infos,$result);
    }
    krsort($result);    return implode(&#39; > &#39;,$result);
}/**
 * 通过catid获取显示菜单完整结构
 * @param  $menuid 菜单ID
 * @param  $cache_file 菜单缓存文件名称
 * @param  $cache_path 缓存文件目录
 * @param  $key 取得缓存值的键值名称
 * @param  $parentkey 父级的ID
 * @param  $linkstring 链接字符
 */function menu_level($menuid, $cache_file, $cache_path = &#39;commons&#39;, $key = &#39;catname&#39;, $parentkey = &#39;parentid&#39;, $linkstring = &#39; > &#39;, $result=array()) {
    $menu_arr = getcache($cache_file, $cache_path);    if (array_key_exists($menuid, $menu_arr)) {        $result[] = $menu_arr[$menuid][$key];        return menu_level($menu_arr[$menuid][$parentkey], $cache_file, $cache_path, $key, $parentkey, $linkstring, $result);
    }
    krsort($result);    return implode($linkstring, $result);
}/**
 * 通过id获取显示联动菜单
 * @param  $linkageid 联动菜单ID
 * @param  $keyid 菜单keyid
 * @param  $space 菜单间隔符
 * @param  $tyoe 1 返回间隔符链接,完整路径名称 3 返回完整路径数组,2返回当前联动菜单名称,4 直接返回ID
 * @param  $result 递归使用字段1
 * @param  $infos 递归使用字段2
 */function get_linkage($linkageid, $keyid, $space = &#39;>&#39;, $type = 1, $result = array(), $infos = array()) {
    if($space==&#39;&#39; || !isset($space))$space = &#39;>&#39;;    if(!$infos) {        $datas = getcache($keyid,&#39;linkage&#39;);        $infos = $datas[&#39;data&#39;];
    }    if($type == 1 || $type == 3 || $type == 4) {        if(array_key_exists($linkageid,$infos)) {            $result[]= ($type == 1) ? $infos[$linkageid][&#39;name&#39;] : (($type == 4) ? $linkageid :$infos[$linkageid]);            return get_linkage($infos[$linkageid][&#39;parentid&#39;], $keyid, $space, $type, $result, $infos);
        } else {            if(count($result)>0) {
                krsort($result);                if($type == 1 || $type == 4) $result = implode($space,$result);                return $result;
            } else {                return $result;
            }
        }
    } else {        return $infos[$linkageid][&#39;name&#39;];
    }
}/**
 * IE浏览器判断
 */function is_ie() {
    $useragent = strtolower($_SERVER[&#39;HTTP_USER_AGENT&#39;]);    if((strpos($useragent, &#39;opera&#39;) !== false) || (strpos($useragent, &#39;konqueror&#39;) !== false)) return false;    if(strpos($useragent, &#39;msie &#39;) !== false) return true;    return false;
}/**
 * 文件下载
 * @param $filepath 文件路径
 * @param $filename 文件名称
 */function file_down($filepath, $filename = &#39;&#39;) {
    if(!$filename) $filename = basename($filepath);    if(is_ie()) $filename = rawurlencode($filename);    $filetype = fileext($filename);    $filesize = sprintf("%u", filesize($filepath));    if(ob_get_length() !== false) @ob_end_clean();
    header(&#39;Pragma: public&#39;);
    header(&#39;Last-Modified: &#39;.gmdate(&#39;D, d M Y H:i:s&#39;) . &#39; GMT&#39;);
    header(&#39;Cache-Control: no-store, no-cache, must-revalidate&#39;);
    header(&#39;Cache-Control: pre-check=0, post-check=0, max-age=0&#39;);
    header(&#39;Content-Transfer-Encoding: binary&#39;);
    header(&#39;Content-Encoding: none&#39;);
    header(&#39;Content-type: &#39;.$filetype);
    header(&#39;Content-Disposition: attachment; filename="&#39;.$filename.&#39;"&#39;);
    header(&#39;Content-length: &#39;.$filesize);
    readfile($filepath);    exit;
}/**
 * 判断字符串是否为utf8编码,英文和半角字符返回ture
 * @param $string
 * @return bool
 */function is_utf8($string) {
    return preg_match(&#39;%^(?:
                    [\x09\x0A\x0D\x20-\x7E] # ASCII
                    | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
                    | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
                    | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
                    | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
                    | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
                    | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
                    | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
                    )*$%xs&#39;, $string);
}/**
 * 组装生成ID号
 * @param $modules 模块名
 * @param $contentid 内容ID
 * @param $siteid 站点ID
 */function id_encode($modules,$contentid, $siteid) {
    return urlencode($modules.&#39;-&#39;.$contentid.&#39;-&#39;.$siteid);
}/**
 * 解析ID
 * @param $id 评论ID
 */function id_decode($id) {
    return explode(&#39;-&#39;, $id);
}/**
 * 对用户的密码进行加密
 * @param $password
 * @param $encrypt //传入加密串,在修改密码时做认证
 * @return array/password
 */function password($password, $encrypt=&#39;&#39;) {
    $pwd = array();    $pwd[&#39;encrypt&#39;] =  $encrypt ? $encrypt : create_randomstr();    $pwd[&#39;password&#39;] = md5(md5(trim($password)).$pwd[&#39;encrypt&#39;]);    return $encrypt ? $pwd[&#39;password&#39;] : $pwd;
}/**
 * 生成随机字符串
 * @param string $lenth 长度
 * @return string 字符串
 */function create_randomstr($lenth = 6) {
    //openssl_random_pseudo_bytes
    $fp = @fopen(&#39;/dev/urandom&#39;,&#39;rb&#39;);    $pr_bits = &#39;&#39;;    if ($fp !== FALSE) {        $pr_bits .= @fread($fp,$lenth/2);
        @fclose($fp);
    }    return bin2hex($pr_bits);    //return random($lenth, &#39;123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&#39;);}/**
 * 生成随机数
 * @param string $lenth 长度
 * @return string 字符串
 */function create_randomnum($min,$max) {
    //openssl_random_pseudo_bytes
    $difference = $max-$min;    $bytesNeeded = ceil($difference/256);    $fp = @fopen(&#39;/dev/urandom&#39;,&#39;rb&#39;);    if ($fp !== FALSE) {        $randomBytes = @fread($fp,$bytesNeeded);
        @fclose($fp);
    }    $sum = 0;    for ($a = 0; $a < $bytesNeeded; $a++){        $sum += ord($randomBytes[$a]);
    }    $sum = $sum % ($difference);    return $sum + $min;    //return random($lenth, &#39;123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ&#39;);}/**
 * 检查密码长度是否符合规定
 *
 * @param STRING $password
 * @return     TRUE or FALSE
 */function is_password($password) {
    $strlen = strlen($password);    if($strlen >= 6 && $strlen <= 20) return true;    return false;
} /**
 * 检测输入中是否含有错误字符
 *
 * @param char $string 要检查的字符串名称
 * @return TRUE or FALSE
 */function is_badword($string) {
    $badwords = array("\\",&#39;&&#39;,&#39; &#39;,"&#39;",&#39;"&#39;,&#39;/&#39;,&#39;*&#39;,&#39;,&#39;,&#39;<&#39;,&#39;>&#39;,"\r","\t","\n","#");    foreach($badwords as $value){        if(strpos($string, $value) !== FALSE) {            return TRUE;
        }
    }    return FALSE;
}/**
 * 检查用户名是否符合规定
 *
 * @param STRING $username 要检查的用户名
 * @return     TRUE or FALSE
 */function is_username($username) {
    $strlen = strlen($username);    if(is_badword($username) || !preg_match("/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/", $username)){        return false;
    } elseif ( 20 < $strlen || $strlen < 2 ) {        return false;
    }    return true;
}/**
 * 检查id是否存在于数组中
 *
 * @param $id
 * @param $ids
 * @param $s
 */function check_in($id, $ids = &#39;&#39;, $s = &#39;,&#39;) {
    if(!$ids) return false;    $ids = explode($s, $ids);    return is_array($id) ? array_intersect($id, $ids) : in_array($id, $ids);
}/**
 * 对数据进行编码转换
 * @param array/string $data       数组
 * @param string $input     需要转换的编码
 * @param string $output    转换后的编码
 */function array_iconv($data, $input = &#39;gbk&#39;, $output = &#39;utf-8&#39;) {
    if (!is_array($data)) {        return iconv($input, $output, $data);
    } else {        foreach ($data as $key=>$val) {            if(is_array($val)) {                $data[$key] = array_iconv($val, $input, $output);
            } else {                $data[$key] = iconv($input, $output, $val);
            }
        }        return $data;
    }
}/**
 * 生成缩略图函数
 * @param  $imgurl 图片路径
 * @param  $width  缩略图宽度
 * @param  $height 缩略图高度
 * @param  $autocut 是否自动裁剪 默认裁剪,当高度或宽度有一个数值为0是,自动关闭
 * @param  $smallpic 无图片是默认图片路径
 */function thumb($imgurl, $width = 100, $height = 100 ,$autocut = 1, $smallpic = &#39;nopic.gif&#39;) {
    global $image;    $upload_url = app_base::load_config(&#39;system&#39;,&#39;upload_url&#39;);    $upload_path = app_base::load_config(&#39;system&#39;,&#39;upload_path&#39;);    if(empty($imgurl)) return IMG_PATH.$smallpic;    $imgurl_replace= str_replace($upload_url, &#39;&#39;, $imgurl);    if(!extension_loaded(&#39;gd&#39;) || strpos($imgurl_replace, &#39;://&#39;)) return $imgurl;    if(!file_exists($upload_path.$imgurl_replace)) return IMG_PATH.$smallpic;    list($width_t, $height_t, $type, $attr) = getimagesize($upload_path.$imgurl_replace);    if($width>=$width_t || $height>=$height_t) return $imgurl;    $newimgurl = dirname($imgurl_replace).&#39;/thumb_&#39;.$width.&#39;_&#39;.$height.&#39;_&#39;.basename($imgurl_replace);    if(file_exists($upload_path.$newimgurl)) return $upload_url.$newimgurl;    if(!is_object($image)) {
        app_base::load_sys_class(&#39;image&#39;,&#39;&#39;,&#39;0&#39;);        $image = new image(1,0);
    }    return $image->thumb($upload_path.$imgurl_replace, $upload_path.$newimgurl, $width, $height, &#39;&#39;, $autocut) ? $upload_url.$newimgurl : $imgurl;
}/**
 * 水印添加
 * @param $source 原图片路径
 * @param $target 生成水印图片途径,默认为空,覆盖原图
 * @param $siteid 站点id,系统需根据站点id获取水印信息
 */function watermark($source, $target = &#39;&#39;,$siteid) {
    global $image_w;    if(empty($source)) return $source;    if(!extension_loaded(&#39;gd&#39;) || strpos($source, &#39;://&#39;)) return $source;    if(!$target) $target = $source;    if(!is_object($image_w)){
        app_base::load_sys_class(&#39;image&#39;,&#39;&#39;,&#39;0&#39;);        $image_w = new image(0,$siteid);
    }        $image_w->watermark($source, $target);    return $target;
}/**
 * 当前路径
 * 返回指定栏目路径层级
 * @param $catid 栏目id
 * @param $symbol 栏目间隔符
 */function catpos($catid, $symbol=&#39; > &#39;){
    $category_arr = array();    $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);    $siteid = $siteids[$catid];    $category_arr = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);    if(!isset($category_arr[$catid])) return &#39;&#39;;    $pos = &#39;&#39;;    $siteurl = siteurl($category_arr[$catid][&#39;siteid&#39;]);    $arrparentid = array_filter(explode(&#39;,&#39;, $category_arr[$catid][&#39;arrparentid&#39;].&#39;,&#39;.$catid));    foreach($arrparentid as $catid) {        $url = $category_arr[$catid][&#39;url&#39;];    //    if(strpos($url, &#39;://&#39;) === false) $url = $siteurl.$url;
        $pos .= &#39;<a href="&#39;.$url.&#39;">&#39;.$category_arr[$catid][&#39;catname&#39;].&#39;</a>&#39;.$symbol;
    }    return $pos;
}/**
 * 根据catid获取子栏目数据的sql语句
 * @param string $module 缓存文件名
 * @param intval $catid 栏目ID
 */function get_sql_catid($file = &#39;category_content_1&#39;, $catid = 0, $module = &#39;commons&#39;) {
    $category = getcache($file,$module);    $catid = intval($catid);    if(!isset($category[$catid])) return false;    return $category[$catid][&#39;child&#39;] ? " catid IN(".$category[$catid][&#39;arrchildid&#39;].") " : " catid=$catid ";
}/**
 * 获取子栏目
 * @param $parentid 父级id
 * @param $type 栏目类型
 * @param $self 是否包含本身 0为不包含
 * @param $siteid 站点id
 */function subcat($parentid = NULL, $type = NULL,$self = &#39;0&#39;, $siteid = &#39;&#39;) {
    if (empty($siteid)) $siteid = get_siteid();    $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);    foreach($category as $id=>$cat) {        if($cat[&#39;siteid&#39;] == $siteid && ($parentid === NULL || $cat[&#39;parentid&#39;] == $parentid) && ($type === NULL || $cat[&#39;type&#39;] == $type)) $subcat[$id] = $cat;        if($self == 1 && $cat[&#39;catid&#39;] == $parentid && !$cat[&#39;child&#39;])  $subcat[$id] = $cat;
    }    return $subcat;
}/**
 * 获取内容地址
 * @param $catid   栏目ID
 * @param $id      文章ID
 * @param $allurl  是否以绝对路径返回
 */function go($catid,$id, $allurl = 0) {
    static $category;    if(empty($category)) {        $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);        $siteid = $siteids[$catid];        $category = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);
    }    $id = intval($id);    if(!$id || !isset($category[$catid])) return &#39;&#39;;    $modelid = $category[$catid][&#39;modelid&#39;];    if(!$modelid) return &#39;&#39;;    $db = app_base::load_model(&#39;content_model&#39;);    $db->set_model($modelid);    $r = $db->setCache()->get_one(array(&#39;id&#39;=>$id), &#39;url&#39;);    if (!empty($allurl)) {        if (strpos($r[&#39;url&#39;], &#39;://&#39;)===false) {            if (strpos($category[$catid][&#39;url&#39;], &#39;://&#39;) === FALSE) {                $site = siteinfo($category[$catid][&#39;siteid&#39;]);                $r[&#39;url&#39;] = substr($site[&#39;domain&#39;], 0, -1).$r[&#39;url&#39;];
            } else {                $r[&#39;url&#39;] = $category[$catid][&#39;url&#39;].$r[&#39;url&#39;];
            }
        }
    }    return $r[&#39;url&#39;];
}/**
 * 将附件地址转换为绝对地址
 * @param $path 附件地址
 */function atturl($path) {
    if(strpos($path, &#39;:/&#39;)) {        
    return $path;
    } else {        
    $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);        
    $siteid =  get_siteid();        
    $siteurl = $sitelist[$siteid][&#39;domain&#39;];        
    $domainlen = strlen($sitelist[$siteid][&#39;domain&#39;])-1;        
    $path = $siteurl.$path;        
    $path = substr_replace($path, &#39;/&#39;, strpos($path, &#39;//&#39;,$domainlen),2);        
    return     $path;
    }
}/**
 * 判断模块是否安装
 * @param $m    模块名称
 */function module_exists($m = &#39;&#39;) {
    if ($m==&#39;admin&#39;) return true;    
    $modules = getcache(&#39;modules&#39;, &#39;commons&#39;);    
    $modules = array_keys($modules);    
    return in_array($m, $modules);
}/**
 * 生成SEO
 * @param $siteid       站点ID
 * @param $catid        栏目ID
 * @param $title        标题
 * @param $description  描述
 * @param $keyword      关键词
 */function seo($siteid, $catid = &#39;&#39;, $title = &#39;&#39;, $description = &#39;&#39;, $keyword = &#39;&#39;) {
    if (!empty($title))$title = strip_tags($title);    
    if (!empty($description)) $description = strip_tags($description);    
    if (!empty($keyword)) $keyword = str_replace(&#39; &#39;, &#39;,&#39;, strip_tags($keyword));    
    $sites = getcache(&#39;sitelist&#39;, &#39;commons&#39;);    
    $site = $sites[$siteid];    
    $cat = array();    
    if (!empty($catid)) {        
    $siteids = getcache(&#39;category_content&#39;,&#39;commons&#39;);        
    $siteid = $siteids[$catid];        
    $categorys = getcache(&#39;category_content_&#39;.$siteid,&#39;commons&#39;);        
    $cat = $categorys[$catid];        
    $cat[&#39;setting&#39;] = string2array($cat[&#39;setting&#39;]);
    }    $seo[&#39;site_title&#39;] =isset($site[&#39;site_title&#39;]) && !empty($site[&#39;site_title&#39;]) ? $site[&#39;site_title&#39;] : $site[&#39;name&#39;];    
    $seo[&#39;keyword&#39;] = !empty($keyword) ? $keyword : $site[&#39;keywords&#39;];    
    $seo[&#39;description&#39;] = isset($description) && !empty($description) ? $description : (isset($cat[&#39;setting&#39;][&#39;meta_description&#39;]) && !empty($cat[&#39;setting&#39;][&#39;meta_description&#39;]) ? $cat[&#39;setting&#39;][&#39;meta_description&#39;] : (isset($site[&#39;description&#39;]) && !empty($site[&#39;description&#39;]) ? $site[&#39;description&#39;] : &#39;&#39;));    $seo[&#39;title&#39;] =  (isset($title) && !empty($title) ? $title.&#39; - &#39; : &#39;&#39;).(isset($cat[&#39;setting&#39;][&#39;meta_title&#39;]) && !empty($cat[&#39;setting&#39;][&#39;meta_title&#39;]) ? $cat[&#39;setting&#39;][&#39;meta_title&#39;].&#39; - &#39; : (isset($cat[&#39;catname&#39;]) && !empty($cat[&#39;catname&#39;]) ? $cat[&#39;catname&#39;].&#39; - &#39; : &#39;&#39;));    foreach ($seo as $k=>$v) {        $seo[$k] = str_replace(array("\n","\r"),    &#39;&#39;, $v);
    }    return $seo;
}/**
 * 获取站点的信息
 * @param $siteid   站点ID
 */function siteinfo($siteid) {
    static $sitelist;    if (empty($sitelist)) $sitelist  = getcache(&#39;sitelist&#39;,&#39;commons&#39;);    
    return isset($sitelist[$siteid]) ? $sitelist[$siteid] : &#39;&#39;;
}/**
 * 生成CNZZ统计代码
 */function tjcode() {
    if(!module_exists(&#39;cnzz&#39;)) return false;    
    $config = getcache(&#39;cnzz&#39;, &#39;commons&#39;);    
    if (empty($config)) {        
    return false;
    
    } else {        
    return &#39;<script src=\&#39;http://pw.m.sbmmt.com/c.php?id=&#39;.$config[&#39;siteid&#39;].&#39;&l=2\&#39; language=\&#39;JavaScript\&#39; charset=\&#39;gb2312\&#39;></script>&#39;;
    }
}/**
 * 生成标题样式
 * @param $style   样式
 * @param $html    是否显示完整的STYLE
 */function title_style($style, $html = 1) {
    $str = &#39;&#39;;    if ($html) $str = &#39; style="&#39;;    $style_arr = explode(&#39;;&#39;,$style);    if (!empty($style_arr[0])) $str .= &#39;color:&#39;.$style_arr[0].&#39;;&#39;;    if (!empty($style_arr[1])) $str .= &#39;font-weight:&#39;.$style_arr[1].&#39;;&#39;;    if ($html) $str .= &#39;" &#39;;    return $str;
}/**
 * 获取站点域名
 * @param $siteid   站点id
 */function siteurl($siteid) {
    static $sitelist;   
     return WEB_PATH;//    
    if(!$siteid) return WEB_PATH;//    
    if(empty($sitelist)) $sitelist = getcache(&#39;sitelist&#39;,&#39;commons&#39;);//    
    return substr($sitelist[$siteid][&#39;domain&#39;],0,-1);}/**
 * 生成上传附件验证
 * @param $args   参数
 * @param $operation   操作类型(加密解密)
 */function upload_key($args) {
    $pc_auth_key = md5(app_base::load_config(&#39;system&#39;,&#39;auth_key&#39;).$_SERVER[&#39;HTTP_USER_AGENT&#39;]);    
    $authkey = md5($args.$pc_auth_key);    return $authkey;
}/**
 * 文本转换为图片
 * @param string $txt 图形化文本内容
 * @param int $fonttype 无外部字体时生成文字大小,取值范围1-5
 * @param int $fontsize 引入外部字体时,字体大小
 * @param string $font 字体名称 字体请放于app\libs\data\font下
 * @param string $fontcolor 字体颜色 十六进制形式 如FFFFFF,FF0000
 */function string2img($txt, $fonttype = 5, $fontsize = 16, $font = &#39;&#39;, $fontcolor = &#39;FF0000&#39;,$transparent = &#39;1&#39;) {
    if(empty($txt)) return false;    
    if(function_exists("imagepng")) {        
    $txt = urlencode(sys_auth($txt));        
    $txt = &#39;<img src="&#39;.APP_PATH.&#39;api.php?op=creatimg&txt=&#39;.$txt.&#39;&fonttype=&#39;.$fonttype.&#39;&fontsize=&#39;.$fontsize.&#39;&font=&#39;.$font.&#39;&fontcolor=&#39;.$fontcolor.&#39;&transparent=&#39;.$transparent.&#39;" align="absmiddle">&#39;;
    }    return $txt;
}/**
 * 获取系统版本号
 */function get_pc_version($type=&#39;&#39;) {
    $version = app_base::load_config(&#39;version&#39;);    
    if($type==1) {        
    return $version[&#39;pc_version&#39;];
    } elseif($type==2) {        
    return $version[&#39;pc_release&#39;];
    } else {       
     return $version[&#39;pc_version&#39;].&#39; &#39;.$version[&#39;pc_release&#39;];
    }
}/**
 * 运行钩子(插件使用)
 */function runhook($method) {
    $time_start = getmicrotime();    
    $data  = &#39;&#39;;    
    $getpclass = FALSE;    
    $hook_appid = getcache(&#39;hook&#39;,&#39;plugins&#39;);    
    if(!empty($hook_appid)) {        
    foreach($hook_appid as $appid => $p) {            
    $pluginfilepath = CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$p.DIRECTORY_SEPARATOR.&#39;hook.class.php&#39;;            
    $getpclass = TRUE;            
    include_once $pluginfilepath;
        }        
        $hook_appid = array_flip($hook_appid);        
        if($getpclass) {            
        $pclass = new ReflectionClass(&#39;hook&#39;);            
        foreach($pclass->getMethods() as $r) {                
        $legalmethods[] = $r->getName();
            }
        }        if(in_array($method,$legalmethods)) {            
        foreach (get_declared_classes() as $class){               
        $refclass = new ReflectionClass($class);               
        if($refclass->isSubclassOf(&#39;hook&#39;)){                  
        if ($_method = $refclass->getMethod($method)) {                          
        $classname = $refclass->getName();                        
        if ($_method->isPublic() && $_method->isFinal()) {
                            
                            plugin_stat($hook_appid[$classname]);                            
                            $data .= $_method->invoke(null);
                        }
                    }
               }
            }
        }        return $data;
    }
}function getmicrotime() {
    list($usec, $sec) = explode(" ",microtime());    
    return ((float)$usec + (float)$sec);
}/**
 * 插件前台模板加载
 * Enter description here ...
 * @param unknown_type $module
 * @param unknown_type $template
 * @param unknown_type $style
 */function p_template($plugin = &#39;content&#39;, $template = &#39;index&#39;,$style=&#39;default&#39;) {
    if(!$style) $style = &#39;default&#39;;    $template_cache = app_base::load_sys_class(&#39;template_cache&#39;);    
    $compiledtplfile = ROOT_PATH.&#39;caches&#39;.DIRECTORY_SEPARATOR.&#39;caches_template&#39;.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.&#39;.php&#39;;    if(!file_exists($compiledtplfile) || (file_exists(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) && filemtime(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;) > filemtime($compiledtplfile))) {        $template_cache->template_compile(&#39;plugin/&#39;.$plugin, $template, &#39;default&#39;);
    } elseif (!file_exists(CODE_PATH.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.&#39;templates&#39;.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;)) {
        showmessage(&#39;Template does not exist.&#39;.DIRECTORY_SEPARATOR.&#39;plugin&#39;.DIRECTORY_SEPARATOR.$plugin.DIRECTORY_SEPARATOR.$template.&#39;.html&#39;);
    }    return $compiledtplfile;
}
/**
 * 读取缓存动态页面
 */function cache_page_start() {
    $relate_url = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? safe_replace($_SERVER[&#39;REQUEST_URI&#39;]) : $php_self.(isset($_SERVER[&#39;QUERY_STRING&#39;]) ? &#39;?&#39;.safe_replace($_SERVER[&#39;QUERY_STRING&#39;]) : $path_info);
    define(&#39;CACHE_PAGE_ID&#39;, md5($relate_url));    $contents = getcache(CACHE_PAGE_ID, &#39;page_tmp/&#39;.substr(CACHE_PAGE_ID, 0, 2));    if($contents && intval(substr($contents, 15, 10)) > SYS_TIME) {        echo substr($contents, 29);        exit;
    }    if (!defined(&#39;HTML&#39;)) define(&#39;HTML&#39;,true);    return true;
}/**
 * 写入缓存动态页面
 */function cache_page($ttl = 360, $isjs = 0) {
    if($ttl == 0 || !defined(&#39;CACHE_PAGE_ID&#39;)) return false;    
    $contents = ob_get_contents();    
    if($isjs) $contents = format_js($contents);    
    $contents = "<!--expiretime:".(SYS_TIME + $ttl)."-->\n".$contents;
    setcache(CACHE_PAGE_ID, $contents, &#39;page_tmp/&#39;.substr(CACHE_PAGE_ID, 0, 2));
}/**
 *
 * 获取远程内容
 * @param $url 接口url地址
 * @param $timeout 超时时间
 */function pc_file_get_contents($url, $timeout=30) {
    $stream = stream_context_create(array(&#39;http&#39; => array(&#39;timeout&#39; => $timeout)));    
    return @file_get_contents($url, 0, $stream);
}/**
 * Function get_vid
 * 获取视频信息
 * @param int $contentid 内容ID 必须
 * @param int $catid 栏目id 取内容里面视频信息时必须
 * @param int $isspecial 是否取专题的视频信息
 */function get_vid($contentid = 0, $catid = 0, $isspecial = 0) {
    static $categorys;    
    if (!$contentid) return false;    
    if (!$isspecial) {        
    if (!$catid) return false;        
    $contentid = intval($contentid);        
    $catid = intval($catid);        
    $siteid = get_siteid();        
    if (!$categorys) {            
    $categorys = getcache(&#39;category_content_&#39;.$siteid, &#39;commons&#39;);
        }        
        $modelid = $categorys[$catid][&#39;modelid&#39;];        
        $video_content = app_base::load_model(&#39;video_content_model&#39;);        
        $r = $video_content->get_one(array(&#39;contentid&#39;=>$contentid, &#39;modelid&#39;=>$modelid), &#39;videoid&#39;, &#39;listorder ASC&#39;);        
        $video_store =app_base::load_model(&#39;video_store_model&#39;);        
        return $video_store->get_one(array(&#39;videoid&#39;=>$r[&#39;videoid&#39;]));
    } else {        
    $special_content = app_base::load_model(&#39;special_content_model&#39;);        
    $contentid = intval($contentid);        
    $video_store =app_base::load_model(&#39;video_store_model&#39;);        
    $r = $special_content->get_one(array(&#39;id&#39;=>$contentid), &#39;videoid&#39;);        
    return $video_store->get_one(array(&#39;videoid&#39;=>$r[&#39;videoid&#39;]));
    }
}/**
 * Function dataformat
 * 时间转换
  * @param $n INT时间
 */
 function dataformat($n) {
    $hours = floor($n/3600);    
    $minite    = floor($n%3600/60);    
    $secend = floor($n%3600%60);    
    $minite = $minite < 10 ? "0".$minite : $minite;    
    $secend = $secend < 10 ? "0".$secend : $secend;    
    if($n >= 3600){        
    return $hours.":".$minite.":".$secend;
    }else{        return $minite.":".$secend;
    }

 } 
 function httpResponse($status, $msg=&#39;&#39;){
     $m = app_base::load_model(&#39;category_model&#39;);     
     $CATEGORYS = $m->select(array(&#39;parentid&#39;=>0),&#39;*&#39;,&#39;&#39;,&#39;listorder&#39;);     
     include CODE_PATH . &#39;libs&#39;.DIRECTORY_SEPARATOR.&#39;data&#39;.DIRECTORY_SEPARATOR.&#39;http&#39;.DIRECTORY_SEPARATOR.$status.&#39;.php&#39;;
 } function array_change_key_case_recursive($arr)
 {
     if(! $arr || !is_array($arr))return array(); 
    return array_map(function($item){
        if(is_array($item))            
        $item = array_change_key_case_recursive($item);        
        return $item;
    },array_change_key_case($arr));
 } 

 function visitauth(){
     $vtime = time();    
     $vsign = md5("cuichuande@ideadata.com.cn#$%" . $vtime);    
     return "tm={$vtime}&sn={$vsign}";
 }?>
Copy after login

The above is the detailed content of Summary of methods for data filtering in common PHP interfaces. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template