Просмотр файла template/functions.php

Размер файла: 42.74Kb
<?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 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");

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;
}

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-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=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("№","&#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){ 
$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']));}
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;}

//------------------ Функция для вывода в КТО-ГДЕ --------------------//
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;  }

//------------------ Функция определения прав доступа (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){ 
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){

$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){

$no_check = array("txt", "prof", "dat", "priv", "gif", "jpg", "png");
GLOBAL $array_check,$totalfiles_check,$totalsize_check,$totalfolders_check;

$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_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=$udata[56].'%';
}

return $health;
}

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

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

return $stamina;
}

?>