summaryrefslogtreecommitdiff
path: root/forum/utils
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
parente61e99c0c24c27aad23c211524b4f32fb2159065 (diff)
Did some work on the forum parser.
Diffstat (limited to 'forum/utils')
-rw-r--r--forum/utils/parser.php64
-rw-r--r--forum/utils/smileys.php16
2 files changed, 45 insertions, 35 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");
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 @@
-<?php
+<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
$smileys = array(
- array(array(":-)", ":)"), "smile.gif"),
- array(array(":-D", ":D"), "biggrinn.gif"),
+ array(array(":-)", ":)"), "smile.gif"),
+ array(array(":-D", ":D"), "biggrinn.gif"),
array(array("X-D", "x-D"), "grinn.gif"),
- array(array(";-)", ";)"), "wink.gif"),
+ array(array(";-)", ";)"), "wink.gif"),
array(array(";(", ";-("), "cry.gif"),
array(array(":(", ":-("), "mad.gif"),
array(array(":smoke:"), "smoke.gif"),
@@ -13,15 +13,15 @@ $smileys = array(
array(array(":butt:"), "butt.gif"),
array(array(":eek:"), "eek.gif"),
array(array(":razz:"), "razz.gif"),
- array(array(":roll:"), "roll.gif"),
+ array(array(":roll:"), "roll.gif"),
array(array(":evil:"), "evil.gif"),
array(array(":lol:"), "lol.gif"),
array(array(":cool:"), "cool.gif"),
// array(array(":thumbsup:"), "thumbsup.gif"),
- array(array(":-p", ":p", ":-P", ":P"), "tongue.png"),
+ array(array(":-p", ":p", ":-P", ":P"), "tongue.png"),
array(array("(R)"), "redface.gif"),
- array(array("\\m/"), "headbanger.gif"),
- array(array("&gt;:O"), "growler.gif"),
+ array(array("\\m/"), "headbanger.gif"),
+ array(array("&gt;:O"), "growler.gif"),
array(array(":thumbsup:"), "thumbsup.gif"),
array(array(":thumbsdown:"), "thumbsdown.gif"),
array(array("=>", "->"), "arrow.gif"),