<?php
// функция обрабатывает текстовые строки перед выводом в браузер
// настоятельно не рекомундуется тут что-либо менять
function output_text($str, $br = 1, $html = 1, $smiles = 1, $links = 1, $bbcode = 1)
{
global $theme_ini;
if ($br && isset($theme_ini['text_width']))
$str = wordwrap($str, $theme_ini['text_width'], ' ', 1);
// преобразуем все к нормальному перевариванию браузером
if ($html) $str = htmlentities($str, ENT_QUOTES, 'UTF-8');
$str = use_filters('ds_pre_output_text', $str);
preg_match_all('/\[code\](.+)\[\/code\]/isU', $str, $replace_code);
if (!empty($replace_code[0])) {
$str = preg_replace('/\[code\](.+)\[\/code\]/isU', '#!%code%;', $str);
}
// обработка ссылок
if ($links)
$str = links($str);
// вставка смайлов
if ($smiles)
$str = smiles($str);
// обработка bbcode
if ($bbcode) {
$str = bbcode($str);
}
// переносы строк
if ($br) {
$str = br($str);
}
if (!empty($replace_code[1])) {
foreach($replace_code[1] AS $key => $value) {
$str = str_replace_once('#!%code%;', '<pre><code>' . trim($replace_code[1][$key]) . '</code></pre>', $str);
}
}
$str = use_filters('ds_output_text', $str);
return stripslashes($str);
}
function str_replace_once($search, $replace, $text)
{
$pos = strpos($text, $search);
return $pos !== false ? substr_replace($text, $replace, $pos, strlen($search)) : $text;
}
// для форм
function input_value_text($str)
{
return output_text($str, 0, 1, 0, 0, 0);
}
function rez_text($text, $maxwords = 15, $maxchar = 100)
{
$sep = ' ';
$sep2 = ' »';
$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) {
$text = iconv_substr($text, 0, $maxchar, 'utf-8');
}
return $text . $sep2;
}
function rez_text2($text, $maxwords = 70, $maxchar = 700)
{
$sep = ' ';
$sep2 = '';
$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) {
$text = iconv_substr($text, 0, $maxchar, 'utf-8');
}
return $text . $sep2;
}
function rez_text3($text, $maxwords = 150, $maxchar = 1500)
{
$sep = ' ';
$sep2 = '';
$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) {
$text = iconv_substr($text, 0, $maxchar, 'utf-8');
}
return $text . $sep2;
}