Файл: vzabave/sys/func/func.php
Строк: 192
<?
function win_to_utf($str){
$str=strtr($str,array(''=>'а',''=>'б',''=>'в',''=>'г',''=>'д',''=>'е',''=>'ё',''=>'ж',''=>'з',''=>'и',''=>'й',''=>'к',''=>'л',''=>'м',''=>'н',''=>'о',''=>'п',''=>'р',''=>'с',''=>'т',''=>'у',''=>'ф',''=>'х',''=>'ц',''=>'ч',''=>'ш',''=>'щ',''=>'ъ',''=>'ы',''=>'ь',''=>'э',''=>'ю',''=>'я',''=>'А',''=>'Б',''=>'В',''=>'Г',''=>'Д',''=>'Е',''=>'Ё',''=>'Ж',''=>'З',''=>'?',''=>'Й',''=>'К',''=>'Л',''=>'М',''=>'Н',''=>'О',''=>'П',''=>'Р',''=>'С',''=>'Т',''=>'У',''=>'Ф',''=>'Х',''=>'Ц',''=>'Ч',''=>'Ш',''=>'Щ',''=>'Ъ',''=>'Ы',''=>'Ь',''=>'Э',''=>'Ю',''=>'Я'));
return $str;
}
function utf_to_win($str){
$str=strtr($str,array('а'=>'','б'=>'','в'=>'','г'=>'','д'=>'','е'=>'','ё'=>'','ж'=>'','з'=>'','и'=>'','й'=>'','к'=>'','л'=>'','м'=>'','н'=>'','о'=>'','п'=>'','р'=>'','с'=>'','т'=>'','у'=>'','ф'=>'','х'=>'','ц'=>'','ч'=>'','ш'=>'','щ'=>'','ъ'=>'','ы'=>'','ь'=>'','э'=>'','ю'=>'','я'=>'','А'=>'','Б'=>'','В'=>'','Г'=>'','Д'=>'','Е'=>'','Ё'=>'','Ж'=>'','З'=>'','И'=>'','Й'=>'','К'=>'','Л'=>'','М'=>'','Н'=>'','О'=>'','П'=>'','Р'=>'','С'=>'','Т'=>'','У'=>'','Ф'=>'','Х'=>'','Ц'=>'','Ч'=>'','Ш'=>'','Щ'=>'','Ъ'=>'','Ы'=>'','Ь'=>'','Э'=>'','Ю'=>'','Я'=>''));
return $str;
}
function getmicrotime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function rus_to_k($str){
$str = strtr($str, array ('а' => 'a','б' => 'b','в' => 'v','г' => 'g','д' => 'd','е' => 'e','ё' => 'e','ж' => 'j','з' => 'z','и' => 'i','й' => 'y','к' => 'k','л' => 'l','м' => 'm','н' => 'n','о' => 'o','п' => 'p','р' => 'r','с' => 's','т' => 't','у' => 'u','ф' => 'f','х' => 'h','ч' => 'c','ц' => 'q','ш' => 'w','щ' => '>','ь' => '<','ы' => 'x','ъ' => '.','э' => ':','ю' => ';','я' => '}','А' => 'a','Б' => 'b','В' => 'v','Г' => 'g','Д' => 'd','Е' => 'e','Ё' => 'e','Ж' => 'j','З' => 'z','И' => 'i','Й' => 'y','К' => 'k','Л' => 'l','М' => 'm','Н' => 'n','О' => 'o','П' => 'p','Р' => 'r','С' => 's','Т' => 't','У' => 'u','Ф' => 'f','Х' => 'h','Ч' => 'c','Ц' => 'q','Ш' => 'w','Щ' => '>','Ь' => '<','Ы' => 'x','Ъ' => '.','Э' => ':','Ю' => ';','Я' => '}'));
return $str;
}
function rus_to_lat($str) {
$str = strtr($str, array ('а' => 'a','б' => 'b','в' => 'v','г' => 'g','д' => 'd','е' => 'e','ё' => 'e','ж' => 'j','з' => 'z','и' => 'i','й' => 'i','к' => 'k','л' => 'l','м' => 'm','н' => 'n','о' => 'o','п' => 'p','р' => 'r','с' => 's','т' => 't','у' => 'u','ф' => 'f','х' => 'h','ц' => 'c','ч' => 'ch','ш' => 'sh','щ' => 'sch','ъ' => "",'ы' => 'y','ь' => "",
'э' => 'ye','ю' => 'yu','я' => 'ya'));
return $str;
}
function 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);
}
function translit($str) {
$str = strtr($str, array ('a' => 'а','b' => 'б','v' => 'в','g' => 'г','d' => 'д','e' => 'е','yo' => 'ё','zh' => 'ж','z' => 'з','i' => 'и','j' => 'й','k' => 'к','l' => 'л','m' => 'м','n' => 'н','o' => 'о','p' => 'п','r' => 'р','s' => 'с','t' => 'т','u' => 'у','f' => 'ф','h' => 'х','c' => 'ц','ch' => 'ч','w' => 'ш','sh' => 'щ','q' => 'ъ','y' => 'ы','x' => 'э','yu' => 'ю','ya' => 'я','A' => 'А','B' => 'Б','V' => 'В','G' => 'Г','D' => 'Д','E' => 'Е','YO' => 'Ё','ZH' => 'Ж','Z' => 'З','I' => 'И','J' => 'Й','K' => 'К','L' => 'Л','M' => 'М','N' => 'Н','O' => 'О','P' => 'П','R' => 'Р','S' => 'С','T' => 'Т','U' => 'У','F' => 'Ф','H' => 'Х','C' => 'Ц','CH' => 'Ч','W' => 'Ш','SH' => 'Щ','Q' => 'Ъ','Y' => 'Ы','X' => 'Э','YU' => 'Ю','YA' => 'Я'));
return $str;
}
function strlen2($str)
{
if (function_exists('mb_strlen')) return mb_strlen($str, 'utf-8');
if (function_exists('iconv_strlen')) return iconv_strlen($str, 'utf-8');
if (function_exists('utf8_decode')) return strlen(utf8_decode($str));
return strlen(utf_to_win($str));
}
function substr2($str)
{
global $db, $user,$set;
$str=substr($str, 0, $set['size_lich']);
$str=preg_replace('#^(?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,0}'.'((?:[x00-x7F]|[xC0-xFF][x80-xBF]+){0,500}).*#s','$1',$str);
return $str;
}
function times($times=NULL)
{
global $db, $_GET;
$timesp=date("j M в H:i", $times);
$timesp = strtr($timesp, array ("Jan" => "Янв","Feb" => "Фев","Mar" => "Марта","May" => "Мая","Apr" => "Апр","Jun" => "Июня","Jul" => "Июля","Aug" => "Авг","Sep" => "Сент","Oct" => "Окт","Nov" => "Ноября","Dec" => "Дек",));
if (isset($_GET['timesp']))$timesp='12';
return $timesp;
}
function opsos($ips=NULL){
global $db, $ip;
if ($ips==NULL)$ips=$ip;
$ipl=ip2long($ips);
if ($db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `opsos` WHERE `min` <= '$ipl' AND `max` >= '$ipl'"), 0)!=0){
$opsos=$db->sql_fetchrow($db->sql_query("SELECT opsos FROM `opsos` WHERE `min` <= '$ipl' AND `max` >= '$ipl' LIMIT 1"));
return check($opsos['opsos']);
}else return false;
}
function page($k_page=1){
$page=1;
$page=check($page);
$k_page=check($k_page);
if (isset($_GET['page'])){
if ($_GET['page']=='end')$page=check(intval($k_page));elseif(is_numeric($_GET['page'])) $page=check(intval($_GET['page']));}
if ($page<1)$page=1;
if ($page>$k_page)$page=$k_page;
return $page;}
// Определяем кол-во страниц
function k_page($k_post=0,$k_p_str=10){
if ($k_post!=0){$v_pages=ceil($k_post/$k_p_str);return $v_pages;}
else return 1;}
$HOSTik = md5($_SERVER['HTTP_HOST']);
function str($link='?',$k_page=1,$page=1){
if ($page<1)$page=1;
$page=check($page);
$k_page=check($k_page);
if ($page!=1)echo '<a href="'.$link.'page=1"><<</a> ';
if ($page>1)echo '<a href="'.$link.'page='.($page-1).'"><</a> ';
echo " ";
if ($page<$k_page)echo ' <a href="'.$link.'page='.($page+1).'" >></a>';
if ($page!=$k_page)echo ' <a href="'.$link.'page=end">>></a>';
echo "<br />";
if ($page!=1)echo '<a href="'.$link.'page=1" >1</a>';else echo '<b>1</b>';
for ($ot=-3; $ot<=3; $ot++){
if ($page+$ot>1 && $page+$ot<$k_page){
if ($ot==-3 && $page+$ot>2)echo " ..";
if ($ot!=0)echo '|<a href="'.$link.'page='.($page+$ot).'" >'.($page+$ot).'</a>';else echo '|<b>'.($page+$ot).'</b>';
if ($ot==3 && $page+$ot<$k_page-1)echo "|..";}}
if ($page!=$k_page)echo '|<a href="'.$link.'page=end" >'.$k_page.'</a>';elseif ($k_page>1)echo '|<b>'.$k_page.'</b>';
}
function str2($link='?',$k_page=1,$page=1){
if ($page<1)$page=1;
$page=check($page);
$k_page=check($k_page);
if ($page!=1)echo "<a href="".$link."_1"><<</a> ";
if ($page>1)echo "<a href="".$link."_".($page-1).""><</a> ";
echo " ";
if ($page<$k_page)echo " <a href="".$link."_".($page+1)."" >></a>";
if ($page!=$k_page)echo " <a href="".$link."_end">>></a>";
echo "<br />";
if ($page!=1)echo "<a href="".$link."_1" >1</a>";else echo "<b>1</b>";
for ($ot=-3; $ot<=3; $ot++){
if ($page+$ot>1 && $page+$ot<$k_page){
if ($ot==-3 && $page+$ot>2)echo " ..";
if ($ot!=0)echo "|<a href="".$link."_".($page+$ot)."" >".($page+$ot)."</a>";else echo "|<b>".($page+$ot)."</b>";
if ($ot==3 && $page+$ot<$k_page-1)echo "|..";}}
if ($page!=$k_page)echo "|<a href="".$link."_end" >$k_page</a>";elseif ($k_page>1)echo "|<b>$k_page</b>";
}
function passgen($k_simb=8) {
$password="";
$small="abcdefghijklmnopqrstuvwxyz";
$large="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$numbers="1234567890";
mt_srand((double)microtime()*1000000);
for ($i=0; $i<$k_simb; $i++) {
$type=mt_rand(1,3);
switch ($type) {
case 1:
$password.=$large[mt_rand(0,25)];
break;
case 2:
$password.=$small[mt_rand(0,25)];
break;
case 3:
$password.=$numbers[mt_rand(0,9)];
break;}}return $password;}
function kikt($t) {
global $db, $time;
$t2 = $t-$time;
if($t2>(60*60*24*30)) $t3 = round($t2/(60*60*24*30)).' месяцев';
else if($t2>(60*60*24)) $t3 = round($t2/(60*60*24)).' дней';
else if($t2>(60*60)) $t3 = round($t2/(60*60)).' часов';
else if($t2>60) $t3 = round($t2/60).' минут';
else $t3 = $t2.' секунд';
return $t3;
}
function lev_neme($lv) {
global $db, $time;
$ln = @$db->sql_fetchrow($db->sql_query ("Select * from levels where level='".intval($lv)."'"));
return $ln['name'];
}
function addmail($usermail, $subject, $msg) {
global $db, $set;
$mail = 'admin@'.$_SERVER['HTTP_HOST'];
$name = $set['name'];
function utf_to_win2($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);
}
$subject = utf_to_win2($subject);
$msg = utf_to_win2($msg);
$name = utf_to_win2($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-rn";
$adds .= "MIME-Version: 1.0n";
$adds .= "Content-Transfer-Encoding: 8bitn";
$adds .= "X-Mailer: PHP v.".phpversion();
return mail($usermail,$subject,$msg,$adds);
}
?>