<?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="d.m.y / H:i"){
global $config_clocks,$sitetime;
if(empty($timestamp)){$timestamp=$sitetime;}
$sdvig=$config_clocks*3600;
$datestamp = date($format,$timestamp+$sdvig);
$today = date("d.m.y",$sitetime+$sdvig);
$datestamp = str_replace($today,"Сегодня",$datestamp);
$datestamp = str_replace("January","Января",$datestamp);
$datestamp = str_replace("February","Февраля",$datestamp);
$datestamp = str_replace("March","Марта",$datestamp);
$datestamp = str_replace("April","Апреля",$datestamp);
$datestamp = str_replace("May","Мая",$datestamp);
$datestamp = str_replace("June","Июня",$datestamp);
$datestamp = str_replace("July","Июля",$datestamp);
$datestamp = str_replace("August","Августа",$datestamp);
$datestamp = str_replace("September","Сентября",$datestamp);
$datestamp = str_replace("October","Октября",$datestamp);
$datestamp = str_replace("November","Ноября",$datestamp);
$datestamp = str_replace("December","Декабря",$datestamp);
return $datestamp;
}
//------------------- Функция полного удаления юзера --------------------//
function delete_users($users){
global $config_priv;
$sublines=file(BASEDIR."local/sub.dat");
foreach($sublines as $slkey=>$slval){
$sdata=explode("|",$slval); if ($users==$sdata[4]) {$stroka=$slkey; break;}
}
if ($stroka!="") {
$subfile=file(BASEDIR."local/sub.dat");
$fp=fopen(BASEDIR."local/sub.dat","w");
flock ($fp,LOCK_EX);
foreach($subfile as $sfkey=>$sfval){ if ($stroka==$sfkey){unset($subfile[$sfkey]); break;} }
fputs($fp, implode($subfile));
flock ($fp,LOCK_UN);
fclose($fp);
unset($stroka);
}
$banklines=file(BASEDIR."local/bank.dat");
foreach($banklines as $blkey=>$blval){
$bdata=explode("|",$blval); if ($users==$bdata[1]) {$strokabank=$blkey; break;}
}
if ($strokabank!="") {
$bankfile=file(BASEDIR."local/bank.dat");
$fpbank=fopen(BASEDIR."local/bank.dat","w");
flock ($fpbank,LOCK_EX);
foreach($bankfile as $bfkey=>$bfval){ if ($strokabank==$bfkey){unset($bankfile[$bfkey]); break;} }
fputs($fpbank, implode($bankfile));
flock ($fpbank,LOCK_UN);
fclose($fpbank);
unset($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("<"=>"<",">"=>">","&"=>"&","$"=>"\$","""=>"\"","'"=>"'","\"=>"\\","%"=>"%","<br>"=>"\r\n","^"=>"^",":"=>":"));
$code=highlight_string($code,true);
$code=strtr($code,array("\r\n"=>"<br>","<br />"=>"<br>","\$"=>"$","'"=>"'","\\"=>"\","%"=>"%","^"=>"^",":"=>":")); //,""=>""
$code='<div class=d>'.$code.'</div>';
return $code;}
//------------------ Вспомогательная функция для bb-кода --------------------//
function img_replaces($m) {
$m = str_replace("http://","",$m);
$file = 'http://' . $m['1'] . '';
$size = getimagesize ("$file");
$ext = strtolower(substr($file, 1 + strrpos($file, ".")));
$ext2 = array("gif", "jpg", "png", "jpeg");
if (in_array($ext, $ext2)) {
if ($size['0'] > '100' || $size['1'] > '100'){
echo '<br><img src="http://' . $m['1'] . '" width="100" height="100" alt="' . $m['2'] . '"><br>';
}else{
echo '<br><img src="http://' . $m['1'] . '" alt="' . $m['2'] . '"><br>';
}
echo '<a href="http://' . $m['1'] . '">Скачать</a> ['.$size['0'].'x'.$size['1'].']<br>';
}else{
echo '' . $file . '';
}
}
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_callback('~\\[img=(http://.+?)\\](.+?)\\[/img\\]~', 'img_replaces', $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('#\[q\](.*?)\[/q\]#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\.-]+\.[0-9a-z]{2,6}[0-9a-zA-Z/\?\.\~&_=/%-:#]*)~', 'url_replace', $message);
return $message;
}
//------------------ Функция перекодировки из UTF в WIN --------------------//
function utf_to_win($str) {
if (function_exists('mb_convert_encoding')) return mb_convert_encoding($str, 'windows-1251', 'utf-8');
if (function_exists('iconv')) return iconv('utf-8', 'windows-1251', $str);
$utf8win1251 = array(
"А"=>"\xC0","Б"=>"\xC1","В"=>"\xC2","Г"=>"\xC3","Д"=>"\xC4","Е"=>"\xC5","Ё"=>"\xA8","Ж"=>"\xC6","З"=>"\xC7","И"=>"\xC8","Й"=>"\xC9","К"=>"\xCA","Л"=>"\xCB","М"=>"\xCC",
"Н"=>"\xCD","О"=>"\xCE","П"=>"\xCF","Р"=>"\xD0","С"=>"\xD1","Т"=>"\xD2","У"=>"\xD3","Ф"=>"\xD4","Х"=>"\xD5","Ц"=>"\xD6","Ч"=>"\xD7","Ш"=>"\xD8","Щ"=>"\xD9","Ъ"=>"\xDA",
"Ы"=>"\xDB","Ь"=>"\xDC","Э"=>"\xDD","Ю"=>"\xDE","Я"=>"\xDF","а"=>"\xE0","б"=>"\xE1","в"=>"\xE2","г"=>"\xE3","д"=>"\xE4","е"=>"\xE5","ё"=>"\xB8","ж"=>"\xE6","з"=>"\xE7",
"и"=>"\xE8","й"=>"\xE9","к"=>"\xEA","л"=>"\xEB","м"=>"\xEC","н"=>"\xED","о"=>"\xEE","п"=>"\xEF","р"=>"\xF0","с"=>"\xF1","т"=>"\xF2","у"=>"\xF3","ф"=>"\xF4","х"=>"\xF5",
"ц"=>"\xF6","ч"=>"\xF7","ш"=>"\xF8","щ"=>"\xF9","ъ"=>"\xFA","ы"=>"\xFB","ь"=>"\xFC","э"=>"\xFD","ю"=>"\xFE","я"=>"\xFF");
return strtr($str, $utf8win1251);
}
//------------------ Функция перекодировки из WIN в UTF --------------------//
function win_to_utf($str) {
if (function_exists('mb_convert_encoding')) return mb_convert_encoding($str, 'utf-8', 'windows-1251');
if (function_exists('iconv')) return iconv('windows-1251', 'utf-8', $str);
$win1251utf8 = array(
"\xC0"=>"А","\xC1"=>"Б","\xC2"=>"В","\xC3"=>"Г","\xC4"=>"Д","\xC5"=>"Е","\xA8"=>"Ё","\xC6"=>"Ж","\xC7"=>"З","\xC8"=>"И","\xC9"=>"Й","\xCA"=>"К","\xCB"=>"Л","\xCC"=>"М",
"\xCD"=>"Н","\xCE"=>"О","\xCF"=>"П","\xD0"=>"Р","\xD1"=>"С","\xD2"=>"Т","\xD3"=>"У","\xD4"=>"Ф","\xD5"=>"Х","\xD6"=>"Ц","\xD7"=>"Ч","\xD8"=>"Ш","\xD9"=>"Щ","\xDA"=>"Ъ",
"\xDB"=>"Ы","\xDC"=>"Ь","\xDD"=>"Э","\xDE"=>"Ю","\xDF"=>"Я","\xE0"=>"а","\xE1"=>"б","\xE2"=>"в","\xE3"=>"г","\xE4"=>"д","\xE5"=>"е","\xB8"=>"ё","\xE6"=>"ж","\xE7"=>"з",
"\xE8"=>"и","\xE9"=>"й","\xEA"=>"к","\xEB"=>"л","\xEC"=>"м","\xED"=>"н","\xEE"=>"о","\xEF"=>"п","\xF0"=>"р","\xF1"=>"с","\xF2"=>"т","\xF3"=>"у","\xF4"=>"ф","\xF5"=>"х",
"\xF6"=>"ц","\xF7"=>"ч","\xF8"=>"ш","\xF9"=>"щ","\xFA"=>"ъ","\xFB"=>"ы","\xFC"=>"ь","\xFD"=>"э","\xFE"=>"ю","\xFF"=>"я");
return strtr($str, $win1251utf8);
}
//------------------ Функция преобразования в нижний регистр для UTF ------------------//
function rus_utf_tolower($str){
if (function_exists('mb_strtolower')) return mb_strtolower($str, 'utf-8');
$arraytolower = 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 strtr($str, $arraytolower);
}
//------------------ Функция определения реального IP --------------------//
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && 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(isset($_SERVER['HTTP_CLIENT_IP']) && 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=check($ip);
//------------------ Функция определения реального браузера --------------------//
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])) {$browsus = htmlspecialchars(stripslashes($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']));}
elseif(isset($_SERVER['HTTP_USER_AGENT'])) {$browsus=htmlspecialchars(stripslashes($_SERVER['HTTP_USER_AGENT']));}
else {$browsus='Not_detected';}
$brow=preg_replace('|http://|i','', $browsus);
$brow=strtok($brow,'(');
$brow=strtok($brow,' ');
$brow=substr($brow,0,22);
$brow=check($brow);
//----------------------- Функция экранирования основных знаков --------------------------//
function check($message){
$message=str_replace("|","I",$message);
$message=str_replace("||","I",$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=preg_replace("|:|",":",$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=stripslashes(trim($message));
return $message;
}
//----------------------- Функция вырезания переноса строки --------------------------//
function no_br($message,$replace=""){
$message=preg_replace ("|[\r\n]+|si",$replace,$message);
return $message;
}
//--------------- Функция замены и вывода смайлов -------------------//
function smiles($string){
global $dostup;
$dir = opendir (BASEDIR."images/smiles");
while ($file = readdir ($dir)) {
if (ereg ("\.gif$", $file)){
$smfile[]=str_replace(".gif","",$file);}}
closedir ($dir);
rsort($smfile);
foreach($smfile as $smval){
$string=str_replace(":$smval",'<img src="'.BASEDIR.'images/smiles/'.$smval.'.gif" alt="">',$string);
}
if ($dostup==101 || $dostup==102 || $dostup==103 || $dostup==105){
$dir = opendir (BASEDIR."images/smiles2");
while ($file = readdir ($dir)) {
if (ereg ("\.gif$", "$file")){
$smfiles[]=str_replace(".gif","",$file);}}
closedir ($dir);
rsort($smfiles);
foreach($smfiles as $smvals){
$string=str_replace(":$smvals",'<img src="'.BASEDIR.'images/smiles2/'.$smvals.'.gif" alt="">',$string);
}}
return $string;
}
//--------------- Функция обратной замены смайлов -------------------//
function nosmiles($string){
$string = preg_replace('|<img src="\.\./images/smiles/(.*?)\.gif" alt="">|',':$1', $string);
$string = preg_replace('|<img src="\.\./images/smiles2/(.*?)\.gif" alt="">|',':$1', $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) {
global $sitetime;
$count=0;
$newcount=0;
$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>$sitetime){
$newcount ++;
}
}}
if($newcount>0){
$input=(int)$count.'/+'.(int)$newcount;
}else{
$input=(int)$count;
}
closedir ($path);
return $input;
}
//--------------- Функция подсчета файлов в библиотеке -------------------//
function count_libdir($dir) {
global $sitetime;
$count=0;
$newcount=0;
$path = opendir($dir);
while ($file = readdir($path)) {
if (ereg(".txt$", $file)){
$count ++;
$filetime=filemtime("$dir/$file")+(3600*24*5);
if($filetime>$sitetime){
$newcount ++;
}
}}
if($newcount>0){
$input=(int)$count.'/+'.(int)$newcount;
}else{
$input=(int)$count;
}
closedir ($path);
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","'","'","Y","a","b","v","g","d","e","z","i","j","k","l","m","n","o","p","r","s","t","u","f","h","c","'","'","y");
$trans2=array("Щ","Щ","Ж","Ж","Ч","Ч","Ш","Ш","Ё","Ё","Э","Э","Ю","Ю","Я","Я","щ","ж","ч","ш","ё","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","ь","ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ь","ы");
$string=str_replace($trans1,$trans2,$string);
return $string;}
//------------------ Функция антимата --------------------//
function antimat($string){
$mat = file_get_contents(BASEDIR."local/antimat.dat");
$arr_mat= explode("|",$mat);
foreach($arr_mat as $value){
if($value!=""){
$string = preg_replace("|$value|iu","***",$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){
if(file_exists(BASEDIR."local/profil/$string.prof")){
$text = file(BASEDIR."local/profil/$string.prof");
if ($text){
$udata = explode(":||:",$text[0]);
$runickname=$udata[65];
if(!empty($runickname) && $udata[36]>=150){
$string=$runickname;
}}}}
return $string;
}
//------------------------- Функция антифлуда ------------------------------//
$php_self=check($_SERVER['PHP_SELF']);
function flooder($ip, $php_self){
global $config_floodstime,$sitetime;
$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) > $sitetime ){
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 = '';
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("А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ъ","Ы","Ь","Э","Ю","Я","а","б","в","г","д","е","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я","Ё","ё");
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 src="\.\./images/smiles/(.*?)\.gif" alt="">|',':$1', $image);
$image = preg_replace('|<img src="\.\./images/smiles2/(.*?)\.gif" alt="">|',':$1', $image);
$image = preg_replace('|<img src="(.*?)" alt="">|','•', $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 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);
}}
//--------------- Функция определение онлайн-статуса ---------------//
function user_online($login) {
global $sitetime;
$statwho='<font color="#FF0000">[Off]</font>';
if(file_exists(BASEDIR."local/datalife/$login.dat")){
$lifefile = file(BASEDIR."local/datalife/$login.dat");
if ($lifefile!=""){
$lifestr = explode("|",$lifefile[0]);
$userlife=$sitetime-$lifestr[0];
if($userlife<600){
$statwho='<font color="#00FF00">[On]</font>';
}}}
return $statwho;
}
//--------------- Функции сжатия страниц ---------------//
function compress_output_gzip($output) {
return gzencode($output, 5);
}
function compress_output_deflate($output) {
return gzdeflate($output, 5);
}
//---------- Функция обработки строк данных и ссылок ---------//
function check_string($string) {
$string = strtolower($string);
$string = str_replace("http://www.","",$string);
$string = str_replace("http://wap.","",$string);
$string = str_replace("http://","",$string);
$string = str_replace("https://","",$string);
$string = strtok($string,'/');
$string = strtok($string,'?');
return $string;
}
//---------- Функция определение должности юзера ---------//
function user_title($login) {
if(file_exists(BASEDIR."local/profil/$login.prof")){
$text = file(BASEDIR."local/profil/$login.prof");
if ($text){
$udata = explode(":||:",$text[0]);
if($udata[7]>=101 && $udata[7]<=105){
if($udata[7]==105){$title='<font color="#FF8000">[Модер]</font>';}
if($udata[7]==103){$title='<font color="#FF8000">[Модер]</font>';}
if($udata[7]==102){$title='<font color="#0000FF">[Админ]</font>';}
if($udata[7]==101){$title='<font color="#0000FF">[Админ]</font>';}
return $title;
}}}
}
//---------- Аналог функции substr для UTF-8 ---------//
function utf_substr($str, $offset, $length = null){
if (function_exists('mb_substr')) return mb_substr($str, $offset, $length, 'utf-8');
if (function_exists('iconv_substr')) return iconv_substr($str, $offset, $length, 'utf-8');
$str=utf_to_win($str);
$str=substr($str,$offset,$length);
return win_to_utf($str);
}
//---------------------- Аналог функции strlen для UTF-8 -----------------------//
function utf_strlen($str){
if (function_exists('mb_strlen')) return mb_strlen($str, 'utf-8');
if (function_exists('iconv_strlen')) return iconv_strlen($str, 'utf-8');
return strlen(utf8_decode($str));
}
//---------- Аналог функции wordwrap для UTF-8 ---------//
function utf_wordwrap($str, $width=75, $break="\n", $cut=false){
$str=utf_to_win($str);
$str=wordwrap($str, $width, $break, $cut);
return win_to_utf($str);
}
//----------------------- Функция определения кодировки ------------------------//
function is_utf($str) {
if (function_exists('mb_detect_encoding')){
if(mb_detect_encoding($str) == "UTF-8") {return 1;} else { return 0;}
}
$letters=array("а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я");
foreach($letters as $letval){
if(strstr($str,$letval)){return 1; break;} else { return 0;}
}}
//--------------------- Функция вырезания битых символов UTF -------------------//
function utf_badstrip($str) {
$ret = '';
for ($i = 0;$i < strlen($str);) {
$tmp = $str{$i++};
$ch = ord($tmp);
if ($ch > 0x7F) {
if ($ch < 0xC0) continue;
elseif ($ch < 0xE0) $di = 1;
elseif ($ch < 0xF0) $di = 2;
elseif ($ch < 0xF8) $di = 3;
elseif ($ch < 0xFC) $di = 4;
elseif ($ch < 0xFE) $di = 5;
else continue;
for ($j = 0;$j < $di;$j++) {
$tmp .= $ch = $str{$i + $j};
$ch = ord($ch);
if ($ch < 0x80 || $ch > 0xBF) continue 2;
}
$i += $di;
}
$ret .= $tmp;
}
return $ret;
}
//----------------------- Функция генерирования уникального ID ------------------------//
function unitime() {
$microtime = explode(' ', microtime());
$unitime=$microtime[1].substr($microtime[0],2,2) ;
return $unitime;
}
//----------------------- Функция отправки письма по e-mail ------------------------//
function addmail($usermail, $subject, $msg, $mail="", $name="") {
global $config_nikname, $config_emails;
if($mail==""){$mail=$config_emails; $name=$config_nikname;}
$subject = utf_to_win($subject);
$msg = utf_to_win($msg);
$name = utf_to_win($name);
$subject = convert_cyr_string($subject, 'w','k');
$msg = convert_cyr_string($msg, 'w','k');
$name = convert_cyr_string($name, 'w','k');
$subject = '=?KOI8-R?B?'.base64_encode($subject).'?=';
$adds = "From: ".$name." <".$mail.">\n";
$adds .= "X-sender: ".$name." <".$mail.">\n";
$adds .= "Content-Type: text/plain; charset=koi8-r\n";
$adds .= "MIME-Version: 1.0\n";
$adds .= "Content-Transfer-Encoding: 8bit\n";
$adds .= "X-Mailer: PHP v.".phpversion();
return mail($usermail,$subject,$msg,$adds);
}
?>