aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB
diff options
context:
space:
mode:
authorTristan Darricau <tristan.darricau@sensiolabs.com>2015-04-27 16:26:40 +0200
committerTristan Darricau <tristan.darricau@sensiolabs.com>2015-04-27 16:26:40 +0200
commit734b89e75cdb02ae436b03d3247cfa820e03f42c (patch)
tree8d348e342bce8db60211ec63deed795c7e5df64e /phpBB
parente7d297740117e644be18e2b9793471da5697c879 (diff)
parent9088f448633ff42d767afac674324d1e26911ab6 (diff)
downloadforums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.gz
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.bz2
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.tar.xz
forums-734b89e75cdb02ae436b03d3247cfa820e03f42c.zip
Merge pull request #3524 from marc1706/ticket/8672
[ticket/8672] Add class for retrieving imagesize without download
Diffstat (limited to 'phpBB')
-rw-r--r--phpBB/composer.json1
-rw-r--r--phpBB/composer.lock53
-rw-r--r--phpBB/config/default/container/services.yml3
-rw-r--r--phpBB/config/default/container/services_avatar.yml3
-rw-r--r--phpBB/includes/functions_upload.php24
-rw-r--r--phpBB/includes/message_parser.php9
-rw-r--r--phpBB/phpbb/avatar/driver/driver.php7
-rw-r--r--phpBB/phpbb/avatar/driver/gravatar.php12
-rw-r--r--phpBB/phpbb/avatar/driver/local.php8
-rw-r--r--phpBB/phpbb/avatar/driver/remote.php33
-rw-r--r--phpBB/phpbb/textformatter/s9e/parser.php14
11 files changed, 113 insertions, 54 deletions
diff --git a/phpBB/composer.json b/phpBB/composer.json
index 46c0e9b361..31462b81eb 100644
--- a/phpBB/composer.json
+++ b/phpBB/composer.json
@@ -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",
diff --git a/phpBB/composer.lock b/phpBB/composer.lock
index ce7e0072d7..872509884c 100644
--- a/phpBB/composer.lock
+++ b/phpBB/composer.lock
@@ -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",
@@ -70,6 +70,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",
"source": {
diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml
index a7a7703982..682eaeb200 100644
--- a/phpBB/config/default/container/services.yml
+++ b/phpBB/config/default/container/services.yml
@@ -202,6 +202,9 @@ services:
template_context:
class: phpbb\template\context
+ upload_imagesize:
+ class: fastImageSize\fastImageSize
+
version_helper:
class: phpbb\version_helper
scope: prototype
diff --git a/phpBB/config/default/container/services_avatar.yml b/phpBB/config/default/container/services_avatar.yml
index e80d57cb59..c74bef3d66 100644
--- a/phpBB/config/default/container/services_avatar.yml
+++ b/phpBB/config/default/container/services_avatar.yml
@@ -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
diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php
index 78e937abea..dcc9bc4874 100644
--- a/phpBB/includes/functions_upload.php
+++ b/phpBB/includes/functions_upload.php
@@ -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);
}
}
diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 3027566f43..9fe598d7fb 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -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']);
diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php
index b3ced7edf7..b6fd380bda 100644
--- a/phpBB/phpbb/avatar/driver/driver.php
+++ b/phpBB/phpbb/avatar/driver/driver.php
@@ -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;
diff --git a/phpBB/phpbb/avatar/driver/gravatar.php b/phpBB/phpbb/avatar/driver/gravatar.php
index 2082e0fd02..badbd9421d 100644
--- a/phpBB/phpbb/avatar/driver/gravatar.php
+++ b/phpBB/phpbb/avatar/driver/gravatar.php
@@ -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)
diff --git a/phpBB/phpbb/avatar/driver/local.php b/phpBB/phpbb/avatar/driver/local.php
index 36087f8ba0..88a139f81e 100644
--- a/phpBB/phpbb/avatar/driver/local.php
+++ b/phpBB/phpbb/avatar/driver/local.php
@@ -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(
diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php
index 4b0ee3f06f..90443c9b4e 100644
--- a/phpBB/phpbb/avatar/driver/remote.php
+++ b/phpBB/phpbb/avatar/driver/remote.php
@@ -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;
- }
+ $error[] = 'UNABLE_GET_IMAGE_SIZE';
+ return false;
+ }
- $width = ($width && $height) ? $width : $image_data[0];
- $height = ($width && $height) ? $height : $image_data[1];
+ 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;
diff --git a/phpBB/phpbb/textformatter/s9e/parser.php b/phpBB/phpbb/textformatter/s9e/parser.php
index 77328ee4d9..e46a0578d2 100644
--- a/phpBB/phpbb/textformatter/s9e/parser.php
+++ b/phpBB/phpbb/textformatter/s9e/parser.php
@@ -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;
}
}