mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 08:47:45 +02:00
Merge pull request #3524 from marc1706/ticket/8672
[ticket/8672] Add class for retrieving imagesize without download
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
},
|
||||
"require": {
|
||||
"lusitanian/oauth": "0.2.*",
|
||||
"marc1706/fast-image-size": "1.0.*",
|
||||
"patchwork/utf8": "1.1.*",
|
||||
"php": ">=5.3.9",
|
||||
"s9e/text-formatter": "dev-release/php5.3",
|
||||
|
53
phpBB/composer.lock
generated
53
phpBB/composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "91cc998d47b703a7bc4f726217d7a3a9",
|
||||
"hash": "d5368b75d221b5573b30307cb2f25f3b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "lusitanian/oauth",
|
||||
@@ -69,6 +69,57 @@
|
||||
],
|
||||
"time": "2013-08-29 21:40:04"
|
||||
},
|
||||
{
|
||||
"name": "marc1706/fast-image-size",
|
||||
"version": "v1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/marc1706/fast-image-size.git",
|
||||
"reference": "ab7b594325cdf6b374d50b3934c8d16dd5249a2a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/marc1706/fast-image-size/zipball/ab7b594325cdf6b374d50b3934c8d16dd5249a2a",
|
||||
"reference": "ab7b594325cdf6b374d50b3934c8d16dd5249a2a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "4.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"fastImageSize\\": "lib",
|
||||
"fastImageSize\\tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Marc Alexander",
|
||||
"email": "admin@m-a-styles.de",
|
||||
"homepage": "https://www.m-a-styles.de",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "fast-image-size is a PHP library that does almost everything PHP's getimagesize() does but without the large overhead of downloading the complete file.",
|
||||
"homepage": "https://www.m-a-styles.de",
|
||||
"keywords": [
|
||||
"fast",
|
||||
"getimagesize",
|
||||
"image",
|
||||
"imagesize",
|
||||
"php",
|
||||
"size"
|
||||
],
|
||||
"time": "2015-04-09 11:19:59"
|
||||
},
|
||||
{
|
||||
"name": "patchwork/utf8",
|
||||
"version": "v1.1.26",
|
||||
|
@@ -202,6 +202,9 @@ services:
|
||||
template_context:
|
||||
class: phpbb\template\context
|
||||
|
||||
upload_imagesize:
|
||||
class: fastImageSize\fastImageSize
|
||||
|
||||
version_helper:
|
||||
class: phpbb\version_helper
|
||||
scope: prototype
|
||||
|
@@ -17,6 +17,7 @@ services:
|
||||
class: phpbb\avatar\driver\gravatar
|
||||
arguments:
|
||||
- @config
|
||||
- @upload_imagesize
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- @path_helper
|
||||
@@ -30,6 +31,7 @@ services:
|
||||
class: phpbb\avatar\driver\local
|
||||
arguments:
|
||||
- @config
|
||||
- @upload_imagesize
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- @path_helper
|
||||
@@ -43,6 +45,7 @@ services:
|
||||
class: phpbb\avatar\driver\remote
|
||||
arguments:
|
||||
- @config
|
||||
- @upload_imagesize
|
||||
- %core.root_path%
|
||||
- %core.php_ext%
|
||||
- @path_helper
|
||||
|
@@ -402,28 +402,28 @@ class filespec
|
||||
{
|
||||
$this->width = $this->height = 0;
|
||||
|
||||
if (($this->image_info = @getimagesize($this->destination_file)) !== false)
|
||||
{
|
||||
$this->width = $this->image_info[0];
|
||||
$this->height = $this->image_info[1];
|
||||
// Get imagesize class
|
||||
$imagesize = new \fastImageSize\fastImageSize();
|
||||
|
||||
if (!empty($this->image_info['mime']))
|
||||
{
|
||||
$this->mimetype = $this->image_info['mime'];
|
||||
}
|
||||
$this->image_info = $imagesize->getImageSize($this->destination_file, $this->mimetype);
|
||||
|
||||
if ($this->image_info !== false)
|
||||
{
|
||||
$this->width = $this->image_info['width'];
|
||||
$this->height = $this->image_info['height'];
|
||||
|
||||
// Check image type
|
||||
$types = fileupload::image_types();
|
||||
|
||||
if (!isset($types[$this->image_info[2]]) || !in_array($this->extension, $types[$this->image_info[2]]))
|
||||
if (!isset($types[$this->image_info['type']]) || !in_array($this->extension, $types[$this->image_info['type']]))
|
||||
{
|
||||
if (!isset($types[$this->image_info[2]]))
|
||||
if (!isset($types[$this->image_info['type']]))
|
||||
{
|
||||
$this->error[] = sprintf($user->lang['IMAGE_FILETYPE_INVALID'], $this->image_info[2], $this->mimetype);
|
||||
$this->error[] = $user->lang('IMAGE_FILETYPE_INVALID', $this->image_info['type'], $this->mimetype);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error[] = sprintf($user->lang['IMAGE_FILETYPE_MISMATCH'], $types[$this->image_info[2]][0], $this->extension);
|
||||
$this->error[] = $user->lang('IMAGE_FILETYPE_MISMATCH', $types[$this->image_info['type']][0], $this->extension);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -339,22 +339,23 @@ class bbcode_firstpass extends bbcode
|
||||
|
||||
if ($config['max_' . $this->mode . '_img_height'] || $config['max_' . $this->mode . '_img_width'])
|
||||
{
|
||||
$stats = @getimagesize(htmlspecialchars_decode($in));
|
||||
$imagesize = new \fastImageSize\fastImageSize();
|
||||
$size_info = $imagesize->getImageSize(htmlspecialchars_decode($in));
|
||||
|
||||
if ($stats === false)
|
||||
if ($size_info === false)
|
||||
{
|
||||
$error = true;
|
||||
$this->warn_msg[] = $user->lang['UNABLE_GET_IMAGE_SIZE'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $stats[1])
|
||||
if ($config['max_' . $this->mode . '_img_height'] && $config['max_' . $this->mode . '_img_height'] < $size_info['height'])
|
||||
{
|
||||
$error = true;
|
||||
$this->warn_msg[] = $user->lang('MAX_IMG_HEIGHT_EXCEEDED', (int) $config['max_' . $this->mode . '_img_height']);
|
||||
}
|
||||
|
||||
if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $stats[0])
|
||||
if ($config['max_' . $this->mode . '_img_width'] && $config['max_' . $this->mode . '_img_width'] < $size_info['width'])
|
||||
{
|
||||
$error = true;
|
||||
$this->warn_msg[] = $user->lang('MAX_IMG_WIDTH_EXCEEDED', (int) $config['max_' . $this->mode . '_img_width']);
|
||||
|
@@ -30,6 +30,9 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/** @var \fastImageSize\fastImageSize */
|
||||
protected $imagesize;
|
||||
|
||||
/**
|
||||
* Current $phpbb_root_path
|
||||
* @var string
|
||||
@@ -73,14 +76,16 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface
|
||||
* Construct a driver object
|
||||
*
|
||||
* @param \phpbb\config\config $config phpBB configuration
|
||||
* @param \fastImageSize\fastImageSize $imagesize fastImageSize class
|
||||
* @param string $phpbb_root_path Path to the phpBB root
|
||||
* @param string $php_ext PHP file extension
|
||||
* @param \phpbb\path_helper $path_helper phpBB path helper
|
||||
* @param \phpbb\cache\driver\driver_interface $cache Cache driver
|
||||
*/
|
||||
public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null)
|
||||
public function __construct(\phpbb\config\config $config, \fastImageSize\fastImageSize $imagesize, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->imagesize = $imagesize;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->path_helper = $path_helper;
|
||||
|
@@ -98,8 +98,8 @@ class gravatar extends \phpbb\avatar\driver\driver
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure getimagesize works...
|
||||
if (function_exists('getimagesize') && ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0))
|
||||
// Get image dimensions if they are not set
|
||||
if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)
|
||||
{
|
||||
/**
|
||||
* default to the minimum of the maximum allowed avatar size if the size
|
||||
@@ -108,20 +108,20 @@ class gravatar extends \phpbb\avatar\driver\driver
|
||||
$row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']);
|
||||
$url = $this->get_gravatar_url($row);
|
||||
|
||||
if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = getimagesize($url)) === false))
|
||||
if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = $this->imagesize->getImageSize($url)) === false))
|
||||
{
|
||||
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
|
||||
if (!empty($image_data) && ($image_data['width'] <= 0 || $image_data['width'] <= 0))
|
||||
{
|
||||
$error[] = 'AVATAR_NO_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
$row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data[0];
|
||||
$row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data[1];
|
||||
$row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data['width'];
|
||||
$row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data['height'];
|
||||
}
|
||||
|
||||
if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)
|
||||
|
@@ -172,13 +172,15 @@ class local extends \phpbb\avatar\driver\driver
|
||||
// Match all images in the gallery folder
|
||||
if (preg_match('#^[^&\'"<>]+\.(?:' . implode('|', $this->allowed_extensions) . ')$#i', $image) && is_file($file_path . '/' . $image))
|
||||
{
|
||||
if (function_exists('getimagesize'))
|
||||
$dims = $this->imagesize->getImageSize($file_path . '/' . $image);
|
||||
|
||||
if ($dims === false)
|
||||
{
|
||||
$dims = getimagesize($file_path . '/' . $image);
|
||||
$dims = array(0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$dims = array(0, 0);
|
||||
$dims = array($dims['width'], $dims['height']);
|
||||
}
|
||||
$cat = ($path == $file_path) ? $user->lang['NO_AVATAR_CATEGORY'] : str_replace("$path/", '', $file_path);
|
||||
$avatar_list[$cat][$image] = array(
|
||||
|
@@ -92,25 +92,22 @@ class remote extends \phpbb\avatar\driver\driver
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure getimagesize works...
|
||||
if (function_exists('getimagesize'))
|
||||
// Get image dimensions
|
||||
if (($width <= 0 || $height <= 0) && (($image_data = $this->imagesize->getImageSize($url)) === false))
|
||||
{
|
||||
if (($width <= 0 || $height <= 0) && (($image_data = @getimagesize($url)) === false))
|
||||
{
|
||||
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
|
||||
{
|
||||
$error[] = 'AVATAR_NO_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
$width = ($width && $height) ? $width : $image_data[0];
|
||||
$height = ($width && $height) ? $height : $image_data[1];
|
||||
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($image_data) && ($image_data['width'] <= 0 || $image_data['height'] <= 0))
|
||||
{
|
||||
$error[] = 'AVATAR_NO_SIZE';
|
||||
return false;
|
||||
}
|
||||
|
||||
$width = ($width && $height) ? $width : $image_data['width'];
|
||||
$height = ($width && $height) ? $height : $image_data['height'];
|
||||
|
||||
if ($width <= 0 || $height <= 0)
|
||||
{
|
||||
$error[] = 'AVATAR_NO_SIZE';
|
||||
@@ -172,15 +169,15 @@ class remote extends \phpbb\avatar\driver\driver
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
|
||||
if (!empty($image_data) && (!isset($types[$image_data['type']]) || !in_array($extension, $types[$image_data['type']])))
|
||||
{
|
||||
if (!isset($types[$image_data[2]]))
|
||||
if (!isset($types[$image_data['type']]))
|
||||
{
|
||||
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
||||
}
|
||||
else
|
||||
{
|
||||
$error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
|
||||
$error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data['type']][0], $extension);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -367,7 +367,6 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
{
|
||||
// Validate the URL
|
||||
$url = BuiltInFilters::filterUrl($url, $url_config, $logger);
|
||||
|
||||
if ($url === false)
|
||||
{
|
||||
return false;
|
||||
@@ -375,26 +374,23 @@ class parser implements \phpbb\textformatter\parser_interface
|
||||
|
||||
if ($max_height || $max_width)
|
||||
{
|
||||
$stats = @getimagesize($url);
|
||||
|
||||
if ($stats === false)
|
||||
$imagesize = new \fastImageSize\fastImageSize();
|
||||
$size_info = $imagesize->getImageSize($url);
|
||||
if ($size_info === false)
|
||||
{
|
||||
$logger->err('UNABLE_GET_IMAGE_SIZE');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($max_height && $max_height < $stats[1])
|
||||
if ($max_height && $max_height < $size_info['height'])
|
||||
{
|
||||
$logger->err('MAX_IMG_HEIGHT_EXCEEDED', array('max_height' => $max_height));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($max_width && $max_width < $stats[0])
|
||||
if ($max_width && $max_width < $size_info['width'])
|
||||
{
|
||||
$logger->err('MAX_IMG_WIDTH_EXCEEDED', array('max_width' => $max_width));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user