Файл: rayb.me/system/func.php
Строк: 227
<?php
list($msec,$sec) = explode(chr(32), microtime());
$gtime = $sec+$msec;
$HOME = 'https://'.$_SERVER['HTTP_HOST'];
require_once ('connect.php');
function go($url){
header("Location: ".$url);
exit;
}
if(is_array($_GET) || is_object($_GET)){
foreach($_GET as $l){
if(!is_string($l) || !preg_match('#^(?:[a-z0-9_-/]+|.+(?!/))*$#i', $l)){
go($HOME);
}
}
unset($l);
}
function strlen2($s){
$r = array('й','ц','у','к','е','н','г','ш','щ','з','х','ъ','ф','ы','в','а','п','р','о','л','д','ж','э','я','ч','с','м','и','т','ь','б','ю','Й','Ц','У','К','Е','Н','Г','Ш','Щ','З','Х','Ъ','Ф','Ы','В','А','П','Р','О','Л','Д','Ж','Э','Я','Ч','С','М','И','Т','Ь','Б','Ю');
return strlen(str_replace($r, '0', $s));
}
function num($m){
if(!is_numeric($m)){
$m = htmlspecialchars(trim($m), ENT_QUOTES, 'utf8mb4');
$m = DB::escape($m);
}else{
$m = intval($m);
$m = abs($m);
}
return $m;
}
function text($m){
$m = htmlspecialchars($m);
$m = DB::escape($m);
return $m;
}
function salt_sha1_md5($v){
$s = 'raybme';
return sha1(md5($s.$v));
}
function href($u){
$h = 'href="'.$u.'"';
return $h;
}
if(isset($_COOKIE['login']) and isset($_COOKIE['password'])){
$login = text($_COOKIE['login']);
$password = text($_COOKIE['password']);
$dbs = DB::Query("SELECT * FROM `users` WHERE `login` = '".$login."' and `password` = '".$password."' LIMIT 1");
$user = mysqli_fetch_assoc($dbs);
if(isset($user['id'])){
if($user['login'] != $login or $user['password'] != $password) {
setcookie("login", "", time() - 86400 * 31, "/");
setcookie("password", "", time() - 86400 * 31, "/");
header('Location: '.$HOME.'');
}
}
$users = mysqli_fetch_assoc(DB::Query("SELECT * FROM `users` WHERE `login` = '".$login."' and `password`='".$password."' LIMIT 1"));
DB::Query("UPDATE `users` SET `viz`='".time()."', `ip`='".text($_SERVER['REMOTE_ADDR'])."',`browser`='".text($_SERVER['HTTP_USER_AGENT'])."',`fix_mesto`='".text($_SERVER['REQUEST_URI'])."' WHERE `id`='".$users['id']."'");
$vremja = time() - $users['viz'];
if($vremja < 120) {
$newtime = $user['online'] + $vremja;
DB::Query("UPDATE `users` SET `online` ='".$newtime."' WHERE `id`='".$users['id']."'");
}
if(isset($user['id']) && $users['login']!=$login or $users['password']!=$password) {
setcookie("login", "", time() - 86400 * 31, "/");
setcookie("password", "", time() - 86400 * 31, "/");
go($HOME);
}
}
$mmsec = (isset($money_updater[0]) * isset($p));
$mdsec = (isset($money_updater[0]) * isset($p));
$myLogin = isset($user) ? $user['login'] : null;
$myID = isset($user) ? $user['id'] : null;
$ulogin = isset($user) ? $user['login'] : null;
$uid = isset($user) ? $user['id'] : null;
define ('H',$_SERVER['DOCUMENT_ROOT'].'/');
$_times = 2;
DB::Query("update `users` set `online` = '".time()."' where (`id` = '".$uid."')");
$money_updater = mysqli_fetch_array(DB::Query("SELECT SUM(`money_sek`) FROM `room_users` WHERE `id_user` = '".$uid."'"));
$acp = mysqli_fetch_array(DB::Query("SELECT SUM(`angels`) FROM `users` WHERE `id_clan` = '".$user['id_clan']."'"));
if($user['id_clan'] >= 1 and $acp[0] >= 100){
$kol = ($acp[0] / 100);
$p = ($kol * $user['x2'] * $user['g_x2']);
}else{
if($user['angels'] < 100){
$p = ($user['x2'] * $user['g_x2']);
}else{
$koll = ($user['angels'] / 100);
$p = ($koll * $user['x2'] * $user['g_x2']);
}
}
if($user['online'] > 1) $times_up = (((time() - $user['online']) * text($money_updater[0] * $p)));
DB::Query("UPDATE `users` SET `gold` = `gold` + '$times_up' WHERE `id` = '$uid'");
if (DB::result(DB::Query("SELECT COUNT(*) FROM `users_count` WHERE `id_user` = '".$uid."'"), 0) == 0)
DB::Query("INSERT INTO `users_count` (`id_user`) VALUES ('".$uid."')");
if (DB::result(DB::Query("SELECT COUNT(*) FROM `sahta` WHERE `id_user` = '".$uid."'"), 0) == 0)
DB::Query("INSERT INTO `sahta` (`id_user`) VALUES ('".$uid."')");
require_once ('func.icons.php');
require_once ('func.msg.php');
function ico($d, $f){
$i = '<img src="/img/'.$d.'/'.$f.'" width="20px" alt="*" />';
return $i;
}
function img($d, $f){
$i = '<img src="/img/'.$d.'/'.$f.'" alt="*" />';
return $i;
}
function time_last($time){
$sec = time()-$time;
if($sec < 60) $_time = $sec." сек. назад";
if($sec >= 60 && $sec < (60*60)) $_time = round($sec/60)." мин. назад";
if($sec >= (60*60) && $sec < ((60*60)*6))$_time = "Сегодня в ".date("H:i",$time);
if($sec >= ((60*60)*6) && $sec < ((60*60)*24)) $_time = round($sec/(60*60))." час. назад";
if($sec >= ((60*60)*24) && $sec < (((60*60)*24)*2)) $_time = "Вчера в ".date("H:i",$time);
if($sec >= (((60*60)*24)*2)){
$__time = date("d F Y в H:i", $time);
$__time = str_replace("January","января",$__time);
$__time = str_replace("February","февраля",$__time);
$__time = str_replace("March","марта",$__time);
$__time = str_replace("April","апреля",$__time);
$__time = str_replace("May","мая",$__time);
$__time = str_replace("June","июня",$__time);
$__time = str_replace("July","июля",$__time);
$__time = str_replace("August","августа",$__time);
$__time = str_replace("September","сентября",$__time);
$__time = str_replace("October","октября",$__time);
$__time = str_replace("November","ноября",$__time);
$__time = str_replace("December","декабря",$__time);
$_time = $__time;
}
return $_time;
}
function tl($tl){
$d=3600*24;
$day=floor($tl/$d);
$tl=$tl-($d*$day);
$hour=floor($tl/3600);
$tl=$tl-(3600*$hour);
$minute=floor($tl/60);
$tl=$tl-(60*$minute);
$second=floor($tl);
$dayt="".($day>0?"".$day." д. ":null)."";
$hourt="".($hour>0?"".$hour." ч. ":null)."";
$minutet="".($minute>0?"".$minute." м. ":null)."";
$secondt="".($second>0?"".$second." с. ":null)."";
if($day>0){
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0){
$secondt=NULL;
$dayt=NULL;
}
return "$dayt$hourt$minutet$secondt";
} /* Вывод оставшегося времени */
function tls($tls){
$d=3600*24;
$day=floor($tls/$d);
$tls=$tls-($d*$day);
$hour=floor($tls/3600);
$tls=$tls-(3600*$hour);
$minute=floor($tls/60);
$tls=$tls-(60*$minute);
$second=floor($tls);
$tlss=(($hour*3600)+($minute*60))+$second;
$dayt="".($day>0?"".$day." д. ":null)."";
$hourt="".($hour>0?"".$hour." ч. ":null)."";
$minutet="".($minute>0?"".$minute." м. ":null)."";
$secondt="".($second>0?"".$second." с. ":null)."";
if($day>0){
$minutet=NULL;
$secondt=NULL;
}
if($hour>0 && $day==0){
$secondt=NULL;
$dayt=NULL;
}
return "".$tlss."";
} /* Вывод оставшегося времени в секундах */
function vremja($time=NULL){
if ($time == NULL)$time = time();
$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 ($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;
}
function time_count($timediff , $as = 0 , $ass = 0, $asss = 0, $assss = 0 , $text_view = 0, $text ='') {
$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
if ($as == true && $dayfield != 0)
{
$d="$dayfield д.";
}else{
$d= NULL;
}
if ($ass == true && $hourfield != 0)
{
$h=" $hourfield ч. ";
}else{
$h= NULL;
}
if ($asss == true && $minutefield != 0)
{
$m=" $minutefield м. ";
}else{
$m= NULL;
}
if ($assss == true && $secondfield != 0)
{
$s=" ".$secondfield." с.";
}else{
$s= NULL;
}
if ($d <0 || $h < 0 || $m < 0 || $s < 0){
if ($text_view == true ){
if ($text == NULL)
$view= 'Время истекло';
else
$view= $text;
}else{
$view = NULL;
}
}else{
$view = $d . $h . $m . $s;
}
return $view;
}
$forum_antispam = mysqli_fetch_assoc(DB::Query("SELECT * FROM `guard` WHERE `id` = '1' "));
$qq = mysqli_fetch_assoc(DB::Query("SELECT * FROM `quest` WHERE `user` = '".$user['id']."' "));
$guest = mysqli_fetch_assoc(DB::Query("SELECT * FROM `guests` WHERE `ip` = '" . text($_SERVER['REMOTE_ADDR']) . "' and `browser`='" . text($_SERVER['HTTP_USER_AGENT']) . "'"));
if ($guest == 0) {
DB::Query("INSERT INTO `guests` SET `ip` = '" . text($_SERVER['REMOTE_ADDR']) . "',`browser` = '" . text($_SERVER['HTTP_USER_AGENT']) . "', `time` = '" . time() . "'");
}
if ($guest != 0) {
DB::Query("UPDATE `guests` SET `time` = '" . text(time()) . "' WHERE `id` = '" . $guest['id'] . "' LIMIT 1");
DB::Query("UPDATE `users` SET `ref` = '" .text($_SERVER['REQUEST_URI']). "' WHERE `id` = '" . $user['id'] . "' limit 1");
}
if(isset($user['id']) && $_SERVER['PHP_SELF'] != '/index.php' && $_SERVER['PHP_SELF'] != '/save.php' && $user['save']!=1){
$_SESSION['msg']='Для полного доступа к игре необходимо сохраниться';
go('/save.php');
}
/*
if($user['test']<1){
if(isset($user['id']) && $_SERVER['PHP_SELF'] != '/index.php' && $_SERVER['PHP_SELF'] != '/those.php' && $user['test']!=1){
go('/those.php');
}
}else{
if(isset($user['id']) && $_SERVER['PHP_SELF'] != '/index.php' && $_SERVER['PHP_SELF'] != '/save.php' && $user['save']!=1){
$_SESSION['msg']='Для полного доступа к игре необходимо сохраниться';
go('/save.php');
}
}
*/
function noauth() {
global $user;
if (isset($user['id'])){
go('/game/');
}
}
function auth() {
global $user;
if(!isset($user['id'])){
go('/login');
}
}
function antihack() {
global $user;
if($user['id'] == 0){
$err = 'Ошибка';
$_SESSION['msg'] = $err;
go('/');
}
if($user['login'] == null){
$err = 'Ошибка';
$_SESSION['msg'] = $err;
go('/');
}
if($user['ip'] == 0){
$err = 'Ошибка';
$_SESSION['msg'] = $err;
go('/');
}
if($user['online'] == 0){
$err = 'Ошибка';
$_SESSION['msg'] = $err;
go('/');
}
if($user['registr'] == 0){
$err = 'Ошибка';
$_SESSION['msg'] = $err;
go('/');
}
}
function page($k_page = 1){
$page = 1;
if(isset($_GET['page'])){
if($_GET['page'] == 'end') $page = intval($k_page);
elseif(is_numeric($_GET['page'])) $page = 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;
}
function str($link = '?', $k_page = 1, $page = 1) {
if ($page < 1) $page = 1;
echo '<div class="content"></div><center>';
if ($page != 1) echo "<a class='pg' href="" . $link . "page=1"><<</a> ";
else echo "<span class='bnt1 pg'>1</span> ";
for ($ot = - 2;$ot <= 2;$ot++) {
if ($page + $ot > 1 && $page + $ot < $k_page) {
if ($ot == - 3 && $page + $ot > 2) echo "";
if ($ot != 0) echo "<a class='pg' href="" . $link . "page=" . ($page + $ot) . "">" . ($page + $ot) . "</a> ";
else echo " <span class='bnt1 pg'> " . ($page + $ot) . "</span> ";
if ($ot == 2 && $page + $ot < $k_page - 1) echo "";
}
}
if ($page != $k_page) echo "<a class='pg' href="" . $link . "page=end"> >></a>";
else echo "<span class='bnt1 pg'>" . $page . "</span> ";
echo "</center>n";
}
require_once ('nf.php');