Файл: public_html/core/func.php
Строк: 374
<?php
/* SYSTEM FILE */
isset($_GET['act']) ? $act=fl($_GET['act']) : '';
session_start();
ob_start();
function fl($m){
global $db;
if(!is_numeric($m)){
$m = htmlspecialchars(trim($m));
} else {
$m = intval(abs($m));
}
return $db->real_escape_string($m);
} /* FILTER */
if(isset($_COOKIE['login']) && isset($_COOKIE['password'])) {
$u = $base -> query("SELECT * FROM `users` WHERE `login` = '".fl($_COOKIE['login'])."' && `password` = '".fl($_COOKIE['password'])."' LIMIT 1") -> fetch_assoc();
if(($u['login'] !== $_COOKIE['login']) or ($u['password'] !== $_COOKIE['password'])){
setcookie("login", "", time() - 3600*24*30*12, "/");
setcookie("password", "", time() - 3600*24*30*12, "/");
header('Location: /');
}
} /* COOKIE */
function trueauth() {
global $u;
if(isset($u)) header('Location: /');
} /* GUEST */
function falseauth($save = null) {
global $u;
if(!isset($u)) header('Location: /');
if($save != null)
{
if($u['save'] == 0) header("Location: /");
}
} /* USER */
function panel() {
global $u;
if($u['admin'] == 0) header('Location: /');
} /* LOCK PANEL */
function sup() {
global $u;
if($u['admin'] < 1) header('Location: /');
} /* LOCK PANEL SUPPORT */
function mod() {
global $u;
if($u['admin'] < 2) header('Location: /');
} /* LOCK PANEL MODER */
function adm() {
global $u;
if($u['admin'] < 3) header('Location: /');
} /* LOCK PANEL ADMIN */
function error($error) {
echo '<div class="error"> '.fl($error).' </div>';
} /* ERROR MESSAGE */
function success($success) {
echo '<div class="success"> '.fl($success).' </div>';
} /* SUCCESS MESSAGE */
function unsave(){
global $u;
if($u['save'] == 0){
echo '<div class="error"> Ваш персонаж не был сохранен </div>';
include_once 'foot.php';
die();
}
}
function tm($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", $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 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){ // Вывод номеров страниц (только на первый взгляд кажется сложно ;))
echo '<div class = "b-mini"><div class="container">
<nav class="pagination">';
if ($page<1)$page=1;
//if ($page!=1)echo "<a class='btn _green' href="".$link."page=1" title='Первая страница'><<</a> ";
if ($page!=1)echo "<a href="".$link."page=1" title='Страница №1' class='prev'>1</a> ";
else echo "<span>1</span> ";
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)."" title='Страница №".($page+$ot)."'>".($page+$ot)."</a> ";
else echo "<span>".($page+$ot)."</span> ";
if ($ot==3 && $page+$ot<$k_page-1)echo " ";}}
if ($page!=$k_page)echo "<a href="".$link."page=end" title='Страница №$k_page'>$k_page</a> ";
elseif ($k_page>1)echo "<span>$k_page</span>";
//if ($page!=$k_page)echo "<a class='btn _blue' href="".$link."page=end" title='Последняя страница'>></a> ";
echo ' </nav>
</div></div>';
}
?>
<style>
@font-face {
font-family: ariales-matic;
src: url(css/ariales-matic.ttf);
}
.shrif {
font-family: ariales-matic, arial;
font-size: 20px;
}
</style>
<?
function db_size($data) {
if ($data < 1024) {
return $data . " bytes";
} else if ($data < 1024000) {
return round(( $data / 1024), 1) . " KB";
} else {
return round(( $data / 1024*1024), 1) . " MB";
}
}
function who($id = 0) {
global $base;
$w = $base-> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
if($w['admin'] == 1) $nick = '<span class="sup">'.$w['login'].'</span>';
elseif($w['admin'] == 2) $nick = '<span class="mod">'.$w['login'].'</span>';
elseif($w['admin'] == 3) $nick = '<span class="adm">'.$w['login'].'</span>';
else $nick = '<span class="ln">'.$w['login'].'</span>';
return (empty($w) ? 'Удален':' <a href="/user/'.$w['id'].'/">'.$nick.'</a>');
}
function name($id = 0, $replyStatus = 0) {
global $base;
$w = $base-> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
if($replyStatus == 1)
{
return (empty($w) ? '' : $w['login'].', ');
}
else
{
if($w['admin'] == 1) $nick = '<span class="sup">'.$w['login'].'</span>';
elseif($w['admin'] == 2) $nick = '<span class="mod">'.$w['login'].'</span>';
elseif($w['admin'] == 3) $nick = '<span class="adm">'.$w['login'].'</span>';
else $nick = $w['login'];
return (empty($w) ? 'Удален': $nick);
}
}
function translite($str){
$ok = array(
"А"=>"a","Б"=>"b","В"=>"v","Г"=>"g",
"Д"=>"d","Е"=>"e","Ж"=>"j","З"=>"z","И"=>"i",
"Й"=>"y","К"=>"k","Л"=>"l","М"=>"m","Н"=>"n",
"О"=>"o","П"=>"p","Р"=>"r","С"=>"s","Т"=>"t",
"У"=>"u","Ф"=>"f","Х"=>"h","Ц"=>"ts","Ч"=>"ch",
"Ш"=>"sh","Щ"=>"sch","Ъ"=>"","Ы"=>"yi","Ь"=>"",
"Э"=>"e","Ю"=>"yu","Я"=>"ya","а"=>"a","б"=>"b",
"в"=>"v","г"=>"g","д"=>"d","е"=>"e","ж"=>"j",
"з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
"м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
"с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
"ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
"ы"=>"yi","ь"=>"","э"=>"e","ю"=>"yu","я"=>"ya",
" -"=> "", ","=> "", " "=> "-", "."=> "", "/"=> "_",
"-"=> ""
);
return strtr($str,$ok);
}
function get_energy($id=0){
global $base;
$g = $base -> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
$energy = $g['energy'];
return $energy;
}
function get_health($id=0){
global $base, $u;
$g = $base -> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
$itemsParams = getWearedItem($id,'head',1)->health + getWearedItem($id,'body',1)->health + getWearedItem($id,'boots',1)->health + getWearedItem($id,'weapon',1)->health;
$vipBoost = getVipBoost($id);
$altarBoost = getAltarBoost($id);
$max_health = $g['max_health']+$itemsParams+getAllianceBuffParams($id)+$vipBoost->params;
$trainBoost = $g['health_train']*5;
$tower = $base->query("SELECT * FROM `towers` WHERE `user` = '".$u['id']."'")->fetch_object();
$wizard = getWizardParams($tower->wizard_level);
$m_h = $max_health+round($max_health*$altarBoost->params)+$trainBoost+$wizard['currentParams'];
if($g['demonstime'] >= time()) $m_h += round($m_h*0.1);
return $m_h;
}
function get_max_health($id=0)
{
return get_health($id);
}
function get_max_energy($id=0){
global $base;
$g = $base -> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
$max_energy = $g['max_energy'];
return $max_energy;
}
function get_power($id=0){
global $base, $u;
$g = $base -> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
$itemsParams = getWearedItem($id,'head',1)->power + getWearedItem($id,'body',1)->power + getWearedItem($id,'boots',1)->power + getWearedItem($id,'weapon',1)->power;
$vipBoost = getVipBoost($id);
$altarBoost = getAltarBoost($id);
$trainBoost = $g['power_train']*5;
$tower = $base->query("SELECT * FROM `towers` WHERE `user` = '".$u['id']."'")->fetch_object();
$wizard = getWizardParams($tower->wizard_level);
$power = $g['power']+$itemsParams+getAllianceBuffParams($id)+$vipBoost->params;
$pow = $power+round($power*$altarBoost->params)+$trainBoost+$wizard['currentParams'];
if($g['demonstime'] >= time()) $pow += round($pow*0.1);
return $pow;
}
function get_block($id=0){
global $base, $u;
$g = $base -> query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1") -> fetch_assoc();
$itemsParams = getWearedItem($id,'head',1)->block + getWearedItem($id,'body',1)->block + getWearedItem($id,'boots',1)->block + getWearedItem($id,'weapon',1)->block;
$vipBoost = getVipBoost($id);
$altarBoost = getAltarBoost($id);
$trainBoost = $g['block_train']*5;
$tower = $base->query("SELECT * FROM `towers` WHERE `user` = '".$u['id']."'")->fetch_object();
$wizard = getWizardParams($tower->wizard_level);
$block = $g['block']+$itemsParams+getAllianceBuffParams($id)+$vipBoost->params;
$bl = $block+round($block*$altarBoost->params)+$trainBoost+$wizard['currentParams'];
if($g['demonstime'] >= time()) $bl += round($bl*0.1);
return $bl;
}
function generateCode($length = 8){
$chars = 'ABCDEFHIKNRSTYZOMGabdefhiknrstyzomg1234567890';
$numChars = strlen($chars);
$string = '';
for ($i = 0; $i < $length; $i++){
$string .= substr($chars, rand(1, $numChars) - 1, 1);
}
return md5($string);
}
function makeUserPayment($user_id, $gems, $silver)
{
global $db;
$count = $db->query("SELECT * FROM `users` WHERE `id` = '".$user_id."'")->num_rows;
$db->query("UPDATE `users` SET `gold` = `gold` - '".$gems."', `silver` = `silver` - '".$silver."' WHERE `id` = '".$user_id."'");
return true;
}
function getWearedItem($user_id, $type, $stats = 0)
{
global $db;
$sql = $db->query("SELECT * FROM `users` WHERE `id` = '".$user_id."'");
$res = $sql->fetch_object();
$itemInInventory = $db->query("SELECT * FROM `inventory` WHERE `id` = '".$res->$type."'");
$itemInfo = $itemInInventory->fetch_object();
$item = $db->query("SELECT * FROM `subject` WHERE `id` = '".$itemInfo->item."'")->fetch_object();
if($stats == 0) return ($res->$type != 0 ? '<a href="/user/'.$user_id.'/item/'.$res->$type.'"><img src="'.$item->images.'" width="45" height="45"></a>' : '<img src="/images/not-equipment.png" width="43" height="41">');
else
{
$boost = getSlotBoost($user_id, $type);
$stonesBoost = getItemStonesBoost($res->$type);
if($res->$type == 0) return (object)["health" => 0, "power" => 0, "block" => 0];
else return (object)["health" => $item->health+$boost+$stonesBoost, "power" => $item->power+$boost+$stonesBoost, "block" => $item->block+$boost+$stonesBoost];
}
}
function getSlotBoost($uid, $type)
{
global $db;
$slotType = $type.'_slot_level';
$usInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$uid."'")->fetch_object();
if($usInfo->$slotType == 1) $boost = 1;
else
{
$buffInfo = $db->query("SELECT * FROM `slot_upgrade_levels` WHERE `level` = '".$usInfo->$slotType."'")->fetch_object();
$boost = $buffInfo->buff;
}
return $boost;
}
function getItemStonesBoost($item_id)
{
global $db;
$stonesInfo = $db->query("SELECT * FROM `stones_item` WHERE `item` = '".$item_id."'");
if($stonesInfo->num_rows == 0)
{
return 0;
}
else
{
$stones_buff = [null,25,50,250,500,2500,5000];
$result = 0;
while($sI = $stonesInfo->fetch_object())
{
$result += $stones_buff[$sI->type];
}
return $result;
}
}
function getAltarBoost($uid)
{
global $db;
$userInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$uid."'")->fetch_object();
if($userInfo->alliance_id == 0) return (object)["mest" => 0, "exp" => 0, "params" => 0, "silver" => 0];
else
{
$allInfo = $db->query("SELECT * FROM `alliances` WHERE `id` = '".$userInfo->alliance_id."'")->fetch_object();
if($allInfo->altar_level == 0) return (object)["mest" => 0, "exp" => 0, "params" => 0, "silver" => 0];
else return (object)["mest" => $allInfo->altar_level, "exp" => $allInfo->altar_level*5/100, "params" => $allInfo->altar_level*2/100, "silver" => $allInfo->altar_level*5/100];
}
}
function msg($msg)
{
return $_SESSION['message'] = $msg;
}
function redirect($location, $msg=null)
{
if($msg != null) msg($msg);
header("Location: ".$location);
exit;
}
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 smiles($t)
{
global $db;
$smilesInfo = $db->query("SELECT * FROM `smiles`");
while($sm = $smilesInfo->fetch_object())
{
$t = str_replace($sm->tag, '<img src="'.$sm->image.'" alt="*" width="35px">', $t);
}
return $t;
}
function viewText($text, $smiles, $bbcodes)
{
if($smiles > 0) $res = smiles($text);
else $res = $text;
$res = Text_Censure::parse($res, 10, "xe2x80xa6", true, "* ");
return $res;
}
function getAllianceBuffParams($uid)
{
global $db;
$usInfo = $db->query("SELECT * FROM `users` WHERE `id` = '".$uid."'")->fetch_object();
if($usInfo->alliance_id == 0) return 0;
else
{
$allInfo = $db->query("SELECT * FROM `alliances` WHERE `id` = '".$usInfo->alliance_id."'")->fetch_object();
$param = 5*$allInfo->level;
return $param;
}
}
/*
*
Округление
*
*/
function getLastNumber($num) {
if($num <= 1000) $_num = $num;
if($num >= 1000) $_num = round($num / 1000, 2).'k';
if($num >= 1000000) $_num = round($num / 1000000, 2).'m';
if($num >= 1000000000) $_num = round($num / 1000000000, 2).'g';
if($num >= 1000000000000) $_num = round($num / 1000000000000, 2).'t';
return $_num;
}