Файл: header/function.inc.php
Строк: 282
<?php
function text_captcha($length){
$val='qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789#';
for ($i=0;$i<strlen($val);$i++){
$v[]=$val[$i];
}
shuffle($v);
$val=implode("",$v);
return substr($val,0,$length);
}
function replacer($text,$r){
foreach ($r as $key=>$value){
$text=str_replace($key,$value,$text);
}
return $text;
}
/*
перевод строки в utf-8
*/
function utf_encode ($s) {
$russ=array("Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю","й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","ё","Ё","№","«","»");
$uni=array("Р™","Р¦","РЈ","Рљ","Р•","Рќ","Р“","РЁ","Р©","Р—","РҐ","РЄ","Р¤","Р«","Р’","Рђ","Рџ","Р ","Рћ","Р›","Р”","Р–","Р","РЇ","Р§","РЎ","Рњ","Р�","Рў","Р¬","Р‘","Р®","Р№","С†","Сѓ","Рє","Рµ","РЅ","Рі","С€","С‰","Р·","С…","СЉ","С„","С‹","РІ","Р°","Рї","СЂ","Рѕ","Р»","Рґ","Р¶","СЌ","СЏ","С‡","СЃ","Рј","Рё","С‚","СЊ","Р±","СЋ","С‘","РЃ","#",'"','"');
$n="";
for ($i=0;$i<strlen($s);$i++){
$numb=array_search($s[$i],$russ);
If ($numb!==false)
$n.=$uni[$numb];
else
$n.=$s[$i];
}
return $n;
}
function txt($st){
$st=str_replace("Р№","й",$st);
$st=str_replace("С†","ц",$st);
$st=str_replace("Сѓ","у",$st);
$st=str_replace("Рє","к",$st);
$st=str_replace("Рµ","е",$st);
$st=str_replace("РЅ","н",$st);
$st=str_replace("Рі","г",$st);
$st=str_replace("С€","ш",$st);
$st=str_replace("С‰","щ",$st);
$st=str_replace("Р·","з",$st);
$st=str_replace("С…","х",$st);
$st=str_replace("СЉ","ъ",$st);
$st=str_replace("С„","ф",$st);
$st=str_replace("С‹","ы",$st);
$st=str_replace("РІ","в",$st);
$st=str_replace("Р°","а",$st);
$st=str_replace("Рї","п",$st);
$st=str_replace("СЂ","р",$st);
$st=str_replace("Рѕ","о",$st);
$st=str_replace("Р»","л",$st);
$st=str_replace("Рґ","д",$st);
$st=str_replace("Р¶","ж",$st);
$st=str_replace("СЌ","э",$st);
$st=str_replace("СЏ","я",$st);
$st=str_replace("С‡","ч",$st);
$st=str_replace("СЃ","с",$st);
$st=str_replace("Рј","м",$st);
$st=str_replace("Рё","и",$st);
$st=str_replace("С‚","т",$st);
$st=str_replace("СЊ","ь",$st);
$st=str_replace("Р±","б",$st);
$st=str_replace("СЋ","ю",$st);
$st=str_replace("Р™","Й",$st);
$st=str_replace("Р¦","Ц",$st);
$st=str_replace("РЈ","У",$st);
$st=str_replace("Рљ","К",$st);
$st=str_replace("Р•","Е",$st);
$st=str_replace("Рќ","Н",$st);
$st=str_replace("Р“","Г",$st);
$st=str_replace("РЁ","Ш",$st);
$st=str_replace("Р©","Щ",$st);
$st=str_replace("Р—","З",$st);
$st=str_replace("РҐ","Х",$st);
$st=str_replace("РЄ","Ъ",$st);
$st=str_replace("Р¤","Ф",$st);
$st=str_replace("Р«","Ы",$st);
$st=str_replace("Р’","В",$st);
$st=str_replace("Рђ","А",$st);
$st=str_replace("Рџ","П",$st);
$st=str_replace("Р ","Р",$st);
$st=str_replace("Рћ","О",$st);
$st=str_replace("Р›","Л",$st);
$st=str_replace("Р”","Д",$st);
$st=str_replace("Р–","Ж",$st);
$st=str_replace("РЇ","Я",$st);
$st=str_replace("Р§","Ч",$st);
$st=str_replace("РЎ","С",$st);
$st=str_replace("Рњ","М",$st);
$st=str_replace("Р�","И",$st);
$st=str_replace("Рў","Т",$st);
$st=str_replace("Р¬","Ь",$st);
$st=str_replace("Р‘","Б",$st);
$st=str_replace("Р®","Ю",$st);
$st=str_replace("С‘","ё",$st);
$st=str_replace("РЃ","Ё",$st);
$st=str_replace("Р","Э",$st);
return $st;
}
function text($st){
$st=txt($st);
$st=del($st);
return $st;
}
function random_pay_text($number)
{
return txt(random_pay($number));
}
function random_text($array){
return trim($array[mt_rand(0,count($array)-1)]);
}
function del($mode){
return trim(htmlspecialchars($mode));
}
function echo_menu($get,$mode,$id,$name,$menu,$g=''){//$get=имя переменной,$mode=настоящий мод,$id=мод текущего меню,$name,$menu-и так понятно.
echo '<div class="main">[<a class="wl" href="';
If ($mode==$id) echo '?'.$g.$get.'=none">-</a>'; else echo '?'.$g.'mode='.$id.'">+</a>';
echo ']<b>'.$name.'</b></div>';
If ($mode==$id){
$t_menu='<div class="mainsub">';
for ($i=0;$i<count($menu);$i++){
$t_menu.='> <a href="'.$menu[$i][0].'" class="white">'.$menu[$i][1].'</a><br/>';
}
$t_menu.='</div>';
echo $t_menu;
}
}
function data_to_day($nach,$kon){
return ceil(($kon-$nach)/86400);
}
function hits($tip){
If (!file_exists("info_text/".$tip.".txt")){
$file=@fopen("info_text/".$tip.".txt","w+");
@fputs($file,date("d.m.y").';1;1');
@fclose($file);
return;
}
$file=@fopen("info_text/".$tip.".txt","r");
$text=@fgets($file,500);
@fclose($file);
$t=explode(";",$text);
$t[2]++;
If ($t[0]!=date("d.m.y")){
$file=@fopen("info_text/".$tip.".txt","w+");
@fputs($file,date("d.m.y").';1;'.$t[2]);
@fclose($file);
return;
}
$t[1]++;
$file=@fopen("info_text/".$tip.".txt","w+");
@fputs($file,$t[0].';'.$t[1].';'.$t[2]);
@fclose($file);
return;
}
function hits_view($tip){
If (!file_exists("info_text/".$tip.".txt")){
$file=@fopen("info_text/".$tip.".txt","w+");
@fputs($file,date("d.m.y").';0;0');
@fclose($file);
}
$file=@fopen("info_text/".$tip.".txt","r");
$text=@fgets($file,500);
@fclose($file);
$t=explode(";",$text);
return $t;
}
function formating($what,$to,$from){
return str_replace("<:".$what.":>",$to,$from);
}
function is_login($login){
If (!preg_match("%^[_0-9a-zA-Zа-яА-Я -]{3,15}+$%",$login)) return false;
return true;
}
function is_password($login){
If (!preg_match("%^[0-9a-zA-Z]{3,15}$%",$login)) return false;
return true;
}
function is_id($id){
If (!is_numeric($id)) return false;
If ($id<1) return false;
If ($id>1000000) return false;
If (floor($id)!=$id) return false;
return true;
}
function id_num_add($id,$min,$max,$float=false){
If (!is_numeric($id)) return false;
If ($id<$min) return false;
If ($id>$max) return false;
If (!$float) If (floor($id)!=$id) return false;
return true;
}
function is_text_add($text,$l,$return=false){
$text=text($text);
$len=strlen($text);
If ($len>$l || $len<1) return false;
If (!$return) return $text;
return true;
}
function echooptions($mas){
foreach($mas as $key=>$value)
echo '<option value="'.$key.'">'.$value.'</option>rn';
}
function rechooptions($mas,$default){
echo '<option value="'.$default.'">'.$mas[$default].'</option>';
foreach($mas as $key=>$value)
If ($key!=$default) echo '<option value="'.$key.'">'.$value.'</option>';
}
function sql_enter($sql,$table,$break=true){
global $_bdq;
$_bdq++;
$result=false;
$result=@mysql_query($sql);
If ($result===false){
//записываем сообщение о ошибке.
@mysql_query("insert into `".$table."` (`error`,`ts`,`adress`) values ('".mysql_real_escape_string(mysql_error())."','".time()."','".($_SERVER['SCRIPT_FILENAME'])."')");
$id=mysql_insert_id();
If ($break) echo '<div class="error">Внутренняя ошибка системы! Если ошибка повторится, то сообщите о ней администратору. номер ошибки:'.$id.'</div>';
return false;
}
return $result;
}
function tr2rus($s)
{
$s=trim($s);
//малые парные
$s=str_replace("'",'ь', $s);
$s=str_replace("''",'Ь', $s);
$s=str_replace('sh','ш', $s);
$s=str_replace('sH','ш', $s);
$s=str_replace('ГЁ','ш', $s);
$s=str_replace('Г©','щ', $s);
$s=str_replace('sch','щ', $s);
$s=str_replace('scH','щ', $s);
$s=str_replace('sCh','щ', $s);
$s=str_replace('sCH','щ', $s);
$s=str_replace('ch','ч', $s);
$s=str_replace('cH','ч', $s);
$s=str_replace('yo','ё', $s);
$s=str_replace('yO','ё', $s);
$s=str_replace('jo','ё', $s);
$s=str_replace('jO','ё', $s);
$s=str_replace('Г©','ё', $s);
$s=str_replace('ye','э', $s);
$s=str_replace('ГС','э', $s);
$s=str_replace('yE','э', $s);
$s=str_replace('ya','я', $s);
$s=str_replace('yA','я', $s);
$s=str_replace('ja','я', $s);
$s=str_replace('jA','я', $s);
$s=str_replace('ГЇ','я', $s);
$s=str_replace('yu','ю', $s);
$s=str_replace('yU','ю', $s);
$s=str_replace('ju','ю', $s);
$s=str_replace('jU','ю', $s);
$s=str_replace('Г®','ю', $s);
$s=str_replace('zh','ж', $s);
$s=str_replace('zH','ж', $s);
$s=str_replace('ts','ц', $s);
$s=str_replace('tS','ц', $s);
$s=str_replace('Г¦','ц', $s);
//мягкий знак
$s=str_replace("ìì",'Ь', $s);
$s=str_replace("Г¬",'ь', $s);
$s=str_replace("''",'Ь', $s);
$s=str_replace("'",'ь', $s);
//большие парные
$s=str_replace('SH','Ш', $s);
$s=str_replace('Sh','Ш', $s);
$s=str_replace('SCH','Щ', $s);
$s=str_replace('SCh','Щ', $s);
$s=str_replace('ScH','Щ', $s);
$s=str_replace('Sch','Щ', $s);
$s=str_replace('Г‰','Щ', $s);
$s=str_replace('CH','Ч', $s);
$s=str_replace('Ch','Ч', $s);
$s=str_replace('YO','Ё', $s);
$s=str_replace('Yo','Ё', $s);
$s=str_replace('JO','Ё', $s);
$s=str_replace('Jo','Ё', $s);
$s=str_replace('YE','Э', $s);
$s=str_replace('Ye','Э', $s);
$s=str_replace('YA','Я', $s);
$s=str_replace('Ya','Я', $s);
$s=str_replace('JA','Я', $s);
$s=str_replace('Ja','Я', $s);
$s=str_replace('ГЏ','Я', $s);
$s=str_replace('YU','Ю', $s);
$s=str_replace('Yu','Ю', $s);
$s=str_replace('JU','Ю', $s);
$s=str_replace('Ju','Ю', $s);
$s=str_replace('ZH','Ж', $s);
$s=str_replace('Zh','Ж', $s);
$s=str_replace('TS','Ц', $s);
$s=str_replace('Ts','Ц', $s);
//малые одиночные
$s=str_replace('a','а', $s);
$s=str_replace('b','б', $s);
$s=str_replace('c','ц', $s);
$s=str_replace('d','д', $s);
$s=str_replace('e','е', $s);
$s=str_replace('f','ф', $s);
$s=str_replace('g','г', $s);
$s=str_replace('h','х', $s);
$s=str_replace('ГҐ','х', $s);
$s=str_replace('i','и', $s);
$s=str_replace('j','й', $s);
$s=str_replace('Г™','й', $s);
$s=str_replace('k','к', $s);
$s=str_replace('l','л', $s);
$s=str_replace('m','м', $s);
$s=str_replace('n','н', $s);
$s=str_replace('o','о', $s);
$s=str_replace('p','п', $s);
$s=str_replace('q','ъ', $s);
$s=str_replace('r','р', $s);
$s=str_replace('s','с', $s);
$s=str_replace('t','т', $s);
$s=str_replace('y','ы', $s);
$s=str_replace('Г«','ы', $s);
$s=str_replace('u','у', $s);
$s=str_replace('v','в', $s);
$s=str_replace('w','в', $s);
$s=str_replace('x','х', $s);
$s=str_replace('z','з', $s);
//большие одиночные
$s=str_replace('A','А', $s);
$s=str_replace('B','Б', $s);
$s=str_replace('C','Ц', $s);
$s=str_replace('D','Д', $s);
$s=str_replace('E','Е', $s);
$s=str_replace('F','Ф', $s);
$s=str_replace('G','Г', $s);
$s=str_replace('H','Х', $s);
$s=str_replace('I','И', $s);
$s=str_replace('J','Й', $s);
$s=str_replace('K','К', $s);
$s=str_replace('L','Л', $s);
$s=str_replace('M','М', $s);
$s=str_replace('N','Н', $s);
$s=str_replace('O','О', $s);
$s=str_replace('P','П', $s);
$s=str_replace('Q','Ъ', $s);
$s=str_replace('R','Р', $s);
$s=str_replace('S','С', $s);
$s=str_replace('T','Т', $s);
$s=str_replace('U','У', $s);
$s=str_replace('V','В', $s);
$s=str_replace('W','В', $s);
$s=str_replace('X','Х', $s);
$s=str_replace('Y','Ы', $s);
$s=str_replace('Z','З', $s);
//исключения
$s=str_replace('т.с','Тс', $s);
$s=str_replace('Т.с','Тс', $s);
$s=str_replace('т.С','тС', $s);
$s=str_replace('Т.С','ТС', $s);
$s=str_replace('с.ч','сч', $s);
$s=str_replace('С.ч','Сч', $s);
$s=str_replace('с.Ч','сЧ', $s);
$s=str_replace('С.Ч','СЧ', $s);
$s=str_replace('ы.е','ые', $s);
$s=str_replace('Ы.е','Ые', $s);
$s=str_replace('ы.Е','ыЕ', $s);
$s=str_replace('Ы.Е','ЫЕ', $s);
$s=str_replace('ы.а','ыа', $s);
$s=str_replace('Ы.а','Ыа', $s);
$s=str_replace('ы.А','ыА', $s);
$s=str_replace('Ы.А','ЫА', $s);
$s=str_replace('с.х','сх', $s);
$s=str_replace('С.х','Сх', $s);
$s=str_replace('с.Х','сХ', $s);
$s=str_replace('С.Х','СХ', $s);
$s=str_replace('ц.х','цх', $s);
$s=str_replace('Ц.х','Цх', $s);
$s=str_replace('ц.Х','цХ', $s);
$s=str_replace('Ц.Х','ЦХ', $s);
$s=str_replace('з.х','зх', $s);
$s=str_replace('З.х','Зх', $s);
$s=str_replace('з.Х','зХ', $s);
$s=str_replace('З.Х','ЗХ', $s);
return $s;
}
function rexplode($sep,$which){
If (strpos($which,$sep)===false) $a[0]=$which; else $a=explode($sep,$which);
return $a;
}
function rsearch($who,$where,$sep,$sep1,$n){
/*
$who-что искать
$where-где
$sep-основной разделитель
$sep1-внутренний разделитель
$n-номер элемента во внутренней подстроке.
пример:
rsearch("hi!","privet,poka;zdarova,hi;hi!,zdarova!",";",",",1);
*/
$res=rexplode($sep,$where);
for ($i=0;$i<count($res);$i++){
$r1=rexplode($sep1,$res[$i]);
If ($r1[$i]==$who) return true;
}
return false;
}
function rimplode($sep,$which){
If (!is_array($which) || count($which)<=1) return $which; else return implode($sep,$which);
}
function num_online($zapros,$online,$time){
$sql="SELECT `id` FROM `".prefix."users` WHERE `where` LIKE '".$zapros."' AND `online`>'".($time-$online*60)."'";
$result=sql_enter($sql,prefix."error");
If (!$result) return false;
return mysql_num_rows($result);
}
function rnd_array($shablon,$array){
/*
Шаблон задаётся в виде:
{:Имя эл. массива:}...{:Имя эл. массива:}...
*/
$rnd=mt_rand(0,count($array)-1);
$result=$shablon;
foreach ($array[$rnd] as $key=>$value) $result=str_replace("{:".$key.":}",$value,$result);
return $result;
}
function new_user()
{
$hyf = time();
$fl = mysql_query("select `login` from `cclub_users` ;");
$countf = mysql_num_rows($fl);
$old = $hyf - (3 * 24 * 3600);
$fl1 = mysql_query("select `login` from `cclub_users` where `ts` > '" . $old . "' ;");
$countf1 = mysql_num_rows($fl1);
$out = $countf;
if ($countf1 > 0)
{
$out = $out . "/<font color='#FF0000'>+$countf1 новых</font>";
}
return $out;
}
function bbcode($text)
{
$text = eregi_replace("(.*)\[url\]\http://([0-9a-z_][0-9a-z./?&=]*)\[/url\](.*)","\1<a href="http://\2">\2</a>\3",$text);
$text = eregi_replace("(.*)\[b\](.*)\[/b\](.*)","\1<b>\2</b>\3",$text);
$text = eregi_replace("(.*)\[i\](.*)\[/i\](.*)","\1<i>\2</i>\3",$text);
$text = eregi_replace("(.*)\[u\](.*)\[/u\](.*)","\1<u>\2</u>\3",$text);
$text = eregi_replace("(.*)\[small\](.*)\[/small\](.*)","\1<small>\2</small>\3",$text);
$text = eregi_replace("(.*)\[big\](.*)\[/big\](.*)","\1<big>\2</big>\3",$text);
$text = preg_replace('#[red](.*?)[/red]#si', '<span style="color:red">1</span>', $text);
$text = preg_replace('#[green](.*?)[/green]#si', '<span style="color:green">1</span>', $text);
$text = preg_replace('#[blue](.*?)[/blue]#si', '<span style="color:blue">1</span>', $text);
$text = str_replace("rn", "<br/>", $text);
return $text;
}
function smile($text)
{
$text = str_replace(":)","<img src='smile/).gif' alt=":)"/>",$text);
$text = str_replace(":-)","<img src="smile/).gif" alt=":)"/>",$text);
$text = str_replace("=)","<img src="smile/).gif" alt=":)"/>",$text);
$text = str_replace(":(","<img src="smile/(.gif" alt=":("/>",$text);
$text = str_replace(":-(","<img src="smile/(.gif" alt=":("/>",$text);
$text = str_replace("=(","<img src="smile/(.gif" alt=":("/>",$text);
$text = str_replace("0_o","<img src="smile/0_o.gif" alt="0_o"/>",$text);
$text = str_replace("o_0","<img src="smile/0_o.gif" alt="0_o"/>",$text);
$text = str_replace(":D","<img src="smile/gg.gif" alt=":D"/>",$text);
$text = str_replace(":-D","<img src="smile/gg.gif" alt=":D"/>",$text);
$text = str_replace("sorry","<img src="smile/sorry.gif" alt="sorry"/>",$text);
$text = str_replace("*sorry*","<img src="smile/sorry.gif" alt="sorry"/>",$text);
$text = str_replace("*SORRY*","<img src="smile/sorry.gif" alt="sorry"/>",$text);
$text = str_replace("8)","<img src="smile/8).gif" alt="8)"/>",$text);
$text = str_replace("bye","<img src="smile/bye.gif" alt="bye"/>",$text);
$text = str_replace("*bye*","<img src="smile/bye.gif" alt="bye"/>",$text);
$text = str_replace("*BYE*","<img src="smile/bye.gif" alt="bye"/>",$text);
$text = str_replace("*aaa*","<img src="smile/aaa.gif" alt="aaa"/>",$text);
$text = str_replace("*AAA*","<img src="smile/aaa.gif" alt="aaa"/>",$text);
$text = str_replace("AAA","<img src="smile/aaa.gif" alt="aaa"/>",$text);
$text = str_replace(":*","<img src="smile/-.gif" alt=":*"/>",$text);
$text = str_replace(":-*","<img src="smile/-.gif" alt=":*"/>",$text);
$text = str_replace(":[","<img src="smile/[.gif" alt=":["/>",$text);
$text = str_replace(":-[","<img src="smile/[.gif" alt=":["/>",$text);
$text = str_replace("*DONT*","<img src="smile/dont.gif" alt="dont"/>",$text);
$text = str_replace("*dont*","<img src="smile/dont.gif" alt="dont"/>",$text);
$text = str_replace("DONT","<img src="smile/dont.gif" alt="dont"/>",$text);
$text = str_replace("*DONT_KNOW*","<img src="smile/dont.gif" alt="dont"/>",$text);
$text = str_replace("*FRIEND*","<img src="smile/friend.gif" alt="FRIEND"/>",$text);
$text = str_replace("FRIEND","<img src="smile/friend.gif" alt="FRIEND"/>",$text);
$text = str_replace("*friend*","<img src="smile/friend.gif" alt="FRIEND"/>",$text);
$text = str_replace(":!","<img src="smile/sick.gif" alt=":!"/>",$text);
$text = str_replace(":-!","<img src="smile/sick.gif" alt=":!"/>",$text);
$text = str_replace("*SICK*","<img src="smile/sick.gif" alt=":!"/>",$text);
$text = str_replace("*UP*","<img src='smile/th.gif' alt='*' />",$text);
$text = str_replace("*up*","<img src='smile/th.gif' alt='*' />",$text);
$text = str_replace("*NO*","<img src='smile/no.gif' alt='*' />",$text);
$text = str_replace("*WALL*","<img src='smile/no.gif' alt='*' />",$text);
$text = str_replace("*DASH*","<img src='smile/wall.gif' alt='*' />",$text);
$text = str_replace(";-)","<img src='smile/podm.gif' alt='*' />",$text);
$text = str_replace(";)","<img src='smile/podm.gif' alt='*' />",$text);
return $text;
}
function antilink($text)
{
$text = eregi_replace("((https?|ftp)://)([[:alnum:]_=/-]+(\.[[:alnum:]_=/-]+)*(/[[:alnum:]+&._=/~%]*(\?[[:alnum:]?+&_=/;%]*)?)?)", "[реклама]", $text);
$text = strtr($text, array(".ru" => "***", ".com" => "***", ".net" => "***", ".org" => "***", ".info" => "***", ".mobi" => "***", ".wen" => "***", ".kmx" => "***", ".h2m" => "***"));
return $text;
}
/*
function antimat($text)
{
$text = strtr($text, array("блядь" => "[cenzor]", "cyкa" => "[cenzor]", "пидap" => "[cenzor]", "xyй" => "[cenzor]", "пиздa" => "[cenzor]", "зaлyпa" => "[cenzor]", "мyдaк" => "[cenzor]", "гнидa" => "[cenzor]", "лox" => "[cenzor]", "гaндoн" => "[cenzor]", "loh" => "[cenzor]"));
return $text;
}
*/
?>