1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-19 15:01:33 +02:00

[ticket/15769] Crop avatars on upload

PHPBB3-15769
This commit is contained in:
mrgoldy
2020-05-10 00:30:30 +02:00
committed by Marc Alexander
parent eb1edd12a1
commit 4d860bf967
17 changed files with 4693 additions and 6 deletions

View File

@@ -18,6 +18,7 @@ use phpbb\config\config;
use phpbb\controller\helper;
use phpbb\event\dispatcher_interface;
use phpbb\files\factory;
use phpbb\image\image_cropper;
use phpbb\path_helper;
use phpbb\storage\exception\exception as storage_exception;
use phpbb\storage\storage;
@@ -100,10 +101,15 @@ class upload extends \phpbb\avatar\driver\driver
return false;
}
$template->assign_vars(array(
'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'],
$use_board = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH;
$web_path = $use_board ? generate_board_url() . '/' : $this->path_helper->get_web_root_path();
$template->assign_vars([
'AVATAR_ALLOWED_EXTENSIONS' => implode(',', preg_replace('/^/', '.', $this->allowed_extensions)),
));
'AVATAR_UPLOAD_SIZE' => $this->config['avatar_filesize'],
'S_CROPPING_AVAILABLE' => image_cropper::is_available(),
'T_ASSETS_PATH' => $web_path . '/assets',
]);
return true;
}
@@ -137,6 +143,7 @@ class upload extends \phpbb\avatar\driver\driver
return false;
}
/** @var \phpbb\files\filespec_storage $file */
$file = $upload->handle_upload('files.types.form_storage', 'avatar_upload_file');
$prefix = $this->config['avatar_salt'] . '_';
@@ -150,6 +157,14 @@ class upload extends \phpbb\avatar\driver\driver
return false;
}
// Lets try to crop the avatar
$data = $request->variable('avatar_cropper_data', '', true);
if (!empty($upload_file['name']) && $data && image_cropper::is_file_supported($file))
{
image_cropper::crop_file_by_data($file, json_decode(htmlspecialchars_decode($data, ENT_COMPAT), true));
}
$filedata = array(
'filename' => $file->get('filename'),
'filesize' => $file->get('filesize'),