<?
function ip_address()
{
if($ip = getenv("HTTP_CLIENT_IP"))
{
return $ip;
}
if($ip = getenv("HTTP_X_FORWARDED_FOR"))
{
return $ip;
}
return getenv("REMOTE_ADDR");
}
function BBcode($text,$status)
{
if($status > 0)
{
$search[] = "#\[b\](.*?)\[/b\]#si";
$search[] = "#\[i\](.*?)\[/i\]#si";
$search[] = "#\[u\](.*?)\[/u\]#si";
$search[] = "#\[br]#si";
$search[] = "#\[font=([a-zA-Z[:space:]]{1,})\](.*?)\[/font\]#si";
$search[] = "#\[color=(.*?)\](.*?)\[/color\]#si";
$search[] = "#\[size=([1-6]{1})\](.*?)\[/size\]#si";
$search[] = "#\[email\]([a-z0-9\._-]{1,})+@([a-z0-9\._-]{1,})+\.([a-z]{2,4})\[/email\]#si";
$search[] = "#\[email=([a-z0-9\._-]{1,})+@([a-z0-9\”_-]{1,})+\.([a-z]{2,4})\](.*?)\[/email\]#si";
$search[] = "#\[a\](.*?)\[/a\]#si";
$search[] = "#\[a=(.*?)](.*?)\[/a\]#si";
$search[] = "#\[img\](.*?)\[/img\]#si";
$replace[] = '<b>\1</b>';
$replace[] = '<i>\1</i>';
$replace[] = '<u>\1</u>';
$replace[] = '<br/>';
$replace[] = '<font face="\1">\2</font>';
$replace[] = '<span style="color:\1;">\2</span>';
$replace[] = '<font size="\1">\2</font>';
$replace[] = '<a href="mailto://\1@\2.\3">\1@\2.\3</a>';
$replace[] = '<a href="mailto:\1@\2.\3">\4</a>';
$replace[] = '<a class="link3" href="\1"><img src="/img/icons/link.png" style="margin-right:2px;width:16px">\1</a>';
$replace[] = '<a class="link3" href="\1"><img src="/img/icons/link.png" style="margin-right:2px;width:16px">\2</a>';
$replace[] = '<img src="\1" alt="o">';
$text = preg_replace($search, $replace, $text);
}
return $text;
}
function json_encode_cyr($str) {
$arr_replace_utf = array('\u0410', '\u0430','\u0411','\u0431','\u0412','\u0432',
'\u0413','\u0433','\u0414','\u0434','\u0415','\u0435','\u0401','\u0451','\u0416',
'\u0436','\u0417','\u0437','\u0418','\u0438','\u0419','\u0439','\u041a','\u043a',
'\u041b','\u043b','\u041c','\u043c','\u041d','\u043d','\u041e','\u043e','\u041f',
'\u043f','\u0420','\u0440','\u0421','\u0441','\u0422','\u0442','\u0423','\u0443',
'\u0424','\u0444','\u0425','\u0445','\u0426','\u0446','\u0427','\u0447','\u0428',
'\u0448','\u0429','\u0449','\u042a','\u044a','\u042b','\u044b','\u042c','\u044c',
'\u042d','\u044d','\u042e','\u044e','\u042f','\u044f');
$arr_replace_cyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е',
'Ё', 'ё', 'Ж','ж','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н','О','о',
'П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ч','ч','Ш','ш',
'Щ','щ','Ъ','ъ','Ы','ы','Ь','ь','Э','э','Ю','ю','Я','я');
$str1 = json_encode($str);
$str2 = str_replace($arr_replace_utf,$arr_replace_cyr,$str1);
return $str2;
}
function converter($last_time, $count_of_day)
{
$count = floor((time() - $last_time)/(86400/$count_of_day));
if($count > $count_of_day)
{
return $count_of_day;
}
return $count;
}
/*Уровни компаний*/
function rating_collective($experience, $maxlevel = 100, $levelscore = 1000)
{
for($i = 0; $i < $maxlevel; $i++)
{
$score = ceil(pow(2.71123, $i)*1000);
if($experience < $score)
{
return array($score, $experience, $i + 1);
}
$experience -= $score;
continue;
}
return array($score, $score, $maxlevel);
}
function moneyf($num)
{
return number_format($num, 0, '', ',');
}
function numf($num)
{
if($num >= 0 and $num < 1000)
{
return $num;
}
if($num >= 1000 and $num < 1000000)
{
return round($num/1000 , 2)."k";
}
if($num >= 1000000 and $num < 1000000000)
{
return round($num/1000000 , 2)."m";
}
if($num >= 1000000000 and $num < 1000000000000)
{
return round($num/1000000000 , 2)."g";
}
if($num >= 1000000000000 && $num < 1000000000000000)
{
return round($num/1000000000000 , 2)."t";
}
if($num >= 1000000000000000 && $num < 1000000000000000000)
{
return round($num/1000000000000000 , 2)."s";
}
if($num >= 1000000000000000000 && $num < 1000000000000000000000)
{
return round($num/1000000000000000000 , 2)."p";
}
if($num >= 1000000000000000000000)
{
return round($num/1000000000000000000000 , 2)."d";
}
return $num;
}
function getOnlyTime($time) {
if($time >= 1 && $time < 60)
{
$time = (string) $time;
}
elseif($time >= 60 && $time < 60*60)
{
$time = (string) floor($time/60);
}
elseif($time >= 60*60 && $time < 60*60*24)
{
$time = (string) floor($time/60 % 60);
}
elseif($time >= 60*60*24)
{
$time = (string) floor($time/60/60/24);
}
else
{
return false;
}
return $time;
}
function atime($time)
{
if($time >= 1 && $time < 60)
{
$time = (string) $time;
if($time[strlen($time)-1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' секунду';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' секунды';
}
else
{
$text = ' секунд';
}
return $time.$text;
}
elseif($time >= 60 && $time < 60*60)
{
$time = (string) floor($time/60);
if($time[strlen($time)-1] == 1 && $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' минуту';
}
elseif($time[strlen($time)-1] >=2 && $time[strlen($time)-1] <= 4 && $time[strlen($time)-2].$time[strlen($time)-1] != '12' && $time[strlen($time)-2].$time[strlen($time)-1] != '14' && $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' минуты';
}
else
{
$text = ' минут';
}
return $time.$text;
}
elseif($time >= 60*60 && $time < 60*60*24)
{
$time2 = (string) floor($time/60 % 60);
if($time2[strlen($time2)-1] == 1 && $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '11')
{
$text1 = ' минуту';
}
elseif($time2[strlen($time2)-1] >=2 && $time2[strlen($time2)-1] <= 4 && $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '12' && $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '14' && $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '13')
{
$text1 = ' минуты';
}
else
{
$text1 = ' минут';
}
$time = (string) floor($time/60/60);
if($time[strlen($time) - 1] == 1 && $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' час';
}
elseif($time[strlen($time)-1] >=2 && $time[strlen($time)-1] <= 4 && $time[strlen($time)-2].$time[strlen($time)-1] != '12' && $time[strlen($time)-2].$time[strlen($time)-1] != '14' && $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' часа';
}
else
{
$text = ' часов';
}
return $time.$text.($time2 > 0 ? ' '.$time2.$text1 : '');
}
elseif($time >= 60*60*24)
{
$time2 = (string) floor($time/60/60 % 24);
$time = (string) floor($time/60/60/24);
if($time2[strlen($time2) - 1] == 1 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '11')
{
$text1 = ' час';
}
elseif($time2[strlen($time2)-1] >=2 and $time2[strlen($time2)-1] <= 4 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '12' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '14' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '13')
{
$text1 = ' часа';
}
else
{
$text1 = ' часов';
}
if($time[strlen($time)-1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' день';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' дня';
}
else
{
$text = ' дней';
}
return $time.$text.($time2 > 0 ? ' '.$time2.$text1 : '');
}
else
{
return false;
}
}
function rsmonth($wmonth){
if($wmonth == '01')
{
$wmonth = 'янв';
}
elseif($wmonth == '02')
{
$wmonth = 'Фев';
}
elseif($wmonth == '03')
{
$wmonth = 'мар';
}
elseif($wmonth == '04')
{
$wmonth = 'апр';
}
elseif($wmonth == '05')
{
$wmonth = 'мая';
}
elseif($wmonth == '06')
{
$wmonth = 'июн';
}
elseif($wmonth == '07')
{
$wmonth = 'июл';
}
elseif($wmonth == '08')
{
$wmonth = 'авг';
}
elseif($wmonth == '09')
{
$wmonth = 'сен';
}
elseif($wmonth == '10')
{
$wmonth = 'окт';
}
elseif($wmonth == '11')
{
$wmonth = 'ноя';
}
elseif($wmonth == '12')
{
$wmonth = 'дек';
}
else
{
$wmonth = 'none';
}
return $wmonth;
}
function otime($time)
{
if($time >= 1 && $time < 60)
{
$time = (string) $time;
if($time[strlen($time)-1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' секунда';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' секунды';
}
else
{
$text = ' секунд';
}
return $time.$text;
}
elseif($time >= 60 && $time < 60*60)
{
$time = (string) floor($time/60);
if($time[strlen($time)-1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' минута';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' минуты';
}
else
{
$text = ' минут';
}
return $time.$text;
}
elseif($time >= 60*60 && $time < 60*60*24)
{
$time2 = (string) floor($time/60 % 60);
if($time2[strlen($time2)-1] == 1 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '11')
{
$text1 = ' минута';
}
elseif($time2[strlen($time2)-1] >=2 and $time2[strlen($time2)-1] <= 4 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '12' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '14' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '13')
{
$text1 = ' минуты';
}
else
{
$text1 = ' минут';
}
$time = (string) floor($time/60/60);
if($time[strlen($time) - 1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' час';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' часа';
}
else
{
$text = ' часов';
}
return $time.$text.($time2 > 0 ? ' '.$time2.$text1 : '');
}
elseif($time >= 60*60*24)
{
$time2 = (string) floor($time/60/60 % 24);
$time = (string) floor($time/60/60/24);
if($time2[strlen($time2) - 1] == 1 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '11')
{
$text1 = ' час';
}
elseif($time2[strlen($time2)-1] >=2 and $time2[strlen($time2)-1] <= 4 and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '12' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '14' and $time2[strlen($time2)-2].$time2[strlen($time2)-1] != '13')
{
$text1 = ' часа';
}
else
{
$text1 = ' часов';
}
if($time[strlen($time)-1] == 1 and $time[strlen($time)-2].$time[strlen($time)-1] != '11')
{
$text = ' день';
}
elseif($time[strlen($time)-1] >=2 and $time[strlen($time)-1] <= 4 and $time[strlen($time)-2].$time[strlen($time)-1] != '12' and $time[strlen($time)-2].$time[strlen($time)-1] != '14' and $time[strlen($time)-2].$time[strlen($time)-1] != '13')
{
$text = ' дня';
}
else
{
$text = ' дней';
}
return $time.$text.($time2 > 0 ? ' '.$time2.$text1 : '');
}
else
{
return false;
}
}
function v($num)
{
$num = (string) $num;
if($num[strlen($num)-1] == 1 and $num[strlen($num)-2].$num[strlen($num)-1] != '11')
{
$text = ' бакс';
}
elseif($num[strlen($num)-1] >=2 and $num[strlen($num)-1] <= 4 and $num[strlen($num)-2].$num[strlen($num)-1] != '12' and $num[strlen($num)-2].$num[strlen($num)-1] != '14' and $num[strlen($num)-2].$num[strlen($num)-1] != '13')
{
$text = ' бакса';
}
else
{
$text = ' баксов';
}
return moneyf($num).$text;
}
function trust($num)
{
$num = (string) $num;
if($num[strlen($num)-1] == 1 and $num[strlen($num)-2].$num[strlen($num)-1] != '11')
{
$text = ' монет';
}
elseif($num[strlen($num)-1] >=2 and $num[strlen($num)-1] <= 4 and $num[strlen($num)-2].$num[strlen($num)-1] != '12' and $num[strlen($num)-2].$num[strlen($num)-1] != '14' and $num[strlen($num)-2].$num[strlen($num)-1] != '13')
{
$text = ' монет';
}
else
{
$text = ' монет';
}
return moneyf($num).$text;
}
function rating($experience, $maxlevel = 150, $levelscore = 100) {
for($i = 0; $i < $maxlevel; $i++)
{
$score = ceil(pow(1.5,$i)*130);
if($experience < $score)
{
return array($score, $experience, $i + 1);
}
$experience -= $score;
continue;
}
return array($score, $score, $maxlevel);
}
function achievement($bronze,$sliver,$gold,$platinum,$brilliant,$current)
{
if($current < $bronze)
{
$avard = '';
$count = 0;
$next = $bronze;
}
elseif($current >= $bronze && $current < $sliver)
{
$avard = 'Бронзовый';
$count = 1;
$next = $sliver;
}
elseif($current >= $sliver && $current < $gold)
{
$avard = 'Серебрянный';
$count = 2;
$next = $gold;
}
elseif($current >= $gold && $current < $platinum)
{
$avard = 'Золотой';
$count = 3;
$next = $platinum;
}
elseif($current >= $platinum && $current < $brilliant)
{
$avard = 'Платиновый';
$count = 4;
$next = $brilliant;
}
elseif($current >= $brilliant)
{
$avard = 'Бриллиантовый';
$count = 5;
$next = false;
}
return array($avard, $next, $count);
}
function num($num)
{
if($num >= 0 and $num < 1000)return $num;
if($num >= 1000 and $num < 1000000) return round($num/1000 , 2)."k";
if($num >= 1000000 and $num < 1000000000)return round($num/1000000 , 2)."m";
if($num >= 1000000000 and $num < 1000000000000)return round($num/1000000000 , 2)."g";
if($num >= 1000000000000 and $num < 1000000000000000)return round($num/1000000000000 , 2)."t";
if($num >= 1000000000000000000 and $num < 1000000000000000000000)return round($num/1000000000000000000 , 2)."s";
if($num >= 1000000000000000000000)return round($num/1000000000000000000000 , 2)."d";
}
function isMobile(){
$agents = array('acs-','alav','alca','amoi','audi','aste','avan','benq','bird','blac','blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno','ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-','maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-','newt','noki','opwv','palm','pana','pant','pdxg','phil','play','pluc','port','prox','qtek','qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar','sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-','tosh','tsm-','upg1','upsi','vk-v','voda','w3c ','wap-','wapa','wapi','wapp','wapr','webc','winw','winw','xda','xda-');
$uagent = $_SERVER['HTTP_USER_AGENT'];
if(stristr($uagent,'windows')&&!stristr($uagent,'windows ce')) return false;
if(
(eregi('up.browser|up.link|windows ce|iemobile|mini|mmp|symbian|midp|wap|phone|pocket|mobile|pda|psp',$uagent)) ||
(stristr($_SERVER['HTTP_ACCEPT'],'text/vnd.wap.wml')||stristr($_SERVER['HTTP_ACCEPT'],'application/vnd.wap.xhtml+xml')) ||
(isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])||isset($_SERVER['X-OperaMini-Features'])||isset($_SERVER['UA-pixels'])) ||
(isset($agents[substr($uagent,0,4)]))||
(strlen($_SERVER['HTTP_X_OPERAMINI_PHONE_UA'])>3)||
(intval($_GET['mobi']) == 1)
) return true;
}
?>