summaryrefslogtreecommitdiff
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
parente61e99c0c24c27aad23c211524b4f32fb2159065 (diff)
Did some work on the forum parser.
-rw-r--r--forum/htdocs/imagecache.php62
-rw-r--r--forum/utils/parser.php64
-rw-r--r--forum/utils/smileys.php16
3 files changed, 107 insertions, 35 deletions
diff --git a/forum/htdocs/imagecache.php b/forum/htdocs/imagecache.php
new file mode 100644
index 0000000..f23a51d
--- /dev/null
+++ b/forum/htdocs/imagecache.php
@@ -0,0 +1,62 @@
+<?php
+
+include_once("config.php");
+include_once($UTIL_DIR . "/ping.php");
+
+
+function rescale($image) {
+
+ $maxwidth = 300;
+ $maxheight = 240;
+
+ $width = imagesx($image);
+ $height = imagesy($image);
+
+ if($width > $maxwidth) $scale = $width / $maxwidth;
+ if($height / $scale > $maxheight) $scale = $height / $maxheight;
+
+ $image_p = imagecreatetruecolor($width / $scale, $height / $scale);
+ imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width / $scale, $height / $scale, $width, $height);
+
+ return $image_p;
+}
+
+
+$fullfilename = $IMAGECACHE . "/" . urlencode($filename);
+
+if(!file_exists($fullfilename)) {
+
+ $url = parse_url($filename);
+ $filetype = strrchr($url["path"], '.');
+
+ if( true || ping($url["hostname"], 1000) != -1) {
+
+ if(strcasecmp($filetype, ".jpeg") == 0 || strcasecmp($filetype, ".jpg") == 0) {
+ $image = imagecreatefromjpeg(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagejpeg($image, $fullfilename, 90);
+ } else if(strcasecmp($filetype, ".gif") == 0) {
+ $image = imagecreatefromgif(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagegif($image, $fullfilename);
+ } else if(strcasecmp($filetype, ".png") == 0) {
+ $image = imagecreatefrompng(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagepng($image, $fullfilename);
+ } else {
+ echo "<p>Unknown image format " . $filetype . "</p>";
+ }
+
+ }
+}
+
+header('Content-Description: File Transfer');
+header('Content-Type: image/jpeg');
+header('Content-Length: ' . filesize($fullfilename));
+header('Content-Disposition: inline; filename=' . basename($filename));
+readfile($fullfilename);
+
+?> \ No newline at end of file
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"),