diff options
Diffstat (limited to 'forum/utils/parser.php')
| -rw-r--r-- | forum/utils/parser.php | 64 | 
1 files changed, 37 insertions, 27 deletions
| 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 @@ -<?php +<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */  include_once($UTIL_DIR . "/convert.php");  include_once($UTIL_DIR . "/smileys.php"); +// +// preg_replace +// strtr +// ereg_replace +// str_replace +// +  function parse($input, $indent = "")  {    global $testing; @@ -21,32 +28,14 @@ function parse($input, $indent = "")  	  $output = $smile;  	} +  // Insert images +  $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/s", "IMAGE$1EGAMI", $output); +  	// Replace URLs with <a></a> 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 . "<a href=\"" . $url . "\"><img alt=\"" . $url . "\" style=\"border: solid red 1px;\" src=\"imagecache.php?filename=" . urlencode($url) . "\"/></a>"; -		} else { -		  $urls .= $pre . "<a href=\"" . $url . "\">" . $url . "</a>"; -		} -		$output = $post; -	} -	$urls .= $output; -	$output = $urls; +  $output = preg_replace("/http:\/\/(.*?)([\n ])/s", "<a href=\"http://$1\">$1</a>$2", $output); + +  // Finish inserting images +  $output = preg_replace("/IMAGE(.*?)EGAMI/s", "<img alt=\"$1\" src=\"imagecache.php?filename=$1\"/>", $output);  	// Replace [quote title=...]...[/quote]          $urls = ""; @@ -97,7 +86,27 @@ function parse($input, $indent = "")          $urls .= $output;          $output = $urls; -        // <b></b> +        $search = array( +                        '/\[b\](.*?)\[\/b\]/is', +                        '/\[i\](.*?)\[\/i\]/is', +                        '/\[u\](.*?)\[\/u\]/is', +                        '/\[img\](.*?)\[\/img\]/is', +                        '/\[url\](.*?)\[\/url\]/is', +                        '/\[url\=(.*?)\](.*?)\[\/url\]/is' +                        ); + +        $replace = array( +                         '<strong>$1</strong>', +                         '<em>$1</em>', +                         '<u>$1</u>', +                         '<img src="$1" />', +                         '<a href="$1">$1</a>', +                         '<a href="$1">$2</a>' +                         ); + +        $output = preg_replace ($search, $replace, $output); +        /* +       // <b></b>          $b = array("[b]", "[B]");          $b = str_replace($b, "<strong>", $output);          $output = $b; @@ -114,6 +123,7 @@ function parse($input, $indent = "")          $i = array("[/i]", "[/i]");          $i = str_replace($i, "</em>", $output);          $output = $i; +        */  	// Replace newlines with <br/> tags  	$nls = array("\n"); | 
