mirror of
https://github.com/mosbth/cimage.git
synced 2025-09-03 04:32:34 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
3b16b4b79d | ||
|
4e940164f9 | ||
|
1943d6606b | ||
|
5eebaa66ce | ||
|
c5cc0314c2 | ||
|
71816261f2 | ||
|
a62d7cb6c2 | ||
|
ccbd08949f | ||
|
6467fcc748 | ||
|
14d22a18e5 | ||
|
6d3687d838 | ||
|
ad8f6c12ee | ||
|
ad4930c3ae |
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2012 - 2014 Mikael Roos, me@mikaelroos.se
|
Copyright (c) 2012 - 2016 Mikael Roos, https://mikaelroos.se, mos@dbwebb.se
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@@ -46,14 +46,14 @@ There are several ways of installing. You either install the whole project which
|
|||||||
|
|
||||||
The [sourcode is available on GitHub](https://github.com/mosbth/cimage). Clone, fork or [download as zip](https://github.com/mosbth/cimage/archive/master.zip).
|
The [sourcode is available on GitHub](https://github.com/mosbth/cimage). Clone, fork or [download as zip](https://github.com/mosbth/cimage/archive/master.zip).
|
||||||
|
|
||||||
**Latest stable version is v0.7.9 released 2015-12-07.**
|
**Latest stable version is v0.7.10 released 2016-04-01.**
|
||||||
|
|
||||||
I prefer cloning like this. Do switch to the latest stable version.
|
I prefer cloning like this. Do switch to the latest stable version.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone git://github.com/mosbth/cimage.git
|
git clone git://github.com/mosbth/cimage.git
|
||||||
cd cimage
|
cd cimage
|
||||||
git checkout v0.7.9
|
git checkout v0.7.10
|
||||||
```
|
```
|
||||||
|
|
||||||
Make the cache-directory writable by the webserver.
|
Make the cache-directory writable by the webserver.
|
||||||
@@ -76,7 +76,7 @@ There are some all-included bundles of `img.php` that can be downloaded and used
|
|||||||
Dowload the version of your choice like this.
|
Dowload the version of your choice like this.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.9/webroot/imgp.php
|
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.10/webroot/imgp.php
|
||||||
```
|
```
|
||||||
|
|
||||||
Open up the file in your editor and edit the array `$config`. Ensure that the paths to the image directory and the cache directory matches your environment, or create an own config-file for the script.
|
Open up the file in your editor and edit the array `$config`. Ensure that the paths to the image directory and the cache directory matches your environment, or create an own config-file for the script.
|
||||||
|
14
REVISION.md
14
REVISION.md
@@ -5,6 +5,20 @@ Revision history
|
|||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.11 (2016-04-18)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Add option for `skip_original` to config file to always skip original, #118.
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.10 (2016-04-01)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Add backup option for images `src-alt`, #141.
|
||||||
|
* Add require of ext-gd in composer.json, #133.
|
||||||
|
* Fix strict mode only reporting 404 when failure, #127.
|
||||||
|
|
||||||
|
|
||||||
v0.7.9 (2015-12-07)
|
v0.7.9 (2015-12-07)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
|
@@ -18,7 +18,11 @@
|
|||||||
"docs": "http://dbwebb.se/opensource/cimage"
|
"docs": "http://dbwebb.se/opensource/cimage"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3"
|
"php": ">=5.3",
|
||||||
|
"ext-gd": "*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-exif": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.9 (2015-12-07)";
|
$version = "v0.7.11 (2016-04-18)";
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -38,16 +38,16 @@ function errorPage($msg, $type = 500)
|
|||||||
$header = "500 Internal Server Error";
|
$header = "500 Internal Server Error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mode == "strict") {
|
||||||
|
$header = "404 Not Found";
|
||||||
|
}
|
||||||
|
|
||||||
header("HTTP/1.0 $header");
|
header("HTTP/1.0 $header");
|
||||||
|
|
||||||
if ($mode == "development") {
|
if ($mode == "development") {
|
||||||
die("[img.php] $msg");
|
die("[img.php] $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode == "strict") {
|
|
||||||
$header = "404 Not Found";
|
|
||||||
}
|
|
||||||
|
|
||||||
error_log("[img.php] $msg");
|
error_log("[img.php] $msg");
|
||||||
die("HTTP/1.0 $header");
|
die("HTTP/1.0 $header");
|
||||||
}
|
}
|
||||||
@@ -409,18 +409,28 @@ if (isset($shortcut)
|
|||||||
$srcImage = urldecode(get('src'))
|
$srcImage = urldecode(get('src'))
|
||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
|
// Get settings for src-alt as backup image
|
||||||
|
$srcAltImage = urldecode(get('src-alt', null));
|
||||||
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
|
if (empty($srcAltImage)) {
|
||||||
|
$srcAltImage = $srcAltConfig;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for valid/invalid characters
|
// Check for valid/invalid characters
|
||||||
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||||
$imagePathConstraint = getConfig('image_path_constraint', true);
|
$imagePathConstraint = getConfig('image_path_constraint', true);
|
||||||
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
||||||
|
|
||||||
|
// Source is remote
|
||||||
|
$remoteSource = false;
|
||||||
|
|
||||||
// Dummy image feature
|
// Dummy image feature
|
||||||
$dummyEnabled = getConfig('dummy_enabled', true);
|
$dummyEnabled = getConfig('dummy_enabled', true);
|
||||||
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
||||||
$dummyImage = false;
|
$dummyImage = false;
|
||||||
|
|
||||||
preg_match($validFilename, $srcImage)
|
preg_match($validFilename, $srcImage)
|
||||||
or errorPage('Filename contains invalid characters.', 404);
|
or errorPage('Source filename contains invalid characters.', 404);
|
||||||
|
|
||||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
|
||||||
@@ -430,19 +440,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
|
|||||||
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
||||||
|
|
||||||
// If source is a remote file, ignore local file checks.
|
// If source is a remote file, ignore local file checks.
|
||||||
|
$remoteSource = true;
|
||||||
|
|
||||||
} elseif ($imagePathConstraint) {
|
} else {
|
||||||
|
|
||||||
// Check that the image is a file below the directory 'image_path'.
|
// Check if file exists on disk or try using src-alt
|
||||||
$pathToImage = realpath($imagePath . $srcImage);
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
$imageDir = realpath($imagePath);
|
|
||||||
|
|
||||||
|
if (!is_file($pathToImage) && !empty($srcAltImage)) {
|
||||||
|
// Try using the src-alt instead
|
||||||
|
$srcImage = $srcAltImage;
|
||||||
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
|
|
||||||
|
preg_match($validFilename, $srcImage)
|
||||||
|
or errorPage('Source (alt) filename contains invalid characters.', 404);
|
||||||
|
|
||||||
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
// Check if src-alt is the dummy image
|
||||||
|
$dummyImage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$dummyImage) {
|
||||||
is_file($pathToImage)
|
is_file($pathToImage)
|
||||||
or errorPage(
|
or errorPage(
|
||||||
'Source image is not a valid file, check the filename and that a
|
'Source image is not a valid file, check the filename and that a
|
||||||
matching file exists on the filesystem.',
|
matching file exists on the filesystem.',
|
||||||
404
|
404
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
|
||||||
|
// Check that the image is a file below the directory 'image_path'.
|
||||||
|
$imageDir = realpath($imagePath);
|
||||||
|
|
||||||
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
||||||
or errorPage(
|
or errorPage(
|
||||||
@@ -668,8 +699,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
BIN
webroot/img/planet.gif
Normal file
BIN
webroot/img/planet.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 KiB |
@@ -10,6 +10,15 @@ return array(
|
|||||||
/**
|
/**
|
||||||
* Set mode as 'strict', 'production' or 'development'.
|
* Set mode as 'strict', 'production' or 'development'.
|
||||||
*
|
*
|
||||||
|
* development: Development mode with verbose error reporting. Option
|
||||||
|
* &verbose and &status enabled.
|
||||||
|
* production: Production mode logs all errors to file, giving server
|
||||||
|
* error 500 for bad usage. Option &verbose and &status
|
||||||
|
* disabled.
|
||||||
|
* strict: Strict mode logs few errors to file, giving server error
|
||||||
|
* 500 for bad usage. Stripped from comments and spaces.
|
||||||
|
* Option &verbose and &status disabled.
|
||||||
|
*
|
||||||
* Default values:
|
* Default values:
|
||||||
* mode: 'production'
|
* mode: 'production'
|
||||||
*/
|
*/
|
||||||
@@ -98,6 +107,20 @@ return array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use backup image if src-image is not found on disk. The backup image
|
||||||
|
* is only available for local images and based on wether the original
|
||||||
|
* image is found on disk or not. The backup image must be a local image
|
||||||
|
* or the dummy image.
|
||||||
|
*
|
||||||
|
* Default value:
|
||||||
|
* src_alt: null //disabled by default
|
||||||
|
*/
|
||||||
|
//'src_alt' => 'car.png',
|
||||||
|
//'src_alt' => 'dummy',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A regexp for validating characters in the image or alias filename.
|
* A regexp for validating characters in the image or alias filename.
|
||||||
*
|
*
|
||||||
@@ -139,6 +162,18 @@ return array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set skip-original to true to always process the image and use
|
||||||
|
* the cached version. Default is false and to use the original
|
||||||
|
* image when its no processing needed.
|
||||||
|
*
|
||||||
|
* Default value:
|
||||||
|
* skip_original: false
|
||||||
|
*/
|
||||||
|
//'skip_original' => true,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function (hook) can be called after img.php has processed all
|
* A function (hook) can be called after img.php has processed all
|
||||||
* configuration options and before processing the image using CImage.
|
* configuration options and before processing the image using CImage.
|
||||||
@@ -188,7 +223,8 @@ return array(
|
|||||||
/**
|
/**
|
||||||
* Check that the imagefile is a file below 'image_path' using realpath().
|
* Check that the imagefile is a file below 'image_path' using realpath().
|
||||||
* Security constraint to avoid reaching images outside image_path.
|
* Security constraint to avoid reaching images outside image_path.
|
||||||
* This means that symbolic links to images outside the image_path will fail.
|
* This means that symbolic links to images outside the image_path will
|
||||||
|
* fail.
|
||||||
*
|
*
|
||||||
* Default value:
|
* Default value:
|
||||||
* image_path_constraint: true
|
* image_path_constraint: true
|
||||||
@@ -379,7 +415,7 @@ return array(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default options for ascii image.
|
* Default options for ascii image.
|
||||||
*
|
*
|
||||||
* Default values as specified below in the array.
|
* Default values as specified below in the array.
|
||||||
* ascii-options:
|
* ascii-options:
|
||||||
|
@@ -3817,7 +3817,7 @@ class CCache
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.9 (2015-12-07)";
|
$version = "v0.7.11 (2016-04-18)";
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -3847,16 +3847,16 @@ function errorPage($msg, $type = 500)
|
|||||||
$header = "500 Internal Server Error";
|
$header = "500 Internal Server Error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mode == "strict") {
|
||||||
|
$header = "404 Not Found";
|
||||||
|
}
|
||||||
|
|
||||||
header("HTTP/1.0 $header");
|
header("HTTP/1.0 $header");
|
||||||
|
|
||||||
if ($mode == "development") {
|
if ($mode == "development") {
|
||||||
die("[img.php] $msg");
|
die("[img.php] $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode == "strict") {
|
|
||||||
$header = "404 Not Found";
|
|
||||||
}
|
|
||||||
|
|
||||||
error_log("[img.php] $msg");
|
error_log("[img.php] $msg");
|
||||||
die("HTTP/1.0 $header");
|
die("HTTP/1.0 $header");
|
||||||
}
|
}
|
||||||
@@ -4218,18 +4218,28 @@ if (isset($shortcut)
|
|||||||
$srcImage = urldecode(get('src'))
|
$srcImage = urldecode(get('src'))
|
||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
|
// Get settings for src-alt as backup image
|
||||||
|
$srcAltImage = urldecode(get('src-alt', null));
|
||||||
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
|
if (empty($srcAltImage)) {
|
||||||
|
$srcAltImage = $srcAltConfig;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for valid/invalid characters
|
// Check for valid/invalid characters
|
||||||
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||||
$imagePathConstraint = getConfig('image_path_constraint', true);
|
$imagePathConstraint = getConfig('image_path_constraint', true);
|
||||||
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
||||||
|
|
||||||
|
// Source is remote
|
||||||
|
$remoteSource = false;
|
||||||
|
|
||||||
// Dummy image feature
|
// Dummy image feature
|
||||||
$dummyEnabled = getConfig('dummy_enabled', true);
|
$dummyEnabled = getConfig('dummy_enabled', true);
|
||||||
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
||||||
$dummyImage = false;
|
$dummyImage = false;
|
||||||
|
|
||||||
preg_match($validFilename, $srcImage)
|
preg_match($validFilename, $srcImage)
|
||||||
or errorPage('Filename contains invalid characters.', 404);
|
or errorPage('Source filename contains invalid characters.', 404);
|
||||||
|
|
||||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
|
||||||
@@ -4239,19 +4249,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
|
|||||||
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
||||||
|
|
||||||
// If source is a remote file, ignore local file checks.
|
// If source is a remote file, ignore local file checks.
|
||||||
|
$remoteSource = true;
|
||||||
|
|
||||||
} elseif ($imagePathConstraint) {
|
} else {
|
||||||
|
|
||||||
// Check that the image is a file below the directory 'image_path'.
|
// Check if file exists on disk or try using src-alt
|
||||||
$pathToImage = realpath($imagePath . $srcImage);
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
$imageDir = realpath($imagePath);
|
|
||||||
|
|
||||||
|
if (!is_file($pathToImage) && !empty($srcAltImage)) {
|
||||||
|
// Try using the src-alt instead
|
||||||
|
$srcImage = $srcAltImage;
|
||||||
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
|
|
||||||
|
preg_match($validFilename, $srcImage)
|
||||||
|
or errorPage('Source (alt) filename contains invalid characters.', 404);
|
||||||
|
|
||||||
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
// Check if src-alt is the dummy image
|
||||||
|
$dummyImage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$dummyImage) {
|
||||||
is_file($pathToImage)
|
is_file($pathToImage)
|
||||||
or errorPage(
|
or errorPage(
|
||||||
'Source image is not a valid file, check the filename and that a
|
'Source image is not a valid file, check the filename and that a
|
||||||
matching file exists on the filesystem.',
|
matching file exists on the filesystem.',
|
||||||
404
|
404
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
|
||||||
|
// Check that the image is a file below the directory 'image_path'.
|
||||||
|
$imageDir = realpath($imagePath);
|
||||||
|
|
||||||
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
||||||
or errorPage(
|
or errorPage(
|
||||||
@@ -4477,8 +4508,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
@@ -3817,7 +3817,7 @@ class CCache
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.9 (2015-12-07)";
|
$version = "v0.7.11 (2016-04-18)";
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -3847,16 +3847,16 @@ function errorPage($msg, $type = 500)
|
|||||||
$header = "500 Internal Server Error";
|
$header = "500 Internal Server Error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mode == "strict") {
|
||||||
|
$header = "404 Not Found";
|
||||||
|
}
|
||||||
|
|
||||||
header("HTTP/1.0 $header");
|
header("HTTP/1.0 $header");
|
||||||
|
|
||||||
if ($mode == "development") {
|
if ($mode == "development") {
|
||||||
die("[img.php] $msg");
|
die("[img.php] $msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($mode == "strict") {
|
|
||||||
$header = "404 Not Found";
|
|
||||||
}
|
|
||||||
|
|
||||||
error_log("[img.php] $msg");
|
error_log("[img.php] $msg");
|
||||||
die("HTTP/1.0 $header");
|
die("HTTP/1.0 $header");
|
||||||
}
|
}
|
||||||
@@ -4218,18 +4218,28 @@ if (isset($shortcut)
|
|||||||
$srcImage = urldecode(get('src'))
|
$srcImage = urldecode(get('src'))
|
||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
|
// Get settings for src-alt as backup image
|
||||||
|
$srcAltImage = urldecode(get('src-alt', null));
|
||||||
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
|
if (empty($srcAltImage)) {
|
||||||
|
$srcAltImage = $srcAltConfig;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for valid/invalid characters
|
// Check for valid/invalid characters
|
||||||
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
$imagePath = getConfig('image_path', __DIR__ . '/img/');
|
||||||
$imagePathConstraint = getConfig('image_path_constraint', true);
|
$imagePathConstraint = getConfig('image_path_constraint', true);
|
||||||
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
|
||||||
|
|
||||||
|
// Source is remote
|
||||||
|
$remoteSource = false;
|
||||||
|
|
||||||
// Dummy image feature
|
// Dummy image feature
|
||||||
$dummyEnabled = getConfig('dummy_enabled', true);
|
$dummyEnabled = getConfig('dummy_enabled', true);
|
||||||
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
$dummyFilename = getConfig('dummy_filename', 'dummy');
|
||||||
$dummyImage = false;
|
$dummyImage = false;
|
||||||
|
|
||||||
preg_match($validFilename, $srcImage)
|
preg_match($validFilename, $srcImage)
|
||||||
or errorPage('Filename contains invalid characters.', 404);
|
or errorPage('Source filename contains invalid characters.', 404);
|
||||||
|
|
||||||
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
|
||||||
@@ -4239,19 +4249,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
|
|||||||
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
|
||||||
|
|
||||||
// If source is a remote file, ignore local file checks.
|
// If source is a remote file, ignore local file checks.
|
||||||
|
$remoteSource = true;
|
||||||
|
|
||||||
} elseif ($imagePathConstraint) {
|
} else {
|
||||||
|
|
||||||
// Check that the image is a file below the directory 'image_path'.
|
// Check if file exists on disk or try using src-alt
|
||||||
$pathToImage = realpath($imagePath . $srcImage);
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
$imageDir = realpath($imagePath);
|
|
||||||
|
|
||||||
|
if (!is_file($pathToImage) && !empty($srcAltImage)) {
|
||||||
|
// Try using the src-alt instead
|
||||||
|
$srcImage = $srcAltImage;
|
||||||
|
$pathToImage = realpath($imagePath . $srcImage);
|
||||||
|
|
||||||
|
preg_match($validFilename, $srcImage)
|
||||||
|
or errorPage('Source (alt) filename contains invalid characters.', 404);
|
||||||
|
|
||||||
|
if ($dummyEnabled && $srcImage === $dummyFilename) {
|
||||||
|
// Check if src-alt is the dummy image
|
||||||
|
$dummyImage = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$dummyImage) {
|
||||||
is_file($pathToImage)
|
is_file($pathToImage)
|
||||||
or errorPage(
|
or errorPage(
|
||||||
'Source image is not a valid file, check the filename and that a
|
'Source image is not a valid file, check the filename and that a
|
||||||
matching file exists on the filesystem.',
|
matching file exists on the filesystem.',
|
||||||
404
|
404
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
|
||||||
|
// Check that the image is a file below the directory 'image_path'.
|
||||||
|
$imageDir = realpath($imagePath);
|
||||||
|
|
||||||
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
|
||||||
or errorPage(
|
or errorPage(
|
||||||
@@ -4477,8 +4508,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user