📄 function.php
字号:
<?php
/*
[BBWPS!] (C)2006-2010 小蜜蜂版权所有.
This is NOT a freeware, use is subject to license terms
*/
if(!defined('IN_SELF')){
//header('HTTP/1.1 404 not found');
exit("Access Denied!");
}
class ZipAllFloder{//压缩文件夹
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
var $dirs = array(".","");
var $dirlen = 0;
function IniVars(){//初始化变量
$this -> datasec = array();
$this -> ctrl_dir = array();
$this -> eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
$this -> old_offset = 0;
$this -> dirs = array(".","");
$this -> dirlen = 0;
}
function ZipFolder($dir,$zipfilename){//将所有二进制数据转化为16进制数据写入到压缩文件
if(substr($dir,-1)!="/"){
$dir .= "/";
}
$this -> dirlen = strlen($dir);
$this -> AddFolderContent($dir);
$out = $this -> get_file();
$this -> IniVars();
$fp = fopen($zipfilename,"w");
fwrite($fp,$out,strlen($out));
fclose($fp);
}
function AddFolderContent($dir){//添加文件夹中文件及文件夹内容
if(is_dir($dir)){
$folder = substr($dir,$this ->dirlen);
if(!in_array($folder,$this->dirs)){
$this->add_Dir($folder);
}
$handle = opendir($dir);
do{
$files = readdir($handle);
if (($files==".")||($files=="..")) continue;
if(is_dir($dir.$files)&&$files!=""){
$this->AddFolderContent($dir.$files."/");
}elseif(is_file($dir.$files)){
$fp = fopen ($dir.$files,"r");
$content = @fread ($fp,filesize($dir.$files));
fclose ($fp);
$this->add_File($content,$folder.$files);
}
}while($files!="");
closedir($handle);
}
}
function get_file(){//获得压缩文件数据
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
return $data . $ctrldir . $this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)).pack('v', sizeof($this -> ctrl_dir)).
pack('V', strlen($ctrldir)) . pack('V', strlen($data)) . "\x00\x00";
}
function add_dir($name){
$name = str_replace("\\", "/", $name);
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$fr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$fr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0);
$this -> datasec[] = $fr;
$new_offset = strlen(implode("", $this->datasec));
$cdrec = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$cdrec .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$cdrec .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 );
$ext = "\xff\xff\xff\xff";
$cdrec .= pack("V", 16 ).pack("V", $this -> old_offset ).$name;
$this -> ctrl_dir[] = $cdrec;
$this -> old_offset = $new_offset;
$this -> dirs[] = $name;
}
function add_File($data, $name, $compact = 1){
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->DosTime());
$hexdtime = '\x' . $dtime[6] . $dtime[7].'\x'.$dtime[4] . $dtime[5] . '\x' . $dtime[2]
. $dtime[3].'\x'.$dtime[0].$dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
if($compact){
$fr = "\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00".$hexdtime;
}else{
$fr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00".$hexdtime;
}
$unc_len = strlen($data); $crc = crc32($data);
if($compact){
$zdata = gzcompress($data); $c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
}else{
$zdata = $data;
}
$c_len=strlen($zdata);
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$fr .= pack('v', strlen($name)).pack('v', 0).$name.$zdata;
$fr .= pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
if($compact){
$cdrec = "\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00";
}else{
$cdrec = "\x50\x4b\x01\x02\x14\x00\x0a\x00\x00\x00\x00\x00";
}
$cdrec .= $hexdtime.pack('V', $crc).pack('V', $c_len).pack('V', $unc_len);
$cdrec .= pack('v', strlen($name) ).pack('v', 0 ).pack('v', 0 );
$cdrec .= pack('v', 0 ).pack('v', 0 ).pack('V', 32 );
$cdrec .= pack('V', $this -> old_offset );
$this -> old_offset = $new_offset;
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
return true;
}
function DosTime() {
$timearray = getdate();
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980; $timearray['mon'] = 1;
$timearray['mday'] = 1; $timearray['hours'] = 0;
$timearray['minutes'] = 0; $timearray['seconds'] = 0;
}
return (($timearray['year']-1980)<<25)|($timearray['mon']<<21)|
($timearray['mday']<<16)|($timearray['hours']<<11)|($timearray['minutes']<<5)|
($timearray['seconds']>>1);
}
}
class StatFolder{//统计文件夹内容
var $Num = 0;
var $Size = 0;
var $TypeNum = 0;
var $FolderNum = 0;
var $Type = array();
function __construct($folder){
$this -> ReadFolder($folder);
}
function StatFolder($folder){
$this -> ReadFolder($folder);
}
function ReadFolder($folder){
if(is_dir($folder)){
$handle = opendir($folder);
do{
$files = readdir($handle);
if (($files==".")||($files=="..")) continue;
if(is_dir($folder."/".$files)&&$files!=""){
$this ->FolderNum++;
$this ->ReadFolder($folder."/".$files);
}elseif(is_file($folder."/".$files)){
$this ->Num++;
$type = fileext($files);
if(!in_array($type,$this ->Type)){
$this ->Type[] = $type;
$this ->TypeNum++;
}
$size = filesize($folder."/".$files);
$this->Size +=$size;
clearstatcache();
}
}while($files!="");
closedir($handle);
}
}
function GetFileNum(){
return $this -> Num;
}
function GetTotalSize(){
$switch = $this->Size/1024;
if($switch<1024){
$return = explode(".",$switch);
if($return[0]==0){
return $this->Size." bytes";
}
return $return[0].".".substr($return[1],0,3)." Kbytes";
}else{
$switch /=1024;
$return = explode(".",$switch);
return $return[0].".".substr($return[1],0,3)." Mbytes";
}
}
function GetTypeNum(){
return $this -> TypeNum;
}
function GetFolderNum(){
return $this -> FolderNum;
}
}
function matchpath($reference,$testpath){//返回$testpath与$reference参照路径匹配度
$reference = explode("/",$reference);
$testpath = explode("/",$testpath);
$num1 = count($reference);
$num2 = count($testpath);
if($num1 < $num2){
return false;
}
$degree = 0;
for($i=0;$i<$num2;$i++){
if(strtolower($testpath[$i])==strtolower($reference[$i])){
$degree++;
continue;
}else{
return false;
break;
}
}
if($degree==$num2){
return true;
}
}
function checkcore($path){//检查核心文件是否包含其中
global $T_corefile;//核心文件中没有哪个项是"0"的,否则循环条件要换
for($i=0;$p=$T_corefile[$i];$i++){
$absps = visualpath(truepath($p,2));
if(matchpath($absps,$path)){
return true;
break;
}
}
}
function copypath($source,$target,$uncover=true){//拷贝整个目录 默认不允许覆盖
global $T_lang;
if(is_dir($target)){
if($uncover){
$errors .= str_replace("--replace--",$target,$T_lang['func'][0]);
$gocover = false;
}else{
$gocover = true;
}
}else{
if(matchpath($target,$source)){//检测目录$source是否包含于$target
$errors .= str_replace("--replace--",$source,$T_lang['func'][1]);
$gocover = false;
}else{
if(@mkdir($target,0777)){
$gocover = true;
}else{
$errors .= str_replace("--replace--",$target,$T_lang['func'][2]);
$gocover = false;
}
}
}
if($gocover){
$handle = opendir($source);
do{
$file = readdir($handle);
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(is_dir($source."/".$file)&&$file!=""){
$errors .= copypath($source."/".$file,$target."/".$file,$uncover);
}elseif(is_file($source."/".$file)){
$gocopy = true;
if(file_exists($target."/".$file)){
if($uncover){
$gocopy = false;
}else{
if(@unlink($target."/".$file)){
$gocopy = true;
}else{
$gocopy = false;
}
}
}
if($gocopy){
if(@copy($source."/".$file,$target."/".$file)){
$errors .= "";
}else{
$errors .= str_replace("--replace--",$source."/".$file,$T_lang['func'][3]);
}
}else{
$errors .= str_replace("--replace--",$target."/".$file,$T_lang['func'][4]);
}
}
}while($file!="");
closedir($handle);
}
if($errors){
return $errors;
}else{
return "";
}
}
function movepath($source,$target,$uncover=true){//移动整个目录 默认不允许覆盖
global $T_lang;
if(is_dir($target)){
if($uncover){
$errors .= str_replace("--replace--",$target,$T_lang['func'][0]);
$gocover = false;
}else{
$gocover = true;
}
}else{
if(matchpath($target,$source)){//检测目录$source是否包含于$target
$errors .= str_replace("--replace--",$source,$T_lang['func'][5]);
$gocover = false;
}else{
if(@mkdir($target,0777)){
$gocover = true;
}else{
$errors .= str_replace("--replace--",$target,$T_lang['func'][2]);
$gocover = false;
}
}
}
if($gocover){
$handle = opendir($source);
do{
$file = readdir($handle);
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(is_dir($source."/".$file)&&$file!=""){
$errors .= movepath($source."/".$file,$target."/".$file,$uncover);
}elseif(is_file($source."/".$file)){
$gocopy = true;
if(file_exists($target."/".$file)){
if($uncover){
$gocopy = false;
}else{
$gocopy = true;
}
}
if($gocopy){
if(@copy($source."/".$file,$target."/".$file)){
unlink($source."/".$file);
}else{
$errors .= str_replace("--replace--",$source."/".$file,$T_lang['func'][3]);
}
}else{
$errors .= str_replace("--replace--",$target."/".$file,$T_lang['func'][6]);
}
}
}while($file!="");
closedir($handle);
}
if($errors){
return $errors;
}else{
if(@rmdir($source."/".$file)){
return "";
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][7]);
}
}
}
function delpath($source){//删除整个目录
global $T_lang,$T_Recycled;
$handle = opendir($source);
do{
$file = readdir($handle);
clearstatcache();
if(substr($file,-1)=="."||substr($file,-2)=="..") continue;
if(is_dir($source."/".$file)&&$file!=""){
$errors .= delpath($source."/".$file);
}elseif(is_file($source."/".$file)){
if(@unlink($source."/".$file)){
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][7]);
}
}
}while($file!="");
closedir($handle);
if($errors){
$errors .= str_replace("--replace--",$source,$T_lang['func'][8]);
return $errors;
}else{
if($source==$T_Recycled){//清空回收站时 这个判断条件用的上
return "";
}else{
if(@rmdir($source)){
return "";
}else{
$errors .= str_replace("--replace--",$source,$T_lang['func'][8]);
return $errors;
}
}
}
}
function limitname($title,$limitlength =13){//限制标题长度
$length = strlen($title);
if($length>$limitlength){
$gbk = 0;
for($i=0;$i<$limitlength-1;$i++){
$temp = substr($title,$i,1);
if(ord($temp)>127) $gbk +=1;
}
if($gbk%2){
$title = substr($title,0,$limitlength)."...";
}else{
$title = substr($title,0,$limitlength-1)."...";
}
}
return $title;
}
function fileext($filename){
return trim(substr(strrchr($filename, '.'), 1));
}
function checkpath($path){//检查path合法和合格性(返回符合本程序的正确路径)
$path = preg_replace("/^[\.](.*)/","root\\1",$path);
//$path = str_replace(".","",$path);
$path = str_replace("\\","/",$path);
$path = ereg_replace("\/{1,}","/",$path);
$path = preg_replace("/(root.*)?[\/]$/i","\\1",$path);
if(is_dir(truepath($path))){
return $path;
}else{
return false;
}
}
function truepath($path,$type=1){//将'root'、'.'替换成真实路径
global $T_basedir,$T_rootdir;
if($type==1){
return preg_replace("/^(root|\.)(.*)/i",$T_rootdir."\\2",$path);
}elseif($type==2){//将程序文件前面的点换成$T_basedir
return preg_replace("/^(root|\.)(.*)/i",$T_basedir."\\2",$path);
}
}
function direction($path){//返回当前路径父路径
if($path=="root"||$path=="."){
$dirname = "root";
}else{
$dirname = dirname($path);
$dirname = preg_replace("/^\.(.*)/","root\\1",$dirname);
}
return $dirname;
}
function visualpath($path){
global $T_rootdir;
return str_replace($T_rootdir,"root",$path);
}
function historypath($path){//历史路径 路径长度超过给定的$T_rlength后只显示后面的$T_rlength长度
global $T_rlength,$T_images,$T_main,$T_Recycled;
$ruote = explode("/",$path);
$num = count($ruote);
if($num<=1){
return;
}else{
if($num-1>$T_rlength){
$i = $num-$T_rlength;
}else{
$i = 1;
}
for(;$i<=$num-1;$i++){
$rs .= "<a href=\"{$T_main}?path=";
$single = "root";
for($j=1;$j<=$i;$j++){
$single .= "/".$ruote[$j];
}
$rs .= urlencode($single)."\">";
$rs .=limitname($ruote[$i])."</a>>>";
}
return $rs;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -