summaryrefslogtreecommitdiff
path: root/forum
diff options
context:
space:
mode:
Diffstat (limited to 'forum')
-rw-r--r--forum/htdocs/imagecache.php62
-rw-r--r--forum/htdocs/index.php26
-rw-r--r--forum/utils/file.php31
-rw-r--r--forum/utils/filehandler.php2
-rw-r--r--forum/utils/files.php5
-rw-r--r--forum/utils/imagecache.php92
-rw-r--r--forum/utils/parser.php93
7 files changed, 181 insertions, 130 deletions
diff --git a/forum/htdocs/imagecache.php b/forum/htdocs/imagecache.php
deleted file mode 100644
index f23a51d..0000000
--- a/forum/htdocs/imagecache.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?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/htdocs/index.php b/forum/htdocs/index.php
index a452f20..f4d2ed7 100644
--- a/forum/htdocs/index.php
+++ b/forum/htdocs/index.php
@@ -1,17 +1,27 @@
<?php
header("Content-Type: text/html; charset=UTF-8");
-/*
-Jonas Mobil:
-"SonyEricssonW660i/R6BC Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
-
-Rasmus Mobil:
-"Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN81-3/11.0.045 Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413"
-*/
include_once("config.php");
+
+// Check login
include_once($UTIL_DIR . "/login.php");
checklogin();
+// Catch the modes that must not output any html.
+if($current_user) {
+ switch($mode) {
+ case "imagecache":
+ include_once($UTIL_DIR. "/imagecache.php");
+ getCachedImage($uri);
+ return;
+
+ case "file":
+ include_once($UTIL_DIR. "/file.php");
+ getFile($filename);
+ return;
+ }
+}
+
include_once($UTIL_DIR . "/clientinfo.php");
?>
<?xml version="1.0" encoding="UTF-8"?>
@@ -66,7 +76,7 @@ if($current_user) {
include_once($UTIL_DIR. "/edit.php");
break;
- case "files":
+ case "filehandler":
include_once($UTIL_DIR. "/filehandler.php");
break;
diff --git a/forum/utils/file.php b/forum/utils/file.php
new file mode 100644
index 0000000..50993b5
--- /dev/null
+++ b/forum/utils/file.php
@@ -0,0 +1,31 @@
+<?php
+
+include_once("config.php");
+include_once($UTIL_DIR . "/mimetypes.php");
+include_once($UTIL_DIR . "/files.php");
+
+function getFile($fid)
+{
+ global $DATA_DIR, $PERMSTORE, $MIME_TYPES;
+ $files = new Files($DATA_DIR . "/files.xml");
+ $file = $files->getFile($fid);
+
+ $filename = $PERMSTORE . "/" . $file->fid;
+
+ $download = false;
+ foreach($MIME_TYPES as $m) {
+ if($m->name == $file->mimetype) $download = !$m->show;
+ }
+
+ //header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header('Content-Description: File Transfer');
+ header('Content-Type: ' . $file->mimetype);
+ header('Content-Length: ' . filesize($filename));
+
+ if($download) header('Content-Disposition: attachment; filename=' . basename($file->name));
+ else header('Content-Disposition: inline; filename=' . basename($file->name));
+
+ readfile($filename);
+}
+
+?> \ No newline at end of file
diff --git a/forum/utils/filehandler.php b/forum/utils/filehandler.php
index 231ddd6..9cacb1c 100644
--- a/forum/utils/filehandler.php
+++ b/forum/utils/filehandler.php
@@ -19,7 +19,7 @@ $files->show();
?>
-<form enctype="multipart/form-data" action="?mode=files&amp;task=upload" method="post">
+<form enctype="multipart/form-data" action="?mode=filehandler&amp;task=upload" method="post">
<p>
File: <input name="userfile" type="file">
</p>
diff --git a/forum/utils/files.php b/forum/utils/files.php
index d714ba2..6cae023 100644
--- a/forum/utils/files.php
+++ b/forum/utils/files.php
@@ -10,15 +10,14 @@ class File {
public function link()
{
- global $PERMSTORE;
- return "file.php?fid=" . $this->fid;
+ return "?mode=file&amp;fid=" . $this->fid;
}
public function show()
{
global $PERMSTORE;
echo "<div class=\"file\">\n";
- echo " <a class=\"delete\" href=\"?mode=files&amp;task=delete&amp;fid=" . $this->fid . "\">Delete</a>\n";
+ echo " <a class=\"delete\" href=\"?mode=filehandler&amp;task=delete&amp;fid=" . $this->fid . "\">Delete</a>\n";
echo " <div class=\"filename\">Filename: <a href=\"" . $this->link() . "\">" . $this->name . "</a>(" . $this->mimetype. ")</div>\n";
echo " <div class=\"filesize\">Size: " . ceil(filesize($PERMSTORE . "/" . $this->fid) / 1024) . "kb</div>\n";
echo "</div>\n";
diff --git a/forum/utils/imagecache.php b/forum/utils/imagecache.php
new file mode 100644
index 0000000..aae5e66
--- /dev/null
+++ b/forum/utils/imagecache.php
@@ -0,0 +1,92 @@
+<?php
+
+include_once("config.php");
+include_once($UTIL_DIR . "/ping.php");
+
+
+function rescale($image) {
+
+ $maxwidth = 300;
+ $maxheight = 240;
+
+ $width = imagesx($image);
+ $height = imagesy($image);
+
+ $scale = 1;
+ 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;
+}
+
+function errorImage($filename)
+{
+ /*
+ header('Content-Description: File Transfer');
+ header('Content-Type: image/jpeg');
+ header('Content-Length: ' . filesize($fullfilename));
+ header('Content-Disposition: inline; filename=' . basename($filename));
+ readfile($fullfilename);
+ */
+ echo "Error fetching image: " . $filename;
+ die(404);
+}
+
+function getCachedImage($filename)
+{
+ global $IMAGECACHE;
+ $fullfilename = $IMAGECACHE . "/" . urlencode($filename);
+
+ if(!file_exists($fullfilename)) {
+
+ $url = parse_url($filename);
+ $filetype = strrchr($url["path"], '.');
+
+ if( true || ping($url["hostname"], 1000) != -1) {
+
+ error_reporting(E_ERROR | E_PARSE);
+
+ switch(tolower($filetype)) {
+ case ".jpeg":
+ case ".jpg":
+ $image = imagecreatefromjpeg(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagejpeg($image, $fullfilename, 90);
+ break;
+
+ case ".gif":
+ $image = imagecreatefromgif(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagegif($image, $fullfilename);
+ break;
+
+ case ".png":
+ $image = imagecreatefrompng(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagepng($image, $fullfilename);
+ break;
+
+ default:
+ if(!$image) errorImage("Unknown image type " . $filetype);
+ break;
+ }
+
+ error_reporting(E_ALL ^ E_NOTICE);
+
+ }
+ }
+
+ 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 e857c7e..b5a80b7 100644
--- a/forum/utils/parser.php
+++ b/forum/utils/parser.php
@@ -7,6 +7,7 @@ include_once($UTIL_DIR . "/smileys.php");
// strtr
// ereg_replace
// str_replace
+// error_reporting
//
function parse($input, $indent = "")
@@ -28,23 +29,32 @@ function parse($input, $indent = "")
$output = $smile;
}
- // Insert images
- $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/s", "IMAGE$1EGAMI", $output);
+ // Find a unique symbols for image start and end markers
+ $imgstartsymbol = "A";
+ $imgstartmarker = $imgstartsymbol;
+ while(strpos($output, $imgstartmarker)) $imgstartmarker .= $imgstartsymbol;
+
+ $imgendsymbol = "B";
+ $imgendmarker = $imgendsymbol;
+ while(strpos($output, $imgendmarker)) $imgendmarker .= $imgendsymbol;
+
+ // Find and mark image URLs (so that they don't get converted into normal <a/> links)
+ $output = preg_replace("/http:\/\/(.*\.jpg|\.gif|\.png|\.jpeg)/", $imgstartmarker."$1".$imgendmarker, $output);
// Replace URLs with <a></a> tags
$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);
+ // Convert marked images to img tags and links
+ $output = preg_replace("/".$imgstartmarker."(.*?)".$imgendmarker."/s", "<a href=\"http://$1\"><img alt=\"$1\" src=\"?mode=imagecache&amp;uri=http://$1\"/></a>", $output);
// Replace [quote title=...]...[/quote]
- $urls = "";
+ $urls = "";
while(($start = strpos($output, "[quote"))) {
- $pre = substr($output, 0, $start);
- $url = substr($output, $start);
- $end = strpos($url, "[/quote]") + strlen("[/quote]");
- $url = substr($url, 0, $end - strlen("[/quote]"));
- $post = substr($output, $start + $end + strlen("[/quote]") );
+ $pre = substr($output, 0, $start);
+ $url = substr($output, $start);
+ $end = strpos($url, "[/quote]") + strlen("[/quote]");
+ $url = substr($url, 0, $end - strlen("[/quote]"));
+ $post = substr($output, $start + $end + strlen("[/quote]") );
$header = substr($url, 0, strpos($url, "]") + 1);
$body = substr($url, strpos($url, "]") + 1);
@@ -54,17 +64,17 @@ function parse($input, $indent = "")
$header = str_replace(array("[quote"), "<div class=\"quote\">", $header);
$header = str_replace(array("]"), " </div>", $header);
- $urls .= $pre . $header . $body . "</div>";
- $output = $post;
+ $urls .= $pre . $header . $body . "</div>";
+ $output = $post;
}
- $urls .= $output;
- $output = $urls;
+ $urls .= $output;
+ $output = $urls;
//
// Hack to make quotes two levels deep.
//
// Replace [quote title=...]...[/quote]
- $urls = "";
+ $urls = "";
while(($start = strpos($output, "[quote"))) {
$pre = substr($output, 0, $start);
$url = substr($output, $start);
@@ -83,48 +93,19 @@ function parse($input, $indent = "")
$urls .= $pre . $header . $body . "</div>";
$output = $post;
}
- $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(
- '<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;
-
- $b = array("[/b]", "[/B]");
- $b = str_replace($b, "</strong>", $output);
- $output = $b;
-
- // <i></i>
- $i = array("[i]", "[I]");
- $i = str_replace($i, "<em>", $output);
- $output = $i;
-
- $i = array("[/i]", "[/i]");
- $i = str_replace($i, "</em>", $output);
- $output = $i;
- */
+ $urls .= $output;
+ $output = $urls;
+
+ $search = array('/\[b\](.*?)\[\/b\]/is',
+ '/\[i\](.*?)\[\/i\]/is',
+ '/\[u\](.*?)\[\/u\]/is');
+
+ $replace = array('<strong>$1</strong>',
+ '<em>$1</em>',
+ '<u>$1</u>');
+ $output = preg_replace ($search, $replace, $output);
+
// Replace newlines with <br/> tags
$nls = array("\n");
$nls = str_replace($nls, "<br/>\n", $output);