Файл: minichat_by_KoT/minichat_by_KoT/function.php
Строк: 444
<?php
##########################################
# ~ Разработка отдельных модулей ~~~~~~~ #
# ~ и написание скриптов на php (c)KoT ~ #
# ~ ICQ: 7675072 ~~~~~~~~~~~~~~~~~~~~~~~ #
# ~ Site: 4atlove.ru ~~~~~~~~~~~~~~~~~~~ #
# ~ E-mail: notefree@bk.ru ~~~~~~~~~~~~~ #
##########################################
//-------------функция микросекунд-------------//
function getmicrotime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
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;
}
/*---------Время по часовому поясу---------*/
$time = ((time() - 3 * 60 * 60) + 120 * 60);
//-------------функция определения айпи и софта-------------//
$ip = preg_replace('|[^0-9.]|', '', $_SERVER['REMOTE_ADDR']);
$ip = stripslashes(htmlspecialchars($ip));
$agent = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
if (!isset($agent)) $agent = $_SERVER['HTTP_USER_AGENT'];
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'])) {
$addr = $_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'])) {
$addr = $_SERVER['HTTP_CLIENT_IP'];
}
else
{
$addr = preg_replace("|[^0-9.]|", "", $_SERVER['REMOTE_ADDR']);
}
$addr = check($addr);
//-------------функция определения айпи и софта-------------//
$ip = false;
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '127.0.0.1' && ereg("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip2['xff'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
$ipa[] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != '127.0.0.1' && ereg("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $_SERVER['HTTP_CLIENT_IP']))
{
$ip2['cl'] = $_SERVER['HTTP_CLIENT_IP'];
$ipa[] = $_SERVER['HTTP_CLIENT_IP'];
}
if (isset($_SERVER['REMOTE_ADDR']) && ereg("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$", $_SERVER['REMOTE_ADDR']))
{
$ip2['add'] = $_SERVER['REMOTE_ADDR'];
$ipa[] = $_SERVER['REMOTE_ADDR'];
}
$ip = $ipa[0];
$iplong = ip2long($ip);
if (isset($_SERVER['HTTP_USER_AGENT']))
{
$ua = $_SERVER['HTTP_USER_AGENT'];
$ua = strtok($ua, '/');
$ua = strtok($ua, '(');
$ua = eregi_replace('[^a-z_./ 0-9-]', null, $ua);
if (isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) && ereg('Opera', $ua))
{
$ua_om = $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'];
$ua_om = strtok($ua_om, '/');
$ua_om = strtok($ua_om, '(');
$ua_om = eregi_replace('[^a-z_. 0-9-]', null, $ua_om);
$ua = 'Opera Mini ('.$ua_om.')';
}
}
else $ua = 'Нет данных';
//-------------чистка...-------------//
if ($time == NULL || $time < time() - 60 * 60 * 24) {
if (function_exists('set_time_limit'))@set_time_limit(100);
$time_z = time() - 604800;
mysql_query("DELETE FROM `letters` WHERE `time` < $time_z"); // чистка записок
mysql_query("DELETE FROM `guests` WHERE `date_last` < '".(time() - 100)."'"); // чистка гостей
mysql_query("DELETE FROM `message` WHERE `time` < '".(time() - 60 * 60 * 24)."'"); // чистка комнат
}
//-------------Функция времени-------------//
function vrem($time = NULL)
{
global $id, $time;
if ($time == NULL) $time = time();
if (isset($id)) $time = $time + 120 * 60 * 60;
$timep = date("j M Y в H:i", $time);
$time_p[0] = date("j n Y", $time);
$time_p[1] = date("H:i", $time);
if ($time_p[0] == date("j n Y")) $timep = date("H:i:s", $time);
if (isset($id)) {
if ($time_p[0] == date("j n Y", time() + 120 * 60 * 60)) $timep = date("H:i:s", $time);
if ($time_p[0] == date("j n Y", time() - 60 * 60 * (24 - 120))) $timep = "Вчера в $time_p[1]";
}
else
{
if ($time_p[0] == date("j n Y")) $timep = date("H:i:s", $time);
if ($time_p[0] == date("j n Y", time() - 60 * 60 * 24)) $timep = "Вчера в $time_p[1]";}
$timep = str_replace("Jan","Янв", $timep);
$timep = str_replace("Feb","Фев", $timep);
$timep = str_replace("Mar","Марта", $timep);
$timep = str_replace("May","Мая", $timep);
$timep = str_replace("Apr","Апр", $timep);
$timep = str_replace("Jun","Июня", $timep);
$timep = str_replace("Jul","Июля", $timep);
$timep = str_replace("Aug","Авг", $timep);
$timep = str_replace("Sep","Сент", $timep);
$timep = str_replace("Oct","Окт", $timep);
$timep = str_replace("Nov","Ноября", $timep);
$timep = str_replace("Dec","Дек", $timep);
return $timep;
}
//-------------Принудительно вырубаем глобальные переменные-------------//
if (ini_get('register_globals')) {
$allowed = array('_ENV' => 1, '_GET' => 1, '_POST' => 1, '_COOKIE' => 1, '_FILES' => 1, '_SERVER' => 1, '_REQUEST' => 1, 'GLOBALS' => 1);
foreach ($GLOBALS as $key => $value) {
if (!isset($allowed[$key])) {
unset($GLOBALS[$key]);
}
}
}
//-------------функция фильтра-------------//
function filtr($a)
{
$text1 = array("rn", "n");
$text2 = array(" ", " ");
$a = trim(htmlspecialchars(stripslashes(str_replace($text1, $text2, $a))));
return $a;
}
//-------------функция подсчета и замены символов-------------//
function strlen2($str)
{
$rus = array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю');
return strlen(str_replace($rus, '0', $str));
}
//-------------функция возраста-------------//
function calc_age($data)
{
$ex_age = explode("-", $data);
$age = date("Y") - $ex_age[2];
if (date("m") < $ex_age[1] || (date("m") == $ex_age[1] && date("d") < $ex_age[0])) {
$age--;
}
$age = (int)$age;
$q1 = abs($age) % 100;
$q2 = $age % 10;
if ($q1 > 10 && $q1 < 20) {
$result = "лет";
} elseif ($q2 > 1 && $q2 < 5) {
$result = "года";
} elseif ($q2 == 1) {
$result = "год";
} else {
$result = "лет";
}
return $age.' '.$result;
}
//-------------Функция вывода быстрых смайлов-------------//
function quicksmiles()
{
echo '<a href="#form" onclick="javascript:tag(' :) ', '');"><img src="smile/smile.gif" alt="image" /></a>
<a href="#form" onclick="javascript:tag(' :( ', '');"><img src="smile/sad.gif" alt="image" /></a>
<a href="#form" onclick="javascript:tag(' =)) ', '');"><img src="smile/biggrin2.gif" alt="image" /></a>
<a href="#form" onclick="javascript:tag(' ;-) ', '');"><img src="smile/wink.gif" alt="image" /></a>
<a href="#form" onclick="javascript:tag(' =] ', '');"><img src="smile/eqr.gif" alt="image" /></a> ';
}
//-------------Вспомогательная функция быстрой вставки-------------//
function quickpaste($form) {
echo '<script language="JavaScript" type="text/javascript">
function tag(text1, text2) {
if ((document.selection)) {
document.form.' . $form . '.focus();
document.form.document.selection.createRange().text = text1+document.form.document.selection.createRange().text+text2;
} else if(document.forms['form'].elements['' . $form . ''].selectionStart!=undefined) {
var element = document.forms['form'].elements['' . $form . ''];
var str = element.value;
var start = element.selectionStart;
var length = element.selectionEnd - element.selectionStart;
element.value = str.substr(0, start) + text1 + str.substr(start, length) + text2 + str.substr(start + length);
} else document.form.' . $form . '.value += text1+text2;
}
</script>';
}
//-------------функция смайлов-------------//
function smiles($text)
{
$f_smiles = file("smile/smiles.txt");
for ($i = 0; $i < count($f_smiles); $i++)
{
$str_sm = explode(' ', trim($f_smiles[$i]));
$str_sm2 = '';
for ($z = 1; $z < count($str_sm); $z++)
{
if ($z > 1)
{
$str_sm2 .= ' ';
}
$str_sm2 .= $str_sm[$z];
}
$str_sm2 = explode(',', $str_sm2);
for ($i2 = 0; $i2 < count($str_sm2); $i2++)
{
$str_sm2[$i2] = stripcslashes(htmlspecialchars($str_sm2[$i2]));
$text = str_replace("$str_sm2[$i2]", '<img src="smile/'.$str_sm[0].'.gif" alt=""/>', $text);
}
}
return $text;
}
//-------------Функция для поединков-------------//
function game()
{
$Sql = mysql_fetch_assoc(mysql_query("SELECT * FROM `fight`"));
global $row, $health, $div3, $bad, $div2, $div5, $copy;
//Если не полное здоровье
if ($row['liven'] == 1) {
$c_health = 65;
} elseif ($row['liven'] == 2) {
$c_health = 110;
} elseif ($row['liven'] == 3) {
$c_health = 180;
} elseif ($row['liven'] == 4) {
$c_health = 300;
} elseif ($row['liven'] == 5) {
$c_health = 570;
} elseif ($row['liven'] == 6) {
$c_health = 700;
} elseif ($row['liven'] == 7) {
$c_health = 1000;
} elseif ($row['liven'] == 8) {
$c_health = 1800;
} elseif ($row['liven'] == 9) {
$c_health = 2500;
} elseif ($row['liven'] == 10) {
$c_health = 3100;
}
if ($row['health'] < $c_health && $row['id'] != $Sql['usid'] && $row['health'] < $c_health && $row['id'] != $Sql['usid2']) {
/*________________________*/
echo $bad . 'Вы не можете учавствовать в бою т.к.<br/>
у Вас не полное здоровье!<br/>
<a href="shop.php?go=hp">Восстановите</a> здоровье и продолжите бой!' . $div5;
echo $div3 . '<a href="fight.php?'.$ref.'"><b>Поединки</b></a><br/>
<a href="menu.php?'.$ref.'"><b>В меню</b></a>' . $div5;
include 'foot.php';
exit();
}
}
//-------------функция цветного ника-------------//
function col($usnick)
{
$view = mysql_fetch_array(mysql_query("SELECT `color` FROM `users` WHERE `user`='".mysql_real_escape_string($usnick)."'"));
$cvetn = $view['color'];
if ($cvetn == 0) $usnick = $usnick;
elseif ($cvetn == 1) $usnick = '<font color="#FAB217">'.$usnick.'</font>';
elseif ($cvetn == 2) $usnick = '<font color="#808080">'.$usnick.'</font>';
elseif ($cvetn == 3) $usnick = '<font color="#008000">'.$usnick.'</font>';
elseif ($cvetn == 4) $usnick = '<font color="#800080">'.$usnick.'</font>';
elseif ($cvetn == 5) $usnick = '<font color="#00FFFF">'.$usnick.'</font>';
elseif ($cvetn == 6) $usnick = '<font color="#FF00FF">'.$usnick.'</font>';
elseif ($cvetn == 7) $usnick = '<font color="#00FF00">'.$usnick.'</font>';
elseif ($cvetn == 8) $usnick = '<font color="#FFFF00">'.$usnick.'</font>';
elseif ($cvetn == 9) $usnick = '<font color="#FF0000">'.$usnick.'</font>';
elseif ($cvetn == 10) $usnick = '<font color="#E90080">'.$usnick.'</font>';
elseif ($cvetn == 11) $usnick = '<font color="#F7BC5B">'.$usnick.'</font>';
elseif ($cvetn == 12) $usnick = '<font color="#B7770D">'.$usnick.'</font>';
elseif ($cvetn == 13) $usnick = '<font color="#000000">'.$usnick.'</font>';
elseif ($cvetn == 14) $usnick = '<font color="#0066FF">'.$usnick.'</font>';
return $usnick;
}
//-------------воспомогательная функция линков-------------//
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>';
}
}
//-------------функция ББ-кодов-------------//
function bb_code($message) {
$message = preg_replace(array('#[code](.*?)[/code]#se'), array("''.highlight('$1').''"), str_replace("]n", "]", $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('#[q](.*?)[/q]#si', '<div class="quote">1</div>', $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('#[del](.*?)[/del]#si', '<del>1</del>', $message);
$message = preg_replace_callback('~\[url=(http://.+?)\](.+?)\[/url\]|(http://(www.)?[0-9a-z.-]+.[a-z]{2,6}[0-9a-zA-Z/?.~&_=/%-:#]*)~', 'url_replace', $message);
return $message;
}
//-------------функция подсветки кода-------------//
function highlight($code) {
$code = strtr($code,array("<br/>"=>"n","<"=>"<",">"=>">","`"=>"`","&"=>"&","$"=>"$","""=>""","'"=>"'","\"=>"\","%"=>"%","^"=>"^",":"=>":",'‘' => "'",'¦' => '|', '$$' => '$', 'I' => '|', "\"" => """));
$code = highlight_string($code,true);
$code = strtr($code,array("$"=>"$","'"=>"'","\"=>"\","%"=>"%","^"=>"^",":"=>":", '<code>' => '', '</code>' => ''));
$code = '<span class="code"><span style="color: #000000">' . $code . '</span></span>';
return $code;
}
//-------------функция вырезания тэгов-------------//
function notags($message) {
$message = strtr($message, array (
'[green]' => '',
'[/green]' => '',
'[red]' => '',
'[/red]' => '',
'[blue]' => '',
'[/blue]' => '',
'[b]' => '',
'[/b]' => '',
'[i]' => '',
'[/i]' => '',
'[u]' => '',
'[/u]' => '',
'[q]' => '',
'[/q]' => ''
));
return $message;
}
//-------------функция записи онлайна-------------//
function whorm($rm = 0, $room = NULL)
{
global $row, $id, $time, $ip, $agent, $last_visit;
$last_visit = date("y-m-d H:i");
if (isset($id)) {
$agent = mysql_real_escape_string(check($agent));
mysql_query("UPDATE `users` SET `onl`='$time', `visit`='$last_visit', `user_ip`='$ip', `user_soft`='$agent', `room`='$room' WHERE `id`='".$row['id']."'");
}
}
//-------------функция инфы о юзере-------------//
function user($ref = NULL, $link = NULL)
{
global $row, $ref, $name, $time;
if (isset($ref)) $ref = check($ref);
if (!ctype_digit($ref)) {
$ruser = rus_to_k($ref);
$result = mysql_query("SELECT * FROM `users` WHERE `ruser`='$ruser' LIMIT 1");
} else {
$result = mysql_query("SELECT * FROM `users` WHERE `id`='$ref' LIMIT 1");
}
$nik = mysql_fetch_array($result);
if ($link == NULL) return $nik['user'];
elseif ($link == true) return '<a href="info.php?nk='.$nik['id'].'">'.$nik['user'].'</a>';
}
//-------------функция инфы о юзере-------------//
function user_inf($ref = NULL, $w = NULL)
{
global $row, $usid, $name, $time;
if (isset($ref)) $ref = check($ref);
if (!ctype_digit($ref)) {
$ruser = rus_to_k($ref);
$result = mysql_query("SELECT * FROM `users` WHERE `ruser`='$ruser' LIMIT 1");
} else {
$result = mysql_query("SELECT * FROM `users` WHERE `id`='$ref' LIMIT 1");
}
$nik = mysql_fetch_array($result);
if ($w == NULL) return esc2($nik['id']);
else return esc2($nik[$w]);
}
//-------------функция пробелов-------------//
function br($msg, $br = '<br/>')
{
$msg = eregi_replace("((<br( ?/?)>)|n|r)+", $br, $msg);
return $msg;
}
//-------------функция записи постов-------------//
function posts_add()
{
global $row, $id;
if (isset($id))
{
$row['posts']++;
mysql_query("UPDATE `users` SET `posts`='".(int)$row['posts']."' WHERE `id`='$row[id]'");
}
}
//-------------Функция переобразование текста в ПрЫгАюЩиЙ регистр-------------//
function font($msg) {
$msg = iconv("UTF-8", "windows-1251", $msg);
$count = strlen($msg);
for($i = 0; $i < $count; $i++) {
$r = $r ? 0 : 1;
$txt .= $r ? mb_strtoupper($msg[$i], 'windows-1251') : mb_strtolower($msg[$i], 'windows-1251');
}
return iconv("windows-1251", "UTF-8", $txt);
}
//-------------функция записи кредитов-------------//
function cred_add()
{
global $row, $id;
if (isset($id))
{
$row['credits']++;
mysql_query("UPDATE `users` SET `credits` = '$row[credits]' WHERE `id` = '$row[id]'");
}
}
//-------------функции линков-------------//
function links_preg1($arr)
{
return '<a href="'.$arr[1].'">'.$arr[2].'</a>';
}
function links_preg2($arr)
{
return $arr[1].'<a href="'.$arr[2].'">'.$arr[2].'</a>'.$arr[4];
}
function links($msg)
{
global $row;
if ($row['level'] == 2) {
$msg = preg_replace_callback('~[url=([^ rnt`'"]+)](.*?)[/url]~iu', 'links_preg1', $msg);
$msg = preg_replace_callback('~(^|s)([a-z]+://([^ rnt`'"]+))(s|$)~iu', 'links_preg2', $msg);
}
return $msg;
}
//-------------функции польз. фильтра-------------//
function esc($text, $br = NULL)
{
if ($br != NULL)
for ($i = 0; $i <= 31; $i++)
{
$text = str_replace(chr($i), NULL, $text);
}
else
{
for ($i = 0; $i < 10; $i++) $text = str_replace(chr($i), NULL, $text);
for ($i = 11; $i < 20; $i++) $text = str_replace(chr($i), NULL, $text);
for ($i = 21; $i <= 31; $i++) $text = str_replace(chr($i), NULL, $text);
}
return $text;
}
function esc2($msg)
{
for ($i = 0; $i < 10; $i++) $msg = str_replace(chr($i), NULL, $msg);
for ($i = 11; $i < 20; $i++) $msg = str_replace(chr($i), NULL, $msg);
for ($i = 21; $i <= 31; $i++) $msg = str_replace(chr($i), NULL, $msg);
return $msg;
}
//-------------функция временного бана-------------//
function kikt($t)
{
global $time;
$t2 = $t - $time;
if ($t2 > (60 * 60 * 24 * 30)) $t3 = round($t2 / (60 * 60 * 24 * 30)) . ' месяцев';
elseif ($t2 > (60 * 60 * 24)) $t3 = round($t2 / (60 * 60 * 24)) . ' дней';
elseif ($t2 > (60 * 60)) $t3 = round($t2 / (60 * 60)) . ' часов';
elseif ($t2 > 60) $t3 = round($t2 / 60) . ' минут';
else $t3 = $t2 . ' секунд';
return $t3;
}
//-------------функция обработки текста-------------//
function text($str, $br = true, $html = true, $smiles = true, $links = true)
{
if ($html == true)
if ($smiles == true)
$str = smiles($str);
if ($links == true)
$str = links($str);
if ($br == true)
{
$str = br($str);
$str = esc($str);
}
else
{
$str = esc($str);
}
return $str;
}
//-------------функция транслита-------------//
function rus_to_k($str)
{
$str = str_replace("а","a",$str);
$str = str_replace("б","b",$str);
$str = str_replace("в","v",$str);
$str = str_replace("г","g",$str);
$str = str_replace("д","d",$str);
$str = str_replace("е","e",$str);
$str = str_replace("ё","e",$str);
$str = str_replace("ж","j",$str);
$str = str_replace("з","z",$str);
$str = str_replace("и","i",$str);
$str = str_replace("й","y",$str);
$str = str_replace("к","k",$str);
$str = str_replace("л","l",$str);
$str = str_replace("м","m",$str);
$str = str_replace("н","n",$str);
$str = str_replace("о","o",$str);
$str = str_replace("п","p",$str);
$str = str_replace("р","r",$str);
$str = str_replace("с","s",$str);
$str = str_replace("т","t",$str);
$str = str_replace("у","u",$str);
$str = str_replace("ф","f",$str);
$str = str_replace("х","h",$str);
$str = str_replace("ч","c",$str);
$str = str_replace("ц","q",$str);
$str = str_replace("ш","w",$str);
$str = str_replace("щ",">",$str);
$str = str_replace("ь","<",$str);
$str = str_replace("ы","x",$str);
$str = str_replace("ъ",".",$str);
$str = str_replace("э",":",$str);
$str = str_replace("ю",";",$str);
$str = str_replace("я","}",$str);
$str = str_replace("А","a",$str);
$str = str_replace("Б","b",$str);
$str = str_replace("В","v",$str);
$str = str_replace("Г","g",$str);
$str = str_replace("Д","d",$str);
$str = str_replace("Е","e",$str);
$str = str_replace("Ё","e",$str);
$str = str_replace("Ж","j",$str);
$str = str_replace("З","z",$str);
$str = str_replace("И","i",$str);
$str = str_replace("Й","y",$str);
$str = str_replace("К","k",$str);
$str = str_replace("Л","l",$str);
$str = str_replace("М","m",$str);
$str = str_replace("Н","n",$str);
$str = str_replace("О","o",$str);
$str = str_replace("П","p",$str);
$str = str_replace("Р","r",$str);
$str = str_replace("С","s",$str);
$str = str_replace("Т","t",$str);
$str = str_replace("У","u",$str);
$str = str_replace("Ф","f",$str);
$str = str_replace("Х","h",$str);
$str = str_replace("Ч","c",$str);
$str = str_replace("Ц","q",$str);
$str = str_replace("Ш","w",$str);
$str = str_replace("Щ",">",$str);
$str = str_replace("Ь","<",$str);
$str = str_replace("Ы","x",$str);
$str = str_replace("Ъ",".",$str);
$str = str_replace("Э",":",$str);
$str = str_replace("Ю",";",$str);
$str = str_replace("Я","}",$str);
return $str;
}
//-------------функция перекодировки из вин в утф-------------//
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);
}
//-------------функция перекодировки из утф в вин-------------//
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);
}
//-------------функция транслита-------------//
function trun_to_rus($in)
{
$trans1 = array("JO","ZH","CH","SH","SCH","JE","JY","JA","jo","zh","ch","sh","sch","je","jy","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("Ё","Ж","Ч","Ш","Щ","Э","Ю","Я","ё","ж","ч","ш","щ","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы");
return str_replace($trans1, $trans2, $in);
}
//-------------функция ретранлсита-------------//
function retranslit($in)
{
$trans1 = array("'",'`',',',' ',"Ё","Ж","Ч","Ш","Щ","Э","Ю","Я","ё","ж","ч","ш","щ","э","ю","я","А","Б","В","Г","Д","Е","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ь","Ы","а","б","в","г","д","е","з","и","й","к","л","м","н","о","п","р","с","т","у","ф","х","ц","ь","ы");
$trans2 = array('_','_','_','_',"JO","ZH","CH","SH","SCH","Je","Jy","Ja","jo","zh","ch","sh","sch","je","jy","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");
return str_replace($trans1, $trans2, $in);
}
//-------------функция экранирования и замены спецсимволов-------------//
function check($message) {
$message = htmlspecialchars($message);
$message = str_replace("rn", "<br/>", $message);
$message = strtr($message, array(chr("0") => "", chr("1") => "", chr("2") => "", chr("3") => "", chr("4") => "", chr("5") => "", chr("6") => "", chr("7") => "", chr("8") => "", chr("9") => "", chr("10") => "", chr("11") => "", chr("12") => "", chr
("13") => "", chr("14") => "", chr("15") => "", chr("16") => "", chr("17") => "", chr("18") => "", chr("19") => "", chr("20") => "", chr("21") => "", chr("22") => "", chr("23") => "", chr("24") => "", chr("25") => "", chr("26") => "", chr("27") =>
"", chr("28") => "", chr("29") => "", chr("30") => "", chr("31") => ""));
$message = iconv('utf-8', 'windows-1251', $message);
$message = mb_substr($message, 0, 1000, 'UTF8');
$message = iconv('windows-1251', 'utf-8', $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 replace_rus($str) {
$str = str_replace("а","|",$str);
$str = str_replace("б","|",$str);
$str = str_replace("в","|",$str);
$str = str_replace("г","|",$str);
$str = str_replace("д","|",$str);
$str = str_replace("е","|",$str);
$str = str_replace("ё","|",$str);
$str = str_replace("ж","|",$str);
$str = str_replace("з","|",$str);
$str = str_replace("и","|",$str);
$str = str_replace("й","|",$str);
$str = str_replace("к","|",$str);
$str = str_replace("л","|",$str);
$str = str_replace("м","|",$str);
$str = str_replace("н","|",$str);
$str = str_replace("о","|",$str);
$str = str_replace("п","|",$str);
$str = str_replace("р","|",$str);
$str = str_replace("с","|",$str);
$str = str_replace("т","|",$str);
$str = str_replace("у","|",$str);
$str = str_replace("ф","|",$str);
$str = str_replace("х","|",$str);
$str = str_replace("ч","|",$str);
$str = str_replace("ц","|",$str);
$str = str_replace("ш","|",$str);
$str = str_replace("щ","|",$str);
$str = str_replace("ь","|",$str);
$str = str_replace("ы","|",$str);
$str = str_replace("ъ","|",$str);
$str = str_replace("э","|",$str);
$str = str_replace("ю","|",$str);
$str = str_replace("я","|",$str);
$str = str_replace("А","|",$str);
$str = str_replace("Б","|",$str);
$str = str_replace("В","|",$str);
$str = str_replace("Г","|",$str);
$str = str_replace("Д","|",$str);
$str = str_replace("Е","|",$str);
$str = str_replace("Ё","|",$str);
$str = str_replace("Ж","|",$str);
$str = str_replace("З","|",$str);
$str = str_replace("?","|",$str);
$str = str_replace("Й","|",$str);
$str = str_replace("К","|",$str);
$str = str_replace("Л","|",$str);
$str = str_replace("М","|",$str);
$str = str_replace("Н","|",$str);
$str = str_replace("О","|",$str);
$str = str_replace("П","|",$str);
$str = str_replace("Р","|",$str);
$str = str_replace("С","|",$str);
$str = str_replace("Т","|",$str);
$str = str_replace("У","|",$str);
$str = str_replace("Ф","|",$str);
$str = str_replace("Х","|",$str);
$str = str_replace("Ч","|",$str);
$str = str_replace("Ц","|",$str);
$str = str_replace("Ш","|",$str);
$str = str_replace("Щ","|",$str);
$str = str_replace("Ь","|",$str);
$str = str_replace("Ы","|",$str);
$str = str_replace("Ъ","|",$str);
$str = str_replace("Э","|",$str);
$str = str_replace("Ю","|",$str);
$str = str_replace("Я","|",$str);
return $str;
}
//-------------Сжатие начало-------------//
if (extension_loaded('zlib') and ini_get('zlib.output_compression') != 1 and ini_get('output_handler') != 'ob_gzhandler')
{
$PREFER_DEFLATE = false;
$FORCE_COMPRESSION = false;
function compress_output_gzip($output)
{
return gzencode($output);
}
function compress_output_deflate($output)
{
return gzdeflate($output, 9);
}
function compress_output_x_gzip($output)
{
return gzcompress($output, 9);
}
if (isset($_SERVER['HTTP_ACCEPT_ENCODING']))
$AE = $_SERVER['HTTP_ACCEPT_ENCODING'];
else
$AE = $_SERVER['HTTP_TE'];
$support_gzip = (strpos($AE, 'gzip') !== FALSE) || $FORCE_COMPRESSION;
$support_deflate = (strpos($AE, 'deflate') !== FALSE) || $FORCE_COMPRESSION;
$support_x_gzip = (strpos($AE, 'x-gzip') !== FALSE) || $FORCE_COMPRESSION;
if ($support_gzip && $support_deflate)
{
$support_deflate = $PREFER_DEFLATE;
}
if ($support_deflate)
{
header("Content-Encoding: deflate");
ob_start("compress_output_deflate");
}
else
{
if ($support_gzip)
{
header("Content-Encoding: gzip");
ob_start("compress_output_gzip");
}
else
{
if ($support_x_gzip)
{
header("Content-Encoding: x_gzip");
ob_start("compress_output_x_gzip");
}
else
{
ob_start();
$config_gzip = 0;
}
}
}
}
else
{
$config_gzip = 0;
}
// Сжатие конец
// Дивы
$div1 = '<div class="head">';
$div2 = '<div class="foot">';
$div3 = '<div class="fon">';
$div4 = '<div class="razd">';
$bad = '<div class="bad">';
$good = '<div class="good">';
$other = '<div class="other">';
$div5 = '</div>';
?>