Файл: mob-lave.ru/core/function/text.php
Строк: 358
<?php
// ----------- Функции обрабатывающие текст ------------- //
function br($msg,$br='<br />'){ // переносы строк
return preg_replace("#((<br( ?/?)>)|n|r)+#i",$br, $msg);
}
function text($str,$br=1,$bbcode=1,$smiles=1,$html=1,$links=1){
if ($html)$str = htmlentities($str, ENT_QUOTES, 'UTF-8'); // преобразуем все к нормальному перевариванию браузером
if ($br) $str=br($str); // переносы строк
if ($links)$str=links($str); // обработка ссылок
if ($smiles) $str=smiles($str); // вставка смайлов
if ($bbcode){
$tmp_str=$str;
$str=bbcode($str); // обработка bbcode
}
return stripslashes($str); // возвращаем обработанную строку
}
function num($num){
return abs(intval(mysql_real_escape_string($num)));
}
function check($check){
$check = mysql_real_escape_string($check);
$search = array('|', ''', '$', '\', '^', '%', '`', " ", "x00", "x1A", "⁄∩");
$replace = array('|', ''', '$', '\', '^', '%', '`', '', '', '', '');
$msg = str_replace($search, $replace, $msg);
$msg = htmlspecialchars(stripslashes(trim($msg)));
return $check;
}
function generate($number){
$arr = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','R','S','T','U','V','X','Y','Z','1','2','3','4','5','6','7','8','9','0');
// Генерируем пароль
$pass = '';
for($i = 0; $i < $number; $i++){
// Вычисляем случайный индекс массива
$index = rand(0, count($arr) - 1);
$pass .= $arr[$index];
}
return $pass;
}
function bbcode($msg){
global $set;
$bbcode=array();$bbcode['/[br]/isU']='<br />'; // новая строка
$bbcode['/[b](.+)[/b]/isU']='<strong>$1</strong>'; // Жирный
$bbcode['/[color=#([A-z0-9]+)](.+)[/color]/isU']='<span style="color:#$1;">$2</span>'; // Цвет текста
$bbcode['/[fon=#([A-z0-9]+)](.+)[/fon]/isU']='<span style="background:#$1;">$2</span>'; // Цвет фона текста
$bbcode['/[cit](.+)[/cit]/isU']='<div class="cit">$1</div>'; // Цитата
$bbcode['/[i](.+)[/i]/isU']='<i>$1</i>'; // Курсив
$bbcode['/[u](.+)[/u]/isU']='<u>$1</u>'; // Подчекнуть
$bbcode['/[right](.+)[/right]/isU']='<div style="text-align:right">$1</div>'; // Текст справа
if (count($bbcode))$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);
return $msg;
}
function links($msg){
$msg = preg_replace('#[url=("|'|)(.*?)("|'|)](.*?)[/url]#si', '<noindex><a rel="nofollow" href="$2">$4</a></noindex>', $msg);
$msg = preg_replace('#[url](.*?)[/url]#si', '<noindex><a rel="nofollow" href="$1">$1</a></noindex>', $msg);
return $msg;
}
function smiles($msg){
global $user, $system;
$q=mysql_query("SELECT * FROM `$system[perfix]_smile`");
while($post = mysql_fetch_array($q)){
$sm=explode("|",$post['smile']);
for ($i=0;$i<count($sm) ;$i++ ){
$msg = str_replace($sm[$i], '<img src="/files/smile/'.$post['name'].'" alt="'.$post['name'].'"/>', $msg);
}
}
return $msg;
}
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_text_jur( $text, $maxwords = 15, $maxchar = 50 ){
$sep=' ';
$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;
}
// -------------- Панель тегов ---------------- //
function panel_bb ($field_id, $elms_array = array()) { // Быстрые теги
global $system;
$array_elsm_keys = array(
'b', // Жырный текст
'i', // Наклонный текст
'u', // Подчеркнутый текст
's', // Перечеркнутый текст
'smiles', // Смайлы
'url', // Ссылка
'color', // Цветной текст
'fon' // Цветной фон
);
foreach ($array_elsm_keys as $key => $value) {
if (!isset($elms_array[$value]))$elms_array[$value] = 1;
}
$count_showed = 0;
foreach ($elms_array as $key => $value) {
if ($value)$count_showed++;
}
if ($count_showed) {
?>
<div id="toolbar" style="display: inline-block; border-radius: 4px; padding: 4px;"></div>
<style>
.bb_hide{background-color: #d9d9d9; padding: 5px; border-radius: 3px; border: 1px solid #708090; display: none; overflow: auto; max-width: 300px; max-height: 350px; position: absolute;}
.bb_opt:hover .bb_hide{display: block;}
.bb_color a {float:left; width:9px; height:9px; margin:1px;padding: 0 !important;}
.bb_color a.categorySelect{width:auto; height:auto; border:none; float:none;}
#quote-show-smiles-categories{width: 96%;background: #fff;border: 1px solid #666;position:relative;}
a.more_links{text-decoration:none;}
#quote-view-all-smiles{width: 96%;background: #fff;border: 1px solid #666;position:relative;}
#smiles_inner_wrap{padding: 5px 15px 5px 5px;}
</style>
<script language="javascript" type="text/javascript">
function tag(text1, text2, text3) {
var element = document.getElementById("<? echo $field_id;?>");
element.focus();
if (document.selection) {
var selected = document.form.document.selection.createRange();
selected.text = text3 + text1 + selected.text + text2 + text3;
} else if (element.selectionStart !== undefined) {
var str = element.value;
var start = element.selectionStart;
var length = element.selectionEnd - element.selectionStart;
element.value = str.substr(0, start) + text3 + text1 + str.substr(start, length) + text2 + text3 + str.substr(start + length);
} else
element.value += text3 + text1 + text2 + text3;
return false;
}
function pasteLink(text) {
var element = document.getElementById("<? echo $field_id;?>");
var str = element.value;
var start = element.selectionStart;
var length = element.selectionEnd - element.selectionStart;
element.value = str.substr(0, start) + text + str.substr(start, length) + str.substr(start + length);
return false;
}
var toolbar = document.getElementById('toolbar');
toolbar.innerHTML += '<? if ($elms_array['b']) { ?><a href="#<? echo $field_id;?>" onclick="return tag('[b]', '[/b]', '')"><div id="dark" class="icon-bold"></div></a> <? } ?>'
+ '<? if ($elms_array['i']) {?><a href="#<? echo $field_id;?>" onclick="return tag('[i]', '[/i]', '')"><div id="dark" class="icon-italic"></div></a><? } ?>'
+ '<? if ($elms_array['u']) {?><a href="#<? echo $field_id;?>" onclick="return tag('[u]', '[/u]', '')"><div id="dark" class="icon-underline"></div></a> <? } ?>'
+ '<? if ($elms_array['s']) {?><a href="#<? echo $field_id;?>" onclick="return tag('[s]', '[/s]', '')"><div id="dark" class="icon-strikethrough"></div></a> <? } ?>'
+ '<span id="quote-show-more_links">'
+ '<? if ($elms_array['url']) {?><a href="#<? echo $field_id;?>" onclick="pasteLink('[url=Ссылка]Название[/url]');"><div id="dark" class="icon-link"></div></a> <? } ?>'
+'<? if ($elms_array['color']) {?><span class="bb_opt" style="display: inline-block; cursor:pointer; padding:0 5px;"><div id="dark" class="icon-type"></div>'
+ "<div class="bb_hide bb_color"><table><tr><?
$query = mysql_query("SELECT * FROM `$system[perfix]_colors_list` WHERE `default` = '1'");
$num = 0;
while($post = mysql_fetch_array($query))
{
$num++;
?><td style='width: 1px'><a href="#<? echo $field_id;?>" onclick="return tag('[color=#<? echo $post['color'];?>]', '[/color]', '');" style="background-color:#<? echo $post['color'];?>;"></a></td><?
if ($num==5)
{
$num=0;
?></tr><tr><?
}
}
?></tr></table></div>"
+'</span><? } ?>'
+ '<? if ($elms_array['fon']) {?><span class="bb_opt" style="display: inline-block; cursor:pointer; padding:0 5px;"><div id="dark" class="icon-font"></div>'
+ "<div class="bb_hide bb_color"><table><tr><?
$query = mysql_query("SELECT * FROM `$system[perfix]_colors_list` WHERE `default` = '1'");
$num = 0;
while($post = mysql_fetch_array($query))
{
$num++;
?><td style='width: 1px'><a href="#<? echo $field_id;?>" onclick="return tag('[fon=#<? echo $post['color'];?>]', '[/fon]', '');" style="background-color:#<? echo $post['color'];?>;"></a></td><?
if ($num==5)
{
$num=0;
?></tr><tr><?
}
}
?></tr></table></div>"
+ '</span><? } ?> '
+ '<? if ($elms_array['smiles']) {?><a href="#<? echo $field_id;?>" onclick="if (document.getElementById('quote-view-all-smiles')){document.getElementById('quote-view-all-smiles').style.display = 'none'} toggle('show-smiles-categories'); return false;" id="addSmilesButton"><div id="dark" class="icon-wondering"></div></a> '
+ '<div class="bb_hide bb_color" id="quote-show-smiles-categories" style="display:none;">'
+ '<div style="position:absolute; top:1px; right:1px;line-height:100%;">'
+ '<a href="#<? echo $field_id;?>" onclick="toggle('show-smiles-categories'); return false;" class="categorySelect more_links red_link"><div id="dark" class="icon-cancel"></div></a>'
+ '</div>'<?
$num = 0;
$query = mysql_query("SELECT * FROM `$system[perfix]_smile_dir` ORDER BY `id` ASC");
while ($post = mysql_fetch_array($query)) {
$num++;
?> + '<a href="#<? echo $field_id;?>" id="cat<? echo $num;?>" onclick="return selectCategory('<? echo $num;?>')" class="categorySelect"><?
$smile = mysql_fetch_array(mysql_query("SELECT * FROM `$system[perfix]_smile` WHERE `dir` = '$post[id]'"));
if ($smile != NULL)
{
echo '<img src="/files/smile/'.$smile['name'].'" width="16px"/>';
}
else echo '<img src="/design/images/bb/toolbar_smile.png" alt="'.htmlspecialchars($post['name']).'" title="'.htmlspecialchars($post['name']).'"/>';?></a>' <?
}
?>+ '</div><? } ?>'
+ '</span>';
<? if ($elms_array['smiles']) {?>
var Smiles_array = [
<?
$num_cat = 0;
$query_cat = mysql_query("SELECT * FROM `$system[perfix]_smile_dir` ORDER BY `id` ASC");
while ($post_cat = mysql_fetch_array($query_cat))
{
$num_cat++;
echo "[";
$num_smiles = 0;
$query_smiles = mysql_query("SELECT * FROM `$system[perfix]_smile` WHERE `dir` = '$post_cat[id]'");
while ($post_smiles = mysql_fetch_array($query_smiles)) {
$num_smiles++;
echo "{text:"$post_smiles[smile]",src:"http://$_SERVER[HTTP_HOST]/files/smile/$post_smiles[name]"}".(mysql_num_rows($query_smiles)!=$num_smiles?",":NULL);
}
echo "]".(mysql_num_rows($query_cat)!=$num_cat?",":NULL)."nnn";
}
?>
];
function selectCategory(category){
category = category - 1;
var this_group_smiles_count = Smiles_array[category].length;
var smilesHtml='<div id="quote-view-all-smiles" style="margin:0 auto;">';
smilesHtml += '<div id="smiles_inner_wrap">';
for (var i=0; i<this_group_smiles_count; i++){
smilesHtml += "<a href='#<? echo $field_id;?>' onclick="return selectSmile('"+Smiles_array[category][i].text+"','')"><img src='"+Smiles_array[category][i].src+"' alt=''/></a> ";
}
smilesHtml += '<div style="position:absolute; top:1px; right:1px;line-height:100%;"><a href="#quote-view-all-smiles-link" onclick="toggle('view-all-smiles'); return false;" class="categorySelect more_links red_link top"><div id="dark" class="icon-cancel"></div></a></div>';
smilesHtml += '<div class="stnd_padd" style="clear:both; border-top: 1px solid #cccaca; margin-top: 10px;"><a href="#back_to_categories" onclick="if (document.getElementById('quote-view-all-smiles')){document.getElementById('quote-view-all-smiles').style.display = 'none'} toggle('show-smiles-categories'); return false;" class="arrow_link">← <span>Вернуться к выбору категорий</span></div>';
smilesHtml += '</div></div>';
document.getElementById("block_for_smiles").innerHTML=smilesHtml;
var hide = document.getElementById('quote-show-smiles-categories');
hide.style.display = 'none';
return false;
}
function selectSmile(text1) {
text1 = text1 + ' ';
var text3 = '';
var element = document.getElementById("<? echo $field_id;?>");
if (document.selection) {
element.focus();
var selected = document.form.document.selection.createRange();
selected.text = text3 + text1 + text3;
} else if (element.selectionStart !== undefined) {
var str = element.value;
var start = element.selectionStart;
var length = element.selectionEnd - element.selectionStart;
element.value = str.substr(0, start) + text3 + text1 + text3 + str.substr(start + length);
} else {
element.value += text3 + text1 + text3;
}
return false;
}
<? } ?>
function toggle(id,inline) {
var quote = document.getElementById('quote-' + id);
var state = quote.style.display;
if (inline){
if(state == 'none') {
quote.style.display = 'inline';
} else {
quote.style.display = 'none';
}
}else{
if(state == 'none') {
quote.style.display = 'block';
} else {
quote.style.display = 'none';
}
}
}
</script>
<div id="block_for_smiles"></div>
<?
}
}
?>