<?php
function CHANGE_EMOTICON($message = ""){
	$message = str_replace(":emo1:","<img src=\"images/emotion/angel_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo2:","<img src=\"images/emotion/angry_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo3:","<img src=\"images/emotion/broken_heart.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo4:","<img src=\"images/emotion/cake.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo5:","<img src=\"images/emotion/confused_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo6:","<img src=\"images/emotion/cry_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo7:","<img src=\"images/emotion/devil_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo8:","<img src=\"images/emotion/embaressed_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo9:","<img src=\"images/emotion/envelope.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo10:","<img src=\"images/emotion/heart.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo11:","<img src=\"images/emotion/kiss.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo12:","<img src=\"images/emotion/lightbulb.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo13:","<img src=\"images/emotion/omg_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo14:","<img src=\"images/emotion/regular_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo15:","<img src=\"images/emotion/sad_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo16:","<img src=\"images/emotion/shades_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo17:","<img src=\"images/emotion/teeth_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo18:","<img src=\"images/emotion/thumbs_down.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo19:","<img src=\"images/emotion/thumbs_up.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo20:","<img src=\"images/emotion/tounge_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo21:","<img src=\"images/emotion/whatchutalkingabout_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo22:","<img src=\"images/emotion/wink_smile.gif\" border=\"0\" align=\"absmiddle\">",$message);
	$message = str_replace(":emo23:","<img src=\"images/emotion2/001.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo24:","<img src=\"images/emotion2/002.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo25:","<img src=\"images/emotion2/003.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo26:","<img src=\"images/emotion2/004.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo27:","<img src=\"images/emotion2/005.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo28:","<img src=\"images/emotion2/006.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo29:","<img src=\"images/emotion2/007.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo30:","<img src=\"images/emotion2/008.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace("::emo31:","<img src=\"images/emotion2/009.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo32:","<img src=\"images/emotion2/010.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo33:","<img src=\"images/emotion2/011.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo34:","<img src=\"images/emotion2/012.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo35:","<img src=\"images/emotion2/013.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo36:","<img src=\"images/emotion2/014.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo37:","<img src=\"images/emotion2/015.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo38:","<img src=\"images/emotion2/016.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo39:","<img src=\"images/emotion2/017.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo40:","<img src=\"images/emotion2/018.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo41:","<img src=\"images/emotion2/019.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo42:","<img src=\"images/emotion2/020.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo43:","<img src=\"images/emotion2/021.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo44:","<img src=\"images/emotion2/022.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo45:","<img src=\"images/emotion2/023.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo46:","<img src=\"images/emotion2/024.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo47:","<img src=\"images/emotion2/025.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo48:","<img src=\"images/emotion2/026.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo49:","<img src=\"images/emotion2/027.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo50:","<img src=\"images/emotion2/028.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo51:","<img src=\"images/emotion2/029.gif\" border=\"0\" align=\"absmiddle\">",$message); 
	$message = str_replace(":emo52:","<img src=\"images/emotion2/030.gif\" border=\"0\" align=\"absmiddle\">",$message); 

	return stripslashes($message);
}

//BB Code
$_BBCONFIG['QuotedBgColor'] = '#F7F7F7';
$_BBCONFIG['QuotedBorderColor'] = '#CCCCCC';
$_BBCONFIG['CodeBgColor'] = '#EFF7FF';
$_BBCONFIG['CodeBorderColor'] = '#BDBEBD';

function BBCODE($string){
	global $_BBCONFIG;
	$string = nl2br($string);
	$patterns = array(
		'`\[b\](.+?)\[/b\]`is',
		'`\[i\](.+?)\[/i\]`is',
		'`\[u\](.+?)\[/u\]`is',
		'`\[strike\](.+?)\[/strike\]`is',
		'`\[color=#([0-9A-F]{6})\](.+?)\[/color\]`is',
		'`\[email\](.+?)\[/email\]`is',
		'`\[img\](.+?)\[/img\]`is',
		'`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
		'`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
		'`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
		'`\[flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
		'`\[quote\](.+?)\[/quote\]`is',
		'`\[indent](.+?)\[/indent\]`is',
		'`\[size=([1-6]+)\](.+?)\[/size\]`is',
		'`\[sup\](.+?)\[/sup\]`is',
		'`\[sub\](.+?)\[/sub\]`is',
		'`\[code\](.+?)\[/code\]`is',
		'`\r\n|\r|\n`',
		'`\t`',
		'`\[img=(.+?)\]`is',
		'`\[align=(left|center|right)\](.+?)\[/align\]`is',
		'`\[glow\](.+?)\[/glow\]`is',
		'`\[shadow\](.+?)\[/shadow\]`is',
		'`\[media\](.+?)\[/media\]`is',
		'`\[movie\](.+?)\[/movie\]`is',
		'`\[center\](.+?)\[/center\]`is',
		'`\[left\](.+?)\[/left\]`is',
		'`\[right\](.+?)\[/right\]`is',
		'`\[\-\-\-\]`is',
			);

	$replaces =  array(
			'<strong>\\1</strong>',
			'<em>\\1</em>',
			'<span style="border-bottom: 1px dotted">\\1</span>',
			'<strike>\\1</strike>',
			'<span style="color:#\1;">\2</span>',
			'<a href="mailto:\1">\1</a>',
			'<img src="\1" alt="" style="border:0px;" />',
			'<a href="\1\2">\6</a>',
			'<a href="\1\2">\1\2</a>',
			'<a href="http://\1">\1</a>',
			'<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
			'<strong>อ้างอิง :</strong><div style="margin:0px 10px;padding:5px;background-color:'.$_BBCONFIG["QuotedBgColor"].';border:1px dotted '.$_BBCONFIG["QuotedBorderColor"].';width:100%;"><em>\1</em></div>',
			'<pre>\\1</pre>',
			'<h\1 style="display:inline">\2</h\1>',
			'<sup>\\1</sup>',
			'<sub>\\1</sub>',
			'<strong style="color:green;font-family:courier new,monospace;font-size:8pt;">Code:</strong><pre style="margin:0px 10px;padding:5px;background-color:'.$_BBCONFIG["CodeBgColor"].';border:1px solid '.$_BBCONFIG["CodeBorderColor"].';width:100%;font-size:10pt;font-family:courier new,monospace;">\1</pre>',
			'',
			'&nbsp;&nbsp;',
			'<img src="\1" alt="" style="border:0px;" />',
			'<div align="\1">\2</div>',
			'<table style=filter:glow(color=#00FF00, strength=3)>\\1</table>',
			'<table style=\"filter:shadow(color=pink, direction=left)\">\\1</table>',
			'<embed src=\\1  TYPE=\"application/x-mplayer2\" align=\"middle\" width=\"200\" height=\"42\" autostart=\"1\" autoplay=\"true\" dhtype=\"wma\">',
			'<object classid=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-oleobject\" width=\"262\" height=\"260\" id=\"MediaPlayer1\">\n<param name=\"URL\" value=\\1  >\n<PARAM NAME=ShowControls VALUE=true>\n<PARAM NAME=ShowStatusBar VALUE=false>\n<PARAM NAME=Autostart VALUE=true>\n<PARAM NAME=ShowPositionControls value=true>\n<PARAM NAME=ShowTracker value=true>\n</object>',
			'<div align=center>\\1</div>',
			'<div align=left>\\1</div>',
			'<div align=right>\\1</div>',
			'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
			);
	$string = preg_replace($patterns, $replaces , $string);
	return stripslashes($string);
}
?>