<?php
#-----------------------------------------------------#
#          ********* WAP-MOTORS *********             #
#             Made by   :  VANTUZ                     #
#               E-mail  :  vsem@pizdec.ru             #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#-----------------------------------------------------#	

//--------------------------- Функция перевода секунд во время -----------------------------//
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; 
}

//--------------------------- Функция временного сдвига -----------------------------//
//         ZooM inc
//Функция выводит текущее время в соответствии со сдвигом времени, указанным в настройках
//  Формат вызова //
/*
  date_fixed([string format[, int timestamp[, int sdvig]]])
    format     Формат вывода: аналогичен первому параметру функции date
    timestamp  Метка времени: аналогична функции time
    sdvig      Сдвиг времени, положительное или отрицательное число
*/
function date_fixed($format="U",$timestamp="",$mysdvig="")
{
 global $config_timezone;     //сдвиг времени из конфига
 if(empty($timestamp)){$timestamp=time();}  //Если $timestamp пустая, то это текущее время
 if(empty($format)){$format="U";}  //Если $format пустая, то это текущее время
 if(!empty($mysdvig)){$config_timezone=$mysdvig;}  //Если $timestamp пустая, то это текущее время
 $sdvig=$config_timezone*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");

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 = ' бакс';}
$string=str_replace($string,$string.$inp,$string);
return $string;  }


//------------------- Функция очистки файлов --------------------//
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;
}



//------------------ Функция вставки BB-кода --------------------//
function bb_code($message){ 
$message=eregi_replace("((https?|ftp)://[[:alnum:]_=/-]+(\\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&amp;._=/~:%#]*(\\?[[:alnum:]?+&amp;._=/%:#]*)?)?)", "<a href='\\1'>\\1</a>", $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('#\[code\](.*?)\[/code\]#si', '<div class=d><code style="white-space:wrap">\1</code></div>', $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('#\[pre\](.*?)\[/pre\]#si', '<pre>\1</pre>', $message);
$message = preg_replace('#\[quote\](.*?)\[/quote\]#si', '<q>\1</q>', $message);
$message = preg_replace('#\[del\](.*?)\[/del\]#si', '<del>\1</del>', $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 ($_SERVER['HTTP_X_FORWARDED_FOR']) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_CLIENT_IP']) $ip = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['REMOTE_ADDR']) $ip = $_SERVER['REMOTE_ADDR'];
else {$ip = 'not detected';}
$ip = preg_replace("/[^0-9.]/", "", $ip);
$ip=htmlspecialchars(stripslashes($ip));


//----------------------- Функция вывода русской даты --------------------------//
$user_time=$config_clocks*3600;
$currHour=date("H",time()+$user_time); 
$currHour= round($currHour); 
$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(":","&#58;",$message); 
$message=preg_replace("/&#58;/",":",$message,3); 
/* 
$message=preg_replace('/(j|J)(s|S)?/i',"***",$message); 
$message=preg_replace('/(s|S)(c|C)(r|R)(i|I)(p|P)(t|T)?/i',"***",$message); 
$message=preg_replace('/(i|I)(m|M)(g|G)?/i',"***",$message); 
$message=preg_replace('/(s|S)(r|R)(c|C)?/i',"***",$message); $message=preg_replace('/(a|A)(l|L)(e|E)(r|R)(t|T)?/i',"***",$message);                      
*/
$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=stripslashes(trim($message));               
return $message;  }


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

//------------------ Функция определения реального браузера --------------------//
if ($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) {
$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));
}else{ $browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));} 
/* if ($_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=str_replace("http://","", $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); 
}} return  $size;} 

//--------------- Функция правильного вывода веса файла -------------------//
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($msg){
$mix = strpos($msg,']');
if ($mix<20)
    { $nik =substr($msg ,0, $mix );
	$msg =substr($msg,$mix);
	}
$msg = str_replace('<br>','[0]',$msg);
$msg = str_replace('[b]','[1]',$msg);
$msg = str_replace('[/b]','[2]',$msg);
$msg = str_replace('[i]','[3]',$msg);
$msg = str_replace('[/i]','[4]',$msg);
$msg = str_replace('[u]','[5]',$msg);
$msg = str_replace('[/u]','[6]',$msg);
$msg = str_replace('[quote','[7]',$msg);
$msg = str_replace('[/quote]','[8]',$msg);
$msg = str_replace('[red]','[9]',$msg);
$msg = str_replace('[/red]','[10]',$msg);
$msg = str_replace('[big]','[11]',$msg);
$msg = str_replace('[/big]','[12]',$msg);
$msg = str_replace('[blue]','[13]',$msg);
$msg = str_replace('[/blue]','[14]',$msg);
$msg = str_replace('[green]','[15]',$msg);
$msg = str_replace('[/green]','[16]',$msg);
$msg = str_replace('[yellow]','[17]',$msg);
$msg = str_replace('[/yellow]','[18]',$msg);
$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("Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы"); 
$msg=str_replace($trans1,$trans2,$msg);
$msg = str_replace('[0]','<br>',$msg);
$msg = str_replace('[1]','[b]',$msg);
$msg = str_replace('[2]','[/b]',$msg);
$msg = str_replace('[3]','[i]',$msg);
$msg = str_replace('[4]','[/i]',$msg);
$msg = str_replace('[5]','[u]',$msg);
$msg = str_replace('[6]','[/u]',$msg);
$msg = str_replace('[7]','[quote',$msg);
$msg = str_replace('[8]','[/quote]',$msg);
$msg = str_replace('[9]','[red]',$msg);
$msg = str_replace('[10]','[/red]',$msg);
$msg = str_replace('[11]','[big]',$msg);
$msg = str_replace('[12]','[/big]',$msg);
$msg = str_replace('[13]','[blue]',$msg);
$msg = str_replace('[14]','[/blue]',$msg);
$msg = str_replace('[15]','[green]',$msg);
$msg = str_replace('[16]','[/green]',$msg);
$msg = str_replace('[17]','[yellow]',$msg);
$msg = str_replace('[18]','[/yellow]',$msg);
if (isset($nik) && $nik !="")
   { $msg = $nik . $msg;}
return $msg;} */

//------------------ Функция транслита букв --------------------//
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=preg_replace('/(с|c|С|C)(у|y|Y|У)(ч|4|Ч)?(к|k|K|К|ча|чa|4a|4а)?(а|a)/i',"***",$string);
	$string=preg_replace('/(п|n|П)(и|u|И)(д|g|Д)(о|o|0|a|а|e|е)?(р|p)(а|a)?(з|c|с)?/i',"***",$string);
	$string=preg_replace('/(х|x|X|Х)(у|У|Y|y)(й|и|Й|И|u|е|e|Е|Ё|ё)(b|в)?(o|0|о|a|а)?/i',"***",$string);
	$string=preg_replace('/(п|n|П)(и|u|И)(з|3|З)(д|g|Д)?/i',"***",$string);
	$string=preg_replace('/(е|e|E|Е)(б|6|Б)(а|a|А|A)(т|л)?/i',"***",$string);
	$string=preg_replace('/(б|6|Б)(л|Л)(я|Я)/i',"***",$string);
return $string;}

//------------------ Функция для вывода в КТО-ГДЕ --------------------//
function str_mess($message){ 
$message=str_replace("/pages/who.php","Кто-где?",$message);
$message=str_replace("/pages/avators.php","Смотрит аватары",$message);
$message=str_replace("/pages/raitinglist.php","В рейтинге толстосумов",$message);
$message=str_replace("/pages/userlist.php","В списке юзеров",$message);
$message=str_replace("/pages/traffic.php","Cмотрит траффик",$message);
$message=str_replace("/votes/vote.php","В голосовании",$message);
$message=str_replace("/votes","В голосовании",$message);
$message=str_replace("/pages/profil.php","В профиле",$message); 
$message=str_replace("/pages/privat.php","Читает приват",$message);
$message=str_replace("/pages/statistik.php","Cмотрит статистику",$message);
$message=str_replace("/pages/anketa.php","Cмотрит анкету",$message);
$message=str_replace("/pages/setting.php","Меняет настройки",$message);
$message=str_replace("/news/komm.php","Комментирует новости",$message);
$message=str_replace("/news","Читает новости",$message);
$message=str_replace("/forum/addtem.php","Создает тему в форуме",$message);
$message=str_replace("/forum","Общается в форуме",$message);
$message=str_replace("/games/bank.php","В банке",$message);
$message=str_replace("/games/magazin.php","В магазине",$message);
$message=str_replace("/games/perevod.php","Переводит деньги",$message);
$message=str_replace("/games/21.php","Играет в очко",$message);
$message=str_replace("/games/bandit.php","Играет в бандита",$message);
$message=str_replace("/games/kosti.php","Играет в кости",$message);
$message=str_replace("/games/hi.php","Играет в \"Угадай число\"",$message);
$message=str_replace("/games/livebank.php","В статистике вкладов",$message);
$message=str_replace("/chat/say.php","Пишет в чате",$message);
$message=str_replace("/chat","Общается в чате",$message);
$message=str_replace("/board/add.php","Добавляет объявление",$message);
$message=str_replace("/board","Читает объявления",$message);
$message=str_replace("/gallery","Смотрит фотки",$message);
$message=str_replace("/book/tegi.php","Смотрит теги",$message);
$message=str_replace("/book","Общается в гостевухе",$message);
$message=str_replace("/mail","Пишет администрации",$message);
$message=str_replace("/pages/faq.php","Читает FAQ",$message);
$message=str_replace("/pages/link.php","Размещает ссылку",$message);
$message=str_replace("/pages/statusfaq.php","Cмотрит статусы",$message);
$message=str_replace("/download/new.php","Просматривает новые файлы",$message);
$message=str_replace("/download/down.php","Скачивает файлы",$message);
$message=str_replace("/download","Скачивает файлы",$message);
$message=str_replace("/smiles.php","Смотрит смайлы",$message);
$message=str_replace("/search/index.php","В поисковике",$message);
$message=str_replace("/input.php","На главной",$message);
$message=str_replace("/index.php","",$message);  
return $message;  }

/* function down_replace($message){ 
$message=str_replace("images","Картинки",$message);
$message=str_replace("music","Музон",$message);
$message=str_replace("video","Видео",$message);
$message=str_replace("games","Игры",$message);    
$message=str_replace("guestbooks","Гостевые книги",$message);
$message=str_replace("biblioteki","Библиотеки",$message);
$message=str_replace("chats","Чаты",$message);
$message=str_replace("connect","Связь",$message);
$message=str_replace("dosug","Развлечения",$message);
$message=str_replace("forums","Форумы",$message);
$message=str_replace("grabbers","Грабберы",$message);
$message=str_replace("informers","Информеры",$message);
$message=str_replace("katalogi","Каталоги",$message);
$message=str_replace("reklama","Реклама",$message);
$message=str_replace("rotor","Раскрутка",$message);
$message=str_replace("masters","Wap-мастеру",$message);
$message=str_replace("servises","Сервисы",$message);
$message=str_replace("builders","Строительство",$message);
$message=str_replace("votes","Опросы",$message);
$message=str_replace("downloads","Загрузки",$message);
$message=str_replace("programs","Программы",$message);
$message=str_replace("raznoe","Разное",$message);
$message=str_replace("protect","Защита",$message);
$message=str_replace("news","Новостные ленты",$message);
$message=str_replace("member","Авторизация",$message);
$message=str_replace("search","Поисковики",$message);
$message=str_replace("wap-motor","Wap-Motor",$message);          
return $message;  }	



 //------------------ Функция изменения вывода файла в библиотеке --------------------//
function to_rus($str){
$str=str_replace(".txt","",$str); 
$str=str_replace("_"," ",$str); 
 
if(substr($str, 0, 1)=="!"){
$str=transliter($str); 
$str=substr($str,1); }
return $str;
} */

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

//------------------ Функция динамически меняющихся заголовков --------------------//
$my_title='';
if (stristr($_SERVER['PHP_SELF'],"forum/index.php")){$my_title = ' - Форум';}
if (stristr($_SERVER['PHP_SELF'],"forum/addtem.php")){$my_title = ' - Форум - добавление темы';}
if (stristr($_SERVER['PHP_SELF'],"forum/search.php")){$my_title = ' - Поиск по форуму';}
if (stristr($_SERVER['PHP_SELF'],"book/index.php")){$my_title = ' - Гостевая книга';}
if (stristr($_SERVER['PHP_SELF'],"book/tegi.php")){$my_title = ' - Справка по тегам';}
if (stristr($_SERVER['PHP_SELF'],"board/index.php")){$my_title = ' - Доска объявлений';}
if (stristr($_SERVER['PHP_SELF'],"board/search.php")){$my_title = ' - Поиск объявлений';}
if (stristr($_SERVER['PHP_SELF'],"board/add.php")){$my_title = ' - Добавление объявления';}
if (stristr($_SERVER['PHP_SELF'],"games/21.php")){$my_title = ' - 21 Очко';}
if (stristr($_SERVER['PHP_SELF'],"games/bandit.php")){$my_title = ' - Однорукий бандит';}
if (stristr($_SERVER['PHP_SELF'],"games/bank.php")){$my_title = ' - Банк';}
if (stristr($_SERVER['PHP_SELF'],"games/kosti.php")){$my_title = ' - Кости';}
if (stristr($_SERVER['PHP_SELF'],"games/hi.php")){$my_title = ' - Угадай число';}
if (stristr($_SERVER['PHP_SELF'],"games/perevod.php")){$my_title = ' - Перевод монет';}
if (stristr($_SERVER['PHP_SELF'],"games/loterea.php")){$my_title = ' - Лотерея';}
if (stristr($_SERVER['PHP_SELF'],"chat/index.php")){$my_title = ' - Мини-чат';}
if (stristr($_SERVER['PHP_SELF'],"chat/say.php")){$my_title = ' - Мини-чат - Добавление сообщений';}
if (stristr($_SERVER['PHP_SELF'],"votes/index.php")){$my_title = ' - Голосование';}
if (stristr($_SERVER['PHP_SELF'],"votes/vote.php")){$my_title = ' - Голосование - Просмотр результатов';}
if (stristr($_SERVER['PHP_SELF'],"votes/allvotes.php")){$my_title = ' -Архив голосований';}
if (stristr($_SERVER['PHP_SELF'],"gallery/index.php")){$my_title = ' - фотогалерея';}
if (stristr($_SERVER['PHP_SELF'],"who.php")){$my_title = ' - Кто-где';}
if (stristr($_SERVER['PHP_SELF'],"vhod.php")){$my_title = ' - Авторизация';}
if (stristr($_SERVER['PHP_SELF'],"userlist.php")){$my_title = ' - Список пользователей';}
if (stristr($_SERVER['PHP_SELF'],"translit.php")){$my_title = ' - Правила транслита';}
if (stristr($_SERVER['PHP_SELF'],"traffic.php")){$my_title = ' - Ваш траффик';}
if (stristr($_SERVER['PHP_SELF'],"anketa.php")){$my_title = ' - Анкета';}
if (stristr($_SERVER['PHP_SELF'],"avators.php")){$my_title = ' - Галерея аватаров';}
if (stristr($_SERVER['PHP_SELF'],"ban.php")){$my_title = ' - Бан';}
if (stristr($_SERVER['PHP_SELF'],"faq.php")){$my_title = ' - FAQ по сайту';}
if (stristr($_SERVER['PHP_SELF'],"link.php")){$my_title = ' - Добавь свой сайт';}
if (stristr($_SERVER['PHP_SELF'],"online.php")){$my_title = ' - Кто в онлайне';}
if (stristr($_SERVER['PHP_SELF'],"onlinewho.php")){$my_title = ' - Онлайн пользователей';}
if (stristr($_SERVER['PHP_SELF'],"privat.php")){$my_title = ' - Моя почта';}
if (stristr($_SERVER['PHP_SELF'],"profil.php")){$my_title = ' - Мой профиль';}
if (stristr($_SERVER['PHP_SELF'],"raitinglist.php")){$my_title = ' - Рейтинг толстосумов';}
if (stristr($_SERVER['PHP_SELF'],"referer.php")){$my_title = ' - Кто-откуда';}
if (stristr($_SERVER['PHP_SELF'],"registration.php")){$my_title = ' - Регистрация';}
if (stristr($_SERVER['PHP_SELF'],"setting.php")){$my_title = ' - Мои настройки';}
if (stristr($_SERVER['PHP_SELF'],"smiles.php")){$my_title = ' - Галерея смайлов';}
if (stristr($_SERVER['PHP_SELF'],"statistik.php")){$my_title = ' - Статистика сайта';}
if (stristr($_SERVER['PHP_SELF'],"statusfaq.php")){$my_title = ' - Статусы пользователей';}
if (stristr($_SERVER['PHP_SELF'],"subdel.php")){$my_title = ' - Отписка от новостей';}
if (stristr($_SERVER['PHP_SELF'],"news/index.php")){$my_title = ' - Новости сайта';}
if (stristr($_SERVER['PHP_SELF'],"news/komm.php")){$my_title = ' -  Комментарии новостей';}
if (stristr($_SERVER['PHP_SELF'],"mpanel")){$my_title = ' - Админка';}
if (stristr($_SERVER['PHP_SELF'],"mail/index.php")){$my_title = ' - Связь с админом';}
if (stristr($_SERVER['PHP_SELF'],"mail/lostpassword.php")){$my_title = ' - Восстановление пароля';}
if (stristr($_SERVER['PHP_SELF'],"help")){$my_title = ' - Помощь';}
if (stristr($_SERVER['PHP_SELF'],"download/index.php")){$my_title = ' - Архив скриптов - Категории';}
if (stristr($_SERVER['PHP_SELF'],"download/down.php")){$my_title = ' - Архив скриптов';}
if (stristr($_SERVER['PHP_SELF'],"download/new.php")){$my_title = ' - Архив скриптов - Новые скрипты';}
if (stristr($_SERVER['PHP_SELF'],"download/zip.php")){$my_title = ' - Архив скриптов - Просмотр архива';}
if (stristr($_SERVER['PHP_SELF'],"download/top.php")){$my_title = ' - Архив скриптов - TOP скриптов';}
if (stristr($_SERVER['PHP_SELF'],"download/search.php")){$my_title = ' - Архив скриптов - Поиск файлов';}


//------------------ Функция правильного вывода статуса --------------------//
function user_status($message){ 
$message=str_replace('101','<font color="FF0000">Суперадмин</font>',$message);
$message=str_replace('102','<font color="FFFF00">Админ</font>',$message);
$message=str_replace('103','<font color="00FF00">Старший Модер</font>',$message);
$message=str_replace('105','<font color="0000FF">Модер</font>',$message);    
$message=str_replace('107','Пользователь',$message);        
return $message;  }	


//------------------ Функция выводящая картинку в загрузках --------------------//
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 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 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=rand(8,12);	
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$len = strlen($salt);
$makepass = '';
mt_srand(10000000*(double)microtime());
for ($i = 0; $i < $length; $i++)
$makepass .= $salt[mt_rand(0,$len - 1)];
return $makepass;
}

?>