diff --git a/build/index.php b/build/index.php index 9f9c4a4..917dd9d 100644 --- a/build/index.php +++ b/build/index.php @@ -2733,7 +2733,9 @@ register_module([ { case "image": $extra_data = []; - $imagesize = getimagesize($temp_filename, $extra_data); + // Check SVG uploads with a special function + $imagesize = $mime_type !== "image/svg+xml" ? getimagesize($temp_filename, $extra_data) : upload_check_svg($temp_filename); + // Make sure that the image size is defined if(!is_int($imagesize[0]) or !is_int($imagesize[1])) { @@ -2741,7 +2743,6 @@ register_module([ exit(page_renderer::render("Upload Error - $settings->sitename", "
Although the file that you uploaded appears to be an image, $settings->sitename has been unable to determine it's dimensions. The uploaded file has been discarded. Go back to try again.
You may wish to consider opening an issue against Pepperminty Wiki (the software that powers $settings->sitename) if this isn't the first time that you have seen this message.
")); } - break; } @@ -2839,7 +2840,10 @@ register_module([ $filepath = $env->storage_prefix . $pageindex->{$env->page}->uploadedfilepath; $mime_type = $pageindex->{$env->page}->uploadedfilemime; - if(isset($_GET["size"]) and $_GET["size"] == "original") + // If the size is set or original, then send (or redirect to) the original image + // Also do the same for SVGs if svg rendering is disabled. + if(isset($_GET["size"]) and $_GET["size"] == "original" or + (empty($settings->render_svg_previews) && $mime_type == "image/svg+xml")) { // Get the file size $filesize = filesize($filepath); @@ -2989,7 +2993,7 @@ register_module([ // We are looking at a page that is paired with an uploaded file $filepath = $pageindex->{$env->page}->uploadedfilepath; $mime_type = $pageindex->{$env->page}->uploadedfilemime; - $dimensions = getimagesize($env->storage_prefix . $filepath); + $dimensions = $mime_type !== "image/svg+xml" ? getimagesize($env->storage_prefix . $filepath) : getsvgsize($env->storage_prefix . $filepath); $fileTypeDisplay = substr($mime_type, 0, strpos($mime_type, "/")); $previewUrl = "?action=preview&size=$settings->default_preview_size&page=" . rawurlencode($env->page); @@ -3000,14 +3004,17 @@ register_module([ case "image": $preview_sizes = [ 256, 512, 768, 1024, 1440 ]; $preview_html .= "\t\t\t"; + + \n\t\t\t"; break; case "video": @@ -3029,7 +3036,8 @@ register_module([ switch($fileTypeDisplay) { case "image": - $fileInfo["Original dimensions"] = "$dimensions[0] x $dimensions[1]"; + $dimensionsKey = $mime_type !== "image/svg+xml" ? "Original demensions" : "Native size"; + $fileInfo[$dimensionsKey] = "$dimensions[0] x $dimensions[1]"; break; } $fileInfo["Uploaded by"] = $pageindex->{$env->page}->lasteditor; @@ -3086,6 +3094,39 @@ function parse_size($size) { } } +function upload_check_svg($temp_filename) +{ + global $settings; + // Check for script tags + if(strpos(file_get_contents($temp_filename), "