Файл: element_function/element_function_standart.php
Строк: 238
<?php
    // Функция на определения IP адресса пользователя.
    function my_ip() { 
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
                $ip = $_SERVER['HTTP_CLIENT_IP'];
            } else {
                $ip = $_SERVER['REMOTE_ADDR'];
            }
            $ip = preg_replace("/[^wx7F-xFFs]/", ".", $ip);
        return $ip;
    }
    
    
    // Функция даты, с русскими месяцами.
    function rdate($param,$time) {
        $MonthNames = array('янв','фев','мар','апр','мая','июн','июл','авг','сен','окт','ноя','дек');
        return date(str_replace('M',$MonthNames[date('n', $time) - 1],$param),$time);
    }
    $data = rdate("d M H:i:s", time());
    // Записываем данные пользователя в массив. false - пользователя не сущетсвует.
    function cache_user($user) {
        $cache_user = readcache('element_users_id_'.$user);
        if (empty($cache_user)) {
        $cache_user = mysql_fetch_array(mysql_query("SELECT * FROM `element_user` WHERE `lost_id` = '$user' LIMIT 1"));
            if ($cache_user) {
                writecache('element_users_id_'.$user,$cache_user);
                return $cache_user;
            } else return false;
        }
    return $cache_user;
    }
    
    function cache_item($item) {
        return mysql_fetch_array(mysql_query("SELECT * FROM `element_item` WHERE `lost_id` = '$item' LIMIT 1"));
    }
    
    function cache_town($town) {
        $cache_town = readcache('element_town_id_'.$town);
        if (empty($cache_town)) {
        $cache_town = mysql_fetch_array(mysql_query("SELECT * FROM `element_town` WHERE `lost_id` = '$town' LIMIT 1"));
            if ($cache_town) {
                writecache('element_town_id_'.$town,$cache_town);
                return $cache_town;
            } else return false;
        }
    return $cache_town;
    }
    function element_settings_game($value) {
        $readcache = readcache('element_settings_game_'.$value);
            if (empty($readcache)) {
                $query = mysql_fetch_array(mysql_query("SELECT `lost_value` FROM `element_options_games` WHERE `lost_options` = '$value' LIMIT 1"));
                    if ($query) {
                        $readcache = $query['lost_value'];
                        writecache('element_settings_game_'.$value, $readcache);
                        return $readcache;
                    } else return false;
            } else return $readcache;
    }
    
    // Авторизация пользователя. false - не авторизован
    function autorization($id,$pass) {
        if ($id AND $pass) {
            $cache_user = cache_user($id);
            if ($cache_user['lost_password'] == $pass) $user = $cache_user; else $user = false;
        } else $user = false;
    return $user;
    }
    
    // Авторазация, проверяем куки и защищаем их.
    $cookie_password = (isset($_COOKIE['password']) AND !empty($_COOKIE['password'])) ? mysql_real_escape_string(addslashes(htmlspecialchars($_COOKIE['password']))) : false;
    $cookie_id = (isset($_COOKIE['id']) AND is_numeric($_COOKIE['id'])) ? (int)mysql_real_escape_string($_COOKIE['id']) : false;
    $user = autorization($cookie_id,$cookie_password);
    // Функция времени генерации страницы, начало
    function generationStart() {
        $start_array = explode(" ", microtime());
        return $start_array[1] + $start_array[0];
    }
    $start_time = generationStart(); 
    
    // Функция времени генерации страницы, конец.
    function generationStop($start_time) {
        $end_array = explode(" ", microtime());
        return round(($end_array[1] + $end_array[0]) - $start_time,3).' сек';
    }
    
    function params($min, $procent) {
        return ($min == 0) ? array(0, 0) : array(ceil(($min * ($procent + 100)) / 100), $procent);
    }
    
    function online_users($user, $exp) {
        $online = readcache('lost_element_online');
        if (!is_array($online)) $online = array();
        
        if (!empty($online[$user])) {
            $explode = explode(".", $online[$user]);
                if ($explode[1] < (time() - 100)) {
                    $online[$user] = $exp.'.'.time();
                    writecache('lost_element_online', $online);
                }
        } else {
            $online[$user] = $exp.'.'.time();
            writecache('lost_element_online', $online);
        }
        return $online;
    }
    
    function Color_Privilege($privilege, $text) {
        $color = array('white', 'moderator', 'game-master', 'admin');
        return '<span class="'.$color[$privilege].'">'.$text.'</span>';
    }
    
    function Timer($time) {
        $timeOut = time() - $time;
        if ($timeOut < 60) $echo = $timeOut.' сек. назад';
        if ($timeOut == 0) $echo = 'сейчас';
        if ($timeOut >= 60) { $echo = $timeOut / 60; $echo = (int)$echo; $echo = $echo.' мин. назад'; }
        if ($timeOut >= 3600) { $echo = $timeOut / 3600; $echo = (int)$echo; $echo = $echo.' ч. назад'; }
        return $echo;
    }
    
    function ikonka_user($race, $on_off) {
        if ($race > 0 AND $race < 5) {
            return '<img src="/images/icons/'.$race.'_'.$on_off.'.png">';
        } else return '';
    }
    
    function Replace_Bytes($size) {
        $filesizename = array("B", "K", "M", "G", "T", "P", "E", "Z", "Y");
        return $size ? round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0B';
    }
    
    // Разбивает число на тысячные
    function nmb_2($count) {
        return number_format($count, 0, "'", "'");
    }
    
    // Функция с список игроков, которым нужно обновить данные в БД
    function user_list_update($user) {
        $cache = readcache('element_user_list_update');
        if (!is_array($cache)) $cache = array();
        
        if ($user > 0) {
            if (empty($cache[$user])) {
                $cache[$user] = 'update';
                writecache('element_user_list_update', $cache);
            }
            return $cache;
        } else return $cache;
    }
    
    // Функция с списком городов, которым нужно обновить данные в БД
    function town_list_update($town) {
        $cache = readcache('element_town_list_update');
        if (!is_array($cache)) $cache = array();
        
        if ($town > 0) {
            if (empty($cache[$town])) {
                $cache[$town] = 'update';
                writecache('element_town_list_update', $cache);
            }
            return $cache;
        } else return $cache;
    }
    // Функция с списком заданий, которые нужно обновить данные в БД
    function quests_list_update($quests) {
        $cache = readcache('element_quests_list_update');
        if (!is_array($cache)) $cache = array();
        
        if ($quests > 0) {
            if (empty($cache[$quests])) {
                $cache[$quests] = 'update';
                writecache('element_quests_list_update', $cache);
            }
            return $cache;
        } else return $cache;
    }
    
    // Функция обновления данных юзера
    function update_params_users($cache_user) {
        if ($cache_user) {
            mysql_query("UPDATE `element_user` SET 
                                    `lost_level` = '$cache_user[lost_level]',
                                    `lost_exp` = '$cache_user[lost_exp]',
                                    `lost_race` = '$cache_user[lost_race]',
                                    `lost_privilege` = '$cache_user[lost_privilege]',
                                    `lost_money_gold` = '$cache_user[lost_money_gold]',
                                    `lost_block_info` = '$cache_user[lost_block_info]',
                                    `lost_male` = '$cache_user[lost_male]',
                                    `lost_resourse_cristalls` = '$cache_user[lost_resourse_cristalls]',
                                    `lost_resourse_irridyi` = '$cache_user[lost_resourse_irridyi]',
                                    `lost_params_strlen` = '$cache_user[lost_params_strlen]',
                                    `lost_params_heatpoints` = '$cache_user[lost_params_heatpoints]',
                                    `lost_params_energy` = '$cache_user[lost_params_energy]',
                                    `lost_params_protection` = '$cache_user[lost_params_protection]',
                                    `lost_params_summa` = '$cache_user[lost_params_summa]',
                                    `lost_other` = '$cache_user[lost_other]',
                                    `lost_labirint` = '$cache_user[lost_labirint]',
                                    `lost_town` = '$cache_user[lost_town]',
                                    `lost_town_other` = '$cache_user[lost_town_other]',
                                    `lost_avatar` = '$cache_user[lost_avatar]',
                                    `lost_params_training` = '$cache_user[lost_params_training]',
                                    `lost_abilities_ogon` = '$cache_user[lost_abilities_ogon]',
                                    `lost_abilities_voda` = '$cache_user[lost_abilities_voda]',
                                    `lost_abilities_zemlya` = '$cache_user[lost_abilities_zemlya]',
                                    `lost_abilities_vozduh` = '$cache_user[lost_abilities_vozduh]',
                                    `lost_time_bank` = '$cache_user[lost_time_bank]',
                                    `lost_arena_tvt_rating` = '$cache_user[lost_arena_tvt_rating]',
                                    `lost_arena_pvp_rating` = '$cache_user[lost_arena_pvp_rating]',
                                    `lost_add_user_exp` = '$cache_user[lost_add_user_exp]',
                                    `lost_add_town_exp` = '$cache_user[lost_add_town_exp]',
                                    `lost_ip` = '$cache_user[lost_ip]',
                                    `lost_user_agent_2` = '$cache_user[lost_user_agent_2]',
                                    `lost_town_altar` = '$cache_user[lost_town_altar]', 
                                    `lost_town_altar_time` = '$cache_user[lost_town_altar_time]', 
                                    `lost_town_altar_params` = '$cache_user[lost_town_altar_params]', 
                                    `lost_blessing` = '$cache_user[lost_blessing]',
                                    `lost_blessing_time` = '$cache_user[lost_blessing_time]'
                                     WHERE `lost_id` = '$cache_user[lost_id]' 
                                     LIMIT 1");
        return true;
        } else return false;
    }
    
?>