From 40a7e25ffea5fd5a537beefa98a41615cc8088e5 Mon Sep 17 00:00:00 2001 From: Curle Date: Thu, 8 Oct 2020 07:04:46 +0100 Subject: [PATCH] Fix the site! --- backend/config.php | 2 +- backend/functions.php | 10 ++++++---- index.php | 17 +++++++++++------ resources/js/main.js | 10 ++++++++-- templates/content.php | 13 ++++++++----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/backend/config.php b/backend/config.php index bdce789..6a95ce4 100644 --- a/backend/config.php +++ b/backend/config.php @@ -14,4 +14,4 @@ $config = array( ini_set("error_reporting", "true"); -error_reporting(E_ALL | E_STRCT); \ No newline at end of file +error_reporting(E_ALL | E_STRICT); diff --git a/backend/functions.php b/backend/functions.php index 085dfa9..7963999 100644 --- a/backend/functions.php +++ b/backend/functions.php @@ -7,7 +7,7 @@ function console_log( $data ) { echo ""; } /** * List the subdirectories of a folder. @@ -107,7 +107,6 @@ function tidyName( $name ) { function isPathValid( $file, $path ) { $realFile = realpath( $file ); $realDir = realpath( $path ); - /** * If the two paths match, then the path is valid */ @@ -143,14 +142,17 @@ function sendFile( $image ) { //$etag = md5_file( $image ); + ob_clean(); header("Last-Modified: $lastModified GMT"); header("Pragma: public"); header("Cache-Control: max-age=$expires"); //header("Etag: $etag"); header("Expires: " . gmdate('D, d M Y H:i:s', time() + $expires) . " GMT"); - header("Content-type: image/jpeg"); + header("Content-type: image/png"); - readfile( $image ); + if(!readfile( $image )) { + console_log("Problem with file $image!"); + } } /** diff --git a/index.php b/index.php index 679500c..8236db9 100644 --- a/index.php +++ b/index.php @@ -16,7 +16,7 @@ require_once("backend/config.php"); require_once("backend/functions.php"); - +$error = ""; $imagesFolder = $config["images"]; @@ -56,9 +56,11 @@ if ( isset( $_GET["image"] ) ) { $image = relativeToAbsolute( stripslashes( $_GET["image"] ), $imagesFolder ); if ( isPathValid( $image, $imagesFolder ) ) { + console_log("Found valid image at " . $imagesFolder . $image); return sendFile($image); } else { $error = "Image not found"; + console_log($error); } } @@ -81,15 +83,17 @@ if ( isset( $_GET["thumb"] ) ) { * We can only spend so much time processing a tiny image, after all. */ - $image = relativeToAbsolute( stripslashes( $_GET["thumb"] ), $imagesFolder ); + $image = relativeToAbsolute( stripslashes( $_GET["thumb"] ), $config["images"]); + $image = str_replace("\/", "//", $image); $thumb = relativeToAbsolute( stripslashes( $_GET["thumb"] ), $config["thumbs"]); + $thumb = str_replace("\/", "//", $thumb); - if ( isPathValid( $image, $imagesFolder ) ) { - + if ( isPathValid( $image, $config["images"] ) ) { + console_log("Image is valid"); if ( !file_exists( $thumb ) ) { createThumbnail( $image, $thumb, $config["thumbs"] ); } - + // Generation can fail! We need to double check else risk a 400 if ( file_exists( $thumb ) ) { return sendFile($thumb); @@ -99,6 +103,7 @@ if ( isset( $_GET["thumb"] ) ) { } else { $error = "Image not found!"; + console_log($error); } } @@ -116,7 +121,7 @@ if ( isset( $_GET["category"] ) ) { if ( isPathValid( $tempDir, $imagesFolder ) ) { console_log("Directory is valid."); - $dir = $tempDir; + $imagesFolder = $tempDir; } else { console_log("Directory is invalid"); $error = "Invalid category"; diff --git a/resources/js/main.js b/resources/js/main.js index f91a1a8..8ee1206 100644 --- a/resources/js/main.js +++ b/resources/js/main.js @@ -11,12 +11,16 @@ $("document").ready(function() { $("#loading").show(); title = encodeURI($(this).children(".title").children("a").attr("href")); Name = $(this).children(".title").children("a").html(); - $("body").load(title); + $("body").load(title, function( response, status, xhr ) { + if ( status == "error" ) { + var msg = "Sorry but there was an error: "; + $( "#error" ).html( msg + xhr.status + " " + xhr.statusText ); + }}); updateURL(title, Name); }); $(".thumb").click(function() { - title = encodeURI($(this).children("a").attr("bref")); + title = encodeURI($(this).children("a").attr("href")); $("#lightbox").html(''); $("#viewer").fadeIn(); return false; @@ -25,4 +29,6 @@ $("document").ready(function() { $("#container").click(function() { $("#viewer").fadeOut(); }); + + $(".loading").hide(); }); \ No newline at end of file diff --git a/templates/content.php b/templates/content.php index fc5e84e..62bf954 100644 --- a/templates/content.php +++ b/templates/content.php @@ -56,13 +56,16 @@ if( count( $pictures ) > 0 ) { ?>
0 ) { ?>
- Loading. + \ No newline at end of file