From 5ccf183b325e899685e4ac6ded56e3c1dd7a26c9 Mon Sep 17 00:00:00 2001
From: deva <deva>
Date: Tue, 28 Oct 2008 12:34:44 +0000
Subject: Fixed annoying bug on url/image parsing.

---
 forum/utils/parser.php | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

(limited to 'forum/utils/parser.php')

diff --git a/forum/utils/parser.php b/forum/utils/parser.php
index f79be2a..e4a164e 100644
--- a/forum/utils/parser.php
+++ b/forum/utils/parser.php
@@ -10,6 +10,8 @@ include_once($UTIL_DIR . "/smileys.php");
 // error_reporting
 //
 
+// http://www1.cs.columbia.edu/~lennox/perlre.html
+
 function parse($input, $indent = "")
 {
   global $testing;
@@ -39,20 +41,20 @@ function parse($input, $indent = "")
   while(strpos($output, $imgendmarker)) $imgendmarker .= $imgendsymbol;
 
   // Find and mark image URLs (so that they don't get converted into normal <a/> links)
-  $output = preg_replace("/http:\/\/(.*?\.jpg|.*?\.gif|.*?\.png|.*?\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output);
+  $output = preg_replace("/http:\/\/(\S*?\.jpg|\S*?\.gif|\S*?\.png|\S*?\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output);
 
-	// Replace URLs with <a></a> tags
-  $output = preg_replace("/http:\/\/(.*?)([\n ]|$)/s", "<a href=\"http://$1\">$1</a>$2", $output);
+  // Replace URLs with <a></a> tags
+  $output = preg_replace("/http:\/\/(\S*?)([\n ]|$)/s", "<a href=\"http://$1\">$1</a>$2", $output);
 
   // Convert marked images to img tags and links
-  $output = preg_replace("/".$imgstartmarker."(.*?)".$imgendmarker."/s", "<a href=\"http://$1\"><img alt=\"$1\" src=\"?mode=imagecache&amp;uri=http://$1\"/></a>", $output);
+  $output = preg_replace("/".$imgstartmarker."(\S*?)".$imgendmarker."/s", "<a href=\"http://$1\"><img alt=\"$1\" src=\"?mode=imagecache&amp;uri=http://$1\"/></a>", $output);
 
-	// Replace URLs with <a></a> tags
+  // Replace file links with their thumbnails.
   $output = preg_replace("/\{\{([0-9]*?)\}\}/s", "<a href=\"?mode=file&amp;fid=$1\"><img src=\"?mode=file&amp;preview=1&amp;fid=$1\"/></a>", $output);
 
-	// Replace [quote title=...]...[/quote]
+  // Replace [quote title=...]...[/quote]
   $urls = "";
-	while(($start = strpos($output, "[quote"))) {
+  while(($start = strpos($output, "[quote"))) {
     $pre = substr($output, 0, $start);
     $url = substr($output, $start);
     $end = strpos($url, "[/quote]") + strlen("[/quote]");
-- 
cgit v1.2.3