<?
function mytrim($s)
{
$s=str_replace("\r","",$s);
$s=str_replace("\n","",$s);
return $s;
}
function dir_name($file)
{
$file=str_replace(chr(92),"/",$file);
$file=str_replace("//","/",$file);
if(substr($file,0,1)=="/") $file=substr($file,1);
$p=strrpos("!$file","/");
if($p>0) $dir=substr($file,0,$p-1); else $dir='';
$dir=str_replace("//","/",$dir);
return $dir;
}
function scan_full($dirname,$format=array())
{
$mas=scandir($dirname);
$m_c=count($mas);
$p=0;
for($i=0;$i<$m_c && $m_c;$i++)
{
if($mas[$i]=='.' || $mas[$i]=='..' || $mas[$i]=='~') continue;
$type=filetype("$dirname/$mas[$i]");
if($type=="file" && in_array(rsh($mas[$i]),$format)) { $m[$p]="$dirname/$mas[$i]"; $p++; continue; }
if($type=="dir") $m=mas_plus($m,@scan_full("$dirname/$mas[$i]",$format));
}
return $m;
}
/* Расскоментируйте это, если у вас php4.* ( если не поддерживает scandir(); )
function scandir($dirname,$format=array())
{
$dir=@opendir("$dirname"); //Папка,которую сканирует скрипт
$k=0;
while(($file=@readdir($dir))!==FALSE)
{
if($file!="." && $file!=".." && $file!="~")
{
$mas[$k]=$file;
$k++;
}
}
@closedir($dir);
return $mas;
}*/
function del_files($dn)
{
if(!is_dir($dn)) { return true; exit; }
$m=scandir($dn);
$m_c=count($m);
$nd=0;
for($i=0;$i<$m_c && $m_c>0;$i++)
{
if($m[$i]=="." || $m[$i]==".." || $m[$i]=="~") continue;
if(is_file("$dn/$m[$i]"))
{
if(@unlink("$dn/$m[$i]")); else $nd++;
continue;
}
if(is_dir("$dn/$m[$i]"))
{
$nnd=@del_files("$dn/$m[$i]");
$nd=$nd+$nnd;
if($nnd==0) @rmdir("$dn/$m[$i]");
}
}
return $nd;
}
function count_files($dirs,$array=array())
{
$a="0";
$dir=@opendir("$dirs"); //Папка,которую сканирует скрипт
while(($file=@readdir($dir))!==FALSE)
{
if(($file!=".")&&($file!="..") && ($file!="~"))
{
$type=filetype("$dirs/$file");
if($type=="dir")
{
$a = $a+count_files("$dirs/$file",$array);
continue;
}
if($type=="file")
{
$rsh_name = rsh($file);
if(!in_array($rsh_name,$array)) continue;
$a++;
}
}
}
@closedir($dir);
return $a;
}
function dirs_links($text)
{
@include('set.php');
$text = del_slash($text);
$sc = substr_count($text,'/');
$tmp = $text;
for($i=0;$i<$sc;$i++)
{
$pos = strrPos($tmp,'/');
if($pos>0)
{
$tmp = del_slash(subStr($tmp,0,$pos--));
$pos_b = strrPos($tmp,'/');
$msv1[$i] = $tmp;
$msv2[$i] = del_slash(subStr($tmp,$pos_b));
}
}
$links[0] = "<a href=\"index.php\">Загрузки</a>";
if(isSet($msv1))
{
$msv1 = array_reverse($msv1);
$msv2 = array_reverse($msv2);
for($i=0;$i<count($msv1);$i++)
{
if(@file_exists("$dir_load/$msv1[$i]/name.dat"))
{
$tmp_dn = @file("$dir_load/$msv1[$i]/name.dat");
$tmp_dn = @trim(htmlspecialchars($tmp_dn[0]));
if($tmp_dn!='' && $tmp_dn!=' ') $msv2[$i]=$tmp_dn;
}
$links[$i+1] = "/<a href=\"index.php?did=$msv1[$i]\">$msv2[$i]</a>";
}
}
return @implode('',$links);
}
function top_dir($dirname)
{
$pos = StrPos('@'.$dirname,'/');
if($pos)
{
$pos = STRRPOS($dirname,'/');
$str = SUBSTR($dirname,0,$pos);
}
else { $str = '..'; }
$l = StrLen($str);
$one = SubStr($str,0,1);
if($one=='/') $strn = SubStr($str,1); else $strn=$str;
$l = StrLen($strn);
$two = SubStr($strn,$l-1,1);
if($two=='/') $strok = SubStr($strn,0,$l-1); else $strok=$strn;
return $strok;
}
function del_slash($str)
{
$str=str_replace('//','/',$str);
$l = StrLen($str);
$one = SubStr($str,0,1);
if($one=='/') $strn = SubStr($str,1); else $strn=$str;
$l = StrLen($strn);
$two = SubStr($strn,$l-1,1);
if($two=='/') $strok = SubStr($strn,0,$l-1); else $strok=$strn;
return $strok;
}
function rsh($fname)
{
$pos = StrPos('@'.$fname,'.');
if($pos)
{
$ps = Strrpos($fname,'.');
$rsh_name = substr($fname,$ps+1);
}
else
{ $rsh_name = ''; }
return strtolower($rsh_name);
}
function ext_rsh($fname)
{
$pos = StrPos('@'.$fname,'.');
if($pos)
{
$ps = Strrpos($fname,'.');
$rsh_name = substr($fname,0,$ps);
}
else
{ $rsh_name = $fname; }
return ($rsh_name);
}
function scan($dirname,$format=array())
{
if(!is_dir($dirname)) { return array(); exit; }
$mas=scandir($dirname);
$m_c=count($mas);
$p=0;
for($i=0;$i<$m_c && $m_c;$i++)
{
if($mas[$i]=='.' || $mas[$i]=='..' || $mas[$i]=='~') continue;
if(is_dir("$dirname/$mas[$i]")) { $m[$p]= $mas[$i]; $p++; continue; }
if(is_file("$dirname/$mas[$i]") && in_array(rsh($mas[$i]),$format)) { $m[$p]=$mas[$i]; $p++; }
}
return $m;
}
function scan_files($dirname,$format=array())
{
$mas=scandir($dirname);
$m_c=count($mas);
$p=0;
for($i=0;$i<$m_c && $m_c;$i++)
{
if($mas[$i]=='.' || $mas[$i]=='..' || $mas[$i]=='~') continue;
$type=filetype("$dirname/$mas[$i]");
if($type=="file" && in_array(rsh($mas[$i]),$format)) { $m[$p]=$mas[$i]; $p++; }
}
return $m;
}
function scan_dirs($dirname)
{
$mas=scandir($dirname);
$m_c=count($mas);
$p=0;
for($i=0;$i<$m_c && $m_c;$i++)
{
if($mas[$i]=='.' || $mas[$i]=='..' || $mas[$i]=='~') continue;
$type=filetype("$dirname/$mas[$i]");
if($type=="dir") { $m[$p]= $mas[$i]; $p++; }
}
return $m;
}
function mas_plus($m1,$m2)
{
$array=$m1;
$c=count($m2);
if($c>0)
{
for($i=0;$i<$c;$i++) $array[count($array)]=$m2[$i];
}
return $array;
}
function security($dn)
{
$dn=str_replace(chr(92),"/",$dn);
$dn=strip_tags($dn);
$dn=del_slash($dn);
$rsh=rsh($dn);
if($rsh=="php" || $rsh=="asp" || $rsh=="cgi" || $rsh=="pl" || $rsh=="php3" || $rsh=="php4") $dn="";
if(strPos("!$dn","..")) $dn="";
elseif(strPos("!$dn","\r")) $dn="";
elseif(strPos("!$dn","\n")) $dn="";
elseif($dn==".") $dn="";
return $dn;
}
function real_size($size,$mode=0)
{
$v1=array(0,0);
if($size>=0 && $size<=999) { $v1[0]=$size; $v1[1]='байт'; }
elseif($size>=1000 && $size<=999999) { $v1[0]=$size/1024; $v1[1]='кБ'; }
elseif($size>=1000000 && $size<=999999999) { $v1[0]=($size/1024)/1024; $v1[1]='мБ'; }
elseif($size>=1000000000) { $v1[0]=$size/1024/1024/1024; $v1[1]='гБ'; }
$p1=strrpos($v1[0],'.');
if($p1>0 && strlen($v1[0])-$p1+1>3) $v1[0]=substr($v1[0],0,$p1+3);
if($mode) return $v1;
if(!$mode) return "$v1[0] $v1[1]";
}
function dual_slash($url)
{
return str_replace('//','/',$url);
}
function rand_id($length=4,$sym=1)
{
$s='';
for($i=1;$i<=$length;$i++)
{
$r = array();
$r[0] = chr( rand(97,122) );
$r[1] = chr( rand(65,90) );
$r[2] = rand(1,9);
if($sym==1) $v = rand(0,2);
if($sym==2) $v = 2;
if($sym==3) $v = rand(0,1);
$s=$s.$r[$v];
}
return $s;
}
function com_count($ds,$did,$fid)
{
$nd=str_replace("/","_!+!_",$did);
if(file_exists("$ds/$nd-+-$fid.dat")) $f=@file("$ds/$nd-+-$fid.dat"); else $f=array();
$f_c=count($f);
return $f_c;
}
function ld($ds,$did,$fid,$n=1)
{
$nd=str_replace("/","_!+!_",$did);
$f=@file_get_contents("$ds/$nd-+-$fid.dat");
$fd=explode("|",$f);
if(!isSet($fd[1])) $fd[1]=0;
if(!isSet($fd[2])) $fd[2]=0;
if(!isSet($fd[3])) $fd[3]=0;
if($fd[$n]=='' || !$fd[$n]) $fd[$n]="0";
return $fd[$n];
}
function rename_z($n)
{
$rsh=rsh($n);
$n=ext_rsh($n);
$l=strlen($n);
$r=false;
$v="";
for($i=1;$i<=$l;$i++)
{
$s=substr($n,$i-1,1);
if($s=='!' && !$r)
{
$r=true;
continue;
}
elseif($s=='^' && $r)
{
$r=false;
continue;
}
$b=substr($n,$i-1,1);
$p=substr($n,$i,1);
if($r && $b=='Y' && ($p=='a' || $p=='A')) { $v.="Я"; $i++; }
elseif($r && $b=='Y' && ($p=='e' || $p=='E')) { $v.="Ё"; $i++; }
elseif($r && $b=='Y' && ($p=='u' || $p=='U')) { $v.="Ю"; $i++; }
elseif($r && $b=='S' && ($p=='h' || $p=='H')) { $v.="Ш"; $i++; }
elseif($r && $b=='C' && ($p=='h' || $p=='H')) { $v.="Ч"; $i++; }
elseif($r && $b=='S' && ($p=='w' || $p=='W')) { $v.="Щ"; $i++; }
elseif($r && $b=='Z' && ($p=='h' || $p=='H')) { $v.="Ж"; $i++; }
elseif($r && $b=='W') { $v.="Э"; }
elseif($r && $b=='y' && $p=='a') { $v.="я"; $i++; }
elseif($r && $b=='y' && $p=='e') { $v.="ё"; $i++; }
elseif($r && $b=='y' && $p=='u') { $v.="ю"; $i++; }
elseif($r && $b=='s' && ($p=='h' || $p=='H')) { $v.="ш"; $i++; }
elseif($r && $b=='c' && ($p=='h' || $p=='H')) { $v.="ч"; $i++; }
elseif($r && $b=='s' && ($p=='w' || $p=='W')) { $v.="щ"; $i++; }
elseif($r && $b=='z' && ($p=='h' || $p=='H')) { $v.="ж"; $i++; }
elseif($r && $b=='w') { $v.="э"; }
elseif($r) $v.=tr_rus($b); else $v.=$b;
}
return "$v";
}
function rus_tr($str)
{
$a=array("й"=>"j","ц"=>"c","у"=>"u","к"=>"k","е"=>"e","н"=>"n","г"=>"g","ш"=>"sh","щ"=>"sw","з"=>"z","х"=>"h","ъ"=>"","ф"=>"f","ы"=>"y","в"=>"v","а"=>"a","п"=>"p","р"=>"r","о"=>"o","л"=>"l","д"=>"d","ж"=>"zh","э"=>"e","я"=>"ya","ч"=>"ch","с"=>"s","м"=>"m","и"=>"i","т"=>"t","ь"=>"","б"=>"b","ю"=>"yu","ё"=>"ye");
$b=array("Й"=>"J","Ц"=>"C","У"=>"U","К"=>"K","Е"=>"E","Н"=>"N","Г"=>"G","Ш"=>"SH","Щ"=>"SW","З"=>"Z","Х"=>"H","Ъ"=>"", "Ф"=>"F","Ы"=>"Y","В"=>"V","А"=>"A","П"=>"P","Р"=>"R","О"=>"O","Л"=>"L","Д"=>"D","Ж"=>"ZH","Э"=>"E", "Я"=>"YA","Ч"=>"CH","С"=>"S","М"=>"M","И"=>"I","Т"=>"T","Ь"=>"","Б"=>"B","Ю"=>"YU","Ё"=>"YE");
$str=strtr($str,$a);
$str=strtr($str,$b);
return $str;
}
function tr_rus($str)
{
$str=strtr($str,array("__"=>" ","yo"=>"ё","zh"=>"ж","ch"=>"ч","sh"=>"ш","sch"=>"щ","ye"=>"э","yu"=>"ю","ya"=>"я","a"=>"а","b"=>"б","v"=>"в","g"=>"г","d"=>"д","e"=>"е","z"=>"з","i"=>"и","j"=>"й","k"=>"к","l"=>"л","m"=>"м","n"=>"н","o"=>"о","p"=>"п","r"=>"р","s"=>"с","t"=>"т","u"=>"у","f"=>"ф","h"=>"х","c"=>"ц","q"=>"ь","y"=>"ы","qq"=>"ъ","QQ"=>"Ъ",
"YO"=>"Ё","ZH"=>"Ж","CH"=>"Ч","SH"=>"Ш","SCH"=>"Щ","YE"=>"Э","YU"=>"Ю","YA"=>"Я","A"=>"А","B"=>"Б","V"=>"В","G"=>"Г","D"=>"Д","E"=>"Е","Z"=>"З","I"=>"И","J"=>"Й","K"=>"К","L"=>"Л","M"=>"М","N"=>"Н","O"=>"О","P"=>"П","R"=>"Р","S"=>"С","T"=>"Т","U"=>"У","F"=>"Ф","H"=>"Х","C"=>"Ц","Q"=>"Ь","Y"=>"Ы"));
return $str;
}
?>