Вход Регистрация
Файл: sys/classes/text.class.php
Строк: 155
<?php

#Работа с текстом

abstract class text {

    static function 
extract16color($color16) {
        
$mask16 = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
        
$color_mask = array("r", "g", "b");
        
$true_color = array(
            
"r" => 0,
            
"g" => 0,
            
"b" => 0);
        
$color16 = substr($color16, 1);
        for (
$icm = 0; $icm < count($color_mask); $icm++) {
            
$color16_temp = array(substr($color16, ($icm * 2), 1), substr($color16, ($icm * 2) + 1, 1));
            for (
$ic = 0; $ic < 2; $ic++) {
                for (
$i = 0; $i < count($mask16); $i++) {
                    if (
$color16_temp[$ic] == $mask16[$i]) {
                        
$color16_temp[$ic] = $i;
                        break;
                    }
                }
            }
            
$true_color[$color_mask[$icm]] = ((int) $color16_temp[0] * 16) + (int) $color16_temp[1];
        }
        return 
$true_color;
    }

    static function 
make16color($color10) {
        
$mask16 = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
        
$color_mask = array("r", "g", "b");
        
$true_color = "#";
        for (
$icm = 0; $icm < count($color_mask); $icm++) {
            
$color10_temp = (int) $color10[$color_mask[$icm]];
            
$true_color .= $mask16[(int) ($color10_temp / 16)];
            
$true_color .= $mask16[$color10_temp % 16];
        }
        return 
$true_color;
    }

    static function 
gradient($text, $sColor, $eColor) {
        
$color_mask = array("r", "g", "b");
        
$color_move = array(
            
"r" => 0,
            
"g" => 0,
            
"b" => 0);
        
$color_add = array(
            
"r" => 0,
            
"g" => 0,
            
"b" => 0);
        
$word = array();
        
$length = strlen($text);
        
$output = "";
        
$Gzip = "";
        
$current_color = "";
        
$max = 0;
        if (
$length > 0) {
            
$sColor = self::extract16color($sColor);
            
$eColor = self::extract16color($eColor);
            
$cColor = $sColor;
            for (
$i = 0; $i < count($color_mask); $i++) {
                
$temp = $sColor[$color_mask[$i]] - $eColor[$color_mask[$i]];
                
$color_add[$color_mask[$i]] = abs($temp);
                if (
abs($temp) > $max) {
                    
$max = abs($temp);
                }
                if (
$temp < 0) {
                    
$color_move[$color_mask[$i]] = 1;
                } else if (
$temp > 0) {
                    
$color_move[$color_mask[$i]] = - 1;
                } else {
                    
$color_move[$color_mask[$i]] = 0;
                }
            }
            for (
$i = 0; $i < $length; $i++) {
                
$char = substr($text, $i, 1);
                
$test = ord($char);
                if (
$test >= 128 and $test <= 255 | $test = "") {
                    
$char = substr($text, $i, 2);
                    
$i++;
                }
                
$word[] = $char;
            }
        }

        
$length = count($word);
        
$koeff_add = @(($max / $length) / $max) * 100;
        for (
$i = 0; $i < $length; $i++) {
            for (
$i2 = 0; $i2 < count($color_mask); $i2++) {
                
$add = (($color_add[$color_mask[$i2]] / 100) * $koeff_add) * $color_move[$color_mask[$i2]];
                
$cColor[$color_mask[$i2]] += $add;
            }
            
$current_color = self::make16color($cColor);
            if (!
$i) {
                
$output .= '<font color = "' . $current_color . '">' . $word[$i];
                
$Gzip = $current_color;
            } else {
                if (
$current_color == $Gzip | $word[$i] == " ") {
                    
$output .= $word[$i];
                } else {
                    
$output .= '</font><font color = "' . $current_color . '">' . $word[$i];
                    
$Gzip = $current_color;
                }
            }
        }
        if (
strlen($output)) {
            
$output .= "</font>";
        }
        return 
$output;
    }

    static function 
smiles($msg) {
        
$q = mysql_query("SELECT * FROM `smiles_spis`");
        while (
$post = mysql_fetch_array($q)) {
            
$msg = str_replace($post['sim'], "<img src = '/style/img/smiles/emotion_$post[name].png' alt = '$post[name]' />", $msg);
        }
        return 
$msg;
    }

    static function 
cut_text($text, $maxwords = 10, $maxchar = 30) {
        
$sep = ' ';
        
$words = @preg_split(" ", $text);
        
$char = iconv_strlen($text, 'utf-8');
        if (
count($words) > $maxwords) {
            
$text = join($sep, array_slice($words, 0, $maxwords));
        }
        return 
$text;
    }

    
#Получение подстроки

    
static function substr($text, $len, $start = 0, $mn = ' (...)') {
        
$text = trim($text);
        if (
function_exists('mb_substr')) {
            return 
mb_substr($text, $start, $len) . (mb_strlen($text) > $len - $start ? $mn : null);
        }
        if (
function_exists('iconv')) {
            return 
iconv_substr($text, $start, $len) . (iconv_strlen($text) > $len - $start ? $mn : null);
        }

        return 
$text;
    }

#Фильтрация текста с ограничением длины в зависимости от типа браузера.

    
static function for_opis($text) {
        
$text = self::substr($text, IS_WEB == 'web' ? 1000 : 300);
        
$text = self::toOutput($text);

        return 
$text;
    }

    static function 
toOutput($str, $br = 1, $html = 1, $smiles = 1, $links = 1, $bbcode = 1) {

        if (
$html) {
            
$str = htmlentities($str, ENT_QUOTES, 'UTF-8');
        } 
// преобразуем все к нормальному перевариванию браузером
        
if ($links) {
            
$str = links($str);
        } 
// обработка ссылок
        
if ($bbcode) {
            
$tmp_str = $str;
            
$str = bbcode($str); // обработка bbcode
        
}

        if (
$smiles && $tmp_str == $str) {
            
$str = self::smiles($str);
        } 
// вставка смайлов
        
if ($br) {
            
$str = self::br($str); // переносы строк
        
}
        
// обработка старых цитат с числом в теге
        
$str = preg_replace('#[(/?)quote_([0-9]+)(]|=)#ui', '[1quote3', $str);

        
// преобразование ссылки на youtube ролик в ИИсщву
        
$str = preg_replace('#(^|s|(|])((https?://)?www.youtube.com/watch?(.*?&)*v=([^ rnt`'"<]+))(,|[|<|s|$)#iuU', '1[youtube]5[/youtube]6', $str);

        // преобразование ссылок в тег URL
        
$str = preg_replace('#(^|s|(|])([a-z]+://([^ rnt`'"<]+))(,|[|<|s|$)#iuU', '1[url="2"]2[/url]4', $str);

        
return $str;
    }

# переносы строк

    
static function br($msg, $br = '<br />') {
        return 
preg_replace("#((<br( ?/?)>)|n|r)+#i", $br, $msg);
    }

# Вырезает все нечитаемые символы

    
static function esc($text, $br = NULL) {
        if (
$br != NULL) {
            for (
$i = 0; $i <= 31; $i++) {
                
$text = str_replace(chr($i), NULL, $text);
            }
        } else {
            for (
$i = 0; $i < 10; $i++) {
                
$text = str_replace(chr($i), NULL, $text);
            }
            for (
$i = 11; $i < 20; $i++) {
                
$text = str_replace(chr($i), NULL, $text);
            }
            for (
$i = 21; $i <= 31; $i++) {
                
$text = str_replace(chr($i), NULL, $text);
            }
        }
        return 
$text;
    }

    static function 
auto_bb($form, $field) {
        global 
$bb_start;
        
$out = '';
        if (!
$bb_start) {
            
$out = '<script language="JavaScript" type="text/javascript">;
    function tag(text1, text2) {
    if ((document.selection)) {
    document.' 
. $form . '.' . $field . '.focus();
    document.' 
. $form . '.document.selection.createRange().text = text1+document.' . $form . '.document.selection.createRange().text+text2;
    } else if(document.forms['' . $form . ''].elements['' . $field . ''].selectionStart!=undefined) {
    var element = document.forms['' . $form . ''].elements['' . $field . ''];
    var str = element.value;
    var start = element.selectionStart;
    var length = element.selectionEnd - element.selectionStart;
    element.value = str.substr(0, start) + text1 + str.substr(start, length) + text2 + str.substr(start + length);
    document.forms['' . $form . ''].elements['' . $field . ''].focus();
    } else document.' 
. $form . '.' . $field . '.value += text1+text2;
    document.forms['' . $form . ''].elements['' . $field . ''].focus();}</script>'
;
            
$bb_start = 1;
        }
        return 
$out . '<div style="margin:1px;padding:2px;">
    <a href="javascript:tag('
[b]', '[/b]')"><img src="/style/img/bb/b.png" alt="b" title="Жирный"/></a>
    <a href="javascript:tag('
[i]', '[/i]')"><img src="/style/img/bb/i.png" alt="i" title="Наклонный"/></a>
    <a href="javascript:tag('
[u]', '[/u]')"><img src="/style/img/bb/u.png" alt="u" title="Подчёркнутый"/></a>
    <a href="javascript:tag('
[s]', '[/s]')"><img src="/style/img/bb/s.png" alt="s" title="Перечёркнутый"/></a>
    <a href="javascript:tag('
[php]', '[/php]')"><img src="/style/img/bb/php.png" alt="cod" title="Код"/></a>
    <a href="javascript:tag('
[url=]', '[/url]')"><img src="/style/img/bb/l.png" alt="url" title="Ссылка" /></a>
    <a href="javascript:tag('
[red]', '[/red]')"><img src="/style/img/bb/red.png" alt="red" title="Красный"/></a>
    <a href="javascript:tag('
[green]', '[/green]')"><img src="/style/img/bb/green.png" alt="green" title="Зелёный"/></a>
    <a href="javascript:tag('
[blue]', '[/blue]')"><img src="/style/img/bb/blue.png" alt="blue" title="Синий"/></a><br />
    </div>'
;
    }

}
Онлайн: 3
Реклама