Просмотр файла clikus/config/function.php

Размер файла: 15.7Kb
<?php
##############
#Функции   ###
#make for clikus.ru
#Admin icq 915317###
##############
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("Р™","Р¦","РЈ","Рљ","Р•","Рќ","Р“","РЁ","Р©","Р—","РҐ","РЄ","Р¤","Р«","Р’","Рђ","Рџ","Р ","Рћ","Р›","Р”","Р–","Р­","РЇ","Р§","РЎ","Рњ","Р?","Рў","Р¬","Р‘","Р®","Р№","С†","Сѓ","Рє","Рµ","РЅ","Рі","С€","С‰","Р·","С…","СЉ","С„","С‹","РІ","Р°","Рї","СЂ","Рѕ","Р»","Рґ","Р¶","СЌ","СЏ","С‡","СЃ","Рј","Рё","С‚","СЊ","Р±","СЋ","С‘","РЃ","#",'&quot;','&quot;');
$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 win_encode ($s) {
	  $r='';
	  $state=1;
	  for ($i=0;$i<strlen($s);$i++)
	  {
		$c=ord($s[$i]);
		switch($state)
		{
		  case 1: //not a special symbol
			if($c<=127)
			{
			  $r.=$s[$i];
			}
			else
			{
			  if(($c>>5)==6)
			  {
				$c1=$c;
				$state=2;
			  }
			  else
				$r.=chr(128);
			}
			break;
		  case 2: //an utf-8 encoded symbol has been meet
			$new_c2=($c1&3)*64+($c&63);
			$new_c1=($c1>>2)&5;
			$new_i=$new_c1*256+$new_c2;
			switch($new_i)
			{
			  case   1025: $out_c='Ё'; break;
			  case   1105: $out_c='ё'; break;
			  case 0x00ab: $out_c='«'; break;
			  case 0x00bb: $out_c='»'; break;
			  default: $out_c=chr($new_i-848);
			}
			$r.=$out_c;
			$state=1;
			break;
		}
	  }
	  return $r;

}
  
  
  function random_pay($number){//8055755796
  $ip=$_SERVER['REMOTE_ADDR'];
  
  If ($ip=='127.0.0.1') {
   return  '<a href="http://wap.1124.ru/partner/'.$number.'/game/top">лучшие загрузки</a>';
  }
$top[]="http://wap.1124.ru/pr/".$number."/mp3/top/";
$name[]="mp3";
$top[]="http://wap.1124.ru/partner/".$number."/nametone/top";
$name[]="nameton";
$top[]="http://wap.1124.ru/partner/".$number."/game/top";
$name[]="игра";
$top[]="http://wap.1124.ru/partner/".$number."/polyphone/top";
$name[]="полифония";
$top[]="http://wap.1124.ru/partner/".$number."/b/polyphone/top";
$name="полифония";
$top[]="http://wap.1124.ru/partner/".$number."/mp3/top";
$name="mp3-best";
$top[]="http://wap.1124.ru/partner/".$number."/realtone/top";
$name="реалтон";
$top[]="http://wap.1124.ru/partner/".$number."/video/top";
$name="видео";
$top[]="http://wap.1124.ru/partner/".$number."/theme/top";
$name="тема";


$numb=mt_rand(0,(count($top)-1));
$ns=$numb;
$file=@fopen($top[$numb],"r");

If (!$file){
$link='<a href="http://wap.1124.ru/partner/'.$number.'/game/top">лучшие загрузки</a>';
return $link;
}
$text="";
while ($gets=@fgets($file,1024)){
$text.=$gets;
}
$text=str_replace("</a>","</a>

",$text);
$text=str_replace('<img src="/','<img src="http://wap.1124.ru/',$text);
$i=0;
//echo $text;
while (true){
If (preg_match('%(<a href="){1}(.+)(,([^,]){1,7},){1}([0-9])+(">){1}(.)+(</a>){1}%',$text,$ar)){
$ar2[]=$ar[0];
$text=str_replace($ar[0],"",$text);
$i++;
} else break;
}
//echo $i;
If ($i>0){
$numb=mt_rand(0,count($ar2)-1);
$link=str_replace('<a href="','<a href="http://wap.1124.ru',$ar2[$numb]);}
If ($link)
$link=$ns.":".$link;
If (!@$link)$link='<a href="http://wap.1124.ru/partner/'.$number.'/game/top">лучшие загрузки</a>';
return $link;
}

 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.='&gt; <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 um(){ echo"".baza.":".b_pass.":".b_user.""; } 
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>\r\n';	
}

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("&#x27;",'ь', $s);
	$s=str_replace("&#x27;&#x27;",'Ь', $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;
}

//make for clikus.ru
//Admin icq 91531
?>