From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- forum/utils/parser.php | 126 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 forum/utils/parser.php (limited to 'forum/utils/parser.php') diff --git a/forum/utils/parser.php b/forum/utils/parser.php new file mode 100644 index 0000000..3c33a9b --- /dev/null +++ b/forum/utils/parser.php @@ -0,0 +1,126 @@ +", $output); + $output = $smile; + } + + // Replace URLs with tags + $urls = ""; + while(($start = strpos($output, "http://"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end1 = strpos($url, " "); + $end2 = strpos($url, "\n"); + if($end1 == 0) { + if($end2 == 0) $end = strlen($url); + else $end = $end2; + } else { + if($end2 == 0) $end = $end1; + else if($end1 < $end2) $end = $end1; + else $end = $end2; + } + $url = substr($url, 0, $end); + $post = substr($output, $start + $end); + if(strstr($url, ".jpg") || strstr($url, ".gif") || strstr($url, ".png")) { + $urls .= $pre . "\"""; + } else { + $urls .= $pre . "" . $url . ""; + } + $output = $post; + } + $urls .= $output; + $output = $urls; + + // Replace [quote title=...]...[/quote] + $urls = ""; + while(($start = strpos($output, "[quote"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end = strpos($url, "[/quote]") + strlen("[/quote]"); + $url = substr($url, 0, $end - strlen("[/quote]")); + $post = substr($output, $start + $end + strlen("[/quote]") ); + + $header = substr($url, 0, strpos($url, "]") + 1); + $body = substr($url, strpos($url, "]") + 1); + + $header = str_replace(array("title"), "", $header); + $header = str_replace(array("="), "
", $header); + $header = str_replace(array("[quote"), "
", $header); + $header = str_replace(array("]"), "
", $header); + + $urls .= $pre . $header . $body . "
"; + $output = $post; + } + $urls .= $output; + $output = $urls; + + // + // Hack to make quotes two levels deep. + // + // Replace [quote title=...]...[/quote] + $urls = ""; + while(($start = strpos($output, "[quote"))) { + $pre = substr($output, 0, $start); + $url = substr($output, $start); + $end = strpos($url, "[/quote]") + strlen("[/quote]"); + $url = substr($url, 0, $end - strlen("[/quote]")); + $post = substr($output, $start + $end + strlen("[/quote]") ); + + $header = substr($url, 0, strpos($url, "]") + 1); + $body = substr($url, strpos($url, "]") + 1); + + $header = str_replace(array("title"), "", $header); + $header = str_replace(array("="), "
", $header); + $header = str_replace(array("[quote"), "
", $header); + $header = str_replace(array("]"), "
", $header); + + $urls .= $pre . $header . $body . "
"; + $output = $post; + } + $urls .= $output; + $output = $urls; + + // + $b = array("[b]", "[B]"); + $b = str_replace($b, "", $output); + $output = $b; + + $b = array("[/b]", "[/B]"); + $b = str_replace($b, "", $output); + $output = $b; + + // + $i = array("[i]", "[I]"); + $i = str_replace($i, "", $output); + $output = $i; + + $i = array("[/i]", "[/i]"); + $i = str_replace($i, "", $output); + $output = $i; + + // Replace newlines with
tags + $nls = array("\n"); + $nls = str_replace($nls, "
\n", $output); + $output = $nls; + + return $output; +} + +?> -- cgit v1.2.3