View file template/functions.php

File size: 38.78Kb
<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  [email protected]             #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#-----------------------------------------------------#	
if (!defined("BASEDIR")) { header("Location:../index.php"); exit; }

//--------------------------- Функция перевода секунд во время -----------------------------//
function maketime($string) {
if($string < 3600){
$string = sprintf("%02d:%02d", (int)($string / 60) % 60, $string % 60); 
}else{
$string = sprintf("%02d:%02d:%02d", (int)($string / 3600) % 24, (int)($string / 60) % 60, $string % 60); 	
}
return $string; 
}

//--------------------------- Функция перевода секунд в дни -----------------------------//
function makestime($string) {

$day=floor($string/86400); 
$hours=floor(($string/3600)-$day*24); 
$min=floor(($string-$hours*3600-$day*86400)/60); 
$sec=$string-($min*60+$hours*3600+$day*86400);

return $day.' дн. '.$hours.':'.$min.':'.$sec; 
}

//--------------------------- Функция временного сдвига -----------------------------//
function date_fixed($timestamp, $format){
 //echo date_fixed(time(),"d.m.y / H:i");
 global $config_clocks;
 if(empty($timestamp)){$timestamp=time();}
 if(empty($format)){$format="d.m.y / H:i";}
 $sdvig=$config_clocks*3600;
 return(date($format,$timestamp+($sdvig)));
}

//------------------- Функция полного удаления юзера --------------------//
function delete_users($users){
global $config_priv;
	
$sublines=file(BASEDIR."local/sub.dat"); 
$subcount=count($sublines);
for ($b=0; $b<$subcount; $b++) {$dt=explode("|",$sublines[$b]); if ($dt[4]==$users) {$stroka=$b; break;}}

if ($stroka!="") {
$subfile=file(BASEDIR."local/sub.dat");
$fp=fopen(BASEDIR."local/sub.dat","w");
flock ($fp,LOCK_EX);
for ($i=0; $i< sizeof($subfile); $i++) { if ($i==$stroka) {unset($subfile[$i]);} }
fputs($fp, implode("",$subfile));
flock ($fp,LOCK_UN);
fclose($fp); 
$stroka=""; 
}


$banklines=file(BASEDIR."local/bank.dat"); 
$bankcount=count($banklines);
for ($bbank=0; $bbank<$bankcount; $bbank++) {$dtbank=explode("|",$banklines[$bbank]); if ($dtbank[1]==$users) {$strokabank=$bbank; break;}}
 
if ($strokabank!="") {
$bankfile=file(BASEDIR."local/bank.dat");
$fpbank=fopen(BASEDIR."local/bank.dat","w");
flock ($fpbank,LOCK_EX);
for ($ibank=0; $ibank< sizeof($bankfile); $ibank++) { if ($ibank==$strokabank) {unset($bankfile[$ibank]);} }
fputs($fpbank, implode("",$bankfile));
flock ($fpbank,LOCK_UN);
fclose($fpbank);   
$strokabank="";
}  	


unlink (BASEDIR."local/privat/$users.$config_priv");
unlink (BASEDIR."local/dataoutput/$users.$config_priv");
unlink (BASEDIR."local/profil/$users.prof"); 
unlink (BASEDIR."local/dataavators/$users.gif");
unlink (BASEDIR."local/dataraiting/$users.dat");
unlink (BASEDIR."local/dataignor/$users.dat");
unlink (BASEDIR."local/datakontakt/$users.dat");
unlink (BASEDIR."local/datalife/$users.dat");

return $users;
}


//--------------- Функция правильного окончания для денег -------------------//
function moneys($string){
$string=(int)$string;	
$p=substr($string, -2);
$inp = ' баксов';
if($p==2||$p==3||$p==4||$p==22||$p==23||$p==24||$p==32||$p==33||$p==34||$p==42||$p==43||$p==44||$p==52||$p==53||$p==54||$p==62||$p==63||$p==64||$p==72||$p==73||$p==74||$p==82||$p==83||$p==84||$p==92||$p==93||$p==94) {$inp = ' бакса';}
if($p==1||$p==21||$p==31||$p==41||$p==51||$p==61||$p==71||$p==81||$p==91){$inp = ' бакс';}
return $string.$inp;  
}


//------------------- Функция очистки файлов --------------------//
function clear_files($files){

$file=file($files);
$fp=fopen($files,"a+");
flock ($fp,LOCK_EX);
ftruncate ($fp,0);
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);

return $files;
}

function highlight_code($code) {
$code=strtr($code,array("&lt;"=>"<","&gt;"=>">","&amp;"=>"&","&#36;"=>"\$","&quot;"=>"\"","&#39;"=>"'","&#92;"=>"\\","&#37;"=>"%","<br>"=>"\r\n","&#94;"=>"^","&#64;"=>"@","&#58;"=>":"));
$code=highlight_string($code,true);
$code=strtr($code,array("\r\n"=>"<br>","<br />"=>"<br>","\$"=>"&#36;","'"=>"&#39;","\\"=>"&#92;","%"=>"&#37;","^"=>"&#94;","@"=>"&#64;",":"=>"&#58;")); //,""=>""
$code='<div class=d>'.$code.'</div>';
return $code;}

//------------------ Вспомогательная функция для bb-кода --------------------//
function url_replace($m) { 
if( !isset($m[3]) ) { 
return '<a href="' . $m[1] . '">' . $m[2] . '</a>'; 
} else { 
return '<a href="' . $m[3] . '">' . $m[3] . '</a>';         
}} 


//------------------ Функция вставки BB-кода --------------------//
function bb_code($message){ 
/*$message = preg_replace('#\[code\](.*?)\[/code\]#si', '<div class=d><code>\1</code></div>', $message);*/
$message = preg_replace('#\[code\](.*?)\[/code\]#ie', 'highlight_code("\1")', $message); 
$message = preg_replace('#\[big\](.*?)\[/big\]#si', '<big>\1</big>', $message);
$message = preg_replace('#\[b\](.*?)\[/b\]#si', '<b>\1</b>', $message);
$message = preg_replace('#\[i\](.*?)\[/i\]#si', '<i>\1</i>', $message);
$message = preg_replace('#\[u\](.*?)\[/u\]#si', '<u>\1</u>', $message);
$message = preg_replace('#\[small\](.*?)\[/small\]#si', '<small>\1</small>', $message);
$message = preg_replace('#\[red\](.*?)\[/red\]#si', '<font color="#FF0000">\1</font>', $message);
$message = preg_replace('#\[green\](.*?)\[/green\]#si', '<font color="#00FF00">\1</font>', $message);
$message = preg_replace('#\[blue\](.*?)\[/blue\]#si', '<font color="#0000FF">\1</font>', $message);
$message = preg_replace('#\[yellow\](.*?)\[/yellow\]#si', '<font color="#FFFF00">\1</font>', $message);
$message = preg_replace('#\[quote\](.*?)\[/quote\]#si', '<q>\1</q>', $message);
$message = preg_replace('#\[del\](.*?)\[/del\]#si', '<del>\1</del>', $message);
$message = preg_replace_callback('~\\[url=(http://.+?)\\](.+?)\\[/url\\]|(http://(www.)?[0-9a-z\.-]+\.[a-z]{2,6}[0-9a-zA-Z/\?\.\~&amp;_=/%-:#]*)~', 'url_replace', $message); 
/* $message=eregi_replace('((https?|ftp)://[[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&amp;._=/~:%#]*(\\?[[:alnum:]?+&amp;._=/%-:#]*)?)?)', '<a href="\\1">\\1</a>', $message); */
return $message; }




//------------------ Функция перекодировки из UTF в WIN --------------------//
$_utf8win1251 = array( 
"\xD0\x90"=>"\xC0","\xD0\x91"=>"\xC1","\xD0\x92"=>"\xC2","\xD0\x93"=>"\xC3","\xD0\x94"=>"\xC4", 
"\xD0\x95"=>"\xC5","\xD0\x81"=>"\xA8","\xD0\x96"=>"\xC6","\xD0\x97"=>"\xC7","\xD0\x98"=>"\xC8", 
"\xD0\x99"=>"\xC9","\xD0\x9A"=>"\xCA","\xD0\x9B"=>"\xCB","\xD0\x9C"=>"\xCC","\xD0\x9D"=>"\xCD", 
"\xD0\x9E"=>"\xCE","\xD0\x9F"=>"\xCF","\xD0\xA0"=>"\xD0","\xD0\xA1"=>"\xD1","\xD0\xA2"=>"\xD2", 
"\xD0\xA3"=>"\xD3","\xD0\xA4"=>"\xD4","\xD0\xA5"=>"\xD5","\xD0\xA6"=>"\xD6","\xD0\xA7"=>"\xD7", 
"\xD0\xA8"=>"\xD8","\xD0\xA9"=>"\xD9","\xD0\xAA"=>"\xDA","\xD0\xAB"=>"\xDB","\xD0\xAC"=>"\xDC", 
"\xD0\xAD"=>"\xDD","\xD0\xAE"=>"\xDE","\xD0\xAF"=>"\xDF","\xD0\x87"=>"\xAF","\xD0\x86"=>"\xB2", 
"\xD0\x84"=>"\xAA","\xD0\x8E"=>"\xA1","\xD0\xB0"=>"\xE0","\xD0\xB1"=>"\xE1","\xD0\xB2"=>"\xE2", 
"\xD0\xB3"=>"\xE3","\xD0\xB4"=>"\xE4","\xD0\xB5"=>"\xE5","\xD1\x91"=>"\xB8","\xD0\xB6"=>"\xE6", 
"\xD0\xB7"=>"\xE7","\xD0\xB8"=>"\xE8","\xD0\xB9"=>"\xE9","\xD0\xBA"=>"\xEA","\xD0\xBB"=>"\xEB", 
"\xD0\xBC"=>"\xEC","\xD0\xBD"=>"\xED","\xD0\xBE"=>"\xEE","\xD0\xBF"=>"\xEF","\xD1\x80"=>"\xF0", 
"\xD1\x81"=>"\xF1","\xD1\x82"=>"\xF2","\xD1\x83"=>"\xF3","\xD1\x84"=>"\xF4","\xD1\x85"=>"\xF5", 
"\xD1\x86"=>"\xF6","\xD1\x87"=>"\xF7","\xD1\x88"=>"\xF8","\xD1\x89"=>"\xF9","\xD1\x8A"=>"\xFA", 
"\xD1\x8B"=>"\xFB","\xD1\x8C"=>"\xFC","\xD1\x8D"=>"\xFD","\xD1\x8E"=>"\xFE","\xD1\x8F"=>"\xFF", 
"\xD1\x96"=>"\xB3","\xD1\x97"=>"\xBF","\xD1\x94"=>"\xBA","\xD1\x9E"=>"\xA2"); 

function utf_to_win($a) { 
global $_utf8win1251; 
if (is_array($a)){ 
foreach ($a as $k => $v) { 
if (is_array($v)) { 
$a[$k] = utf_to_win($v); 
} else { 
$a[$k] = strtr($v, $_utf8win1251); 
}} 
return $a; 
} else { 
return strtr($a, $_utf8win1251); 
} 
} 

//------------------ Функция перекодировки из WIN в UTF --------------------//
$_win1251utf8 = array( 
"\xC0"=>"\xD0\x90","\xC1"=>"\xD0\x91","\xC2"=>"\xD0\x92","\xC3"=>"\xD0\x93","\xC4"=>"\xD0\x94", 
"\xC5"=>"\xD0\x95","\xA8"=>"\xD0\x81","\xC6"=>"\xD0\x96","\xC7"=>"\xD0\x97","\xC8"=>"\xD0\x98", 
"\xC9"=>"\xD0\x99","\xCA"=>"\xD0\x9A","\xCB"=>"\xD0\x9B","\xCC"=>"\xD0\x9C","\xCD"=>"\xD0\x9D", 
"\xCE"=>"\xD0\x9E","\xCF"=>"\xD0\x9F","\xD0"=>"\xD0\xA0","\xD1"=>"\xD0\xA1","\xD2"=>"\xD0\xA2", 
"\xD3"=>"\xD0\xA3","\xD4"=>"\xD0\xA4","\xD5"=>"\xD0\xA5","\xD6"=>"\xD0\xA6","\xD7"=>"\xD0\xA7", 
"\xD8"=>"\xD0\xA8","\xD9"=>"\xD0\xA9","\xDA"=>"\xD0\xAA","\xDB"=>"\xD0\xAB","\xDC"=>"\xD0\xAC", 
"\xDD"=>"\xD0\xAD","\xDE"=>"\xD0\xAE","\xDF"=>"\xD0\xAF","\xAF"=>"\xD0\x87","\xB2"=>"\xD0\x86", 
"\xAA"=>"\xD0\x84","\xA1"=>"\xD0\x8E","\xE0"=>"\xD0\xB0","\xE1"=>"\xD0\xB1","\xE2"=>"\xD0\xB2", 
"\xE3"=>"\xD0\xB3","\xE4"=>"\xD0\xB4","\xE5"=>"\xD0\xB5","\xB8"=>"\xD1\x91","\xE6"=>"\xD0\xB6", 
"\xE7"=>"\xD0\xB7","\xE8"=>"\xD0\xB8","\xE9"=>"\xD0\xB9","\xEA"=>"\xD0\xBA","\xEB"=>"\xD0\xBB", 
"\xEC"=>"\xD0\xBC","\xED"=>"\xD0\xBD","\xEE"=>"\xD0\xBE","\xEF"=>"\xD0\xBF","\xF0"=>"\xD1\x80", 
"\xF1"=>"\xD1\x81","\xF2"=>"\xD1\x82","\xF3"=>"\xD1\x83","\xF4"=>"\xD1\x84","\xF5"=>"\xD1\x85", 
"\xF6"=>"\xD1\x86","\xF7"=>"\xD1\x87","\xF8"=>"\xD1\x88","\xF9"=>"\xD1\x89","\xFA"=>"\xD1\x8A", 
"\xFB"=>"\xD1\x8B","\xFC"=>"\xD1\x8C","\xFD"=>"\xD1\x8D","\xFE"=>"\xD1\x8E","\xFF"=>"\xD1\x8F", 
"\xB3"=>"\xD1\x96","\xBF"=>"\xD1\x97","\xBA"=>"\xD1\x94","\xA2"=>"\xD1\x9E"); 

function win_to_utf($a) { 
global $_win1251utf8; 
if (is_array($a)){ 
foreach ($a as $k=>$v) { 
if (is_array($v)) { 
$a[$k] = win_to_utf($v); 
} else { 
$a[$k] = strtr($v, $_win1251utf8); 
}} 
return $a; 
} else { 
return strtr($a, $_win1251utf8); 
}} 


//------------------ Функция преобразования в нижний регистр для UTF ------------------//
function rus_utf_tolower($str){
$str=strtr($str,array("А"=>"а","Б"=>"б","В"=>"в","Г"=>"г","Д"=>"д","Е"=>"е","Ё"=>"ё","Ж"=>"ж","З"=>"з","И"=>"и","Й"=>"й","К"=>"к","Л"=>"л","М"=>"м","Н"=>"н","О"=>"о","П"=>"п","Р"=>"р","С"=>"с","Т"=>"т","У"=>"у","Ф"=>"ф","Х"=>"х","Ц"=>"ц","Ч"=>"ч","Ш"=>"ш","Щ"=>"щ","Ь"=>"ь","Ъ"=>"ъ","Ы"=>"ы","Э"=>"э","Ю"=>"ю","Я"=>"я",
"A"=>"a","B"=>"b","C"=>"c","D"=>"d","E"=>"e","I"=>"i","F"=>"f","G"=>"g","H"=>"h","J"=>"j","K"=>"k","L"=>"l","M"=>"m","N"=>"n","O"=>"o","P"=>"p","Q"=>"q","R"=>"r","S"=>"s","T"=>"t","U"=>"u","V"=>"v","W"=>"w","X"=>"x","Y"=>"y","Z"=>"z"));
 return $str;
}



//------------------ Функция определения реального IP --------------------//
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $_SERVER['HTTP_X_FORWARDED_FOR'])){$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];}
elseif(preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $_SERVER['HTTP_CLIENT_IP'])) {$ip = $_SERVER['HTTP_CLIENT_IP'];}
else {$ip = preg_replace("/[^0-9.]/", "",$_SERVER['REMOTE_ADDR']);}
$ip=htmlspecialchars(stripslashes($ip));


//----------------------- Функция вывода русской даты --------------------------//
$user_time=$config_clocks*3600;
$currHour=round(date("H",time()+$user_time)); 
$currDate=date("d F Y", time()+$user_time);
$curr=date("i:s", time()+$user_time);
$currTime=date("$currHour:i:s", time()+$user_time);
$currTime2=date("$currHour:i", time());
  
$currDate = str_replace("January","Января",$currDate);
$currDate = str_replace("February","Февраля",$currDate);
$currDate = str_replace("March","Марта",$currDate);
$currDate = str_replace("April","Апреля",$currDate);
$currDate = str_replace("May","Мая",$currDate);
$currDate = str_replace("June","Июня",$currDate);
$currDate = str_replace("July","Июля",$currDate);
$currDate = str_replace("August","Августа",$currDate);
$currDate = str_replace("September","Сентября",$currDate);
$currDate = str_replace("October","Октября",$currDate);
$currDate = str_replace("November","Ноября",$currDate);
$currDate = str_replace("December","Декабря",$currDate); 


//----------------------- Функция экранирования основных знаков --------------------------//
function check($message){ 
$message=str_replace("|","I",$message); 
$message=str_replace("||","I",$message);
$message=htmlspecialchars($message);                  
$message=str_replace("'","&#39;",$message);            
$message=str_replace("\"","&#34;",$message);  
$message=str_replace("/\\\$/","&#36;",$message);    
$message=str_replace("$","&#36;",$message);          
$message=str_replace("\\","&#92;", $message);                            
$message=str_replace("@","&#64;", $message);      
$message=str_replace("`","", $message);  
$message=str_replace("^","&#94;", $message);   
$message=str_replace("%","&#37;", $message);  
$message=str_replace("№","&#8470;", $message); 
$message=str_replace("©","&#169;", $message);   
$message=str_replace("™","&#153;", $message);   
$message=str_replace("®","&#174;", $message);   
$message=str_replace("”","&#148;", $message);   
$message=str_replace("“","&#147;", $message);   
$message=str_replace("…","&#8230;", $message);   
$message=str_replace("«","&#171;", $message);   
$message=str_replace("»","&#187;", $message);   
$message=str_replace("°","&#176;", $message);   
$message=str_replace(":","&#58;",$message); 
$message=preg_replace("/&#58;/",":",$message,3); 
$message=stripslashes(trim($message));               
return $message;  }

//----------------------- Функция удаления основных знаков --------------------------//
function check_full($message){ 
$message=str_replace("|","I",$message); 
$message=str_replace("||","I",$message);
$message=str_replace("&","",$message);
$message=str_replace("\"","",$message);
$message=str_replace(">","",$message);
$message=str_replace("<","",$message);
$message=htmlspecialchars($message);                  
$message=str_replace("'","",$message);            
$message=str_replace("\"","",$message);  
$message=str_replace("/\\\$/","",$message);    
$message=str_replace("$","",$message);          
$message=str_replace("\\","", $message);                            
$message=str_replace("@","", $message);      
$message=str_replace("`","", $message);    
$message=str_replace("%","", $message);
$message=str_replace("^","", $message); 
$message=str_replace("№","", $message); 
$message=str_replace("©","", $message);   
$message=str_replace("™","", $message);   
$message=str_replace("®","", $message);   
$message=str_replace("”","", $message);   
$message=str_replace("“","", $message);   
$message=str_replace("…","", $message);   
$message=str_replace("«","", $message);   
$message=str_replace("»","", $message);   
$message=str_replace("°","", $message); 
$message=stripslashes(trim($message));               
return $message;  }


//----------------------- Функция вырезания переноса строки --------------------------//
function no_br($message,$replace){ 
$message=preg_replace ("|[\r\n]+|si",$replace,$message);
return $message;  }

//------------------ Функция определения реального браузера --------------------//
if ($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));}
elseif($_SERVER['HTTP_USER_AGENT']) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} 
else {$browsus='Not_detected';}
$brow=strtok($browsus,'(');
$brow=strtok($brow,' ');
$brow=substr($brow,0,22);
$brow=preg_replace('#http://#i','', $brow);


//--------------- Функция замены и вывода смайлов -------------------//
function smiles($string){
global $log;
$dir = opendir (BASEDIR."images/smiles"); 
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$smfile[]=$file;
}}
closedir ($dir);
rsort($smfile);
$countsm=count($smfile);
for($sm=0;$sm<$countsm;$sm++){
$file2=str_replace(".gif","",$smfile[$sm]);
$string=str_replace(":$file2",'<img src="'.BASEDIR.'images/smiles/'.$smfile[$sm].'" alt="">',$string);
$file3=transliter($file2);
$string=str_replace(":$file3",'<img src="'.BASEDIR.'images/smiles/'.$smfile[$sm].'" alt="">',$string);
}


$user = file(BASEDIR."local/profil/$log.prof"); 
if ($user!=""){
$udata = explode(":||:",$user[0]);
$dostup=check($udata[7]);
if ($dostup==101 || $dostup==102 || $dostup==103 || $dostup==105){
$dir = opendir (BASEDIR."images/smiles2"); 
while ($file = readdir ($dir)) {
if (ereg (".gif$", "$file")){
$smfiles[]=$file;
}}
closedir ($dir);
rsort($smfiles);
$countsm=count($smfiles);
for($sm=0;$sm<$countsm;$sm++){
$file2=str_replace(".gif","",$smfiles[$sm]);
$string=str_replace(":$file2",'<img src="'.BASEDIR.'images/smiles2/'.$smfiles[$sm].'" alt="">',$string); 
$file3=transliter($file2);
$string=str_replace(":$file3",'<img src="'.BASEDIR.'images/smiles2/'.$smfiles[$sm].'" alt="">',$string);
}}
}
return $string;  
}

//--------------- Функция подсчета веса директории -------------------//
function  read_dir($dir) { 
if ($path = opendir($dir)) while ($file_name = readdir($path)) {
if (($file_name!=='.') && ($file_name!=="..")){ 
if ( is_dir($dir."/".$file_name)) $size +=read_dir($dir."/".$file_name); else  $size += filesize($dir."/".$file_name); 
}} 
closedir ($dir); 
return  $size;} 

//--------------- Функция подсчета файлов в загрузках -------------------//
function  count_dir($dir) { 
if ($path = opendir($dir)) while ($file = readdir($path)) {
if (( $file != ".")&&($file != "..")&&($file != ".htaccess")&&($file != "index.php")&&($file != "name.dat")&& !ereg (".txt$", "$file")&& !ereg (".JPG$", "$file")&& !ereg (".GIF$", "$file")) {
	
$count ++;

$filetime=filemtime("$dir/$file")+(3600*24*5);
if($filetime>time()){	
$newcount ++;
}
}}

if($newcount>0){	
$input=(int)$count.'/+'.(int)$newcount; 
}else{
$input=(int)$count;
}

closedir ($dir); 
return  $input;
} 


//--------------- Функция подсчета файлов в библиотеке -------------------//
function  count_libdir($dir) { 
if ($path = opendir($dir)) while ($file = readdir($path)) {
if (ereg(".txt$", $file)){
	
$count ++;

$filetime=filemtime("$dir/$file")+(3600*24*5);
if($filetime>time()){	
$newcount ++;
}
}}

if($newcount>0){	
$input=(int)$count.'/+'.(int)$newcount; 
}else{
$input=(int)$count;
}

closedir ($dir); 
return  $input;
} 


//--------------- Функция правильного вывода веса файла -------------------//
function formatsize($file_size){

if($file_size >= 1073741824){
$file_size = round($file_size / 1073741824 * 100) / 100 . " Gb";
}elseif(
$file_size >= 1048576){
$file_size = round($file_size / 1048576 * 100) / 100 . " Mb";
}elseif(
$file_size >= 1024){
$file_size = round($file_size / 1024 * 100) / 100 . " Kb";
}else{
$file_size = round($file_size) . " b";}
return $file_size;
}


//--------------- Функция правильного вывода времени -------------------//
function formattime($file_time){

if($file_time >= 86400){
$file_time = 'суток: '.round((($file_time / 60) / 60) / 24, 1);
}elseif(
$file_time >= 3600){
$file_time = 'часов:  '.round(($file_time / 60) / 60, 1);
}elseif(
$file_time >= 60){
$file_time =  'минут: '.round($file_time / 60);
}else{
$file_time = 'секунд:  '.round($file_time);}
return $file_time;
}

//------------------ Функция транслита букв --------------------//
function transliter($string){
$trans1=array("CSH","Csh","ZH","Zh","CH","Ch","SH","Sh","JO","Jo","JE","Je","JU","Ju","JA","Ja","csh","zh","ch","sh","jo","je","ju","ja","A","B","V","G","D","E","Z","I","J","K","L","M","N","O","P","R","S","T","U","F","H","C","&#39;","'","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","&#39;","'","y");
$trans2=array("Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы"); 
$string=str_replace($trans1,$trans2,$string);
return $string;}


//------------------ Функция антимата --------------------//
function antimat($string){
	
$string=utf_to_win($string);
      
$mat = utf_to_win(file_get_contents(BASEDIR."local/antimat.dat")); 
$arr_mat= explode("|",$mat);
    
foreach($arr_mat as $value){
if($value!=""){
    $string = preg_replace("/$value/i","***",$string); 
}}
$string=win_to_utf($string);

return $string;}

//------------------ Функция определения прав доступа (CHMOD) --------------------//
function permissions($filez){
$filez = decoct(fileperms("$filez")) % 1000;
return $filez;
}

//------------------ Функция правильного вывода статуса --------------------//
function user_status($message){ 
if($message==101){$status='Суперадмин';}
elseif($message==102){$status='Админ';}
elseif($message==103){$status='Старший модер';}
elseif($message==105){$status='Модер';}
else{$status='Пользователь';}
return $status;  }	


//------------------ Функция выводящая картинку в загрузках --------------------//
function raiting_vote($string){ 	
if($string==0){$string=str_replace('0','<img src="../images/img/rating0.gif" alt="0"/>',$string);}
if($string>'0' && $string<='0.5'){ $string=str_replace($string,'<img src="../images/img/rating1.gif" alt="0.5"/>',$string); }
if($string>'0.5' && $string<='1'){ $string=str_replace($string,'<img src="../images/img/rating2.gif" alt="1"/>',$string); }   
if($string>'1' && $string<='1.5'){ $string=str_replace($string,'<img src="../images/img/rating3.gif" alt="1.5"/>',$string); }  
if($string>'1.5' && $string<='2'){ $string=str_replace($string,'<img src="../images/img/rating4.gif" alt="2"/>',$string); } 
if($string>'2' && $string<='2.5'){ $string=str_replace($string,'<img src="../images/img/rating5.gif" alt="2.5"/>',$string); } 
if($string>'2.5' && $string<='3'){ $string=str_replace($string,'<img src="../images/img/rating6.gif" alt="3"/>',$string); }  
if($string>'3' && $string<='3.5'){ $string=str_replace($string,'<img src="../images/img/rating7.gif" alt="3.5"/>',$string); }
if($string>'3.5' && $string<='4'){ $string=str_replace($string,'<img src="../images/img/rating8.gif" alt="4"/>',$string); }  
if($string>'4' && $string<='4.5'){ $string=str_replace($string,'<img src="../images/img/rating9.gif" alt="4.5"/>',$string); } 
if($string>'4.5' && $string<='5'){ $string=str_replace($string,'<img src="../images/img/rating10.gif" alt="5"/>',$string); }       
return $string;  }	


//--------------- Функция русского ника -------------------//
function nickname($string){
global $config_includenick;
if($config_includenick==1){
$text = file(BASEDIR."local/profil/$string.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$runickname=check($udata[65]);
if(!empty($runickname) && $udata[36]>=150){
$string=str_replace($string,$runickname,$string);}
}}
return $string;  
}

//------------------------- Функция антифлуда ------------------------------//
$php_self=check($_SERVER['PHP_SELF']);
function flooder($ip, $php_self){
global  $config_floodstime;

$old_db = file(BASEDIR."local/flood.dat");
$new_db = fopen(BASEDIR."local/flood.dat", w);
flock ($new_db,LOCK_EX);
$result = FALSE;

foreach($old_db as $old_db_line){
$old_db_arr = explode("|", $old_db_line);

if(($old_db_arr[0] + $config_floodstime) > time() ){
	
fputs ($new_db, $old_db_line);

if($old_db_arr[1] == $ip && $old_db_arr[2] == $php_self)
{ $result = TRUE; }}}

fflush($new_db);
flock ($new_db,LOCK_UN);
fclose($new_db);
return $result;
}


//------------------ Функция шифрования по ключу --------------------//
function dec_to_base64($str){
$str=strtr($str,array("64"=>"=","63"=>"/","62"=>"+","61"=>"9","60"=>"8","59"=>"7","58"=>"6","57"=>"5","56"=>"4","55"=>"3","54"=>"2","53"=>"1","52"=>"0","51"=>"z","50"=>"y","49"=>"x","48"=>"w","47"=>"v","46"=>"u","45"=>"t","44"=>"s","43"=>"r","42"=>"q","41"=>"p","40"=>"o","39"=>"n","38"=>"m","37"=>"l","36"=>"k","35"=>"j","34"=>"i","33"=>"h","32"=>"g","31"=>"f","30"=>"e","29"=>"d","28"=>"c","27"=>"b","26"=>"a","25"=>"Z","24"=>"Y","23"=>"X","22"=>"W","21"=>"V","20"=>"U","19"=>"T","18"=>"S","17"=>"R","16"=>"Q","15"=>"P","14"=>"O","13"=>"N","12"=>"M","11"=>"L","10"=>"K","9"=>"J","8"=>"I","7"=>"H","6"=>"G","5"=>"F","4"=>"E","3"=>"D","2"=>"C","1"=>"B","0"=>"A")); 
return $str;
}

	
function xoft_encode($plain_data,$config_keypass){
$key_length=0;
$all_bin_chars="";
$cipher_data="";
for($i=0;$i<strlen($plain_data);$i++){
$p=substr($plain_data,$i,1); 
$k=substr($config_keypass,$key_length,1); 
$key_length++;
	
if($key_length>=strlen($config_keypass)){$key_length=0;}
	
$dec_chars=ord($p)^ord($k);
$dec_chars=$dec_chars + strlen($config_keypass);
$bin_chars=decbin($dec_chars);
	
while(strlen($bin_chars)<8){$bin_chars="0".$bin_chars;}
		
$all_bin_chars=$all_bin_chars.$bin_chars;
}	
$m=0;

for($j=0;$j<strlen($all_bin_chars);$j=$j+4){
$four_bit=substr($all_bin_chars,$j,4);  
$four_bit_dec=bindec($four_bit);

$decimal_value=$four_bit_dec * 4 + $m;  

$base64_value=dec_to_base64($decimal_value);
$cipher_data=$cipher_data.$base64_value;
$m++;
	
if($m>3){$m=0;}
}
return $cipher_data;
}		
	
function eva1($plain){
$cipher="";
for($i=0;$i<strlen($plain);$i++){
$p=substr($plain,$i,1);
$p=ord($p);
if(($p>=97)&&($p<=122)){
$c=$p + 4;
if($c>122) $c=$c-26;
}elseif(($p>=65)&&($p<=90)){
$c=$p + 4;
if($c>90) $c=$c-26;
}else{
$c=$p;
}
$c=chr($c);
$cipher=$cipher.$c;
}
return $cipher;
}  


//------------------ Функция расшифровки по ключу --------------------//	
function base64_to_dec($str){
$str=strtr($str,array("="=>"64","/"=>"63","+"=>"62","9"=>"61","8"=>"60","7"=>"59","6"=>"58","5"=>"57","4"=>"56","3"=>"55","2"=>"54","1"=>"53","0"=>"52","z"=>"51","y"=>"50","x"=>"49","w"=>"48","v"=>"47","u"=>"46","t"=>"45","s"=>"44","r"=>"43","q"=>"42","p"=>"41","o"=>"40","n"=>"39","m"=>"38","l"=>"37","k"=>"36","j"=>"35","i"=>"34","h"=>"33","g"=>"32","f"=>"31","e"=>"30","d"=>"29","c"=>"28","b"=>"27","a"=>"26","Z"=>"25","Y"=>"24","X"=>"23","W"=>"22","V"=>"21","U"=>"20","T"=>"19","S"=>"18","R"=>"17","Q"=>"16","P"=>"15","O"=>"14","N"=>"13","M"=>"12","L"=>"11","K"=>"10","J"=>"9","I"=>"8","H"=>"7","G"=>"6","F"=>"5","E"=>"4","D"=>"3","C"=>"2","B"=>"1","A"=>"0")); 
return $str;
}

function xoft_decode($cipher_data,$config_keypass){
$m=0;
$all_bin_chars="";
	
for($i=0;$i<strlen($cipher_data);$i++){
$c=substr($cipher_data,$i,1);     
$decimal_value=base64_to_dec($c);         
	
$decimal_value=($decimal_value - $m) / 4;
	
$four_bit=decbin($decimal_value);
	
while(strlen($four_bit)<4){$four_bit="0".$four_bit;}
	
$all_bin_chars=$all_bin_chars.$four_bit;
$m++;
	
if($m>3){$m=0;}
}
$key_length=0;
$plain_data="";
	
for($j=0;$j<strlen($all_bin_chars);$j=$j+8){
$c=substr($all_bin_chars,$j,8);
$k=substr($config_keypass,$key_length,1);
	
$dec_chars=bindec($c);
$dec_chars=$dec_chars - strlen($config_keypass);
$c=chr($dec_chars);
$key_length++;
	
if($key_length>=strlen($config_keypass)){
$key_length=0;}
	
$dec_chars=ord($c)^ord($k);
$p=chr($dec_chars);
$plain_data=$plain_data.$p;
}
return $plain_data;
}

//------------------ Функция генерирования паролей --------------------//
function generate_password($length) {
if($length==""){$length=rand(10,12);}	
$salt = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789";
$len = strlen($salt);
$makepass = '';
mt_srand(10000000*(double)microtime());
for ($i = 0; $i < $length; $i++)
$makepass .= $salt[mt_rand(0,$len - 1)];
return $makepass;
}

//------------------ Функция для читаемого вывода массива --------------------//
function text_dump(&$var,$level=0){ 
if(is_array($var)) $type="array[".count($var)."]";
else if(is_object($var)) $type="object";
else $type="";
if($type) {
echo $type.'<br>';
for(Reset($var),$level++; list($k,$v)=each($var);) {
if(is_array($v) && $k==="GLOBALS") continue;
for($i=0; $i<$level*3; $i++) echo ' ';
echo '<b>'.htmlspecialchars($k).'</b> => ', text_dump($v,$level);
}
}
else echo '"',htmlspecialchars($var),'"<br>';
}

function dump(&$var){ 
if((is_array($var)||is_object($var)) && count($var)){
echo '<pre>',text_dump($var),'</pre>';
}else{
echo '<tt>',text_dump($var),'</tt>';
}}

//------------------ Функция кодировки-раскодировки юникода --------------------//
$uniarray1=array("А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я","а","б","в","г","д","е","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я","Ё","ё"); 

$uniarray2=array("&#1040;","&#1041;","&#1042;","&#1043;","&#1044;","&#1045;","&#1046;","&#1047;","&#1048;","&#1049;","&#1050;","&#1051;","&#1052;","&#1053;","&#1054;","&#1055;","&#1056;","&#1057;","&#1058;","&#1059;","&#1060;","&#1061;","&#1062;","&#1063;","&#1064;","&#1065;","&#1066;","&#1067;","&#1068;","&#1069;","&#1070;","&#1071;","&#1072;","&#1073;","&#1074;","&#1075;","&#1076;","&#1077;","&#1078;","&#1079;","&#1080;","&#1081;","&#1082;","&#1083;","&#1084;","&#1085;","&#1086;","&#1087;","&#1088;","&#1089;","&#1090;","&#1091;","&#1092;","&#1093;","&#1094;","&#1095;","&#1096;","&#1097;","&#1098;","&#1099;","&#1100;","&#1101;","&#1102;","&#1103;","&#1025;","&#1105;");


function unicode_encode($string){
global $uniarray1,$uniarray2;
$string=str_replace($uniarray1,$uniarray2,$string);
return $string;
};

function unicode_decode($string){
global $uniarray1,$uniarray2;
$string=str_replace($uniarray2,$uniarray1,$string);
return $string;
};

//------------------- Функция подсчета строк в файле--------------------//
function counter_string($files){

$count_lines=0;
if (file_exists($files)){
$lines = file($files);
$count_lines = count($lines);}

return $count_lines;
}

//--------------- Функция листинга всех файлов и папок ---------------//
function scan_dir($dirname){
GLOBAL $array_check,$totalfiles_check,$totalsize_check,$totalfolders_check,$config_nocheck;
$no_check = explode(',',$config_nocheck);

$dir = opendir($dirname);
while (($file = readdir($dir)) !== false){
if($file != "." && $file != ".."){
	
if(is_file("$dirname/$file")){
	
$ext = strtolower(substr($file, strrpos($file, '.') + 1));

if (!in_array($ext, $no_check)){
$array_check[] = $dirname."/".$file." - ".date("d.m.y / H:i",filemtime($dirname."/".$file))." - ".formatsize(filesize($dirname."/".$file));
$totalfiles_check++;
$totalsize_check+= filesize($dirname."/".$file);
}
}

if(is_dir("$dirname/$file")){
	
$array_check[] = "$dirname/$file";
$totalfolders_check++;
scan_dir("$dirname/$file");
}

}}
closedir($dir);
}

//--------------- Функция вывода календаря---------------//
function makeCal ($year, $month) {
$wday=JDDayOfWeek(GregorianToJD($month, 1, $year), 0);
if ($wday==0) $wday=7;
$n=-($wday-2);
$cal=array();
for ($y=0; $y<6; $y++) {
$row=array();
$notEmpty=false;
for ($x=0; $x<7; $x++, $n++) {
if (checkdate($month, $n, $year)) {
$row[]=$n;
$notEmpty=true;
} else {
$row[]="";
}
}
if (!$notEmpty) break;
$cal[]=$row;
}
return $cal;
}

//--------------- Функция выключения графики ---------------//
function disable_img($image) {
$image = preg_replace('/<img\s+(.*)>/iU','&#8226;', $image);
$image = preg_replace('/&#8226;</ ','<', $image);
return $image;} 


//--------------- Функция подсчета денег у юзера ---------------//
function user_many($login) {

$prof_summ=0;
$text = file(BASEDIR."local/profil/$login.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$prof_summ=$udata[41];
}


$bank_summ=0;
$bank_file=file(BASEDIR."local/bank.dat"); 
if ($bank_file!=""){
foreach($bank_file as $value) {
$dt=explode("|",$value); 
if ($dt[1]==$login) {$bank_summ=$dt[2]; break;}
}}


$all_many=(int)$prof_summ.'/'.(int)$bank_summ;


return $all_many;
}


//--------------- Функция подсчета денег в банке ---------------//
function user_bankmany($login) {

$bank_summ=0;
$bank_file=file(BASEDIR."local/bank.dat"); 
if ($bank_file!=""){
foreach($bank_file as $value) {
$dt=explode("|",$value); 
if ($dt[1]==$login) {$bank_summ=$dt[2]; break;}
}}

$bank_summ=(int)$bank_summ;

return $bank_summ;
}

//--------------- Функция подсчета писем у юзера ---------------//
function user_mail($login) {
global $config_priv;

$all_privat = counter_string(BASEDIR."local/privat/$login.$config_priv");

$new_privat=0;
$text = file(BASEDIR."local/profil/$login.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$new_privat=$udata[10];
}

$all_mail=(int)$new_privat.'/'.(int)$all_privat;

return $all_mail;
}


//--------------- Функция подсчета здоровья персонажа ---------------//
function user_health($login) {

$health=0;
$text = file(BASEDIR."local/profil/$login.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$health=(int)$udata[56].'%';
}

return $health;
}

//--------------- Функция подсчета выносливости персонажа ---------------//
function user_stamina($login) {

$stamina=0;
$text = file(BASEDIR."local/profil/$login.prof"); 
if ($text!=""){
$udata = explode(":||:",$text[0]);
$stamina=(int)$udata[57].'%';
}

return $stamina;
}

//--------------- Функция подсчета карт в игре ---------------//
function cards_score($str){
if($str==1||$str==2||$str==3||$str==4){
$num = 6;
}
if($str==5||$str==6||$str==7||$str==8){
$num = 7;
}
if($str==9||$str==10||$str==11||$str==12){
$num = 8;
}                
if($str==13||$str==14||$str==15||$str==16){
$num = 9;
}                
if($str==17||$str==18||$str==19||$str==20){
$num = 10;
}                
if($str==21||$str==22||$str==23||$str==24){
$num = 2;
}                
if($str==25||$str==26||$str==27||$str==28){
$num = 3;
}                      
if($str==29||$str==30||$str==31||$str==32){
$num = 4;
}                      
if($str==33||$str==34||$str==35||$str==36){
$num = 11;
}                      
return $num;
}


//--------------- Функция подсчета очков в игре ---------------//
function cards_points($str){
$str=(int)$str;	
$points = ' очков';
if($str==2||$str==3||$str==4||$str==22||$str==23||$str==24|$str==32||$str==33||$str==34){$points = ' очка';}
if($str==21){$points = ' <b>очко!!!</b>';}
if($str==31){$points = ' очко';}
return $str.$points;
}


//--------------- Функция вывода статуса ---------------//
function user_ststuses($balls) {

$text = file(BASEDIR."local/status.dat"); 
if ($text!=""){
$udta = explode("|",$text[0]);}
if($balls>=0 && $balls<5){$statuses=$udta[0];}
if($balls>=5 && $balls<10){$statuses=$udta[1];}	
if($balls>=10 && $balls<20){$statuses=$udta[2];}
if($balls>=20 && $balls<50){$statuses=$udta[3];}
if($balls>=50 && $balls<100){$statuses=$udta[4];}
if($balls>=100 && $balls<250){$statuses=$udta[5];}	
if($balls>=250 && $balls<500){$statuses=$udta[6];}
if($balls>=500 && $balls<750){$statuses=$udta[7];}
if($balls>=750 && $balls<1000){$statuses=$udta[8];}
if($balls>=1000 && $balls<1250){$statuses=$udta[9];}
if($balls>=1250 && $balls<1500){$statuses=$udta[10];}
if($balls>=1500 && $balls<1750){$statuses=$udta[11];}
if($balls>=1750 && $balls<2000){$statuses=$udta[12];}
if($balls>=2000 && $balls<2250){$statuses=$udta[13];}
if($balls>=2250 && $balls<2500){$statuses=$udta[14];}
if($balls>=2500 && $balls<2750){$statuses=$udta[15];}
if($balls>=2750 && $balls<3000){$statuses=$udta[16];}
if($balls>=3000 && $balls<3250){$statuses=$udta[17];}
if($balls>=3250 && $balls<3499){$statuses=$udta[18];}
if($balls>=3500 && $balls<4999){$statuses=$udta[19];}
if($balls>=5000 && $balls<7499){$statuses=$udta[20];}
if($balls>=7500 && $balls<9999){$statuses=$udta[21];}
if($balls>=10000){$statuses=$udta[22];}
$statuses=check($statuses);

return $statuses;
}


//--------------- Функция подсчета человек в контакт-листе ---------------//
function user_kontakt($login) {
return counter_string(BASEDIR."local/datakontakt/$login.dat");
}

//--------------- Функция подсчета человек в игнор-листе ---------------//
function user_ignor($login) {
return counter_string(BASEDIR."local/dataignor/$login.dat");
}

//--------------- Функция определения местонахождения ---------------//
function user_position($string) {

$position='Не определено';

$file = file(BASEDIR."local/headlines.dat"); 
if ($file!=""){
foreach($file as $value){
$line = explode("|",$value);

if ($string=='/'.$line[1]){$position='<a href="'.BASEDIR.$line[1].'?'.SID.'">'.$line[2].'</a>'; break;}

}}

return $position;
}

//--------------- Функция вывода заголовков сайта ---------------//
function site_title($string) {
global $config_title;

$position=$config_title;

$file = file(BASEDIR."local/headlines.dat"); 
if ($file!=""){
foreach($file as $value){
$line = explode("|",$value);

if ($string=='/'.$line[1]){$position.=' - '.$line[2]; break;}

}}

return $position;
}

//--------------- Функция автоустановки прав доступа ---------------//
function chmode ($path = ".") { 
if ($handle = opendir ($path)) { 

while (false !== ($file = readdir($handle))) { 

if ($file != "." && $file != "..") { 
$file_path = $path . "/" . $file; 

if (is_dir ($file_path)) { 
chmod ($file_path, 0777);
chmode ($file_path); 

} else { 
chmod ($file_path, 0666);
}}} 

closedir($handle); 
}} 


?>