📄 global.func.php
字号:
<?php
##
# Project: PHPDisk
# This is NOT a freeware, use is subject to license terms.
#
# Site: http://www.phpdisk.com
#
# $Id: global.func.php 237 2009-03-08 10:11:56Z along $
#
# Copyright (C) 2008-2009 PHPDisk Team. All Rights Reserved.
#
##
if(!defined('IN_PHPDISK')) {
exit('[PHPDisk] Access Denied');
}
function template($tpl,$tpl_name,$make = 0){
$tpl_cache_dir = PHPDISK_ROOT."./system/{$tpl_name}/";
if(!is_dir($tpl_cache_dir)){
mkdir($tpl_cache_dir,0777);
write_file($tpl_cache_dir.'index.htm','PHPDisk');
}
$tpl_cache_file = $tpl_cache_dir.$tpl.".tpl.php";
if($make || !file_exists($tpl_cache_file)){
$str = read_file(PHPDISK_ROOT."./templates/{$tpl_name}/".$tpl.".tpl.html");
$str = preg_replace("/\<\!\-\-\#(.+?)\#\-\-\>/si","<?php \\1 ?>", $str);
$str = preg_replace("/\{([A-Z_]+)\}/","<?=\\1?>",$str);
$str = preg_replace("/\{(\\\$[a-z0-9_\'\"\[\]]+)\}/si", "<?=\\1?>", $str);
$str = preg_replace("/\{\<\?\=(\\\$[a-z0-9_\'\"\[\]]+)\?\>\}/si","{\\1}",$str);
$content = str_replace(array('{#','#}'),array('<?=','?>'),$str);
$prefix = "<?php ".LF;
$prefix .= "// This is PHPDISK auto-generated file. Do NOT modify me.".LF.LF;
$prefix .= "if(!defined('IN_PHPDISK'))".LF;
$prefix .= "\texit('[PHPDisk] Access Denied');".LF;
$prefix .= "?>".LF;
write_file($tpl_cache_file,$prefix.$content);
template($tpl,$tpl_name);
}else{
return $tpl_cache_file;
}
}
function lang($lang_name){
$file = LANG_DIR.$lang_name.'.lang.php';
if(!file_exists($file)){
exit("Language pack [$lang_name] does not exist!");
}else{
return $file;
}
}
function write_cache($cache){
global $db,$timestamp;
if($cache =='settings' || $cache =='stats'){
$q = $db->query("select * from pd_{$cache}");
while($rs = $db->fetch_array($q)){
$str_c .= "\t'".$rs['vars']."' => '".$rs['value']."',".LF.LF;
}
$db->free($q);
unset($rs);
$str = "<?php".LF.LF;
$str .= "// This is PHPDISK auto-generated file. Do NOT modify me.".LF;
$str .= "// Cache Time: ".date("Y-m-d H:i:s",$timestamp).LF.LF;
$str .= "\${$cache} = array(".LF.LF;
$str .= $str_c;
$str .= ");".LF.LF;
$str .= "?>".LF;
write_file(PHPDISK_ROOT."./system/{$cache}.inc.php",$str);
}elseif($cache =='groups'){
$q = $db->query("select * from pd_groups");
while($rs = $db->fetch_array($q)){
$str_c .= "\t'".$rs['gid']."' => array(".LF.LF;
$str_c .= "\t\t'max_messages' => '".$rs['max_messages']."',".LF.LF;
$str_c .= "\t\t'max_flow_down' => '".$rs['max_flow_down']."',".LF.LF;
$str_c .= "\t\t'max_flow_view' => '".$rs['max_flow_view']."',".LF.LF;
$str_c .= "\t\t'max_storage' => '".$rs['max_storage']."',".LF.LF;
$str_c .= "\t\t'max_filesize' => '".$rs['max_filesize']."',".LF.LF;
$str_c .= "\t\t'max_disks' => '".$rs['max_disks']."',".LF.LF;
$str_c .= "\t\t'max_folders' => '".$rs['max_folders']."',".LF.LF;
$str_c .= "\t\t'max_files' => '".$rs['max_files']."',".LF.LF;
$str_c .= "\t\t'down_trans_rate' => '".$rs['down_trans_rate']."',".LF.LF;
$str_c .= "\t\t'view_trans_rate' => '".$rs['view_trans_rate']."',".LF.LF;
$str_c .= "\t\t'watermark' => '".$rs['watermark']."',".LF.LF;
$str_c .= "\t),".LF.LF;
}
$db->free($q);
unset($rs);
$str = "<?php".LF.LF;
$str .= "// This is PHPDISK auto-generated file. Do NOT modify me.".LF;
$str .= "// Cache Time: ".date("Y-m-d H:i:s",$timestamp).LF.LF;
$str .= "\$group_settings = array(".LF.LF;
$str .= $str_c;
$str .= ");".LF.LF;
$str .= "?>".LF;
write_file(PHPDISK_ROOT."./system/group_settings.inc.php",$str);
}
}
// filter bad chars
function replace_inject_str($str){
$bad_chars = array("\\","'",'"','/','*',',','<','>',"\r","\t","\n",'$','(',')','%','?',';','^','#',':','&','%');
$replace_chars = '';
return str_replace($bad_chars,$replace_chars,$str);
}
function phpdisk_user(){
global $pd_uid,$pd_pwd;
if(!$pd_uid || !$pd_pwd){
echo "<script language='javascript'>".LF;
echo "self.parent.location = '".urr("index","item=account&action=login&ref=".$_SERVER['REQUEST_URI'])."';".LF;
echo "</script>".LF;
}
}
function phpdisk_admin(){
global $db,$pd_uid,$pd_pwd,$pd_gid,$timestamp;
$admin_not_login =0;
$rs = $db->fetch_one_array("select * from pd_adminsession where userid='$pd_uid' limit 1");
if($rs['hashcode'] != gpc('phpdisk_info','C','')){
$admin_not_login =1;
}
unset($rs);
if(!$pd_uid || !$pd_pwd || $pd_gid !=1 || $admin_not_login){
echo "<script language='javascript'>".LF;
echo "self.parent.location = '".urr("index","item=account&action=adminlogin&ref=".$_SERVER['REQUEST_URI'])."';".LF;
echo "</script>".LF;
}
}
function checklength($str,$min,$max){
if(!$str || strlen($str) > $max || strlen($str) < $min){
return true;
}
}
function ifselected($int1,$int2,$type = 'int'){
if($type == 'int'){
if(intval($int1) == intval($int2)){
return " selected";
}
}elseif($type == 'str'){
if(strval($int1) == strval($int2)){
return " selected";
}
}
}
function ifchecked($int1,$int2,$type = 'int'){
if($type == 'int'){
if(intval($int1) == intval($int2)){
return " checked";
}
}elseif($type == 'str'){
if(strval($int1) == strval($int2)){
return " checked";
}
}
}
function replace_js($str){
return preg_replace("'<script[^>]*?>(.*?)</script>'si","[script]\\1[/script]",$str);
}
function custom_time($format, $time){
global $pub_lang;
$s = time() - $time;
if($s < 60){
return $s.$pub_lang['custom_time_1'];
}
$m = $s / 60;
if($m < 60){
return floor($m).$pub_lang['custom_time_2'];
}
$h = $m / 60;
if($h < 24){
return floor($h).$pub_lang['custom_time_3'];
}
$d = $h / 24;
if($d < 2){
return $pub_lang['custom_time_4'].date("H:i", $time);
}
if($d <3){
return $pub_lang['custom_time_5'].date("H:i", $time);
}
if($d <= 30){
return floor($d).$pub_lang['custom_time_6'];
}
return date($format, $time);
}
function file_icon($ext){
$icon = PHPDISK_ROOT."./images/filetype/".$ext.".gif";
if(file_exists($icon)){
$img = "<img src='images/filetype/{$ext}.gif' width='16' height='16' align='absmiddle' border='0' />";
}else{
$img = "<img src='images/filetype/file.gif' width='16' height='16' align='absmiddle' border='0' />";
}
return $img;
}
function get_byte_value($v){
$v = trim($v);
$l = strtolower($v[strlen($v) - 1]);
switch($l){
case 'g':
$v *= 1024;
case 'm':
$v *= 1024;
case 'k':
$v *= 1024;
}
return $v;
}
function mime_type( $ext ){
$mime = array(
'avi' => 'video/x-msvideo',
'bmp' => 'image/bmp',
'css' => 'text/css',
'js' => 'application/x-javascript js',
'doc' => 'application/msword',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'mov' => 'video/quicktime',
'mpeg' => 'video/mpeg',
'mp3' => 'audio/mpeg mpga mp2 mp3',
'pdf' => 'application/pdf',
'php' => 'text/html',
'png' => 'image/png',
'qt' => 'video/quicktime',
'rar' => 'application/x-rar',
'swf' => 'application/x-shockwave-flash swf',
'txt' => 'text/plain',
'torrent' => 'application/x-bittorrent',
'wmv' => 'video/x-ms-wmv',
'xml' => 'text/xml',
'xsl' => 'text/xml',
'xls' => 'application/msexcel x-excel',
'zip' => 'application/zip x-zip',
);
return isset($mime[$ext]) ? $mime[$ext] : 'application/octet-stream';
}
function redirect($url,$str,$timeout = 2000,$target = ''){
global $pub_lang,$lang;
$lang = array_merge($pub_lang,$lang);
if($timeout ==0){
header("Location:$url");
}else{
$msg = '';
if(is_array($str)){
for($i=0;$i<count($str);$i++){
$msg .= "<li>路".$str[$i]."</li>".LF;
}
}else{
$msg = $str;
}
require_once template('message',TPL_NAME);
$rtn = "<script>".LF;
$rtn .= "<!--".LF;
$rtn .= "function redirect() {".LF;
if($target =='top'){
$rtn .= " self.parent.location.href = '$url';".LF;
}else{
$rtn .= " document.location.href = '$url';".LF;
}
$rtn .= "}".LF;
$rtn .= "setTimeout('redirect();', $timeout);".LF;
$rtn .= "-->".LF;
$rtn .= "</script>".LF;
echo $rtn;
}
}
function is_bad_chars($str){
$bad_chars = array("\\",' ',"'",'"','/','*',',','<','>',"\r","\t","\n",'$','(',')','%','+','?',';','^','#',':','銆
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -