Файл: system/funcs.php
Строк: 176
<?php
function bb ($string)
{
        
        //$string = preg_replace_callback('~\[url=(https?://.+?)\](.+?)\[/url\]|(https?://(www.)?[0-9a-z.-]+.[0-9a-z]{2,6}[0-9a-zA-Z/?.~&_=/%-:#]*)~', 'url_replace', $string);
        
       
        
        $codes = array (
                // ссылка
                '/[url=(.+)](.+)[/url]/is'        =>'<a href="1">2</a>',
                '/[url](.+)[/url]/isU'             =>'<a href="1">1</a>',
                // наклонный текст
                '/[i](.+)[/i]/isU'                => '<i>1</i>',
                // жирный текст
                '/[b](.+)[/b]/isU'                => '<b>1</b>',
                // подчеркнутый текст
                '/[u](.+)[/u]/isU'                => '<u>1</u>',
                // мелкий текст
                '/[small](.+)[/small]/i'          => '<span style="font-size:10px;">1</span>',
                // большой текст
                '/[big](.+)[/big]/i'              => '<span style="font-size:16px;">1</span>',
                // красный
                '/[red](.+)[/red]/i'              => '<span style="color:red;">1</span>',
                // зеленый
                '/[green](.+)[/green]/i'          => '<span style="color:green;">1</span>',
                // синий
                '/[blue](.+)[/blue]/i'            => '<span style="color:blue;">1</span>',
                // выделение кода
                '/[code](.+)[/code]/is'           => '<code>1</code>',
                '/[cit](.*)[/cit]/is'             => '<div class="cit">1</div>',
                '/[reit=([0-9.]{1,})](.*)[/reit]/ies'=> 'hide_rated ("1", "2")'
        );
        
        $string = preg_replace (array_keys($codes), array_values ($codes), $string);
        
        // badurl
        
        $f = file ('./system/badmsg.txt');        
        $c = count($f); 
        if ($c!=0) {
                for ($i = 0; $i < $c; $i++) {
                        $l = trim ($f[ $i ]);
                        if (!empty ($l)) {
                                $string = preg_replace ('/' . $l . '/i', ' ??? ', $string);
                        }
                }
        }
 
        // новая строка
        $string = str_replace ("rn", "<br/>", $string);
        $string = str_replace ("[br]", "<br/>", $string);
        // us{[int]} // вывод пользователя
        $string = preg_replace_callback ('/us{(d*)}/', 'uNick', $string);
        // file{[int]} // вывод файла
        $string = preg_replace_callback ('/file{(d*)}/', 'fname', $string);
        // [php][string][/php] // выделение php кода
        $string = preg_replace_callback ('/[php](.+)[/php]/i', 'highlight_code', $string);
        
        
        $query = DB :: $dbs -> query ("SELECT * FROM `smile`");
        while ($smile = $query -> fetch ()) {
                $string = str_replace ($smile['name'], '<img src="/images/smiles/' . $smile['filename'] . '" alt=""/>', $string);
        }
        
        return $string;
}
function fname ($matches) {
        if (is_array ($matches)) {
                $id = $matches[1];
        }
        else {
                $id = $matches;
        }
        $query = DB :: $dbs -> query ("SELECT * FROM `zc_f` WHERE (`dop`='da') AND (`id`='" . $id . "')");
        if ($query -> rowCount () != 0) {
        
                $f = $query -> fetch ();
                
                
                $ext = substr ($f['filename'], strrpos ($f['filename'], '.') + 1);
                $out .= '<img src="/images/mime/' . strtolower ($ext) . '.png" alt="*"/> ';
                $out .= '<a href="/zc/file' . $f['id'] . '">' . $f['name'] . '</a> ';
        
        }
        else {
                $out .= 'Файл удален.';
        }
        return $out;        
}
// 
function highlight_code($matches)
{
        // если callback функция
        if (is_array($matches)) {
                $code = $matches[1];
        }
        else {
                $code = $matches;
        }
                
        // перепреобразование кода
        $code = strtr ($code, array (
                '<'   => '<',
                '>'   => '>',
                '&'  => '&',
                '"' => '"',
                '$'  => '$',
                '%'  => '%', 
                '''  => "'",
                '\'  => '\',
                '^'  => '^',
                '`'  => '`',
                '|' => '|'
        ));
        
        // новая строка
        $code = strtr ($code, array (
                "<br/>" => "rn",
                "\"    => ""
        ));
        
        $code = highlight_string($code, true);
        return $code;
    
}
function hide_rated($reit = 0, $matches)
{
        
        global $us;
        
        // если callback функция
        if (is_array($matches)) {
                $string = $matches[1];
        }
        else {
                $string = $matches;
        }
        
        
        if ($us['reit']>=$reit) {
                return $string;
        }
        else {
                return '<div class="cit"><font color="red">Для просмотра этого блока необходимо набрать <b>' . $reit . '</b> рейтинга</font></div>';
        }
}
function endi ($count, $msg = array ())
{
        
        $count = (int) $count;
        
        $max = $count % 100;
        $min = $count % 10;
        if ($max > 10 && $max < 20) {
                return $count . ' ' . $msg[2];
        }
        
        if ($min > 1  && $min < 5 ) {
                return $count . ' ' . $msg[1];
        }
        
        if ($min == 1) {
                return $count . ' ' . $msg[0];
        }
        
                return $count . ' ' . $msg[2];
}
function datef ($time)
{
    
        $t = time ();
        
            if (($t - $time) <= 60) {
            
                $out .= endi ((time () - $time), array (
                        'секунду',
                        'секунды',
                        'секунд'
                ));
                $out .= ' назад';
                
        }
        elseif (($t - $time) <= 3600) {
                
                $out .= endi ((($t - $time)/60), array (
                        'минуту',
                        'минуты',
                        'минут'
                ));
                $out .= ' назад';
        }
        else {
                
                $timesp = date("j M Y  в H:i", $time);
                
                $timesp = str_replace (date ("j M Y", $t), 'Сегодня', $timesp);
                
                $timesp = str_replace (date ("j M Y", strtotime ("-1 day")), 'Вчера', $timesp);
                
                $timesp = strtr ($timesp, array (
                        'Jan' => 'Января',
                        'Feb' => 'Февраля',
                        'Mar' => 'Марта',
                        'May' => 'Мая',
                        'Apr' => 'Апреля',
                        'Jun' => 'Июня',
                        'Jul' => 'Июля',
                        'Aug' => 'Августа',
                        'Sep' => 'Сентября',
                        'Oct' => 'Октября',
                        'Nov' => 'Ноября',
                        'Dec' => 'Декабря'
                ));
            
                $out .= $timesp;
        }
    
        return $out;
    
}
function timef ($time)
{
        
        
        
        $days    = floor ( $time / 86400 );
        $hours   = floor (($time / 3600 ) - ( $days * 24 ) );
        $minutes = floor (($time - ( $hours * 3600 ) - ( $days * 86400 ) ) / 60 );
        $seconds = floor ( $time - ( ( $minutes * 60 ) + ( $hours * 3600 ) + ( $days * 86400) ) ); 
        
        if ($days != 0) {
                $out .= endi ($days, array (
                        'день',
                        'дня',
                        'дней'
                ));
                if ($hours!=0 || $minutes!=0 || $seconds!=0) {
                        $out .= ', ';
                }
        }
        if ($hours != 0) {
                $out .= endi ($hours, array (
                        'час',
                        'часа',
                        'часов'
                ));
                if ($minutes!=0 || $seconds!=0) {
                        $out .= ', ';
                }
        }
        if ($minutes != 0) {
                $out .= endi ($minutes, array (
                        'минуту',
                        'минуты',
                        'минут'
                ));
                if ($seconds!=0) {
                        $out .= ', ';
                }
        }
        if ($seconds != 0) {
                $out .= endi ($seconds, array (
                        'секунду',
                        'секунды',
                        'секунд'
                ));
        }
        
        return $out;
        
}
function sizef ($size)
{
        if ($size >= 1048576000) {
                $out = round (($size / 1073741824), 2) . ' Гб';
        } elseif ($size >= 1024000) {
                $out = round(($size / 1048576), 2) . ' Мб';
        } elseif ($size >= 1000) {
                $out = round(($size / 1024), 2) . ' Кб';
        } else {
                $out = round ($size) . ' б';
        }
        
        return $out;
}
function gradient ($string, $from = '', $to = '')
{
        
        $string = iconv ('utf-8', 'windows-1251', $string);
        
        
        //
        $to   = array (
                hexdec ($to[0] . $to[1]),     // r
                hexdec ($to[2] . $to[3]),     // g
                hexdec ($to[4] . $to[5])      // b
        );
        
        
        //
        $from = array (
                hexdec ($from[0] . $from[1]), // r
                hexdec ($from[2] . $from[3]), // g
                hexdec ($from[4] . $from[5])  // b
        );
        
        $levels = strlen ($string);
        for ($i = 1; $i <= $levels; $i++) {
                
                for ($ii = 0; $ii < 3; $ii++) {
                        $tmp[ $ii ] = $from[ $ii ] - $to[ $ii ];
                        $tmp[ $ii ] = floor ($tmp[ $ii ] / $levels);
                        $rgb[ $ii ] = $from[ $ii ] - ($tmp[ $ii ] * $i);
                        if ($rgb[ $ii ] > 255) {
                                $rgb[ $ii ] = 255;
                        }
                        $rgb[ $ii ] = dechex ($rgb[ $ii ]);
                        if (strlen($rgb[ $ii ]) < 2) {
                                $rgb[ $ii ] = '0' . $rgb[ $ii ];
                        }
                }
        
                $out .= '<span style="color: #' . $rgb[0] . $rgb[1] . $rgb[2] . '">' . $string[ $i - 1 ] . '</span>';
                
        }
        
        return iconv ('windows-1251', 'utf-8', $out);
        
}
// 
function uNick ($matches)
{
    
        if (is_array ($matches)) {
                $id = $matches[1];
        }
        else {
                $id = $matches;
        }
        
        $query = DB :: $dbs -> query ("SELECT `id`,`nick`,`sex`,`last`,`level`,`mosh`,`nickcolor1`,`nickcolor2` FROM `us` WHERE (`id`='" . $id . "')");
        if ($query -> rowCount () != 0) {
                $u = $query -> fetch ();
                
                
                //
                     if ($u['level']  > 3) $level = 'соз';
                else if ($u['level'] == 3) $level = 'ст. адм';
                else if ($u['level'] == 2) $level = 'адм';
                else if ($u['level'] == 1) $level = 'мд';
            
                $out .= '<img src="/files/ico/'. ( $u['last'] > ( time () - 3600) ? ( file_exists ($_SERVER['DOCUMENT_ROOT'] . '/files/ico/' . $u['id'] . '.png') ? $u['id']: ( $u['sex']=='Муж' ? 'mon' : 'jon' ) ) : ( $u['sex'] == 'Муж' ? 'mof' : 'jof' ) ) .'.png" alt=""/>';
              
                $out .= '<a href="/us' . $u['id'] . '" style="text-decoration:none;color:black;"><b>' . (isset ($u['nickcolor1'], $u['nickcolor2']) ? gradient ($u['nick'], $u['nickcolor1'], $u['nickcolor2']) :$u['nick'] ) . '</b></a>';
              
                if ($u['level']!= 0) {
                        $out .= ' <span style="color:green;">[' . $level . ']</span>';
                }
                if ($u['mosh']!=0) {
                        $out .= ' [<b style="color:red;">мошенник</b>]';
                }
        }
        else {
                $out = 'Удален';
        }
        
        return $out;
        
}
function pages ($self)
{
    
        global $page, $pages;
    
        $out .= 'Стр. ';
        if ($page != 1) {
                $out .= '<a href="' . $self . '/page1"><<</a> ';
                $out .= '<a href="' . $self . '/page' . ($page - 1) . '"><</a> ';  
        }
        
        if (($page - 2) > 0) {
                $out .= '<a href="' . $self .'/page'. ($page - 2) .'">'. ($page - 2) .'</a>';
                $out .= ' | ';  
        }
        
        if (($page - 1) > 0) {
                $out .= '<a href="' . $self .'/page'. ($page - 1) .'">'. ($page - 1) .'</a>';
                $out .= ' | ';  
        }
        
        // 
        $out .= $page;
        if (($page + 1) <= $pages) {
                $out .= ' | ';
                $out .= '<a href="' . $self . '/page' . ($page + 1) .'">' . ($page + 1) . '</a>'; 
        }
        
        if($page + 2 <= $pages) {
                $out .= ' | ';
                $out .= '<a href="' . $self . '/page' . ($page + 2) .'">' . ($page + 2) . '</a>';  
        }
        if ($page != $pages) {
                $out .= ' <a href="' . $self . '/page' . ($page + 1) . '">></a>';
                $out .= ' <a href="'.$self.'/page' . $pages .'">>></a>';  
        }
        
        return $out;
    
}
function passgen($count = 8)
{
        
        $symbols = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
        
        for ($i = 0; $i < $count; $i ++) {
                $out .= $symbols [ mt_rand (0, 61) ];
        }
        
        return  $out;
        
}