diff options
Diffstat (limited to 'phpBB')
-rw-r--r-- | phpBB/config/default/container/services_files.yml | 6 | ||||
-rw-r--r-- | phpBB/includes/functions_posting.php | 5 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/remote.php | 9 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/driver/upload.php | 26 | ||||
-rw-r--r-- | phpBB/phpbb/files/upload.php | 31 | ||||
-rw-r--r-- | phpBB/phpbb/plupload/plupload.php | 2 |
6 files changed, 47 insertions, 32 deletions
diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 6f0b10cce1..cd27d0745c 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -9,3 +9,9 @@ services: - @filesystem - @mimetype.guesser - @plupload + + files.upload: + class: phpbb\files\upload + scope: prototype + arguments: + - @filesystem diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index e91f8bb56d..75ac20a337 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -404,14 +404,14 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL) function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\mimetype\guesser $mimetype_guesser = null, \phpbb\plupload\plupload $plupload = null) { global $auth, $user, $config, $db, $cache; - global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_filesystem; + global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_container; $filedata = array( 'error' => array() ); include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); - $upload = new fileupload($phpbb_filesystem); + $upload = $phpbb_container->get('files.upload'); if ($config['check_attachment_content'] && isset($config['mime_triggers'])) { @@ -433,6 +433,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage $extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id)); $upload->set_allowed_extensions(array_keys($extensions['_allowed_'])); + /** @var \phpbb\files\filespec $file */ $file = ($local) ? $upload->local_upload($local_storage, $local_filedata, $mimetype_guesser) : $upload->form_upload($form_name, $mimetype_guesser, $plupload); if ($file->init_error()) diff --git a/phpBB/phpbb/avatar/driver/remote.php b/phpBB/phpbb/avatar/driver/remote.php index 90443c9b4e..0526b9184e 100644 --- a/phpBB/phpbb/avatar/driver/remote.php +++ b/phpBB/phpbb/avatar/driver/remote.php @@ -114,13 +114,8 @@ class remote extends \phpbb\avatar\driver\driver return false; } - if (!class_exists('fileupload')) - { - include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext); - } - - $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')) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index b31609b982..4cdb65ce84 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -34,6 +34,11 @@ class upload extends \phpbb\avatar\driver\driver protected $dispatcher; /** + * @var \phpbb\files\factory + */ + protected $files_factory; + + /** * Construct a driver object * * @param \phpbb\config\config $config phpBB configuration @@ -43,9 +48,10 @@ class upload extends \phpbb\avatar\driver\driver * @param \phpbb\path_helper $path_helper phpBB path helper * @param \phpbb\mimetype\guesser $mimetype_guesser Mimetype guesser * @param \phpbb\event\dispatcher_interface $dispatcher phpBB Event dispatcher object + * @param \phpbb\files\factory $files_factory File classes factory * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\cache\driver\driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\filesystem\filesystem_interface $filesystem, \phpbb\path_helper $path_helper, \phpbb\mimetype\guesser $mimetype_guesser, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, \phpbb\cache\driver\driver_interface $cache = null) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; @@ -54,6 +60,7 @@ class upload extends \phpbb\avatar\driver\driver $this->path_helper = $path_helper; $this->mimetype_guesser = $mimetype_guesser; $this->dispatcher = $dispatcher; + $this->files_factory = $files_factory; $this->cache = $cache; } @@ -99,12 +106,17 @@ class upload extends \phpbb\avatar\driver\driver return false; } - if (!class_exists('fileupload')) - { - include($this->phpbb_root_path . 'includes/functions_upload.' . $this->php_ext); - } - - $upload = new \fileupload($this->filesystem, 'AVATAR_', $this->allowed_extensions, $this->config['avatar_filesize'], $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], (isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); + /** @var \phpbb\files\upload $upload */ + $upload = $this->files_factory->get('upload') + ->set_error_prefix('AVATAR_') + ->set_allowed_extensions($this->allowed_extensions) + ->set_max_filesize($this->config['avatar_filesize']) + ->set_allowed_dimensions( + $this->config['avatar_min_width'], + $this->config['avatar_min_height'], + $this->config['avatar_max_width'], + $this->config['avatar_max_height']) + ->set_disallowed_content((isset($this->config['mime_triggers']) ? explode('|', $this->config['mime_triggers']) : false)); $url = $request->variable('avatar_upload_url', ''); $upload_file = $request->file('avatar_upload_file'); diff --git a/phpBB/phpbb/files/upload.php b/phpBB/phpbb/files/upload.php index 7501247e06..8666b857a5 100644 --- a/phpBB/phpbb/files/upload.php +++ b/phpBB/phpbb/files/upload.php @@ -40,24 +40,15 @@ class upload * Init file upload class. * * @param \phpbb\filesystem\filesystem_interface $filesystem - * @param string $error_prefix Used error messages will get prefixed by this string - * @param array $allowed_extensions Array of allowed extensions, for example array('jpg', 'jpeg', 'gif', 'png') - * @param int $max_filesize Maximum filesize - * @param int $min_width Minimum image width (only checked for images) - * @param int $min_height Minimum image height (only checked for images) - * @param int $max_width Maximum image width (only checked for images) - * @param int $max_height Maximum image height (only checked for images) - * @param bool|array $disallowed_content If enabled, the first 256 bytes of the file must not - * contain any of its values. Defaults to false. * */ - function fileupload(\phpbb\filesystem\filesystem_interface $filesystem, $error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false) + public function __construct(\phpbb\filesystem\filesystem_interface $filesystem) { - $this->set_allowed_extensions($allowed_extensions); - $this->set_max_filesize($max_filesize); - $this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height); - $this->set_error_prefix($error_prefix); - $this->set_disallowed_content($disallowed_content); +// $this->set_allowed_extensions($allowed_extensions); +// $this->set_max_filesize($max_filesize); +// $this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height); +// $this->set_error_prefix($error_prefix); +// $this->set_disallowed_content($disallowed_content); $this->filesystem = $filesystem; } @@ -82,6 +73,8 @@ class upload { $this->allowed_extensions = $allowed_extensions; } + + return $this; } /** @@ -93,6 +86,8 @@ class upload $this->min_height = (int) $min_height; $this->max_width = (int) $max_width; $this->max_height = (int) $max_height; + + return $this; } /** @@ -104,6 +99,8 @@ class upload { $this->max_filesize = (int) $max_filesize; } + + return $this; } /** @@ -115,6 +112,8 @@ class upload { $this->disallowed_content = array_diff($disallowed_content, array('')); } + + return $this; } /** @@ -123,6 +122,8 @@ class upload function set_error_prefix($error_prefix) { $this->error_prefix = $error_prefix; + + return $this; } /** diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php index ca78167ec0..35f3a0071e 100644 --- a/phpBB/phpbb/plupload/plupload.php +++ b/phpBB/phpbb/plupload/plupload.php @@ -303,7 +303,7 @@ class plupload $this->temporary_directory, $this->config['plupload_salt'], md5($file_name), - \filespec::get_extension($file_name) + \phpbb\files\filespec::get_extension($file_name) ); } |