• Модуль: imbot
  • Путь к файлу: ~/bitrix/modules/imbot/lib/bot/network.php
  • Класс: BitrixImBotBotNetwork
  • Вызов: Network::uploadAvatar
static function uploadAvatar($avatarUrl = '', $hash = '')
{
	if (!$avatarUrl)
	{
		return '';
	}

	if (!$ar = parse_url($avatarUrl))
	{
		return '';
	}

	if (!preg_match('#.(png|jpg|jpeg|gif|webp)$#i', $ar['path'], $matches))
	{
		return '';
	}

	try
	{
		$hash = md5($hash . $avatarUrl);
		$tempPath =  CFile::getTempName('', $hash.'.'.$matches[1]);

		$http = new MainWebHttpClient();
		$http->setPrivateIp(false);
		if ($http->download($avatarUrl, $tempPath))
		{
			$recordFile = CFile::makeFileArray($tempPath);
		}
		else
		{
			return '';
		}
	}
	catch (MainIOIoException $exception)
	{
		return '';
	}

	if (!CFile::isImage($recordFile['name'], $recordFile['type']))
	{
		return '';
	}

	if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0 && $recordFile['size'] < 1000000)
	{
		$recordFile['MODULE_ID'] = 'imbot';
	}
	else
	{
		$recordFile = '';
	}

	return $recordFile;
}