2011-04-17 19:29:48 -07:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
2013-02-03 23:02:35 +01:00
|
|
|
* @package phpBB3
|
2011-04-18 10:44:29 -07:00
|
|
|
* @copyright (c) 2011 phpBB Group
|
2013-02-03 23:02:35 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
2011-04-17 19:29:48 -07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
if (!defined('IN_PHPBB'))
|
|
|
|
{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles avatars hosted remotely
|
2013-02-03 23:02:35 +01:00
|
|
|
* @package phpBB3
|
2011-04-17 19:29:48 -07:00
|
|
|
*/
|
2012-11-16 17:19:04 +01:00
|
|
|
class phpbb_avatar_driver_remote extends phpbb_avatar_driver
|
2011-04-17 19:29:48 -07:00
|
|
|
{
|
|
|
|
/**
|
2011-04-18 10:44:29 -07:00
|
|
|
* @inheritdoc
|
2011-04-17 19:29:48 -07:00
|
|
|
*/
|
2012-11-30 15:12:34 +01:00
|
|
|
public function get_data($row)
|
2011-04-17 19:29:48 -07:00
|
|
|
{
|
2012-11-30 15:12:34 +01:00
|
|
|
return array(
|
|
|
|
'src' => $row['avatar'],
|
|
|
|
'width' => $row['avatar_width'],
|
|
|
|
'height' => $row['avatar_height'],
|
|
|
|
);
|
2011-04-17 19:29:48 -07:00
|
|
|
}
|
2011-04-17 21:58:51 -07:00
|
|
|
|
|
|
|
/**
|
2011-04-18 10:44:29 -07:00
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2013-01-07 22:49:48 +01:00
|
|
|
public function prepare_form($request, $template, $row, &$error)
|
2011-04-17 21:58:51 -07:00
|
|
|
{
|
2011-04-20 09:46:36 -07:00
|
|
|
$template->assign_vars(array(
|
2013-01-07 22:49:48 +01:00
|
|
|
'AVATAR_REMOTE_WIDTH' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_remote_width', 0),
|
|
|
|
'AVATAR_REMOTE_HEIGHT' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar_height']) ? $row['avatar_height'] : $request->variable('avatar_remote_width', 0),
|
2012-11-25 00:54:34 +01:00
|
|
|
'AVATAR_REMOTE_URL' => ((in_array($row['avatar_type'], array(AVATAR_REMOTE, $this->get_name(), 'remote'))) && $row['avatar']) ? $row['avatar'] : '',
|
2011-04-20 09:46:36 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2013-01-07 22:49:48 +01:00
|
|
|
public function process_form($request, $template, $row, &$error)
|
2011-04-20 09:46:36 -07:00
|
|
|
{
|
2013-01-07 22:49:48 +01:00
|
|
|
$url = $request->variable('avatar_remote_url', '');
|
|
|
|
$width = $request->variable('avatar_remote_width', 0);
|
|
|
|
$height = $request->variable('avatar_remote_height', 0);
|
2012-04-07 19:19:13 +02:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if (!preg_match('#^(http|https|ftp)://#i', $url))
|
|
|
|
{
|
|
|
|
$url = 'http://' . $url;
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2012-12-01 00:27:52 +01:00
|
|
|
if (!function_exists('validate_data'))
|
2012-11-26 23:06:38 +01:00
|
|
|
{
|
|
|
|
require($this->phpbb_root_path . 'includes/functions_user' . $this->php_ext);
|
|
|
|
}
|
2011-06-18 21:12:29 -07:00
|
|
|
|
2012-12-11 21:02:37 +01:00
|
|
|
$validate_array = validate_data(
|
|
|
|
array(
|
|
|
|
'url' => $url,
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'url' => array('string', true, 5, 255),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$error = array_merge($error, $validate_array);
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if (!empty($error))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
// Check if this url looks alright
|
|
|
|
// This isn't perfect, but it's what phpBB 3.0 did, and might as well make sure everything is compatible
|
2013-01-25 01:24:15 +01:00
|
|
|
if (!preg_match('#^(http|https|ftp)://(?:(.*?\.)*?[a-z0-9\-]+?\.[a-z]{2,4}|(?:\d{1,3}\.){3,5}\d{1,3}):?([0-9]*?).*?\.('. self::REGEX_ALLOWED_EXT . ')$#i', $url))
|
2011-04-20 09:46:36 -07:00
|
|
|
{
|
|
|
|
$error[] = 'AVATAR_URL_INVALID';
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
// Make sure getimagesize works...
|
|
|
|
if (function_exists('getimagesize'))
|
|
|
|
{
|
2012-11-25 01:18:27 +01:00
|
|
|
if (($width <= 0 || $height <= 0) && (($image_data = getimagesize($url)) === false))
|
2011-04-18 22:54:35 -07:00
|
|
|
{
|
2011-04-20 09:46:36 -07:00
|
|
|
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
|
|
|
return false;
|
2011-04-18 23:34:56 -07:00
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
|
2011-04-18 22:54:35 -07:00
|
|
|
{
|
|
|
|
$error[] = 'AVATAR_NO_SIZE';
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
$width = ($width && $height) ? $width : $image_data[0];
|
|
|
|
$height = ($width && $height) ? $height : $image_data[1];
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if ($width <= 0 || $height <= 0)
|
|
|
|
{
|
|
|
|
$error[] = 'AVATAR_NO_SIZE';
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2012-11-26 23:06:38 +01:00
|
|
|
if (!class_exists('fileupload'))
|
|
|
|
{
|
2012-12-27 20:42:05 +01:00
|
|
|
include($this->phpbb_root_path . 'includes/functions_upload' . $this->php_ext);
|
2012-11-26 23:06:38 +01:00
|
|
|
}
|
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
$types = fileupload::image_types();
|
|
|
|
$extension = strtolower(filespec::get_extension($url));
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if (!empty($image_data) && (!isset($types[$image_data[2]]) || !in_array($extension, $types[$image_data[2]])))
|
|
|
|
{
|
|
|
|
if (!isset($types[$image_data[2]]))
|
2011-04-18 22:54:35 -07:00
|
|
|
{
|
2011-04-20 09:46:36 -07:00
|
|
|
$error[] = 'UNABLE_GET_IMAGE_SIZE';
|
2011-04-18 22:54:35 -07:00
|
|
|
}
|
2011-04-20 09:46:36 -07:00
|
|
|
else
|
2011-04-18 22:54:35 -07:00
|
|
|
{
|
2011-04-20 09:46:36 -07:00
|
|
|
$error[] = array('IMAGE_FILETYPE_MISMATCH', $types[$image_data[2]][0], $extension);
|
2011-04-18 22:54:35 -07:00
|
|
|
}
|
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
return false;
|
|
|
|
}
|
2011-04-18 22:54:35 -07:00
|
|
|
|
2011-04-20 09:46:36 -07:00
|
|
|
if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
|
|
|
|
{
|
|
|
|
if ($width > $this->config['avatar_max_width'] || $height > $this->config['avatar_max_height'])
|
|
|
|
{
|
|
|
|
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-17 21:58:51 -07:00
|
|
|
}
|
2011-04-20 09:46:36 -07:00
|
|
|
|
|
|
|
if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
|
2011-04-17 21:58:51 -07:00
|
|
|
{
|
2011-04-20 09:46:36 -07:00
|
|
|
if ($width < $this->config['avatar_min_width'] || $height < $this->config['avatar_min_height'])
|
|
|
|
{
|
|
|
|
$error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $width, $height);
|
|
|
|
return false;
|
|
|
|
}
|
2011-04-17 21:58:51 -07:00
|
|
|
}
|
2011-04-20 09:46:36 -07:00
|
|
|
|
|
|
|
return array(
|
2011-06-18 22:50:52 -07:00
|
|
|
'avatar' => $url,
|
|
|
|
'avatar_width' => $width,
|
|
|
|
'avatar_height' => $height,
|
2011-04-20 09:46:36 -07:00
|
|
|
);
|
2011-04-17 21:58:51 -07:00
|
|
|
}
|
2011-04-17 19:29:48 -07:00
|
|
|
}
|