aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/avatar/driver/remote.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/avatar/driver/remote.php')
-rw-r--r--phpBB/phpbb/avatar/driver/remote.php82
1 files changed, 49 insertions, 33 deletions
diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php
index 36623942df..0526b9184e 100644
--- a/phpBB/phpbb/avatar/driver/remote.php
+++ b/phpBB/phpbb/avatar/driver/remote.php
@@ -1,9 +1,13 @@
<?php
/**
*
-* @package phpBB3
-* @copyright (c) 2011 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
*
*/
@@ -11,12 +15,11 @@ namespace phpbb\avatar\driver;
/**
* Handles avatars hosted remotely
-* @package phpBB3
*/
class remote extends \phpbb\avatar\driver\driver
{
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function get_data($row)
{
@@ -28,7 +31,7 @@ class remote extends \phpbb\avatar\driver\driver
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function prepare_form($request, $template, $user, $row, &$error)
{
@@ -42,7 +45,7 @@ class remote extends \phpbb\avatar\driver\driver
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function process_form($request, $template, $user, $row, &$error)
{
@@ -50,6 +53,11 @@ class remote extends \phpbb\avatar\driver\driver
$width = $request->variable('avatar_remote_width', 0);
$height = $request->variable('avatar_remote_height', 0);
+ if (empty($url))
+ {
+ return false;
+ }
+
if (!preg_match('#^(http|https|ftp)://#i', $url))
{
$url = 'http://' . $url;
@@ -84,46 +92,54 @@ 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 ($width <= 0 || $height <= 0)
+ if (!empty($image_data) && ($image_data['width'] <= 0 || $image_data['height'] <= 0))
{
$error[] = 'AVATAR_NO_SIZE';
return false;
}
- if (!class_exists('fileupload'))
+ $width = ($width && $height) ? $width : $image_data['width'];
+ $height = ($width && $height) ? $height : $image_data['height'];
+
+ if ($width <= 0 || $height <= 0)
{
- include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext);
+ $error[] = 'AVATAR_NO_SIZE';
+ return false;
}
- $types = \fileupload::image_types();
- $extension = strtolower(\filespec::get_extension($url));
+ $types = \phpbb\files\upload::image_types();
+ $extension = strtolower(\phpbb\files\filespec::get_extension($url));
// Check if this is actually an image
if ($file_stream = @fopen($url, 'r'))
{
// Timeout after 1 second
stream_set_timeout($file_stream, 1);
+ // read some data to ensure headers are present
+ fread($file_stream, 1024);
$meta = stream_get_meta_data($file_stream);
- foreach ($meta['wrapper_data'] as $header)
+
+ if (isset($meta['wrapper_data']['headers']) && is_array($meta['wrapper_data']['headers']))
+ {
+ $headers = $meta['wrapper_data']['headers'];
+ }
+ else if (isset($meta['wrapper_data']) && is_array($meta['wrapper_data']))
+ {
+ $headers = $meta['wrapper_data'];
+ }
+ else
+ {
+ $headers = array();
+ }
+
+ foreach ($headers as $header)
{
$header = preg_split('/ /', $header, 2);
if (strtr(strtolower(trim($header[0], ':')), '_', '-') === 'content-type')
@@ -148,15 +164,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;
@@ -188,7 +204,7 @@ class remote extends \phpbb\avatar\driver\driver
}
/**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function get_template_name()
{