<?
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,$user;

	$bbcode=array();
	$bbcode['/\[br\]/isU']='<br />';

	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_big'])$bbcode['/\[big\](.+)\[\/big\]/isU'] = '<span style="font-size:large;">$1</span>';
	if ($set['bb_small'])$bbcode['/\[small\](.+)\[\/small\]/isU'] = '<span style="font-size:small;">$1</span>';
	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_size'])$bbcode['/\[size=([0-9]+)\](.+)\[\/size\]/isU'] = '<span style="font-size:$1px;">$2</span>';

  	$bbcode['/\[cit\](.+)\[\/cit\]/isU'] = '<div class="cit">$1</div>';
  	$bbcode['/\[marquee\](.+)\[\/marquee\]/isU'] = '<marquee>$1</marquee>';
  	$bbcode['/\[right\](.+)\[\/right\]/isU'] = '<div style="text-align: right;">$1</div>';
  	$bbcode['/\[left\](.+)\[\/left\]/isU'] = '<div style="text-align: left;">$1</div>';
  	$bbcode['/\[center\](.+)\[\/center\]/isU'] = '<center>$1</center>';
	$bbcode['/\[background=(.+)\](.+)\[\/background\]/isU'] = '<div style="background-color:$1; display: block;">$2</div>';
	$bbcode['/\[color=(.+)\](.+)\[\/color\]/isU'] = '<span style="color:$1;">$2</span>';
      	//$bbcode['/\[youtube=(.+)\](.+)\[\/youtube\]/isU'] = '<span id="you-$1-play"><a id="you-$1" href="$1"><img src="/style/value/youtube.png"> $2</a></span>';
  	$bbcode['/\[img=(.+)\]/isU'] = '<a href="http://lafac.ru/$1$2"><img style="max-width: 200px; max-height: 200px;" src="http://lafac.ru/$1" alt="Доступно только для Lafac.Ru"/></a>';
	$bbcode['/\[mp3=(.+)\]/isU'] = '<a href="http://lafac.ru$1">Скачать</a><br /><object type="application/x-shockwave-flash" data="/dewplayer-rect.swf" width="200" height="20" id="dewplayer-rect" name="dewplayer-rect"><br /><param name="movie" value="/dewplayer-rect.swf" /><br /><param name="flashvars" value="mp3=$1" /></object>';
	$bbcode['/\[video=(.+)\]/isU'] = '<script type="text/javascript" src="http://lafac.ru/player.js"></script><br /><script class="splayer"> var params = {"playlist":[{"video":[{"url":"http://lafac.ru$1"}],"duration":0,"posterUrl":"http://lafac.ru/style/image.png"}],"uiLanguage":"ru","width":260,"height":170,"design":{"hide":["shareCodeButton"]},"behavior":{"autoHideControlBar":true}}; player.embed(params); </script>';
	

	
	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;
}
?>