From f6d90d8d3504fc1ba428da81e77c4484c4646f30 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 10 Oct 2008 20:26:15 +0000 Subject: Did some work on the forum parser. --- forum/utils/parser.php | 64 ++++++++++++++++++++++++++++--------------------- forum/utils/smileys.php | 16 ++++++------- 2 files changed, 45 insertions(+), 35 deletions(-) (limited to 'forum/utils') diff --git a/forum/utils/parser.php b/forum/utils/parser.php index 3c33a9b..e857c7e 100644 --- a/forum/utils/parser.php +++ b/forum/utils/parser.php @@ -1,7 +1,14 @@ - 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; + $output = preg_replace("/http:\/\/(.*?)([\n ])/s", "$1$2", $output); + + // Finish inserting images + $output = preg_replace("/IMAGE(.*?)EGAMI/s", "\"$1\"", $output); // Replace [quote title=...]...[/quote] $urls = ""; @@ -97,7 +86,27 @@ function parse($input, $indent = "") $urls .= $output; $output = $urls; - // + $search = array( + '/\[b\](.*?)\[\/b\]/is', + '/\[i\](.*?)\[\/i\]/is', + '/\[u\](.*?)\[\/u\]/is', + '/\[img\](.*?)\[\/img\]/is', + '/\[url\](.*?)\[\/url\]/is', + '/\[url\=(.*?)\](.*?)\[\/url\]/is' + ); + + $replace = array( + '$1', + '$1', + '$1', + '', + '$1', + '$2' + ); + + $output = preg_replace ($search, $replace, $output); + /* + // $b = array("[b]", "[B]"); $b = str_replace($b, "", $output); $output = $b; @@ -114,6 +123,7 @@ function parse($input, $indent = "") $i = array("[/i]", "[/i]"); $i = str_replace($i, "", $output); $output = $i; + */ // Replace newlines with
tags $nls = array("\n"); diff --git a/forum/utils/smileys.php b/forum/utils/smileys.php index e0a2d1a..59a0a41 100644 --- a/forum/utils/smileys.php +++ b/forum/utils/smileys.php @@ -1,10 +1,10 @@ -", "->"), "arrow.gif"), -- cgit v1.2.3