HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/limestate-api/lib/Data.php
<?php

class Data
{
    static $colors = array(
        'ff3065', '2abb9f', '9e61b6', 'b24d7d', 'e75555', '30bde6', '3052e6', '7930e6', '30e63d', '9be630'
    );

    static $N0 = 'ноль';
    static $Ne0 = array(
             0 => array('','один','два','три','четыре','пять','шесть',
                        'семь','восемь','девять','десять','одиннадцать',
                        'двенадцать','тринадцать','четырнадцать','пятнадцать',
                        'шестнадцать','семнадцать','восемнадцать','девятнадцать'),
             1 => array('','одна','две','три','четыре','пять','шесть',
                        'семь','восемь','девять','десять','одиннадцать',
                        'двенадцать','тринадцать','четырнадцать','пятнадцать',
                        'шестнадцать','семнадцать','восемнадцать','девятнадцать')
             );

    static $Ne1 = array('','десять','двадцать','тридцать','сорок','пятьдесят',
             'шестьдесят','семьдесят','восемьдесят','девяносто');

    static $Ne2 = array('','сто','двести','триста','четыреста','пятьсот',
             'шестьсот','семьсот','восемьсот','девятьсот');

    static $Ne3 = array(1 => 'тысяча', 2 => 'тысячи', 5 => 'тысяч');

    static $Ne6 = array(1 => 'миллион', 2 => 'миллиона', 5 => 'миллионов');

    public static function getVar($name, $default = NULL, $method = false)
    {
        if (strtolower($_SERVER['REQUEST_METHOD']) == 'post' && (!$method || $method == 'POST') ) {
            if (isset($_POST[$name])) {
                if (is_array($_POST[$name])) return $_POST[$name];
                    else return $_POST[$name];
            } else if (isset($_GET[$name])) {
                if (is_array($_GET[$name])) return $_GET[$name];
                    else return stripslashes($_GET[$name]);
            } else return $default;
        } else if (isset($_GET[$name]) && (!$method || $method == 'GET')) {
            if (is_array($_GET[$name])) return $_GET[$name];
                else return stripslashes($_GET[$name]);
        } else return $default;
    }

    //Генератор ключевых слов
    public static function gen_keywords($row, $n=4){
            $keywords = array("web студия", "web дизайн студия", "создание сайтов", "дизайн создание сайтов", "web студия петербург", "web дизайн студия петербург", "веб дизайн", "веб студия", "веб дизайн студия", "веб-студия", "разработка сайтов", "создание сайтов петербург", "Поддержка сайтов", "поддержка сайтов", "Раскрутка сайтов", "раскрутка сайтов", "Продвижение сайтов", "продвижение сайтов", "видеомонтаж", "оцифровка", "фотография", "Фотографы", "Свадебная фотография", "фото", "фото съёмка", "видео съёмка", "операторы", "оператор", "студия", "Cms", "cms", "CMS", "развитие", "рост", "дизайн", "design", "иллюстрация", "типографика", "графический дизайн", "графика", "баннеры", "полиграфия", "полиграфическая продукция", "сайты", "сайт", "Санкт-Петербург", "Петербург", "рекламная продукция", "реклама", "бизнес");

            $text = $row->introtext.$row->text.$row->title;

            while ($pos = strpos($text,"display: none")){
                    $first = substr($text,0,$pos);
                    $second = substr($text,$pos);
                    $start = substr($first,0,strpos($first,strrchr($first,"<")));
                    $ftag = substr($first,strpos($first,strrchr($first,"<"))+1);
                    $tag = substr($ftag,0,strpos($ftag," "));

                    $spos = strpos($second,"</".$tag.">");

                    $text = $start.substr($second,$spos+strlen("</".$tag.">"));
            }

            $text = strip_tags_smart($text);

            $words = array();
            foreach($keywords as $keyword){
                    if (strpos($text," ".$keyword." ")){
                            str_replace(" ".$keyword." ", "", $text, $count);
                            if (isset($words[$keyword])) $words[$keyword]++; else $words[$keyword]=$count;
                    }
            }
            arsort($words);

            $c=0;
            foreach($words as $key=>$val){
                    $row->metakeywords .= $key;
                    if ($c >= $n) break; else $row->metakeywords .= ", ";
                    $c++;
            }

            while ($c < $n){
                    $row->metakeywords .= $keywords[rand(0,count($keywords))];
                    if ($c >= $n) break; else $row->metakeywords .= ", ";
                    $c++;
            }

            return $row->metakeywords;
    }

    // Функция для смены расскладки и транслитерации (R-расскладка, T-транслитерация)
    public static function puntoSwitcher($word,$type='R',$special=false){
            $ru = 	array( '',
                    'Ё', '!', '"', '№', ';', '%', ':', '?', '*', '(', ')', '_', '+',
                    'Й', 'Ц', 'У', 'К', 'Е', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ъ', '/',
                    'Ф', 'Ы', 'В', 'А', 'П', 'Р', 'О', 'Л', 'Д', 'Ж', 'Э',
                    'Я', 'Ч', 'С', 'М', 'И', 'Т', 'Ь', 'Б', 'Ю', ',',
                    'ё', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
                    'й', 'ц', 'у', 'к', 'е', 'н', 'г', 'ш', 'щ', 'з', 'х', 'ъ', '\\',
                    'ф', 'ы', 'в', 'а', 'п', 'р', 'о', 'л', 'д', 'ж', 'э',
                    'я', 'ч', 'с', 'м', 'и', 'т', 'ь', 'б', 'ю', '.');

            $eng = 	array('',
                    '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
                    'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '|',
                    'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"',
                    'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
                    '`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
                    'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\',
                    'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'',
                    'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/');

            $ruTrans = array ('',
                    'Ё', 'Й', 'Ц', 'У', 'К', 'Е', 'Н', 'Г', 'Ш', 'Щ', 'З', 'Х', 'Ъ',
                    'Ф', 'Ы', 'В', 'А', 'П', 'Р', 'О', 'Л', 'Д', 'Ж', 'Э',
                    'Я', 'Ч', 'С', 'М', 'И', 'Т', 'Ь', 'Б', 'Ю',
                    'ё', 'й', 'ц', 'у', 'к', 'е', 'н', 'г', 'ш', 'щ', 'з', 'х', 'ъ',
                    'ф', 'ы', 'в', 'а', 'п', 'р', 'о', 'л', 'д', 'ж', 'э',
                    'я', 'ч', 'с', 'м', 'и', 'т', 'ь', 'б', 'ю');

            $engTrans = array ('',
                    'JO', 'J', 'TS', 'U', 'K', 'E', 'N', 'G', 'SH', 'SHH', 'Z', 'H', ',\'',
                    'F', 'Y', 'V', 'A', 'P', 'R', 'O', 'L', 'D', 'ZH', 'E-',
                    'YA', 'CH', 'S', 'M', 'I', 'T', '\'', 'B', 'YU',
                    'jo', 'j', 'ts', 'u', 'k', 'e', 'n', 'g', 'sh', 'shh', 'z', 'h', ',\'',
                    'f', 'y', 'v', 'a', 'p', 'r', 'o', 'l', 'd', 'zh', 'e-',
                    'ya', 'ch', 's', 'm', 'i', 't', '\'', 'b', 'yu');

            //Проверяем каких букв больше в слове
            $ruCount = 0; $engCount = 0;
            mb_internal_encoding('UTF-8');
            for ($i=0;$i<mb_strlen($word);$i++){
                    if (in_array(mb_substr($word,$i,1),$ru)) $ruCount++;
                    if (in_array(mb_substr($word,$i,1),$eng)) $engCount++;
            }
            //echo 'ru: '.$ruCount.' eng: '.$engCount.'<br />';

            $newWord = '';
            if (($type == 'R' && $ruCount >= $engCount) || $type == 'R->eng') { // Если раскладка в английский
                    for ($i=0;$i<mb_strlen($word);$i++){
                            if(!$special && in_array(mb_substr($word,$i,1),array('\\','/'))) continue;
                            $newChar = $eng[array_search(mb_substr($word,$i,1),$ru)];
                            if ($newChar) $newWord .= $newChar; else $newWord .= mb_substr($word,$i,1);

                            //echo mb_substr($word,$i,1).' -> '.array_search(mb_substr($word,$i,1),$ru).' -> '.$eng[array_search(mb_substr($word,$i,1),$ru)].'<br />';
                    }
            } else if (($type == 'R' && $ruCount < $engCount) || $type == 'R->ru') { // Если раскладка в русский
                    for ($i=0;$i<mb_strlen($word);$i++){
                            if(!$special && in_array(mb_substr($word,$i,1),array('\\','/'))) continue;
                            $newChar = $ru[array_search(mb_substr($word,$i,1),$eng)];
                            if ($newChar) $newWord .= $newChar; else $newWord .= mb_substr($word,$i,1);

                            //echo mb_substr($word,$i,1).' -> '.array_search(mb_substr($word,$i,1),$eng).' -> '.$ru[array_search(mb_substr($word,$i,1),$eng)].'<br />';
                    }
            } else if (($type == 'T' && $ruCount >= $engCount) ||  $type == 'T->eng'){ // Если транслитерация в английский
                    for ($i=0;$i<mb_strlen($word);$i++){
                            if(!$special && in_array(mb_substr($word,$i,1),array('\\','/'))) continue;
                            $newChar = $engTrans[array_search(mb_substr($word,$i,1),$ruTrans)];
                            if ($newChar) $newWord .= $newChar; else $newWord .= mb_substr($word,$i,1);

                            //echo mb_substr($word,$i,1).' -> '.array_search(mb_substr($word,$i,1),$ru).' -> '.$eng[array_search(mb_substr($word,$i,1),$ru)].'<br />';
                    }
            } else if (($type == 'T' && $ruCount < $engCount) ||  $type == 'T->ru'){ // Если транслитерация в русский
                    for ($i=0;$i<mb_strlen($word);$i++){
                            $currentChar = mb_substr($word,$i,1);
                            if(!$special && in_array($currentChar,array('\\','/'))) continue;

                            if (in_array($currentChar,array('J', 'T', 'S', 'Z', 'E', 'Y', 'C', 'j', 't','s', 'y', 'z', 'e', 'c'))){
                                    $nextChar = mb_substr($word,$i+1,1);
                                    $nnextChar = mb_substr($word,$i+2,1);
                                    switch ($currentChar){
                                            case 'J' :
                                                    if ($nextChar == 'O' || $nextChar == 'o') { $newChar = 'Ё'; $i++; } break;
                                            case 'j' :
                                                    if ($nextChar == 'O' || $nextChar == 'o') { $newChar = 'ё'; $i++; } break;
                                            case 'T' :
                                                    if ($nextChar == 'S' || $nextChar == 's') { $newChar = 'Ц'; $i++; } break;
                                            case 't' :
                                                    if ($nextChar == 'S' || $nextChar == 's') { $newChar = 'ц'; $i++; } break;
                                            case 'S' :
                                                    if (($nextChar == 'H' || $nextChar == 'h') && ($nnextChar == 'H' || $nnextChar == 'h')) { $newChar = 'Щ'; $i++; $i++;}
                                                            else if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'Ш'; $i++;}
                                                    break;
                                            case 's' :
                                                    if (($nextChar == 'H' || $nextChar == 'h') && ($nnextChar == 'H' || $nnextChar == 'h')) { $newChar = 'Ш'; $i++; $i++;}
                                                            else if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'ш'; $i++;}
                                                    break;
                                            case 'Z' :
                                                    if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'Ж'; $i++; } break;
                                            case 'z' :
                                                    if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'ж'; $i++; } break;
                                            case 'E' :
                                                    if ($nextChar == '-') { $newChar = 'Э'; $i++; } break;
                                            case 'e' :
                                                    if ($nextChar == '-') { $newChar = 'э'; $i++; } break;
                                            case 'C' :
                                                    if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'Ч'; $i++; } break;
                                            case 'c' :
                                                    if ($nextChar == 'H' || $nextChar == 'h') { $newChar = 'ч'; $i++; } break;
                                            case 'Y' :
                                                    if ($nextChar == 'A' || $nextChar == 'a') { $newChar = 'Я'; $i++; }
                                                            else if ($nextChar == 'U' || $nextChar == 'u') { $newChar = 'У'; $i++; }
                                                    break;
                                            case 'y' :
                                                    if ($nextChar == 'A' || $nextChar == 'a') { $newChar = 'я'; $i++; }
                                                            else if ($nextChar == 'U' || $nextChar == 'u') { $newChar = 'у'; $i++; }
                                                    break;
                                    }
                                    if (!empty($newChar)) $newWord .= $newChar;
                                            else {
                                                    $newChar = $ruTrans[array_search($currentChar,$engTrans)];
                                                    if ($newChar) $newWord .= $newChar; else $newWord .= $currentChar;
                                            }
                            } else {
                                    $newChar = $ruTrans[array_search($currentChar,$engTrans)];
                                    if (!empty($newChar)) $newWord .= $newChar; else $newWord .= $currentChar;
                            }

                            //echo mb_substr($word,$i,1).' -> '.array_search(mb_substr($word,$i,1),$ru).' -> '.$eng[array_search(mb_substr($word,$i,1),$ru)].'<br />';
                    }
            }

            return $newWord;
    }

    public static function strip_tags_smart(
        /*string*/ $s,
        array $allowable_tags = null,
        /*boolean*/ $is_format_spaces = true,
        array $pair_tags = array('script', 'style', 'map', 'iframe', 'frameset', 'object', 'applet', 'comment', 'button'),
        array $para_tags = array('p', 'td', 'th', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'form', 'title', 'pre', 'textarea')
    )
    {

        static $_callback_type  = false;
        static $_allowable_tags = array();
        static $_para_tags      = array();

        static $re_attrs_fast_safe =  '(?![a-zA-Z\d])  #óòâåðæäåíèå, êîòîðîå ñëåäóåò ñðàçó ïîñëå òàãà
                                       #ïðàâèëüíûå àòðèáóòû
                                       (?>
                                           [^>"\']+
                                         | (?<=[\=\x20\r\n\t]|\xc2\xa0) "[^"]*"
                                         | (?<=[\=\x20\r\n\t]|\xc2\xa0) \'[^\']*\'
                                       )*
                                       #ðàçáèòûå àòðèáóòû
                                       [^>]*';

        if (is_array($s))
        {
            if ($_callback_type === 'strip_tags')
            {
                $tag = strtolower($s[1]);
                if ($_allowable_tags &&
                    (array_key_exists($tag, $_allowable_tags) || array_key_exists('<' . trim(strtolower($s[0]), '< />') . '>', $_allowable_tags))
                    ) return $s[0];
                if ($tag == 'br') return "\r\n";
                if ($_para_tags && array_key_exists($tag, $_para_tags)) return "\r\n\r\n";
                return '';
            }
            if ($_callback_type === 'strip_spaces')
            {
                if (substr($s[0], 0, 1) === '<') return $s[0];
                return ' ';
            }
            trigger_error('Unknown callback type "' . $_callback_type . '"!', E_USER_ERROR);
        }

        if (($pos = strpos($s, '<')) === false || strpos($s, '>', $pos) === false)
        {
            return $s;
        }

        $re_tags = '/<[\/\!]? ([a-zA-Z][a-zA-Z\d]* (?>\:[a-zA-Z][a-zA-Z\d]*)?)' . $re_attrs_fast_safe . '>/sx';

        $patterns = array(
            '/<([\?\%]) .*? \\1>/sx',
            '/<\!\[CDATA\[ .*? \]\]>/sx',

            '/<\!--.*?-->/s',
            '/<\! (?:--)?
                  \[
                  (?> [^\]"\']+ | "[^"]*" | \'[^\']*\' )*
                  \]
                  (?:--)?
             >/sx',
        );
        if ($pair_tags)
        {
            foreach ($pair_tags as $k => $v) $pair_tags[$k] = preg_quote($v, '/');

            $patterns[] = '/<((?i:' . implode('|', $pair_tags) . '))' . $re_attrs_fast_safe . '> .*? <\/(?i:\\1)' . $re_attrs_fast_safe . '>/sx';
        }

        $i = 0;
        $max = 99;
        while ($i < $max)
        {
            $s2 = preg_replace($patterns, '', $s);
            if (preg_last_error() !== PREG_NO_ERROR)
            {
                $i = 999;
                break;
            }

            if ($i == 0)
            {
                $is_html = ($s2 != $s || preg_match($re_tags, $s2));
                if (preg_last_error() !== PREG_NO_ERROR)
                {
                    $i = 999;
                    break;
                }
                if ($is_html)
                {
                    if ($is_format_spaces)
                    {
                        $_callback_type = 'strip_spaces';
                        $s2 = preg_replace_callback('/  [\x09\x0a\x0c\x0d]+
                                                      | <((?i:pre|textarea))' . $re_attrs_fast_safe . '>
                                                        .+?
                                                        <\/(?i:\\1)' . $re_attrs_fast_safe . '>
                                                     /sx', __FUNCTION__, $s2);
                        $_callback_type = false;
                        if (preg_last_error() !== PREG_NO_ERROR)
                        {
                            $i = 999;
                            break;
                        }
                    }

                    if ($allowable_tags) $_allowable_tags = array_flip($allowable_tags);

                    if ($para_tags) $_para_tags = array_flip($para_tags);
                }
            }

            if ($is_html)
            {
                $_callback_type = 'strip_tags';
                $s2 = preg_replace_callback($re_tags, __FUNCTION__, $s2);
                $_callback_type = false;
                if (preg_last_error() !== PREG_NO_ERROR)
                {
                    $i = 999;
                    break;
                }
            }

            if ($s === $s2) break;
            $s = $s2; $i++;
        }
        if ($i >= $max) $s = strip_tags($s);

        if ($is_format_spaces)
        {
            $s = preg_replace('/\x20\x20+/s', ' ', trim($s));
            $s = str_replace(array("\r\n\x20", "\x20\r\n"), "\r\n", $s);
            $s = preg_replace('/\r\n[\r\n]+/s', "\r\n\r\n", $s);
        }
        return $s;
    }

    // Форматирование alias'ов и проверка на повторение
    public static function convert_alias($alias){
            $alias = puntoSwitcher($alias,'T->eng');
            if ($alias == '') $alias = date('YmdHis',time());
            return $alias;
    }

    // Форматирование тегов, для сохранения
    public static function convert_tags($tags){
            $tags = explode(",",$tags);
            $tagline = "";
            foreach($tags as $tag){
                    if ($tag != "") $tagline .= trim($tag).",";
            }
            $tagline = substr($tagline,0,strlen($tagline)-1);

            return $tagline;
    }

    public static function convert_access($r_access,$r_type){
            $access = "";
            if (isset($r_access)) foreach($r_access as $oneaccess) $access .= $oneaccess.";"; else $access = "";

            // Проверка обобщения привязки
            switch($r_type){
                    case "all" :
                            return "all";
                            break;
                    case "choose" :
                            return $access;
                            break;
                    case "not" :
                            return "not:".$access;
                            break;
            }
    }

    public static function convert_pids($r_pids,$r_type){
            $pids = "";
            if (isset($r_pids)) foreach($r_pids as $pid){
                    $pids .= $pid.";";
            } else $pids = "";

            // Проверка обобщения привязки
            switch($r_type){
                    case "all" :
                            return "all";
                            break;
                    case "choose" :
                            return $pids;
                            break;
                    case "not" :
                            return "not:".$pids;
                            break;
            }
    }

    public static function convert_text($text,$intro=false){
            if (($hrpos = strpos($text,'<hr id=\"readmore\" />')) !== FALSE){
                    if ($intro) return substr($text,0,$hrpos); else return substr($text,$hrpos+22);
            } else {
                    if ($intro) return ''; else return $text;
            }
    }

    public static function daysRemaining($etime)
    {
        if ($etime == 0) return '';

        $edate = strtotime(date('Y-m-d',strtotime($etime))); //floor(strtotime($etime)/(60*60*24))+1;
        $today = strtotime(date('Y-m-d',time()));

        $remain = floor( ($edate-$today)/(60*60*24));
        switch ($remain){
                case 0 	: return 'сегодня'; break;
                case -1	: return 'вчера'; break;
                case 1	: return 'завтра'; break;
                case 2	: return 'послезавтра'; break;
                case -2	: return 'позавчера'; break;
        }

        if ($remain < -2 && $remain > -5) return abs($remain).' дня назад';
        if ($remain < -5 && $remain > -7) return abs($remain).' дней назад';
        if ($remain <= -7) return 'больше недели назад';

        if ($remain < 5 && $remain > 2) return 'через '.$remain.' дня';
        if ($remain < 7 && $remain > 5) return 'через '.$remain.' дней';
        if ($remain <= -7) return 'больше чем через неделю';

        return date('d.m.Y', strtotime($etime));
    }

    public static function formatDate($date, $format = 'default'){
        if (strtotime($date) == 0) {
            return '-';
        } else {
            switch($format) {
                case 'long':
                    return date('j', strtotime($date)) . ' '
                        . Data::new_month(date('m', strtotime($date))) . ' '
                        . date('Y', strtotime($date)) . ' года, '
                        . date('H:i', strtotime($date));
                    break;
                case 'normal':
                    return date('d.m.Y H:i', strtotime($date));
                case 'date':
                    return date('d.m.Y', strtotime($date));
                    break;
                case 'default':
                default:
                    return self::new_date($date);
                    break;
            }
        }
    }

    public static function formatTimingDate($time){
            if ($time == 0) return ' - ';
            return new_date($time).' '.date('H:i',strtotime($time));
    }

    public static function new_date($date){
        $time = strtotime($date);
        $amonth = array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
        $new_date = date("d",$time) . "&nbsp" . $amonth[date("m",$time)-1];
        return $new_date;
    }

    public static function showTime($time){

            $min = ceil($time/60);
            $rmin = $min%60;
            $hours = floor($min/60);
            $rhours = $hours%24;
            $days = floor($hours/24);

            $str = $rmin;
            if ($hours > 0) $str = $rhours.':'.$rmin;
            if ($days > 0) {
                    $str = $days.' ';
                    if ($days >5 && $days < 20) $str .= 'дней';
                            else switch ($days%10){
                                    case 1: $str .= 'день'; break;
                                    case 2:
                                    case 3:
                                    case 4: $str .= 'дня'; break;
                                    default: $str .=  'дней'; break;
                            }
                    $str .= ' '.$rhours.':'.$rmin;
            }

            return $str;
    }

    public static function checkTime($onetime){
            if ($onetime->ftime == 0) return 0;
            return strtotime($onetime->ftime) - strtotime($onetime->stime);
    }

    public static function getTimeinHours($onetime){
            if ($onetime->ftime == 0) return 0;
            return ceil(Data::checkTime($onetime)/60/60*100)/100;
    }

    /**
     * @param $to
     * @param string $subject
     * @param string $message
     * @param string $header
     * @deprecated
     */
    public static function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
            $header_ = 'MIME-Version: 1.0' ."\r\n"
                    .'Content-type: text/plain; charset=UTF-8'."\r\n"
                    .'From: TODO <todo@noreply.eveli.net>'."\r\n";
            mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
            //sendtomailer($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
    }

    public static function mail_html($to, $subject = '(No subject)', $message = '', $header = '') {
            $header_ = 'MIME-Version: 1.0' ."\r\n"
                    .'Content-type: text/html; charset=UTF-8'."\r\n"
                    .'From: TODO <todo@noreply.eveli.net>'."\r\n";
            mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
            //sendtomailer($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
    }

    public static function money_format($sum)
    {
        return number_format($sum, 2, ',', ' ').' руб.';
    }

    public static function getRealIpAddr(){
        if (!empty($_SERVER['HTTP_CLIENT_IP'])){
                    $ip=$_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
                    $ip=$_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }

    public static function sendtomailer($to, $subject = '(No subject)', $message = '', $header = ''){
            $mail['to'] = mysql_real_escape_string($to);
            $mail['subject'] = mysql_real_escape_string($subject);
            $mail['body'] = mysql_real_escape_string($message);
            $mail['headers'] = mysql_real_escape_string($header);
            $mail['from'] = 'todo@noreply.eveli.net';
            $mail['status'] = 0;
            $mail['senddate'] = date('Y-m-d H:i:s',time());

            echo insert_record('todo_mailer',$mail);
    }

    /**
     * Множественное число
     *
     * @param int $howmuch
     * @param array $input Например: [0] - комментариев, [1] - комментарий, [2] - комментария
     * @return string
     */
    public static function plural($howmuch,$input) {
            $howmuch = (int)$howmuch;
            $l2 = substr($howmuch,-2);
            $l1 = substr($howmuch,-1);
            if($l2 > 10 && $l2 < 20) return $input[0];
            else
            switch ($l1) {
                    case 0: return $input[0]; break;
                    case 1: return $input[1]; break;
                    case 2: case 3: case 4: return $input[2]; break;
                    default: return $input[0]; break;
            }
            return false;
    }

    public static function new_month($month){
            $amonth = array("Января", "Февраля", "Марта", "Апреля", "Мая", "Июня", "Июля", "Августа", "Сентября", "Октября", "Ноября", "Декабря");

            return $amonth[$month-1];
    }

    public static function get_norm($year,$month){
            $years[2012] = array('167','96','159','167','167','168','159','176','184','160','184','168','167','96');

            $curyear = $years[$year];

            $norm = ceil($curyear[$month]/2 + $curyear[$month+1]/2);

            return $norm;
    }

    public static function written_number($i, $female=false) {
      if ( ($i<0) || ($i>=1e9) || !is_int($i) ) {
        return false; // Аргумент должен быть неотрицательным целым числом, не превышающим 1 миллион
      }
      if($i==0) {
        return self::$N0;
      }
      else {
        return preg_replace( array('/s+/','/\s$/'),
                             array(' ',''),
                             self::num1e9($i, $female));
        return self::num1e9($i, $female);
      }
    }

    public static function num_125($n) {
      /* форма склонения слова, существительное с числительным склоняется
       одним из трех способов: 1 миллион, 2 миллиона, 5 миллионов */
      $n100 = $n % 100;
      $n10 = $n % 10;
      if( ($n100 > 10) && ($n100 < 20) ) {
        return 5;
      }
      elseif( $n10 == 1) {
        return 1;
      }
      elseif( ($n10 >= 2) && ($n10 <= 4) ) {
        return 2;
      }
      else {
        return 5;
      }
    }

    public static function num1e9($i, $female) {
      if($i<1e6) {
        return self::num1e6($i, $female);
      }
      else {
        return self::num1000(intval($i/1e6), false) . ' ' .
          self::$Ne6[self::num_125(intval($i/1e6))] . ' ' . self::num1e6($i%1e6, $female);
      }
    }

    public static function num1e6($i, $female) {
      if($i<1000) {
        return self::num1000($i, $female);
      }
      else {
        return self::num1000(intval($i/1000), true) . ' ' .
          self::$Ne3[self::num_125(intval($i/1000))] . ' ' . self::num1000($i%1000, $female);
      }
    }

    public static function num1000($i, $female) {
      if( $i<100) {
        return self::num100($i, $female);
      }
      else {
        return self::$Ne2[intval($i/100)] . (($i%100)?(' '. self::num100($i%100, $female)):'');
      }
    }

    public static function num100($i, $female) {
      $gender = $female?1:0;
      if ($i<20) {
        return self::$Ne0[$gender][$i];
      }
      else {
        return self::$Ne1[intval($i/10)] . (($i%10)?(' ' . self::$Ne0[$gender][$i%10]):'');
      }
    }

    public static function utf_ucfirst($txt)
    {
        return mb_strtoupper(mb_substr($txt, 0, 1, 'UTF-8'), 'UTF-8') . mb_substr($txt, 1, mb_strlen($txt), 'UTF-8');
    }

    public static function money_to_float($amount)
    {
        $amount = str_replace(' ', '', $amount);
        $amount = str_replace(',', '.', $amount);

        return (float)$amount;
    }

    private static function uploadeOneFile($fileData, $folder, $addDate = false, $newFileName = false, $force = false)
    {
        $tempFile = $fileData['tmp_name'];

        $year = date('Y', time());
        $month = date('m', time());
        $day = date('d', time());

        $targetPath = ROOT . $folder . '/';
        $targetPath = str_replace('//', '/', $targetPath);

        if ($addDate) {
            $targetPath .= $year . '/' . $month . '/' . $day . '/';
        }

        if (!file_exists($targetPath)) {
            if (!mkdir($targetPath, 0755, true)) {
                throw new Exception('Невозможно создать директорию для загрузки файла: ' . $targetPath);
            }
        }

        if (!$newFileName) {
            $newFileName = Data::puntoSwitcher($fileData['name'], 'T->eng');
            $newFileName = trim(str_replace(array(' ', '\'', '"', '—', '#', '-'), '', $newFileName));
        }

        $targetFile =  $targetPath . $newFileName;
        $targetFile = str_replace('//', '/', $targetFile);

        if (file_exists($targetFile)) {
            if ($force) {
                unlink($targetFile);
            } else {
                $pathParts = pathinfo($targetFile);

                $num = 2;
                $targetFile = $pathParts['dirname'] . '/' . $pathParts['filename'] . '_' . $num . '.' . $pathParts['extension'];
                while (file_exists($targetFile)) {
                    $num++;
                    $targetFile = $pathParts['dirname'] . '/' . $pathParts['filename'] . '_' . $num . '.' . $pathParts['extension'];
                }
            }
        }

        move_uploaded_file($tempFile, $targetFile);

        return substr($targetFile, strlen(ROOT) - 1);
    }

    public static function uploadFile($fieldName, $folder = 'uploads', $multiply = false, $addDate = true, $newFileName = false, $force = false)
    {
        if (!empty($_FILES)) {
            if (is_array($_FILES[$fieldName]['tmp_name'])) {
                $filesData = array();
                foreach($_FILES[$fieldName] as $key => $values) {
                    foreach($values as $i => $value) {
                        $filesData[$i][$key] = $value;
                    }
                }
                $filePathes = array();
                foreach($filesData as $fileData) {
                    if (empty($fileData['tmp_name'])) continue;
                    $filePathes[] = self::uploadeOneFile($fileData, $folder, $addDate, $newFileName, $force);
                }
                return $filePathes;
            } else {
                return self::uploadeOneFile($_FILES[$fieldName], $folder, $addDate, $newFileName, $force);
            }
        } else {
            return false;
        }
    }

    public static function quote($string)
    {
        preg_match_all('/(http[s]?:\/\/[^\s,]*+)/u', $string, $matches);
        $string = htmlentities($string, ENT_QUOTES, "UTF-8");

        if (!empty($matches[0])) foreach($matches[0] as $url) {
            $holder = htmlentities($url, ENT_QUOTES, "UTF-8");
            $string = str_replace($holder, $url, $string);
        }
        return $string;
    }

    public static function cut($string, $length = 30) {
    	if ($length + 3 < mb_strlen($string)) {
    		return mb_substr($string, 0, $length) . '...';
	    } else {
    		return $string;
	    }
    }

    public static function amount($amount, $currencyId = 1) {
    	$sym = Account::$currencies4[$currencyId];
    	$amount = number_format( $amount, 2, ',', ' ' );

    	return str_replace('0', $amount, $sym);

    }

}