<?php
class Func {
public static function addCastleJournal($castleID, $text, $time_log) {
DB::getInstance()->query("INSERT INTO `castle_journal` (`id_castle` ,`text` ,`time` , `date`) VALUES (?,?,?,?)", [$castleID, $text, time(), $time_log]);
}
public static function addNotification($userID, $text, $time_log) {
DB::getInstance()->query("INSERT INTO `user_notification` (`id_user` ,`text` ,`time` , `date` ,`read`) VALUES (?,?,?,?,?)", [$userID, $text, time(), $time_log, 'no']);
}
public static function getPointGlory($rewardPointGlory) {
global $u;
$rewardPointGlory = ceil($rewardPointGlory / rand(60, 100));
DB::getInstance()->query("UPDATE `users` SET `pointGlory` = ? WHERE `id` = ?", [$u['pointGlory'] + $rewardPointGlory, $u['id']]);
}
public static function addTimeAfterFight($numFight, $nameNumColumFight, $nameColumTime, $nameTableLocation) {
global $u;//global u;
if ($numFight <= 5) {
$addTime = array(15, 30, 45, 60, 75, 90);//Time wait
DB::getInstance()->query("UPDATE `" . $nameTableLocation . "` SET `" . $nameColumTime . "` = ? WHERE `id_user` = ? ", [$nameTableLocation[$nameNumColumFight] + time() + 60 * $addTime[$numFight], $u['id']]);
DB::getInstance()->query("UPDATE " . USERS . " SET `" . $nameNumColumFight . "` = ? WHERE `id` = ? ", [$u[$nameNumColumFight] + 1, $u['id']]);
} else {
DB::getInstance()->query("UPDATE `" . $nameTableLocation . "` SET `" . $nameColumTime . "` = ? WHERE `id_user` = ? ", [$nameTableLocation[$nameNumColumFight] + time() + 60 * 120, $u['id']]);
}
}
public static function userCastleIcon($idCastle) {
$user_castle = DB::getInstance()->queryFetch("SELECT `kindom` FROM `castles` WHERE `id` = ? ", [$idCastle]); //Clan user
if ($user_castle) {
$ico = '<img src="/modules/castle/images/ico/' . $user_castle['kindom'] . '.png">';
return $ico;
}
}
public static function smallAvatarImg($sex) {
if ($sex == 'male')
$img = '/images/icons/male.png" width="25px"';
else if ($sex == 'female') {
$img = '/images/icons/female.png" width="25px"';
} else {
}
return $img;
}
public static function a_href($text) {
$link = '<a href="' . $text . '">';
return $link;
}
public static function cut_text($text, $maxwords = 50, $maxchar = 50) {
$sep = ' ';
$words = explode($sep, $text);
$char = iconv_strlen($text, 'utf-8');
if (count($words) > $maxwords) {
$text = join($sep, array_slice($words, 0, $maxwords));
}
if ($char > $maxchar) {
$sep2 = '...';
$text = iconv_substr($text, 0, $maxchar, 'utf-8');
}
return $text . $sep2;
}
public static function div($dir) {
return '<div class="' . $dir . '"> ';
}
public static function color($dir) {
return '<font color="' . $dir . '"> ';
}
public static function span($dir) {
$span = '<span class="' . $dir . '"> ';
return $span;
}
public static function img_icon25px($dir) {
$img = '<img src="/images/icons/' . $dir . '.png" width="25px" alt="IMAGE" />';
return $img;
}
public static function hrefLink($temp) {
$link = '<a href="/' . $temp . '">';
return $link;
}
public static function action($act) {
return isset($_GET[$act]) ? self::clearString($_GET[$act]) : '';
}
public static function online($time, $user) {
if ($user < $time)
$status = color('lime') . ' онлайн' . COLOR_CLOSE;
else
$status = color('tomato') . ' оффлайн' . COLOR_CLOSE;
return $status;
}
public static function output($string) {
$string = self::clearFullSpecialChars($string);
$string = nl2br($string);
return $string;
}
public static function clearFullSpecialChars($string) {
$string = filter_var($string, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$string = htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
return strip_tags(trim(strtr(htmlentities(stripcslashes($string), ENT_QUOTES, 'UTF-8'), array('$' => '$', '%' => '%', '_' => '_'))));
}
public static function clearString($string) {
$string = filter_var($string, FILTER_SANITIZE_STRING);
return $string;
}
public static function clearInt($string) {
$string = filter_var($string, FILTER_SANITIZE_NUMBER_INT);
$string = intval($string);
return $string;
}
}