From f6d90d8d3504fc1ba428da81e77c4484c4646f30 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 10 Oct 2008 20:26:15 +0000 Subject: Did some work on the forum parser. --- forum/htdocs/imagecache.php | 62 +++++++++++++++++++++++++++++++++++++++++++ forum/utils/parser.php | 64 ++++++++++++++++++++++++++------------------- forum/utils/smileys.php | 16 ++++++------ 3 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 forum/htdocs/imagecache.php 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 @@ + $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 "

Unknown image format " . $filetype . "

"; + } + + } +} + +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 @@ - 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 . "\"""; - } else { - $urls .= $pre . "" . $url . ""; - } - $output = $post; - } - $urls .= $output; - $output = $urls; + $output = preg_replace("/http:\/\/(.*?)([\n ])/s", "$1$2", $output); + + // Finish inserting images + $output = preg_replace("/IMAGE(.*?)EGAMI/s", "\"$1\"", $output); // Replace [quote title=...]...[/quote] $urls = ""; @@ -97,7 +86,27 @@ function parse($input, $indent = "") $urls .= $output; $output = $urls; - // + $search = array( + '/\[b\](.*?)\[\/b\]/is', + '/\[i\](.*?)\[\/i\]/is', + '/\[u\](.*?)\[\/u\]/is', + '/\[img\](.*?)\[\/img\]/is', + '/\[url\](.*?)\[\/url\]/is', + '/\[url\=(.*?)\](.*?)\[\/url\]/is' + ); + + $replace = array( + '$1', + '$1', + '$1', + '', + '$1', + '$2' + ); + + $output = preg_replace ($search, $replace, $output); + /* + // $b = array("[b]", "[B]"); $b = str_replace($b, "", $output); $output = $b; @@ -114,6 +123,7 @@ function parse($input, $indent = "") $i = array("[/i]", "[/i]"); $i = str_replace($i, "", $output); $output = $i; + */ // Replace newlines with
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 @@ -", "->"), "arrow.gif"), -- cgit v1.2.3