[ticket/16764] Remove remote avatar from converter

PHPBB3-16764
This commit is contained in:
rubencm 2021-04-24 16:04:10 +02:00
parent e543874d08
commit e1bbef7774
3 changed files with 0 additions and 131 deletions

View file

@ -42,7 +42,6 @@ define('USER_ACTIVATION_ADMIN', 2);
define('USER_ACTIVATION_DISABLE', 3);
define('AVATAR_UPLOAD', 1);
define('AVATAR_REMOTE', 2);
define('AVATAR_GALLERY', 3);
define('USER_NORMAL', 0);

View file

@ -377,40 +377,6 @@ function mimetype($filename)
}
}
/**
* Obtain the dimensions of all remotely hosted avatars
* This should only be called from execute_last
* There can be significant network overhead if there are a large number of remote avatars
* @todo Look at the option of allowing the user to decide whether this is called or to force the dimensions
*/
function remote_avatar_dims()
{
global $db;
$sql = 'SELECT user_id, user_avatar
FROM ' . USERS_TABLE . '
WHERE user_avatar_type = ' . AVATAR_REMOTE;
$result = $db->sql_query($sql);
$remote_avatars = array();
while ($row = $db->sql_fetchrow($result))
{
$remote_avatars[(int) $row['user_id']] = $row['user_avatar'];
}
$db->sql_freeresult($result);
foreach ($remote_avatars as $user_id => $avatar)
{
$width = (int) get_remote_avatar_dim($avatar, 0);
$height = (int) get_remote_avatar_dim($avatar, 1);
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_avatar_width = ' . (int) $width . ', user_avatar_height = ' . (int) $height . '
WHERE user_id = ' . $user_id;
$db->sql_query($sql);
}
}
function import_avatar_gallery($gallery_name = '', $subdirs_as_galleries = false)
{
global $config, $convert, $user;
@ -810,23 +776,15 @@ function get_avatar_dim($src, $axis, $func = false, $arg1 = false, $arg2 = false
{
case AVATAR_UPLOAD:
return get_upload_avatar_dim($src, $axis);
break;
case AVATAR_GALLERY:
return get_gallery_avatar_dim($src, $axis);
break;
case AVATAR_REMOTE:
// see notes on this functions usage and (hopefully) model $func to avoid this accordingly
return get_remote_avatar_dim($src, $axis);
break;
default:
$default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
$default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
return $axis ? $default_y : $default_x;
break;
}
}
@ -922,88 +880,6 @@ function get_gallery_avatar_dim($source, $axis)
return $avatar_cache[$orig_source][$axis];
}
/**
* Obtain the size of the specified remote avatar (using the cache if possible) and cache the value
* Whilst it's unlikely that remote avatars will be duplicated, it is possible so caching seems the best option
* This should only be called from a post processing step due to the possibility of network timeouts
*/
function get_remote_avatar_dim($src, $axis)
{
if (empty($src))
{
return 0;
}
static $remote_avatar_cache = array();
// an ugly hack: we assume that the dimensions of each remote avatar are accessed exactly twice (x and y)
if (isset($remote_avatar_cache[$src]))
{
$retval = $remote_avatar_cache[$src][$axis];
unset($remote_avatar_cache);
return $retval;
}
$url_info = @parse_url($src);
if (empty($url_info['host']))
{
return 0;
}
$host = $url_info['host'];
$port = (isset($url_info['port'])) ? $url_info['port'] : 0;
$protocol = (isset($url_info['scheme'])) ? $url_info['scheme'] : 'http';
if (empty($port))
{
switch (strtolower($protocol))
{
case 'ftp':
$port = 21;
break;
case 'https':
$port = 443;
break;
default:
$port = 80;
}
}
$timeout = @ini_get('default_socket_timeout');
@ini_set('default_socket_timeout', 2);
// We're just trying to reach the server to avoid timeouts
$fp = @fsockopen($host, $port, $errno, $errstr, 1);
if ($fp)
{
$remote_avatar_cache[$src] = @getimagesize($src);
fclose($fp);
}
$default_x = (defined('DEFAULT_AVATAR_X_CUSTOM')) ? DEFAULT_AVATAR_X_CUSTOM : DEFAULT_AVATAR_X;
$default_y = (defined('DEFAULT_AVATAR_Y_CUSTOM')) ? DEFAULT_AVATAR_Y_CUSTOM : DEFAULT_AVATAR_Y;
$default = array($default_x, $default_y);
if (empty($remote_avatar_cache[$src]) || empty($remote_avatar_cache[$src][0]) || empty($remote_avatar_cache[$src][1]))
{
$remote_avatar_cache[$src] = $default;
}
else
{
// We trust gallery and uploaded avatars to conform to the size settings; we might have to adjust here
if ($remote_avatar_cache[$src][0] > $default_x || $remote_avatar_cache[$src][1] > $default_y)
{
$bigger = ($remote_avatar_cache[$src][0] > $remote_avatar_cache[$src][1]) ? 0 : 1;
$ratio = $default[$bigger] / $remote_avatar_cache[$src][$bigger];
$remote_avatar_cache[$src][0] = (int) ($remote_avatar_cache[$src][0] * $ratio);
$remote_avatar_cache[$src][1] = (int) ($remote_avatar_cache[$src][1] * $ratio);
}
}
@ini_set('default_socket_timeout', $timeout);
return $remote_avatar_cache[$src][$axis];
}
function set_user_options()
{
global $convert_row;

View file

@ -1508,15 +1508,9 @@ function phpbb_avatar_type($type)
{
case 1:
return AVATAR_UPLOAD;
break;
case 2:
return AVATAR_REMOTE;
break;
case 3:
return AVATAR_GALLERY;
break;
}
return 0;