Location: PHPKode > scripts > Particle Gallery > includes/bbcode.php
<?php
function bbcode($code){
	global $config, $dbprefix, $db;
	
	// should the HTML be stripped?
	if ($config["allowhtml"] <> "true"){
		$code = strip_tags($code, "<hr>,<br>");
	}
	
	if ($config["allowbbcode"] == "true"){
		$patterns[0] = "|\[b\](.*?)\[/b\]|s";
	    $patterns[1] = "|\[i\](.*?)\[/i\]|s";
	    $patterns[2] = "|\[u\](.*?)\[/u\]|s";
	    $patterns[3] = "|\[center\](.*?)\[/center\]|s";
	    $patterns[4] = "|\[url\](.*?)\[/url\]|s";
	    $patterns[5] = "|\[url=(.*?)\](.*?)\[/url\]|s";
	    $patterns[6] = "|\[hr\](.*?),(.*?)\[/hr\]|s";
	    $patterns[7] = "|\[img\](http://.*?)\[/img\]|s";
		$patterns[8] = "|\[s\](.*?)\[/s\]|s";
		
	    $replacements[0] = "<b>\$1</b>";
	    $replacements[1] = "<i>\$1</i>";
	    $replacements[2] = "<u>\$1</u>";
	    $replacements[3] = "<center>\$1</center>";
	    $replacements[4] = "<a href=\"\$1\">\$1</a>";
	    $replacements[5] = "<a href=\"\$1\">\$2</a>";
	    $replacements[6] = "<hr size=\"\$1\" width=\"\$2\" />";
	    $replacements[7] = "<img src=\"\$1\" border=\"0\" />";
		$replacements[8] = "<s>\$1</s>";
		
		ksort($patterns);
	    ksort($replacements);
	    $replaced = preg_replace($patterns, $replacements, $code);
	    $code = $replaced;
		
	    // parse in lists
	    $tok2 = split("\n", $code . "\n");
	    $inlist = 0; $listtype = 1; $res = "";
	    foreach ($tok2 as $tok){
	    	// is this line a list line?
	    	if ((substr($tok, 0, 1) == "*") || (substr($tok, 0, 1) == "#")){
	    		// this is a list item
	    		if ($inlist == 0){
	    			if (substr($tok, 0, 1) == "*"){
	    				$res .= "<ul>\n";
	    				$listtype = 1;
	    			} else {
	    				$res .= "<ol>\n";
	    				$listtype = 2;
	    			}
	    		}
	    		
	    		// add the line in
	    		if (substr($tok, -1) == "\r"){
	    			$res .= "\t<li>" . substr(substr($tok, 0, -1), 1) . "</li>\n";
	    		} else {
	    			$res .= "\t<li>" . substr(substr($tok, 0), 1) . "</li>\n";
	    		}
	    		$inlist = 1;
	    	} else {
	    		// not a list item
	    		if ($inlist == 1){
	    			if ($listtype == 1){
	    				$res .= "</ul>\n";
	    			} else {
	    				$res .= "</ol>\n";
	    			}
	    		}
	    		
	    		// add the line in
	    		$res .= $tok . "\n";
	    		$inlist = 0;
	    	}
	    }
	    $code = $res;
	    // end parsinng list items
	}
	
	// encode new files
	$code = str_replace("\r\n\r\n", "<br /><br />", $code);
    
	return $code;
}
?>
Return current item: Particle Gallery