⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.php

📁 网络硬盘_支持1GB文件上传和续传_无错版
💻 PHP
📖 第 1 页 / 共 4 页
字号:
* used in admin panle to remember the search info* $input: array, the source vars* $prefix: string, a filter on vars*/function input2session($input,$prefix=''){    $parts=split(',',$prefix);    foreach($input as $name=>$value)    {        if(!is_array($value))        {            if($parts)            foreach($parts as $part)            {                if(substr($name,0,strlen($part))==$part)                {                    $_SESSION[$name]=$value;                    break;                }            }            else            {                $_SESSION[$name]=$value;            }        }    }}/*** record cookie into the session* $prefix: string, a filter on vars*/function cookie2session($prefix=''){global $_COOKIE;    $parts=split(',',$prefix);    foreach($_COOKIE as $name=>$value)    {        $name=substr($name,4);        if($parts)        foreach($parts as $part)        {            if(substr($name,0,strlen($part))==$part)            {                $_SESSION[$name]=$value;                break;            }        }        else        {            $_SESSION[$name]=$value;        }    }}/*** record session into the cookie* $prefix: string, a filter on vars*/function session2cookie($prefix=''){global $_COOKIE;    $parts=split(',',$prefix);    foreach($_SESSION as $name=>$value)    {        if(!is_array($value))        {            if($parts)            foreach($parts as $part)            {                if(substr($name,0,strlen($part))==$part)                {                    setCookies($name,$value);                    break;                }            }            else            {                setCookies($name,$value);            }        }    }}/*** build nice format for bytes* $size: digital* $mode: set to 1 will remove the numbers after the first dot*/function convertsize($size,$mode=0){   $times = 0;   $comma = '.';   while ($size>1024){      $times++;      $size = $size/1024;   }   $size2 = floor($size);   $rest = $size - $size2;   $rest = $rest * 100;   $decimal = floor($rest);   $addsize = $decimal;   if ($decimal<10) {$addsize .= '0';};   if ($times == 0){$addsize=$size2;} else   {$addsize=$size2.$comma.substr($addsize,0,2);}   switch ($times) {      case 0 : $mega = " Byte"; break;      case 1 : $mega = " KB"; break;      case 2 : $mega = " MB"; break;      case 3 : $mega = " GB"; break;      case 4 : $mega = ' TB'; break;   }   if($mode==1&&(($pos=strrpos($addsize,'.')))!==false)$addsize=substr($addsize,0,$pos);   $addsize .= $mega;   return $addsize;}/*** clean input data* @ $input is a array or object* @ $filters is a array*/function clean_input(&$input,$filters=array()){    if(!is_array($input)&&!is_object($input)) return '';    $is_obj = is_object($input);    foreach($filters as $varname=>$vartype)    {        if((!$is_obj&&!isset($input[$varname]))||($is_obj&&!isset($input->$varname))) continue;        $varvalue = $is_obj ? $input->$varname:$input[$varname];                if(is_array($vartype)) {$varfunc = $vartype[1];$vartype = $vartype[0];}        switch ($vartype) 	    {            case INT:      $is_obj ? $input->$varname = intval($varvalue)                                   : $input[$varname] = intval($varvalue);                           break;			case UINT:                           $is_obj ? $input->$varname = ($varvalue = intval($varvalue)) < 0 ? 0 : $varvalue                                   : $input[$varname] = ($varvalue = intval($varvalue)) < 0 ? 0 : $varvalue;                           break;            case NUM:                           $is_obj ? $input->$varname = strval($varvalue) + 0                                   : $input[$varname] = strval($varvalue) + 0;                           break;			case UNUM:                           $is_obj ? $input->$varname = ($varvalue = (strval($varvalue)) < 0) ? 0 : $varvalue                                   : $input[$varname] = ($varvalue = (strval($varvalue)) < 0) ? 0 : $varvalue;                           break;			case STR:      $is_obj ? $input->$varname = strval($varvalue)                                   : $input[$varname] = strval($varvalue);                           break;            case BRSTR:    $is_obj ? $input->$varname = nl2br(strval($varvalue))                                   : $input[$varname] = nl2br(strval($varvalue));                           break;			case NOHTML:   $is_obj ? $input->$varname = htmlspecialchars(trim(strval($varvalue)))                                   : $input[$varname] = htmlspecialchars(trim(strval($varvalue)));                           break;			case BOOL:     $is_obj ? $input->$varname = intval(!empty($varvalue))                                   : $input[$varname] = intval(!empty($varvalue));                           break;			case ARR:      $is_obj ? $input->$varname = (is_array($varvalue)) ? $varvalue : array()                                   : $input[$varname] = (is_array($varvalue)) ? $varvalue : array();                           break;            case XSS:      $is_obj ? $input->$varname = preg_replace(array('#javascript#i', '#vbscript#i'),array('java script',   'vb script',$varvalue))                                   : $input[$varname] = preg_replace(array('#javascript#i', '#vbscript#i'),array('java script',   'vb script',$varvalue));            case CNT:      $is_obj ? $input->$varname = $varfunc                                   : $input[$varname] = $varfunc;                           break;            case DATE:     $is_obj ? $input->$varname = ($varvalue) ? strtotime(($varvalue)) : time()                                   : $input[$varname] = ($varvalue) ? strtotime(($varvalue)) : time();                           break;            case CSM:                           if(!function_exists($varfunc)) break;                           $is_obj ? $input->$varname = $varfunc($input->$varname)                                   : $input[$varname] = $varfunc($input[$varname]);                           break;            case ENUM:     $is_obj ? $input->$varname = in_array($input->$varname,$varfunc) ? $input->$varname : current($varfunc)                                   : $input[$varname] = in_array($input[$varname],$varfunc) ? $input[$varname] : current($varfunc);                           break;        }    }}/*** clean single input data* @ $var is a array or object* @ $vartype is a var type to convert* @ $varfunc is a custom function to apply the $var*/function clean_var(&$var,$vartype=INT,$varfunc=null){    if(is_array($input)||is_object($input)) return '';    $varvalue = $var;    switch ($vartype) 	{        case INT:   $var = intval($varvalue);   break;		case UINT:  $var = ($varvalue = intval($varvalue)) < 0 ? 0 : $varvalue;  break;        case NUM:   $var = strval($varvalue) + 0;  break;		case UNUM:  $var = ($varvalue = (strval($varvalue)) < 0) ? 0 : $varvalue; break;		case STR:   $var = strval($varvalue); break;        case BRSTR: $var = nl2br(strval($varvalue)); break;        case ESC:   $var = mysql_escape_string($varvalue); break;		case NOHTML:$var = htmlspecialchars(trim(strval($varvalue))); break;		case BOOL:  $var = !empty($varvalue); break;        case XSS:   $var = preg_replace(array('#javascript#i', '#vbscript#i'),array('java script',   'vb script',$varvalue));        case CNT:   $var = $varfunc; break;        case DATE:  $var = ($varvalue) ? strtotime(($varvalue)) : time(); break;        case CSM:   if(!function_exists($varfunc)) break;                    $var = $varfunc($var); break;        case ENUM:  $var = in_array($var,$varfunc) ? $var : current($varfunc); break;    }}function grabRemoteContent($url){    $content = '';    if(function_exists('curl_init'))    {        $ch = curl_init();        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_HEADER, 0);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);        $content = curl_exec($ch);        curl_close($ch);    }    elseif(function_exists('fsockopen'))    {        require_once(ROOT.'/includes/http.php');        $http = new http_class();        $http->follow_redirect=0;        $error=$http->GetRequestArguments($url,$arguments);        $arguments["Headers"]["Pragma"]="nocache";        $arguments["Referer"]=$url;        $error=$http->Open($arguments);        if($error=="")        {           $error=$http->SendRequest($arguments);           if($error=="")           {               $headers=array();               $error=$http->ReadReplyHeaders($headers);               if($error=="")               {                   $red_location = $headers['location'];                   for(;;)  		           {                       $error=$http->ReadReplyBody($body,4096);                       if(strlen($body)==0) break;                       $content .= $body;		           }               }    	    }	    }	    $http->Close();        if(!empty($error))        {            $content = $error;        }    }    elseif(ini_get('allow_url_fopen'))    {        $content = file_get_contents($url);    }    else    {        $content = ('could not get contents from $url');    }    return $content;}/*** debug function*/if(!function_exists('trace')){function trace(){    for ($i=0; $i<func_num_args(); $i=$i+2)    {        $title = func_get_arg($i);        $vars  = func_get_arg($i+1);        trace_echo($title, $vars);    }}}if(!function_exists('trace_echo')){function trace_echo($title,$vars,$direct=1){    echo "<pre><b>$title</b>:\r\r".(!$direct?'<textarea cols=60>':'');	print_r($vars);	echo (!$direct?'</textarea>':'')."\r\r</pre>";}}function startTimer() {global $starttime;    $mtime = microtime ();    $mtime = explode (' ', $mtime);    $mtime = $mtime[1] + $mtime[0];    $starttime = $mtime;}function endTimer() {global $starttime;    $mtime = microtime ();    $mtime = explode (' ', $mtime);    $mtime = $mtime[1] + $mtime[0];    $endtime = $mtime;    $totaltime = round (($endtime - $starttime), 5);    return $totaltime;}/*** redirect to a new page at front end* @ $url is the url to redirect*/function do_redirect($url,$printinfo,$type='standby'){global $baseUrl,$db,$baseWeb,$user,$LANG,$input,$template;    $redirect_url = strtolower(substr($url,0,7))=='http://' ? "$url" : "$baseWeb/$baseUrl$url";    if ($type=='simple'||$type=='header')    {        if(!headers_sent($filename, $linenum))        {            header('Location: '.$redirect_url);            exit;        }    }    if ($type=='simple')    {        echo <<<EOF<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta HTTP-EQUIV=Refresh CONTENT="1; URL=$url"><title>Redirecting....</title></head><body><script>window.setTimeout("location.href='$url';",1000);</script>$filename, $linenum</body></html>EOF;        exit;    }        require_once("header.php");    $template->assign_vars(array(        'redirect_url'=>$redirect_url,        'error_text'  =>$printinfo,        'PAGETILE'    =>$LANG[SITEERRORS],    ));    $template->set_filenames(array(    	'body' => 'siteerrors.html')    	);    $template->pparse('body');    require_once("footer.php");    exit();}/*** redirect to a new page in admin panel* @ $url is the url to redirect*/function redirect($url,$html){global $baseUrl,$baseWeb,$input;    if(strtolower(substr($url,0,7))=='http://')    $redirect_url="$url";    else    $redirect_url=$baseWeb.(defined('IN_ADMIN')?'/admin':'').'/'.$baseUrl.$url;    echo <<<EOF<style>TABLE, TR, TD                   { font-family: Verdana,Arial; font-size: 12px;  }BODY                            { font: 10px Verdana; background-color: #FCFCFC; padding: 0; margin: 0 }.tablewrap {background-color:#EEF2F7;            border-bottom:1px solid #D1DCEB;            border-right:1px solid #D1DCEB ;		    border-top:1px solid #FFF;			border-left:1px solid #FFF; }</style><br><br><script>window.setTimeout("location.href='$redirect_url';",2500);</script><table width=70% align=center class=tablewrap><tr><td>          $html<br /><br />		  Please wait while we transfer you...<br /><br />	      (<a href='$redirect_url'>Or click here if you do not wish to wait</a>)</td></tr></table>EOF;    exit();}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -