📄 function.php
字号:
$dtelapsed_sec = ($dtelapsed % 60); # gets number of seconds $dtelapsed_min = ((($dtelapsed - $dtelapsed_sec) % 3600) / 60); # gets number of minutes $dtelapsed_hours = (((($dtelapsed - $dtelapsed_sec) - ($dtelapsed_min * 60)) % 86400) / 3600); # gets number of hours; assuming that we won't be going into days! if ($dtelapsed_sec < 10) { $dtelapsed_sec = "0$dtelapsed_sec"; } # append leading zero if ($dtelapsed_min < 10) { $dtelapsed_min = "0$dtelapsed_min"; } # append leading zero if ($dtelapsed_hours < 10) { $dtelapsed_hours = "0$dtelapsed_hours"; } # append leading zero $dtelapsedf = "$dtelapsed_hours:$dtelapsed_min:$dtelapsed_sec"; # display as 00:00:00 ## # Upload speed ## $bSpeed = 0; # if not yet determined if ($dtelapsed > 0) # avoid divide by zero errors { $bSpeed = $iRead / $dtelapsed; # Bytes uploaded / Seconds elapsed = Bytes/Second speed $bitSpeed = $bSpeed * 8; # bps $kbitSpeed = $bitSpeed / 1000; # Kbps } else { $kbitSpeed = $bSpeed; # just pass the zero value } $bSpeedf = sprintf("%d",$kbitSpeed); # remove decimals ## # Est remaining time # Calculate remaining time based on upload speed so far ## $bRemaining = $iTotal - $iRead; # Total size - amount uploaded = amount remaining $dtRemaining = 0; if ($bSpeed > 0) { # Bytes remaining / Bytes/Second = Seconds $dtRemaining = $bRemaining / $bSpeed; } $dtRemaining = sprintf("%d",$dtRemaining); # remove decimals $dtRemaining_sec = ($dtRemaining % 60); # gets number of seconds $dtRemaining_min = ((($dtRemaining - $dtRemaining_sec) % 3600) / 60); # gets number of minutes $dtRemaining_hours = (((($dtRemaining - $dtRemaining_sec) - ($dtRemaining_min * 60)) % 86400) / 3600); # gets number of hours; assuming that we won't be going into days! if ($dtRemaining_sec < 10) { # append leading zero $dtRemaining_sec = "0$dtRemaining_sec"; } if ($dtRemaining_min < 10) { # append leading zero $dtRemaining_min = "0$dtRemaining_min"; } if ($dtRemaining_hours < 10) { # append leading zero $dtRemaining_hours = "0$dtRemaining_hours"; } $dtRemainingf = "$dtRemaining_hours:$dtRemaining_min:$dtRemaining_sec"; # display as 00:00:00 $percent = @($iRead * 100 / $iTotal); $percent = sprintf("%d",$percent ); # remove decimals flush(); echo "<script>parent.showProgress('$iRead,$iTotal,$dtRemainingf,$dtelapsedf,$bSpeedf,$percent')</script>";}/*** validate path, remove the relative path...*/function valid_path($path){ $path = str_replace(base64_decode('XA=='),'/',$path); $absolute=0; if(substr($path,0,1)=='/') { $absolute=1; $path = substr($path,1); } $parts=split('/',$path); $valid_path=$absolute?'/':''; foreach($parts as $part) { $part = str_replace('..','',$part); if(!$part) continue; $valid_path.=$valid_path?$part.'/':$part.'/'; } return $valid_path;}function CrontabLog($cron_id, $results){global $input,$db; if(!$cron_id) return 0; ($hook = YABPlugin::fetch_hook('crontab_log',__FILE__,__LINE__)) ? eval($hook) : ''; $update_time = time(); $db->setQuery("insert into cronlogs set results='$results', date='$update_time',cron_id='$cron_id'"); $db->query(); # update timestamp of crontabs $db->setQuery("update crontabs set last_update='$update_time' where cron_id='$cron_id'"); $db->query();}/*** validate file, call valid_path*/function valid_file($file){ $path = valid_path($file); $path = str_replace('/','',$path); return $path;}function blank($var){ return ($var != '');}function remove_blank($string,$sep=','){ return implode($sep,array_filter(explode($sep,$string),'blank'));}/*** encrypt and decrypt a string*/// --------------// This function takes a clear-text password and returns an encrypted password// Written by Jakub// --------------function encryptStr($str,$encryption_string=null) {// XOR with random string (which is set in settings.inc.php) ($hook = YABPlugin::fetch_hook('encryptstr',__FILE__,__LINE__)) ? eval($hook) : ''; $str_encrypted = ""; $encryption_string = $encryption_string==null?'~!@#$%^&*()_+|':$encryption_string; if ($encryption_string % 2 == 1) { // we need even number of characters $encryption_string .= $encryption_string{0}; } for ($i=0; $i < strlen($str); $i++) { // encrypts one character - two bytes at once $str_encrypted .= sprintf("%02X", hexdec(substr($encryption_string, 2*$i % strlen($encryption_string), 2)) ^ ord($str{$i})); } return $str_encrypted;} // End function encryptPasswordfunction decryptStr($str_encrypted,$encryption_string=null) {// --------------// This function takes an encrypted password and returns the clear-text password// Written by Jakub// --------------// XOR with random string (which is set in settings.inc.php) ($hook = YABPlugin::fetch_hook('decryptstr',__FILE__,__LINE__)) ? eval($hook) : ''; $password = ""; $encryption_string = $encryption_string==null?'~!@#$%^&*()_+|':$encryption_string; if ($encryption_string % 2 == 1) { // we need even number of characters $encryption_string .= $encryption_string{0}; } for ($i=0; $i < strlen($str_encrypted); $i += 2) { // decrypts two bytes - one character at once $password .= chr(hexdec(substr($encryption_string, $i % strlen($encryption_string), 2)) ^ hexdec(substr($str_encrypted, $i, 2))); } return $password;} // End function decryptPassword/*** create a temp file with $prefix and $postfix*/function mytempname($dir, $prefix='', $postfix=''){ if ($dir[strlen($dir) - 1] == '/') { $trailing_slash = ""; } else { $trailing_slash = "/"; } // Check if the $dir is a directory if (!is_dir(realpath($dir)) || filetype(realpath($dir)) != "dir") { return false; } // Check if the directory is writeable if (!is_writable($dir)){ return false; } // Create the temporary filename do { $seed = substr(md5(microtime()), 0, 8); $filename = $dir . $trailing_slash . $prefix . $seed . $postfix; } while (file_exists($filename)); $filename = $prefix . $seed . $postfix; return $filename;} // end mytempnam/*** convert special character to "-"*/function makeurls($name){ //first convert spanish charter $specs=array('á'=>'a','é'=>'e','í'=>'i','ó' =>'o','ú'=>'u','?' =>'n'); foreach($specs as $k => $v) { $name=str_replace($k,$k,$name); } $name=str_replace(chr($k),'-',$name); for ($k = 1; $k <= 47; $k++) { $name=str_replace(chr($k),'-',$name); } for ($k = 58; $k <= 64; $k++) { $name=str_replace(chr($k),'-',$name); } for ($k = 91; $k <= 96; $k++) { $name=str_replace(chr($k),'-',$name); } for ($k = 123; $k <= 255; $k++) { $name=str_replace(chr($k),'-',$name); } return $name;}function buildGETQuery($input){ if(is_array($input)) foreach($input as $key=> $value) { if(is_array($value)) { foreach($value as $k=> $v) { if(!is_array($v)) $myquery.=$key.'%5B'.$k."%5D=".urlencode(clean_value($v))."&"; } } else $myquery.=$key."=".urlencode(clean_value($value))."&"; } return $myquery;}/*** parse request info and build in one array $input*/function parse_incoming(){ global $_GET, $_POST, $HTTP_CLIENT_IP, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR; $return = array(); if( is_array($_GET) ) { while( list($k, $v) = each($_GET) ) { if( is_array($_GET[$k]) ) { while( list($k2, $v2) = each($_GET[$k]) ) { $return[$k][ clean_key($k2) ] =clean_value($v2); } } else { $return[ clean_key($k) ] =clean_value($v); } } } // Overwrite GET data with post data if( is_array($_POST) ) { while( list($k, $v) = each($_POST) ) { if ( is_array($_POST[$k]) ) { while( list($k2, $v2) = each($_POST[$k]) ) { $return[$k][ clean_key($k2) ] =clean_value($v2); } } else { $return[ clean_key($k) ] =clean_value($v); } } } $return['REQUEST_METHOD']=$_SERVER['REQUEST_METHOD']; $return['IP_ADDRESS']=$_SERVER['SERVER_ADDR']; $return['IP_CLIENT']=$_SERVER['REMOTE_ADDR']; $return['IP_CLIENT'] = $_SERVER['HTTP_X_FORWARDED_FOR'] ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER[REMOTE_ADDR]; define('IS_POST',$return['REQUEST_METHOD']=='POST'); return $return;}/*** called in parse_incoming*/function clean_key($key){ return $key;}/*** called in parse_incoming*/function clean_value($val){ if ( get_magic_quotes_gpc()!=0 ) { $val = stripslashes($val); } return $val;}/*** set cookie with a nice interface* $name: string* $value: string*/function setCookies($name,$value,$sticky=1){ if ($sticky == 1) { $expires = time() + 60*60*24*365; } if($_SERVER[HTTP_HOST]!='127.0.0.1'&&$_SERVER[HTTP_HOST]!='localhost') { if(strtolower(substr($_SERVER[HTTP_HOST],0,4))=='www.') $cookie_domain = substr($_SERVER[HTTP_HOST],3); else $cookie_domain = '.'.$_SERVER[HTTP_HOST]; } else { $cookie_domain = ""; } $cookie_path = "/"; $name = "yab_".$name; setcookie($name, $value, $expires, $cookie_path, $cookie_domain);}/*** get cookie with a nice interface* $name: string*/function getCookies($name){global $_COOKIE; if (isset($_COOKIE["yab_".$name])) { return urldecode($_COOKIE["yab_".$name]); } else { return FALSE; }}/*** get cookie with a nice interface* $name: string*/function getCookieFrom($cookiename,$source){ $cookiename = 'yab_'.$cookiename; $cookiestring=$source; $index1=strpos($cookiestring,$cookiename); if ($index1===false || $cookiename=="") return ""; $index2=strpos($cookiestring,';',$index1); if ($index2===false) $index2=strlen($cookiestring); return PHPunescape(substr($cookiestring,$index1+strlen($cookiename)+1,$index2-$index1-strlen($cookiename)-1));}/*** record input into the cookie of client side* used in admin panle to remember the search info on user PC* $input: array, the source vars* $prefix: string, a filter on vars*/function input2cookie($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) { setCookies($name,$value); break; } } else { setCookies($name,$value); } } }}/*** record input into the session of users
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -