summaryrefslogtreecommitdiff
path: root/forum/utils/parser.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-10 20:26:15 +0000
committerdeva <deva>2008-10-10 20:26:15 +0000
commitf6d90d8d3504fc1ba428da81e77c4484c4646f30 (patch)
treef32447635738a4619a847f8e5cba4c8182221a0a /forum/utils/parser.php
parente61e99c0c24c27aad23c211524b4f32fb2159065 (diff)
Did some work on the forum parser.
Diffstat (limited to 'forum/utils/parser.php')
-rw-r--r--forum/utils/parser.php64
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");