From 07882614bfd402132d2f8df23cc23c2c013b5f14 Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 11 Oct 2008 10:55:28 +0000 Subject: Did a lot of work on the imagecache, and the filehandler. Now both are functional, and used indirectly throught index.php, thus requiering login for access. --- forum/utils/parser.php | 93 ++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 56 deletions(-) (limited to 'forum/utils/parser.php') diff --git a/forum/utils/parser.php b/forum/utils/parser.php index e857c7e..b5a80b7 100644 --- a/forum/utils/parser.php +++ b/forum/utils/parser.php @@ -7,6 +7,7 @@ include_once($UTIL_DIR . "/smileys.php"); // strtr // ereg_replace // str_replace +// error_reporting // function parse($input, $indent = "") @@ -28,23 +29,32 @@ function parse($input, $indent = "") $output = $smile; } - // Insert images - $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/s", "IMAGE$1EGAMI", $output); + // Find a unique symbols for image start and end markers + $imgstartsymbol = "A"; + $imgstartmarker = $imgstartsymbol; + while(strpos($output, $imgstartmarker)) $imgstartmarker .= $imgstartsymbol; + + $imgendsymbol = "B"; + $imgendmarker = $imgendsymbol; + while(strpos($output, $imgendmarker)) $imgendmarker .= $imgendsymbol; + + // Find and mark image URLs (so that they don't get converted into normal links) + $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output); // Replace URLs with tags $output = preg_replace("/http:\/\/(.*?)([\n ])/s", "$1$2", $output); - // Finish inserting images - $output = preg_replace("/IMAGE(.*?)EGAMI/s", "\"$1\"", $output); + // Convert marked images to img tags and links + $output = preg_replace("/".$imgstartmarker."(.*?)".$imgendmarker."/s", "\"$1\"", $output); // Replace [quote title=...]...[/quote] - $urls = ""; + $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]") ); + $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); @@ -54,17 +64,17 @@ function parse($input, $indent = "") $header = str_replace(array("[quote"), "
", $header); $header = str_replace(array("]"), "
", $header); - $urls .= $pre . $header . $body . ""; - $output = $post; + $urls .= $pre . $header . $body . ""; + $output = $post; } - $urls .= $output; - $output = $urls; + $urls .= $output; + $output = $urls; // // Hack to make quotes two levels deep. // // Replace [quote title=...]...[/quote] - $urls = ""; + $urls = ""; while(($start = strpos($output, "[quote"))) { $pre = substr($output, 0, $start); $url = substr($output, $start); @@ -83,48 +93,19 @@ function parse($input, $indent = "") $urls .= $pre . $header . $body . ""; $output = $post; } - $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; - - $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; - */ + $urls .= $output; + $output = $urls; + + $search = array('/\[b\](.*?)\[\/b\]/is', + '/\[i\](.*?)\[\/i\]/is', + '/\[u\](.*?)\[\/u\]/is'); + + $replace = array('$1', + '$1', + '$1'); + $output = preg_replace ($search, $replace, $output); + // Replace newlines with
tags $nls = array("\n"); $nls = str_replace($nls, "
\n", $output); -- cgit v1.2.3