<?
function bbcodehightlight($arr)
{
$arr[0]=html_entity_decode($arr[0], ENT_QUOTES, 'UTF-8');
return '<div class="cit" style="overflow:scroll;clip:auto;max-width:480px;">'.preg_replace('#<code>(.*?)</code>#si', '\\1' ,highlight_string($arr[0],1)).'</div>'."\n";
}



function BBcode($msg)
{
global $set;
$bbcode=array();
if ($set['bb_i'])$bbcode['/\[i\](.+)\[\/i\]/isU'] ='<em>$1</em>';
if ($set['bb_b'])$bbcode['/\[b\](.+)\[\/b\]/isU'] ='<strong>$1</strong>';
if ($set['bb_u'])$bbcode['/\[u\](.+)\[\/u\]/isU'] ='<span style="text-decoration:underline;">$1</span>';	
if ($set['bb_tbl'])$bbcode['/\[tbl=(.+)\/(.+)\](.+)\/(.+)\/(.+)\/(.+)\/(.+)\/(.+)\[\/tbl\]/isU'] ='<table>
<tr>
<td bgcolor="#$1" valign="top">$3</td>
<td bgcolor="#$2" valign="top">$4</td>
<td bgcolor="#$1" valign="top">$5</td>
</tr>
<tr>
<td bgcolor="#$2" valign="top">$6</td>
<td bgcolor="#$1" valign="top">$7</td>
<td bgcolor="#$2" valign="top">$8</td>
</tr></table>';
if ($set['bb_in'])$bbcode['/\[in\](.+)\[\/in\]/isU'] ='<input type="text" value="$1" />';
if ($set['bb_small'])$bbcode['/\[small\](.+)\[\/small\]/isU'] ='<span style="font-size:small;">$1</span>';
if ($set['bb_big'])$bbcode['/\[big\](.+)\[\/big\]/isU'] ='<span style="font-size:large;">$1</span>';
if ($set['bb_size'])$bbcode['/\[s=([0-9]+)\](.+)\[\/s\]/isU'] ='<span style="font-size:$1px;">$2</span>';
if ($set['bb_das'])$bbcode['/\[das\](.+)\[\/das\]/isU'] ='<span style="border:1px dashed;">$1</span>';
if ($set['bb_marq'])$bbcode['/\[marq\](.+)\[\/marq\]/isU'] ='<marquee>$1</marquee>';
if ($set['bb_c'])$bbcode['/\[c\](.+)\[\/c\]/isU'] ='<center>$1</center>';
if ($set['bb_sol'])$bbcode['/\[sol\](.+)\[\/sol\]/isU'] ='<span style="border:1px solid;">$1</span>';
if ($set['bb_ex'])$bbcode['/\[ex\](.+)\[\/ex\]/isU'] ='<span style="text-decoration:line-through;">$1</span>';
if ($set['bb_up'])$bbcode['/\[up\](.+)\[\/up\]/isU'] ='<span style="text-decoration:overline;">$1</span>';
if ($set['bb_bl'])$bbcode['/\[bl\](.+)\[\/bl\]/isU'] ='<span style="text-decoration:blink;">$1</span>';
if ($set['bb_dot'])$bbcode['/\[dot\](.+)\[\/dot\]/isU'] ='<span style="border:1px dotted;">$1</span>';
if ($set['bb_scrw'])$bbcode['/\[scr-w\](.+)\[\/scr-w\]/isU'] ='<span style="background-color:#ffffff;"><span style="color:#ffffff;"><span style="border:1px dashed;">$1</span></span></span>';
if ($set['bb_scrb'])$bbcode['/\[scr-b\](.+)\[\/scr-b\]/isU'] ='<span style="background-color:#000000;"><span style="color:#000000;"><span style="border:1px dashed;">$1</span></span></span>';
if ($set['bb_dou'])$bbcode['/\[dou\](.+)\[\/dou\]/isU'] ='<span style="border:3px double #E1E1E4;">$1</span>';
if ($set['bb_code'])$bbcode['/\[code\](.+)\[\/code\]/isU'] ='<code>$1</code>';
if ($set['bb_red'])$bbcode['/\[red\](.+)\[\/red\]/isU'] ='<span style="color:#ff0000;">$1</span>';
if ($set['bb_yellow'])$bbcode['/\[yellow\](.+)\[\/yellow\]/isU'] ='<span style="color:#ffff22;">$1</span>';
if ($set['bb_green'])$bbcode['/\[green\](.+)\[\/green\]/isU'] ='<span style="color:#00bb00;">$1</span>';
if ($set['bb_blue'])$bbcode['/\[blue\](.+)\[\/blue\]/isU'] ='<span style="color:#0000bb;">$1</span>';
if ($set['bb_white'])$bbcode['/\[white\](.+)\[\/white\]/isU'] ='<span style="color:#ffffff;">$1</span>';
if ($set['bb_img'])$bbcode['/\[img\](.+)\[\/img\]/isU'] ='<img src="$1" alt="" />';
if ($set['bb_f'])$bbcode['/\[f=([0-9]+)\/([0-9]+)\/([0-9]+)\](.+)\[\/f\]/isU'] = "<a href='/forum/$1/$2/$3'>$4</a>";
if ($set['bb_u'])$bbcode['/\[u=([0-9]+)\](.+)\[\/u\]/isU'] = "<a href='/info.php?id=$1'>$2</a>";

if (count($bbcode))$msg= preg_replace(array_keys($bbcode), array_values($bbcode), $msg);

if ($set['bb_code']){
$msg=preg_replace_callback('#&lt;\?(.*?)\?&gt;#sui', 'bbcodehightlight', $msg);
$msg=preg_replace('#\[code\](.*?)\[/code\]#si', '\1', $msg);
}
return $msg;
}

//быстрая вставка бб кодов
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:2px;padding:1px;border:1px solid #333">
			   BB-код<br />
<a href="javascript:tag(\'[b]\', \'[/b]\')"><img src="/style/bb/b.png" alt="b" title="Жирный"/></a>
               <a href="javascript:tag(\'[i]\', \'[/i]\')"><img src="/style/bb/i.png" alt="i" title="Наклонный"/></a><a href="javascript:tag(\'[u]\', \'[/u]\')"><img src="/style/bb/u.png" alt="u" title="Подчёркнутый"/></a>
               <a href="javascript:tag(\'[s]\', \'[/s]\')"><img src="/style/bb/s.png" alt="s" title="Перечёркнутый"/></a>
               <a href="javascript:tag(\'[php]\', \'[/php]\')"><img src="/style/bb/cod.png" alt="cod" title="Код"/></a>
               <a href="javascript:tag(\'[url=]\', \'[/url]\')"><img src="/style/bb/l.png" alt="url" title="Ссылка" /></a>
               <a href="javascript:tag(\'[red]\', \'[/red]\')"><img src="/style/bb/re.png" alt="red" title="Красный"/></a>
               <a href="javascript:tag(\'[green]\', \'[/green]\')"><img src="/style/bb/gr.png" alt="green" title="Зелёный"/></a><a href="javascript:tag(\'[blue]\', \'[/blue]\')"><img src="/style/bb/bl.png" alt="blue" title="Синий"/></a><br />
Смайлы<br />
<a href="javascript:tag(\':-)\',\'\')"><img src="/style/smiles/smile.gif" alt="улыбка" title="Улыбка"/></a>
<a href="javascript:tag(\':-(\',\'\')"><img src="/style/smiles/sad.gif" alt="печаль" title="Печаль"/></a>
<a href="javascript:tag(\':-D\',\'\')"><img src="/style/smiles/biggrin.gif" alt="смех" title="Смех"/></a>
<a href="javascript:tag(\':-))\',\'\')"><img src="/style/smiles/i-m_so_happy.gif" alt="довольный" title="Довольный"/></a>
<a href="javascript:tag(\'8-)\',\'\')"><img src="/style/smiles/dirol.gif" alt="в очках" title="В очках"/></a>
<a href="javascript:tag(\'*YES*\',\'\')"><img src="/style/smiles/yes3.gif" alt="да" title="Да"/></a>
<a href="javascript:tag(\'*NO*\',\'\')"><img src="/style/smiles/nea.gif" alt="неа" title="Неа"/></a>
<a href="javascript:tag(\'*BRAVO*\',\'\')"><img src="/style/smiles/clapping.gif" alt="браво" title="Браво"/></a>
</div>';

}
?>