<?php

###########################
#Скрипт: Keo v1#
#Автор: GulievMMA#
#Версия: v1#
#Страна: Азербайджан#
#Город: Сумгайыт#
#Спорт: ММА#
#Сайт: KeoTop.Ru#
#Сайт: H9M.Ru#
#Телеграм: @AnarQuliyevMMA#
#E-mail: guliev.mma@gmail.com  #
#WhatsApp: +994 (77) 768-39-39#
#WhatsApp: +994 (55) 968-78-69#
############################
#Скрипт Принадлежит Мне , Продавать и Распростронять Нельзя (!)#
############################

header("Expires: on, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
ob_start();
function exits()
{
header("Location: ".PATH."/");
die();
}

$GDD = 'Версия';
$reit = 'Рейтинг WAP сайтов';

function data($time)
	{
		$month = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		$month_rus = array('Янв','Фев','Мар','Апр','Мая','Июн','Июл','Авг','Сент','Окт','Ноя','Дек');
		$timep = date("j M Y - H:i:s", $time);
		$timep = str_replace($month,$month_rus,$timep);
		return $timep;
	}
function navigation($all,$napage,$page,$url,$total)
	{
		if(!($all<=$napage))
			{
			
				if($page-1>0)
					{
						$left='<span class="pages"><a href="'.$url.''.($page-1).'"><</a></span>'; 
					}

				if($page+1>0 && $page<$total)
					{ 
						$right='<span class="pages"><a href="'.$url.''.($page+1).'">></a></span>'; 
					}


 if($page-3>0)$first='<span class="pages"><a href="'.$url.'1">1</a></span>';
 if($page+3<=$total)$last='[..]<span class="pages"><a href="'.$url.''.($total).'">'.($total).'</a></span>'; 

					if($page-2>0)$page2left='<span class="pages"><a href="'.$url.''.($page-2).'">'.($page-2).'</a></span>';
					if($page-1>0)$page1left='<span class="pages"><a href="'.$url.''.($page-1).'">'.($page-1).'</a></span>'; 
					if($page+1<=$total)$page1right='<span class="pages"><a href="'.$url.''.($page+1).'">'.($page + 1).'</a></span>'; 
                    if($page+2<=$total)$page2right='<span class="pages"><a href="'.$url.''.($page+2).'">'.($page + 2).'</a></span>';

				echo '<div class="row"><center>'.$left.''.$first.''.$page2left.''.$page1left.'<span class="buti">'.$page.'</span>'.$page1right.$page2right.$last.''.$right.'</center></div>';

			}
	}
	
function stats_forum() {
	global $config;
	if (@filemtime('../local/temp/forum.dat') < time()-$config['cache_counters']) {
		$forum_topics = mysqli_result(mysqli_query($mysqli,"SELECT COUNT(`id`) FROM `forum_topics`"), 0);
		$forum_msg = mysqli_result(mysqli_query($mysqli,"SELECT COUNT(`id`) FROM `forum_msg`"), 0);
		$forum_msg_new = mysqli_result(mysqli_query($mysqli,"SELECT COUNT(`id`) FROM `forum_msg` WHERE `time` > '".(time()-86400)."'"), 0);
		
		$new = '';
		if ($forum_msg_new > 0) {
			$new = '<span style="color:white">+'.$forum_msg_new.'</span>';
		}
		
		$put = '['.$forum_topics.'/'.$forum_msg.'] '.$new;
		
		file_put_contents('../local/temp/forum.dat', $put, LOCK_EX);
	} 

	return file_get_contents('../local/temp/forum.dat');
}
function ftopics_index() {
	global $config;
	if (@filemtime('../local/temp/ftopics_index.dat') < time()-$config['cache_counters']) {
		file_put_contents('../local/temp/ftopics_index.dat', '', LOCK_EX);
		$ftopic_r = mysqli_query($mysqli,"SELECT * FROM `forum_topics` ORDER BY `last_time` DESC LIMIT 5");
		while ($t = mysqli_fetch_array($ftopic_r)) {
			$t_msg = mysqli_result(mysqli_query($mysqli,"SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$t[id]'"), 0);
			
			if ($t['stuck']) {
				$pic = '<img src="/images/forum_tstuck.gif">';
			} elseif($t['closed'] == 1 and empty($t['stuck'])) {
				$pic = '<img src="/images/forum_tclosed.png">';
			} else {
				$pic = '<img src="/images/forum_t.png">';
			}

			$put = $pic.' <a href="/forum/topic.php?id='.$t['id'].'">'.$t['title'].'</a> ('.$t_msg.') <a href="/forum/topic.php?act=end&amp;id='.$t['id'].'">&raquo;&raquo;</a><br />';
			file_put_contents('../local/temp/ftopics_index.dat', $put, FILE_APPEND | LOCK_EX);
		}
	}
	return file_get_contents('../local/temp/ftopics_index.dat');
}

function unreg()
	{	
		global $user_data;
		if($user_data)
			{
				header("Location: ../?");
				exit;
			}
	}
function reg()
	{
		global $user_data;
		if(!$user_data)
			{
				header("Location: ../m/authentication");
				exit;
			}
	}
function level($level)
	{
		global $user_data;
		if($user_data AND $user_data['level'] < $level OR !$user_data)
			{
				header("Location: ../?");
			}
	}
function bb($msg){
  		
    $msg = preg_replace("#\[red\](.*?)\[/red\]#si", "<span style=\"color: red\">\\1</span>", $msg);
    $msg = preg_replace("#\[blue\](.*?)\[/blue\]#si", "<span style=\"color: blue\">\\1</span>", $msg);
    $msg = preg_replace("#\[black\](.*?)\[/black\]#si", "<span style=\"color: black\">\\1</span>", $msg);
    $msg = preg_replace("#\[green\](.*?)\[/green\]#si", "<span style=\"color: green\">\\1</span>", $msg);
    $msg = preg_replace("#\[orange\](.*?)\[/orange\]#si", "<span style=\"color: orange\">\\1</span>", $msg);
    $msg = preg_replace("#\[pink\](.*?)\[/pink\]#si", "<span style=\"color: pink\">\\1</span>", $msg);
    $msg = preg_replace("#\[gray\](.*?)\[/gray\]#si", "<span style=\"color: gray\">\\1</span>", $msg);
    $msg = preg_replace("#\[big\](.*?)\[/big\]#si", "<span style=\"font-size: 20px\">\\1</span>", $msg);
    $msg = preg_replace("#\[small\](.*?)\[/small\]#si", "<span style=\"font-size: 8px\">\\1</span>", $msg);
    $msg = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $msg);
    $msg = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $msg);
    $msg = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $msg);
    $msg = preg_replace("#\[strike\](.*?)\[/strike\]#si", "<strike>\\1</strike>", $msg);
    $msg = preg_replace("#\[q\](.*?)\[/q\]#si", "<div class=\"quote\">\\1</div>", $msg);
$msg = preg_replace('/\[font\=([a-zA-Z0-9\#]*)\](.*?)\[\/font\]/is', '<span style="background-color:$1">$2</span>', $msg);
$msg = preg_replace("#\[img\](.*?)\[/img\]#si", "<a href='\\1'><img src=\"\\1\" width='50' height='50'></a>", $msg);
/*$msg = preg_replace_callback('~\[url=((https?|ftp)://.+?)\](.+?)\[/url\]|((https?|ftp)://[0-9a-zа-яё/.;?=\(\)\_\-&%#]+)~ui', 'url_replace', $msg);*/
$msg = preg_replace("#\[url\](.*?)\[/url\]#si", "<a href='\\1'><img src='http://bymas.ru/files/downloads/247/249/250/251/9493/047.png'> <font color='orange'>link</font></a>", $msg);
    $msg = preg_replace("#\[/br\]#si", "</br>", $msg);
    return nl2br($msg);
}



function bb2($msg){
    $msg = preg_replace("#\[red\](.*?)\[/red\]#si", "<span style=\"color: red\">\\1</span>", $msg);
    $msg = preg_replace("#\[blue\](.*?)\[/blue\]#si", "<span style=\"color: blue\">\\1</span>", $msg);
    $msg = preg_replace("#\[black\](.*?)\[/black\]#si", "<span style=\"color: black\">\\1</span>", $msg);
    $msg = preg_replace("#\[green\](.*?)\[/green\]#si", "<span style=\"color: green\">\\1</span>", $msg);
    $msg = preg_replace("#\[orange\](.*?)\[/orange\]#si", "<span style=\"color: orange\">\\1</span>", $msg);
    $msg = preg_replace("#\[pink\](.*?)\[/pink\]#si", "<span style=\"color: pink\">\\1</span>", $msg);
    $msg = preg_replace("#\[gray\](.*?)\[/gray\]#si", "<span style=\"color: gray\">\\1</span>", $msg);
    $msg = preg_replace("#\[big\](.*?)\[/big\]#si", "<span style=\"font-size: 20px\">\\1</span>", $msg);
    $msg = preg_replace("#\[small\](.*?)\[/small\]#si", "<span style=\"font-size: 8px\">\\1</span>", $msg);
    $msg = preg_replace("#\[b\](.*?)\[/b\]#si", "<b>\\1</b>", $msg);
    $msg = preg_replace("#\[u\](.*?)\[/u\]#si", "<u>\\1</u>", $msg);
    $msg = preg_replace("#\[i\](.*?)\[/i\]#si", "<i>\\1</i>", $msg);
    $msg = preg_replace("#\[strike\](.*?)\[/strike\]#si", "<strike>\\1</strike>", $msg);
    $msg = preg_replace("#\[q\](.*?)\[/q\]#si", "<div class=\"quote\">\\1</div>", $msg);
$msg = preg_replace('/\[font\=([a-zA-Z0-9\#]*)\](.*?)\[\/font\]/is', '<span style="background-color:$1">$2</span>', $msg);
$msg = preg_replace("#\[img\](.*?)\[/img\]#si", "<a href='\\1'><img src=\"\\1\" width='50' height='50'></a>", $msg);
/*$msg = preg_replace_callback('~\[url=((https?|ftp)://.+?)\](.+?)\[/url\]|((https?|ftp)://[0-9a-zа-яё/.;?=\(\)\_\-&%#]+)~ui', 'url_replace', $msg);*/
$msg = preg_replace("#\[url\](.*?)\[/url\]#si", "<a href='\\1'><img src='http://bymas.ru/files/downloads/247/249/250/251/9493/047.png'> <font color='orange'>link</font></a>", $msg);
    $msg = preg_replace("#\[/br\]#si", "</br>", $msg);
    return nl2br($msg);
}
function ccdate($time, $user_4_online) {
    if (date('d.m.y', $time) == date('d.m.y', time())) {
        $date = date('<b>H:i</b>', $time);
    } else {
        $date = date('d.m.y, H:i', $time);
    }

   
    return '<span style="font-size: 10px">'.$date.'</span>';
}
function navig($page, $link, $pages) {
    global $lang;
    if ($pages > 1) {
echo '</div><div class="main">';
        for ($k = 1; $k <= $pages; $k++) {
            if ( $k == 1 or $k == $pages or 2 >= ($page - $k) and -2 <= ($page - $k) ) {
                if ($k == $page) {
$write = '<b class="number">'.$k.'</b>';
                } else {
$write = '<a class="number" href="'.$link.'p='.$k.'">'.$k.'</a>';
                }
                echo $write;
            }
        }
		echo '</div>';
    }
}
function note() {
    if (isset($_SESSION['note'])) {
        echo '<b>'.$_SESSION['note'].'</b><br />';
        unset($_SESSION['note']);
    }
}

function filter($t){ 
$t = trim(htmlspecialchars($t)); 
$t = str_replace("%","",$t); 
$t = str_replace("\r","",$t);
$t = str_replace("\n","<br>",$t);
$t = str_replace("|","&#166;",$t);
$t = preg_replace("/s(w+s)1/i","$1",$t);
return $t; 
}

function stats($t){ 
$t = intval($t); 
$t = number_format($t);
$t = str_replace(","," ",$t);
return $t; 
}

function browser()
	{
global $ua; 
if (preg_match('/opera min/i', $ua)) $browser = 'Opera Mini'; 
else if (preg_match('/Chrome/i', $ua))$browser = 'Chrome'; 
else if (preg_match('/Opera/i', $ua)) $browser = 'Opera'; 
else if (preg_match('/MSIE/i', $ua)) $browser = 'IE'; 
else if (preg_match('/Mozilla/i', $ua)) $browser = 'Mozilla'; 
else if (preg_match('/ucweb/i', $ua)) $browser = 'UCWeb'; 
else $browser = 'Неизвестно'; 
return $browser;
	}
	

function getCI($url)
    {
     	$url = str_replace("http://", "", $url);
     	$url = str_replace("www.", "", $url);
     	$url = str_replace("wap.", "", $url);
     	$ci_url = "http://bar-navig.yandex.ru/u?ver=2&show=32&url=http://www.".$url."/";
     	$ci_data = implode("", file("$ci_url"));
     	preg_match("/value=\"(.\d*)\"/", $ci_data, $ci);
		if ($ci[1] == "")
      	return 0; // Если не смогли определить ТИЦ...
     	else
      	return $ci[1]; // Вот оно счастье...
    }
///////////////////PR

$googlehost='toolbarqueries.google.com';
$googleua='Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5';

function StrToNum($Str, $Check, $Magic) {
    $Int32Unit = 4294967296;
    $length = strlen($Str);
    for ($i = 0; $i < $length; $i++) {
        $Check *= $Magic;
        if ($Check >= $Int32Unit) {
            $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit));
            $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check;
        }
        $Check += ord($Str{$i});
    }
    return $Check;
}

function HashURL($String) {
    $Check1 = StrToNum($String, 0x1505, 0x21);
    $Check2 = StrToNum($String, 0, 0x1003F);

    $Check1 >>= 2;
    $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F);
    $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF);
    $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF);

    $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F );
    $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 );

    return ($T1 | $T2);
}

function CheckHash($Hashnum) {
    $CheckByte = 0;
    $Flag = 0;

    $HashStr = sprintf('%u', $Hashnum) ;
    $length = strlen($HashStr);

    for ($i = $length-1; $i >= 0;  $i--) {
        $Re = $HashStr{$i};
        if (1 === ($Flag % 2)) {
            $Re += $Re;
            $Re = (int)($Re / 10) + ($Re % 10);
        }
        $CheckByte += $Re;
        $Flag ++;
    }

    $CheckByte %= 10;
    if (0 !== $CheckByte) {
        $CheckByte = 10 - $CheckByte;
        if (1 === ($Flag % 2) ) {
            if (1 === ($CheckByte % 2)) {
                $CheckByte += 9;
            }
            $CheckByte >>= 1;
        }
    }

    return '7'.$CheckByte.$HashStr;
}
function redirect($url) {
    header('location: '.$url);
    exit;
}

function bbpanel($form, $field) {
	return '<script language="JavaScript" type="text/javascript">
	function tag(text1, text2) {
	if ((document.selection)) {
		document.' . $form . '.' . $field . '.focus();
		document.' . $form . '.document.selection.createRange().text = text1+document.' . $form . '.document.selection.createRange().text+text2;
	} else if(document.forms[\'' . $form . '\'].elements[\'' . $field . '\'].selectionStart!=undefined) {
		var element = document.forms[\'' . $form . '\'].elements[\'' . $field . '\'];
		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 . '.' . $field . '.value += text1+text2;
	}
	</script>
	<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
	
	<a href="javascript:tag(\'[b]\', \'[/b]\')"><img src="/images/bb/bold.png" alt="b" title="Жирный"/></a>
	<a href="javascript:tag(\'[i]\', \'[/i]\')"><img src="/images/bb/italic.png" alt="i" title="Наклонный"/></a>
	<a href="javascript:tag(\'[u]\', \'[/u]\')"><img src="/images/bb/underline.png" alt="u" title="Подчёркнутый"/></a>
	<a href="javascript:tag(\'[strike]\', \'[/strike]\')"><img src="/images/bb/strike.png" alt="s" title="Перечёркнутый"/></a>
	<a href="javascript:tag(\'[url=]\', \'[/url]\')"><img src="/images/bb/link.png" alt="url" title="Ссылка" /></a>
	<a href="javascript:tag(\' :)\', \'\')"><img src="/images/smiles/1.gif" alt=":)" title=":)" /></a>
	<a href="javascript:tag(\' :(\', \'\')"><img src="/images/smiles/7.gif" alt=":(" title=":(" /></a>
	<a href="javascript:tag(\' ;/\', \'\')"><img src="/images/smiles/33.gif" alt=";/" title=";/" /></a>
	';

}
function id($login){

    $login = mysqli_real_escape_string($mysqli,htmlspecialchars(trim($login)));
    $user_r = mysqli_query($mysqli,"SELECT `id` FROM `top_users` WHERE `login` = '$login'");
    $user = mysqli_fetch_assoc($user_r);
    if (isset($user['id'])) {
        return $user['id'];
    }
    return FALSE;
}
function login($id, $type) {
	// types: 0 "just login from DB", 1 "login + color", 2 "icon, login & color"
	// типы: 0 "просто логин с БД", 1 "логин + цвет", 2 "иконка, логин и цвет"
    if ($id == 0) {
		switch ($type) {
			case '1': $user['login'] = 'Гость'; break;
			case '2': $user['login'] = '<img src="../images/icons/g.png" alt="" /> Гость'; break;
			default: $user['login'] = 'Гость'; break;
		}
    } elseif ($id == -1) {
		switch ($type) {
			case '1': $user['login'] = 'System'; break;
			case '2': $user['login'] = '<img src="../images/icons/s.png" alt="" /> System'; break;
			default: $user['login'] = 'System'; break;
		}
    } else {
        $user_r = mysqli_query($mysqli,"SELECT `login`, `level` FROM `top_users` WHERE `id` = '$id'");
        $user = mysqli_fetch_assoc($user_r);
        if ($user['login']) {
			switch ($type) {
				case '1':
					switch($user['level']) {
						case '1': $user['login'] = '<font color="green">'.$user['login'].'</font>'; break;
						
						case '2': $user['login'] = '<font color="blue">'.$user['login'].'</font>'; break;
						case '3': $user['login'] = '<font color="red">'.$user['login'].'</font>'; break;
						case '4': $user['login'] = '<font color="red">'.$user['login'].'</font>'; break;
						default: $user['login'] = $user['login']; break;
					}
				break;
				
				case '2':
					switch($user['level']) {
						case '1': $user['login'] = '<img src="../images/icons/m'.$user['gender'].'.png" alt="" /> <font color="green">'.$user['login'].'</font>'; break;
						
case '2': $user['login'] = '<img src="../images/icons/m'.$user['gender'].'.png" alt="" /> <b><font color="blue">'.$user['login'].'</font><font color="green"> [мод]</font></b>'; break;
case '3': $user['login'] = '<img src="../images/icons/a'.$user['gender'].'.png" alt="" /><b> <font color="red">'.$user['login'].'</font><font color="green"> [адм]</font></b>'; break;
case '4': $user['login'] = '<img src="../images/icons/3000.png" alt="" /> <b><font color="#9A32CD">'.$user['login'].'</font><font color="green"> [соз]</font> </b>'; break;
						default: $user['login'] = '<img src="../images/icons/u'.$user['gender'].'.png" alt="" /> '.$user['login']; break;
					}
				break;
				
				default:
					$user['login'] = $user['login'];
				break;
			}
        } else {
			switch ($type) {
				case '1': $user['login'] = '<font color="grey">Удален</font>'; break;
				case '2': $user['login'] = '<img src="../images/icons/g.png" alt="" /> <font color="grey">удален</font>'; break;
				default: $user['login'] = 'удален'; break;
			}
        }
    }
	return $user['login'];
}
function error($error){
    echo '<div class="title">ϸ颪ힹ�/div><div class="body">'.$error;
    return;
}

function ext($filename) {
    return substr(strrchr($filename, '.'), 1);
}

function generate($number){
    $arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','R','S','T','U','V','X','Y','Z','1','2','3','4','5','6','7','8','9','0');  
    // ĥ鱳檠𐡰לּ  
    $pass = '';  
    for($i = 0; $i < $number; $i++){
        // û�檠򬴷᪭硨믠�򩣠
        $index = rand(0, count($arr) - 1);
        $pass .= $arr[$index];  
    }
    return $pass;  
}

function nav($link){
    echo '<br /><a href="'.$link.'">Назад</a></div>';
    return;
}
function access ($access) {
    global $u;
    if ($u['id']) {
        if ($u['level'] == $access or $u['level'] > $access) {
            return true;
        }
    }
    return false;
}

function getch($url) { return CheckHash(HashURL($url)); }

function getpr($url) {
    global $googlehost,$googleua;
    $ch = getch($url);
    $fp = fsockopen($googlehost, 80, $errno, $errstr, 30);
    if ($fp) {
        $out = "GET /tbr?features=Rank&sourceid=navclient-ff&client=navclient-auto-ff&ch=$ch&q=info:$url HTTP/1.1\r\n";
        $out .= "User-Agent: $googleua\r\n";
        $out .= "Host: $googlehost\r\n";
        $out .= "Connection: Close\r\n\r\n";

        fwrite($fp, $out);
        while (!feof($fp)) {
            $data = fgets($fp, 128);
            $pos = strpos($data, "Rank_");
            if($pos === false){

			} else{
                $pr=substr($data, $pos + 9);
                $pr=trim($pr);
                $pr=str_replace("\n",'',$pr);
				if ($pr == "") {return 0;}
				else {
                return $pr;
				}
            }
         }
         fclose($fp);
     }

}

?>