Location: PHPKode > scripts > OekakiPoteto > oekakipoteto/niftytoo.php
<?
//niftyToo code by Marcello (http://www.cellosoft.com)



	function nifty2_convert($in) {
		$out = str_replace("<","&lt;",$in);
		$out = str_replace(">","&gt;",$out);
		$out = nl2br($out);
		$out = stripslashes($out);
		//$out = nl2br(htmlentities($in,ENT_NOQUOTES));
		
		//$out = eregi_replace('&amp;(#[0-9]{1,5});','&\\1;',$out);
		//$out = preg_replace('/&amp;(#[0-9]{1,5});/i','&\\1;',$out);
		
		$mode=1;

		nifty2_replace($out, 'no', "nifty2_fix_brackets('\\1')", $mode, 'es');
		$out = str_replace("[[","&#91;",$out);
		$out = str_replace("]]","&#93;",$out);

		$out = ereg_replace('([^]:,]|^)(http://[[:alnum:]\?\$:+_%&=@#!/.~-]+[[:alnum:]+_%/-])','\\1<a href="\\2" target="_blank">\\2</a>',$out);


		nifty2_customtag($out,'uriel','I would rather rule in Hell than serve in Heaven!');
		nifty2_customtag($out,'cello','uberl33t');

//
// URLS

		nifty2_replace($out, 'url', "'<a href=\"'.nifty2_nice_url('\\1').'\"'.nifty2_url_target('\\1').'>\\2</a>'", $mode, 'me', '[^]"]+');
		nifty2_replace($out, 'url', "'<a href=\"'.nifty2_nice_url('\\1').'\"'.nifty2_url_target('\\1').'>\\1</a>'", $mode, 'me');
		nifty2_replace($out, 'email', "'<a href=\"mailto:'.nifty2_fix_brackets('\\1').'\">\\2</a>'", $mode, 'me', '[^]"]+');
		nifty2_replace($out, 'email', "'<a href=\"mailto:'.nifty2_fix_brackets('\\1').'\">\\1</a>'", $mode, 'me');
		$out = preg_replace('/\[email[:=\s](.+?)\]/mei',"'<a href=\"mailto:'.nifty2_fix_brackets('\\1').'\">\\1</a>'",$out);
//
// BASIC FORMATTING

		nifty2_replacetag($out, 'b', $mode);
		nifty2_replacetag($out, 'u', $mode);
		nifty2_replacetag($out, 'i', $mode);
		nifty2_replacetag($out, 'strike', $mode);

//
// INTERMEDIATE FORMATTING
		nifty2_replacetag($out, 'sub', $mode);
		nifty2_replacetag($out, 'sup', $mode);
//
// ADVANCED FORMATTING
		nifty2_replace($out, 'color', '<font color="\\1">\\2</font>', $mode, 's', '#[0-9A-Fa-f]{6}|[a-zA-Z]+');
		nifty2_replace($out, 'color', '<font color="\\1" style="background:\\2">\\3</font>', $mode, 's', '#[0-9A-Fa-f]{6}|[a-zA-Z]+)\s+on\s+(#[0-9A-Fa-f]{6}|[a-zA-Z]+',2);

		return $out;
	}


	function nifty2_replacetag(&$text,$tag,$mode=1) {
		nifty2_replace($text,$tag,'<'.$tag.'>\\1</'.$tag.'>',$mode);
	}
	function nifty2_customtag(&$text,$tag,$replace,$mode=1) {
		$text = preg_replace('/\['.$tag.'\]/i',$replace,$text);
		nifty2_replace($text,$tag,'<'.$tag.'>\\1</'.$tag.'>',$mode);
	}
	function nifty2_replace(&$text,$tag,$replace,$mode=1,$flags='s',$parameter=null,$parameters=0) {
		if ($parameter&&isset($parameters)) $parameters=1;
		if ($mode==1)
			$text = preg_replace('/\['.$tag.($parameters?'[:=\s]\s*('.$parameter.')':'').'\](.+?)[\n\r\f]?(?:$|\[\/'.$tag.'\])/i'.$flags, $replace, $text);
		else
			$text = preg_replace('/(\['.$tag.($parameters?'[:=\s]\s*(?:'.nifty2_strip_parentheses($parameter).')':'').'\])(.+?)[\n\r\f]?($|\[\/'.$tag.'\])/i'.str_replace('e','',$flags), ($mode==-1?'\\2':'<font color="red">\\1</font>\\2<font color="red">\\3</font>'), $text);
	}
	function nifty2_smiley(&$text,$smile,$name) {
		$text = str_replace("[$smile]",'<img src="/images/smilies/'.$name.'.gif" border="0">',$text);
	}
	function nifty2_html($text) {
		return str_replace(']','&#93;',str_replace('[','&#91;',$text));
	}
	function nifty2_fix_brackets($text) {
		return stripslashes(str_replace(']','&#93;',str_replace('[','&#91;',$text)));
	}
	function nifty2_nice_url($url) {
		$url=str_replace(' ','%20',str_replace('<','&lt;',nifty2_fix_brackets(stripslashes($url))));
		if (!eregi('(^[a-z]+):',$url)) return "http://$url";
		return $url;
	}
	function nifty2_url_target($url) {
		$parse=parse_url(nifty2_nice_url($url));
		if (ereg(MATCHDOMAIN,$parse[host])&&ereg('^'.PATH,$parse[path])) return;
		if ($parse[scheme]=='mailto'||$parse[scheme]=='irc') return;
		return ' target="_blank"';
	}
	function nifty2_strip_br($text) {
		return stripslashes(preg_replace('/<br\s*\/>/i','',$text));
	}
	function nifty2_strip_parentheses($text) {
		return str_replace('(','(?:',$text);
	}
?>
Return current item: OekakiPoteto