From 4ed0de9f4124c0876dcd005e97e92bc6d0114340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 19 Jul 2017 09:10:33 +0200 Subject: [PATCH 01/34] [ticket/15276] Use storage in avatars PHPBB3-15276 --- .../default/container/services_avatar.yml | 2 +- .../default/container/services_files.yml | 1 - .../default/container/services_storage.yml | 9 + phpBB/install/schemas/schema_data.sql | 3 +- phpBB/phpbb/avatar/driver/upload.php | 51 ++--- .../db/migration/data/v330/storage_avatar.php | 28 +++ phpBB/phpbb/files/types/form_storage.php | 138 ++++++++++++ phpBB/phpbb/files/types/remote_storage.php | 207 ++++++++++++++++++ .../storage/adapter/adapter_interface.php | 7 + 9 files changed, 408 insertions(+), 38 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v330/storage_avatar.php create mode 100644 phpBB/phpbb/files/types/form_storage.php create mode 100644 phpBB/phpbb/files/types/remote_storage.php diff --git a/phpBB/config/default/container/services_avatar.yml b/phpBB/config/default/container/services_avatar.yml index 6cc38516ae..d5d17b54a0 100644 --- a/phpBB/config/default/container/services_avatar.yml +++ b/phpBB/config/default/container/services_avatar.yml @@ -61,7 +61,7 @@ services: - '@config' - '%core.root_path%' - '%core.php_ext%' - - '@filesystem' + - '@storage.avatar' - '@path_helper' - '@dispatcher' - '@files.factory' diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 96682d6713..a846fbf385 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -12,7 +12,6 @@ services: - '@language' - '@php_ini' - '@upload_imagesize' - - '%core.root_path%' - '@mimetype.guesser' - '@plupload' diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index abf51d5f97..bad2139bae 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -1,9 +1,18 @@ services: + +# Storages + storage.avatar: + class: phpbb\storage\storage + arguments: + - '@storage.adapter.factory' + - 'avatar' + # Factory storage.adapter.factory: class: phpbb\storage\adapter_factory arguments: - '@config' + - '@service_container' - '@storage.adapter_collection' - '@storage.provider_collection' diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index ef3472a89a..b28d39a494 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -55,7 +55,6 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_max_height' INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_max_width', '90'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_min_height', '20'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_min_width', '20'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_path', 'images/avatars/upload'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('avatar_salt', 'phpbb_avatar'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact', 'contact@yourdomain.tld'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_contact_name', ''); @@ -288,6 +287,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_json INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_vendor_dir', 'vendor-ext/'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_enable_on_install', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_purge_on_remove', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\adapter', 'phpbb\storage\provider\local'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1); diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index d765a27871..bd33b7610d 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -19,9 +19,9 @@ namespace phpbb\avatar\driver; class upload extends \phpbb\avatar\driver\driver { /** - * @var \phpbb\filesystem\filesystem_interface + * @var \phpbb\storage\storage */ - protected $filesystem; + protected $storage; /** * @var \phpbb\event\dispatcher_interface @@ -39,18 +39,18 @@ class upload extends \phpbb\avatar\driver\driver * @param \phpbb\config\config $config phpBB configuration * @param string $phpbb_root_path Path to the phpBB root * @param string $php_ext PHP file extension - * @param \phpbb\filesystem\filesystem_interface $filesystem phpBB filesystem helper + * @param \phpbb\storage\storage phpBB avatar storage * @param \phpbb\path_helper $path_helper phpBB path helper * @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\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, \phpbb\cache\driver\driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\storage\storage $storage, \phpbb\path_helper $path_helper, \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; $this->php_ext = $php_ext; - $this->filesystem = $filesystem; + $this->storage = $storage; $this->path_helper = $path_helper; $this->dispatcher = $dispatcher; $this->files_factory = $files_factory; @@ -116,7 +116,7 @@ class upload extends \phpbb\avatar\driver\driver if (!empty($upload_file['name'])) { - $file = $upload->handle_upload('files.types.form', 'avatar_upload_file'); + $file = $upload->handle_upload('files.types.form_storage', 'avatar_upload_file'); } else if (!empty($this->config['allow_avatar_remote_upload']) && !empty($url)) { @@ -156,7 +156,7 @@ class upload extends \phpbb\avatar\driver\driver return false; } - $file = $upload->handle_upload('files.types.remote', $url); + $file = $upload->handle_upload('files.types.remote_storage', $url); } else { @@ -169,26 +169,11 @@ class upload extends \phpbb\avatar\driver\driver // If there was an error during upload, then abort operation if (count($file->error)) { - $file->remove(); + $file->remove($this->storage); $error = $file->error; return false; } - // Calculate new destination - $destination = $this->config['avatar_path']; - - // Adjust destination path (no trailing slash) - if (substr($destination, -1, 1) == '/' || substr($destination, -1, 1) == '\\') - { - $destination = substr($destination, 0, -1); - } - - $destination = str_replace(array('../', '..\\', './', '.\\'), '', $destination); - if ($destination && ($destination[0] == '/' || $destination[0] == "\\")) - { - $destination = ''; - } - $filedata = array( 'filename' => $file->get('filename'), 'filesize' => $file->get('filesize'), @@ -203,7 +188,6 @@ class upload extends \phpbb\avatar\driver\driver * * @event core.avatar_driver_upload_move_file_before * @var array filedata Array containing uploaded file data - * @var string destination Destination directory where the file is going to be moved * @var string prefix Prefix for the avatar filename * @var array row Array with avatar row data * @var array error Array of errors, if filled in by this event file will not be moved @@ -212,7 +196,6 @@ class upload extends \phpbb\avatar\driver\driver */ $vars = array( 'filedata', - 'destination', 'prefix', 'row', 'error', @@ -224,14 +207,14 @@ class upload extends \phpbb\avatar\driver\driver if (!count($error)) { // Move file and overwrite any existing image - $file->move_file($destination, true); + $file->move_file($this->storage, true); } // If there was an error during move, then clean up leftovers $error = array_merge($error, $file->error); if (count($error)) { - $file->remove(); + $file->remove($this->storage); return false; } @@ -268,10 +251,9 @@ class upload extends \phpbb\avatar\driver\driver { $error = array(); - $destination = $this->config['avatar_path']; $prefix = $this->config['avatar_salt'] . '_'; $ext = substr(strrchr($row['avatar'], '.'), 1); - $filename = $this->phpbb_root_path . $destination . '/' . $prefix . $row['id'] . '.' . $ext; + $filename = $prefix . $row['id'] . '.' . $ext; /** * Before deleting an existing avatar @@ -284,21 +266,20 @@ class upload extends \phpbb\avatar\driver\driver * @since 3.1.6-RC1 */ $vars = array( - 'destination', 'prefix', 'row', 'error', ); extract($this->dispatcher->trigger_event('core.avatar_driver_upload_delete_before', compact($vars))); - if (!count($error) && $this->filesystem->exists($filename)) + if (!count($error) && $this->storage->exists($filename)) { try { - $this->filesystem->remove($filename); + $this->storage->delete($filename); return true; } - catch (\phpbb\filesystem\exception\filesystem_exception $e) + catch (\phpbb\storage\exception\exception $e) { // Fail is covered by return statement below } @@ -316,12 +297,12 @@ class upload extends \phpbb\avatar\driver\driver } /** - * Check if user is able to upload an avatar + * Check if user is able to upload an avatar to a temporary folder * * @return bool True if user can upload, false if not */ protected function can_upload() { - return ($this->filesystem->exists($this->phpbb_root_path . $this->config['avatar_path']) && $this->filesystem->is_writable($this->phpbb_root_path . $this->config['avatar_path']) && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')); + return (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'); } } diff --git a/phpBB/phpbb/db/migration/data/v330/storage_avatar.php b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php new file mode 100644 index 0000000000..5eac0b8346 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php @@ -0,0 +1,28 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v330; + +use \phpbb\storage\provider; + +class storage_avatar extends \phpbb\db\migration\migration +{ + public function update_data() + { + return array( + array('config.add', array('storage\\avatar\\adapter', provider\local::class)), + array('config.add', array('storage\\avatar\\config\\path', $this->config['avatar_path'])), + array('config.remove', array('avatar_path')), + ); + } +} diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php new file mode 100644 index 0000000000..09bd850538 --- /dev/null +++ b/phpBB/phpbb/files/types/form_storage.php @@ -0,0 +1,138 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\files\types; + +use bantu\IniGetWrapper\IniGetWrapper; +use phpbb\files\factory; +use phpbb\files\filespec; +use phpbb\language\language; +use phpbb\plupload\plupload; +use phpbb\request\request_interface; + +class form_storage extends base +{ + /** @var factory Files factory */ + protected $factory; + + /** @var language */ + protected $language; + + /** @var IniGetWrapper */ + protected $php_ini; + + /** @var plupload */ + protected $plupload; + + /** @var request_interface */ + protected $request; + + /** @var \phpbb\files\upload */ + protected $upload; + + /** + * Construct a form upload type + * + * @param factory $factory Files factory + * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper + * @param plupload $plupload Plupload + * @param request_interface $request Request object + */ + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) + { + $this->factory = $factory; + $this->language = $language; + $this->php_ini = $php_ini; + $this->plupload = $plupload; + $this->request = $request; + } + + /** + * {@inheritdoc} + */ + public function upload() + { + $args = func_get_args(); + return $this->form_upload($args[0]); + } + + /** + * Form upload method + * Upload file from users harddisk + * + * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified) + * + * @return filespec $file Object "filespec" is returned, all further operations can be done with this object + * @access public + */ + protected function form_upload($form_name) + { + $upload = $this->request->file($form_name); + unset($upload['local_mode']); + + $result = $this->plupload->handle_upload($form_name); + if (is_array($result)) + { + $upload = array_merge($upload, $result); + } + + /** @var filespec $file */ + $file = $this->factory->get('filespec_storage') + ->set_upload_ary($upload) + ->set_upload_namespace($this->upload); + + if ($file->init_error()) + { + $file->error[] = ''; + return $file; + } + + // Error array filled? + if (isset($upload['error'])) + { + $error = $this->upload->assign_internal_error($upload['error']); + + if ($error !== false) + { + $file->error[] = $error; + return $file; + } + } + + // Check if empty file got uploaded (not catched by is_uploaded_file) + if (isset($upload['size']) && $upload['size'] == 0) + { + $file->error[] = $this->language->lang($this->upload->error_prefix . 'EMPTY_FILEUPLOAD'); + return $file; + } + + // PHP Upload file size check + $file = $this->check_upload_size($file); + if (sizeof($file->error)) + { + return $file; + } + + // Not correctly uploaded + if (!$file->is_uploaded()) + { + $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED'); + return $file; + } + + $this->upload->common_checks($file); + + return $file; + } +} diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php new file mode 100644 index 0000000000..92dbfd1d8e --- /dev/null +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -0,0 +1,207 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\files\types; + +use bantu\IniGetWrapper\IniGetWrapper; +use phpbb\config\config; +use phpbb\files\factory; +use phpbb\files\filespec; +use phpbb\language\language; +use phpbb\request\request_interface; + +class remote_storage extends base +{ + /** @var config phpBB config */ + protected $config; + + /** @var factory Files factory */ + protected $factory; + + /** @var language */ + protected $language; + + /** @var IniGetWrapper */ + protected $php_ini; + + /** @var request_interface */ + protected $request; + + /** @var \phpbb\files\upload */ + protected $upload; + + /** @var string phpBB root path */ + protected $phpbb_root_path; + + /** + * Construct a form upload type + * + * @param config $config phpBB config + * @param factory $factory Files factory + * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper + * @param request_interface $request Request object + * @param string $phpbb_root_path phpBB root path + */ + public function __construct(config $config, factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request, $phpbb_root_path) + { + $this->config = $config; + $this->factory = $factory; + $this->language = $language; + $this->php_ini = $php_ini; + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * {@inheritdoc} + */ + public function upload() + { + $args = func_get_args(); + return $this->remote_upload($args[0]); + } + + /** + * Remote upload method + * Uploads file from given url + * + * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif + * @return filespec $file Object "filespec" is returned, all further operations can be done with this object + * @access public + */ + protected function remote_upload($upload_url) + { + $upload_ary = array(); + $upload_ary['local_mode'] = true; + + if (!preg_match('#^(https?://).*?\.(' . implode('|', $this->upload->allowed_extensions) . ')$#i', $upload_url, $match)) + { + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'URL_INVALID')); + } + + $url = parse_url($upload_url); + + $upload_ary['type'] = 'application/octet-stream'; + + $url['path'] = explode('.', $url['path']); + $ext = array_pop($url['path']); + + $url['path'] = implode('', $url['path']); + $upload_ary['name'] = utf8_basename($url['path']) . (($ext) ? '.' . $ext : ''); + + $remote_max_filesize = $this->get_max_file_size(); + + $guzzle_options = [ + 'timeout' => $this->upload->upload_timeout, + 'connect_timeout' => $this->upload->upload_timeout, + 'verify' => !empty($this->config['remote_upload_verify']) ? (bool) $this->config['remote_upload_verify'] : false, + ]; + $client = new \GuzzleHttp\Client($guzzle_options); + + try + { + $response = $client->get($upload_url, $guzzle_options); + } + catch (\GuzzleHttp\Exception\ClientException $clientException) + { + return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'URL_NOT_FOUND'); + } + catch (\GuzzleHttp\Exception\RequestException $requestException) + { + if (strpos($requestException->getMessage(), 'cURL error 28') !== false || preg_match('/408|504/', $requestException->getCode())) + { + return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'REMOTE_UPLOAD_TIMEOUT'); + } + else + { + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); + } + } + catch (\Exception $e) + { + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED')); + } + + $content_length = $response->getBody()->getSize(); + if ($remote_max_filesize && $content_length > $remote_max_filesize) + { + $max_filesize = get_formatted_filesize($remote_max_filesize, false); + + return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'WRONG_FILESIZE', $max_filesize['value'], $max_filesize['unit'])); + } + + if ($content_length == 0) + { + return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'EMPTY_REMOTE_DATA'); + } + + $data = $response->getBody(); + + $filename = tempnam(sys_get_temp_dir(), unique_id() . '-'); + + if (!($fp = @fopen($filename, 'wb'))) + { + return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'NOT_UPLOADED'); + } + + $upload_ary['size'] = fwrite($fp, $data); + fclose($fp); + unset($data); + + $upload_ary['tmp_name'] = $filename; + + /** @var filespec $file */ + $file = $this->factory->get('filespec_storage') + ->set_upload_ary($upload_ary) + ->set_upload_namespace($this->upload); + $this->upload->common_checks($file); + + return $file; + } + + /** + * Get maximum file size for remote uploads + * + * @return int Maximum file size + */ + protected function get_max_file_size() + { + $max_file_size = $this->upload->max_filesize; + if (!$max_file_size) + { + $max_file_size = $this->php_ini->getString('upload_max_filesize'); + + if (!empty($max_file_size)) + { + $unit = strtolower(substr($max_file_size, -1, 1)); + $max_file_size = (int) $max_file_size; + + switch ($unit) + { + case 'g': + $max_file_size *= 1024; + // no break + case 'm': + $max_file_size *= 1024; + // no break + case 'k': + $max_file_size *= 1024; + // no break + } + } + } + + return $max_file_size; + } +} diff --git a/phpBB/phpbb/storage/adapter/adapter_interface.php b/phpBB/phpbb/storage/adapter/adapter_interface.php index b2f6043741..7e64873c1e 100644 --- a/phpBB/phpbb/storage/adapter/adapter_interface.php +++ b/phpBB/phpbb/storage/adapter/adapter_interface.php @@ -22,6 +22,13 @@ interface adapter_interface */ public function configure($options); + /** + * Dumps content into a file. + * + * @param array options Storage-specific options. + */ + public function configure($options); + /** * Dumps content into a file. * From 0417482d55660fe5b074ad236f41e3d158d04abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 20 Jul 2017 05:27:33 +0200 Subject: [PATCH 02/34] [ticket/15276] Fix migration PHPBB3-15276 --- phpBB/phpbb/db/migration/data/v330/storage_avatar.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migration/data/v330/storage_avatar.php b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php index 5eac0b8346..3d415ee558 100644 --- a/phpBB/phpbb/db/migration/data/v330/storage_avatar.php +++ b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php @@ -13,14 +13,12 @@ namespace phpbb\db\migration\data\v330; -use \phpbb\storage\provider; - class storage_avatar extends \phpbb\db\migration\migration { public function update_data() { return array( - array('config.add', array('storage\\avatar\\adapter', provider\local::class)), + array('config.add', array('storage\\avatar\\adapter', \phpbb\storage\provider\local::class)), array('config.add', array('storage\\avatar\\config\\path', $this->config['avatar_path'])), array('config.remove', array('avatar_path')), ); From ef00bb4da52eae43a5f56ee6d8340bf8e6dd1db3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 20 Jul 2017 07:56:05 +0200 Subject: [PATCH 03/34] [ticket/15276] Resolve conflicts PHPBB3-15276 --- phpBB/config/default/container/services_files.yml | 1 + phpBB/config/default/container/services_storage.yml | 1 - phpBB/phpbb/storage/adapter/adapter_interface.php | 7 ------- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index a846fbf385..96682d6713 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -12,6 +12,7 @@ services: - '@language' - '@php_ini' - '@upload_imagesize' + - '%core.root_path%' - '@mimetype.guesser' - '@plupload' diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index bad2139bae..618c1d6c16 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -12,7 +12,6 @@ services: class: phpbb\storage\adapter_factory arguments: - '@config' - - '@service_container' - '@storage.adapter_collection' - '@storage.provider_collection' diff --git a/phpBB/phpbb/storage/adapter/adapter_interface.php b/phpBB/phpbb/storage/adapter/adapter_interface.php index 7e64873c1e..b2f6043741 100644 --- a/phpBB/phpbb/storage/adapter/adapter_interface.php +++ b/phpBB/phpbb/storage/adapter/adapter_interface.php @@ -22,13 +22,6 @@ interface adapter_interface */ public function configure($options); - /** - * Dumps content into a file. - * - * @param array options Storage-specific options. - */ - public function configure($options); - /** * Dumps content into a file. * From 41af01b1ee574415f1e85f463298913720620c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 20 Jul 2017 17:27:29 +0200 Subject: [PATCH 04/34] [ticket/15276] Rename exception PHPBB3-15276 --- phpBB/phpbb/avatar/driver/upload.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index bd33b7610d..829aee6a72 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -13,6 +13,8 @@ namespace phpbb\avatar\driver; +use \phpbb\storage\exception\exception as storage_exception; + /** * Handles avatars uploaded to the board */ @@ -279,7 +281,7 @@ class upload extends \phpbb\avatar\driver\driver $this->storage->delete($filename); return true; } - catch (\phpbb\storage\exception\exception $e) + catch (storage_exception $e) { // Fail is covered by return statement below } From 929e32e80de408a423ec2404389e51b5d0c9e99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 21 Jul 2017 10:47:11 +0200 Subject: [PATCH 05/34] [ticket/15276] Use storage in avatar test PHPBB3-15276 --- tests/avatar/manager_test.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 762fd776e3..2f2f753039 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -36,6 +36,13 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->will($this->returnArgument(0)); $filesystem = new \phpbb\filesystem\filesystem(); + $adapter = new \phpbb\storage\adapter\local($filesystem, $phpbb_root_path); + $adapter->configure(['path' => 'images/avatars/upload']); + $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); + $adapter_factory_mock->expects($this->any()) + ->method('get') + ->willReturn($adapter); + $storage = new \phpbb\storage\storage($adapter_factory_mock, ''); // Prepare dependencies for avatar manager and driver $this->config = new \phpbb\config\config(array()); @@ -86,6 +93,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case { if ($driver !== 'upload') { + $cur_avatar = $this->getMockBuilder('\phpbb\avatar\driver\\' . $driver) ->setMethods(array('get_name')) ->setConstructorArgs(array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache)) @@ -95,7 +103,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case { $cur_avatar = $this->getMockBuilder('\phpbb\avatar\driver\\' . $driver) ->setMethods(array('get_name')) - ->setConstructorArgs(array($this->config, $phpbb_root_path, $phpEx, $filesystem, $path_helper, $dispatcher, $files_factory, $cache)) + ->setConstructorArgs(array($this->config, $phpbb_root_path, $phpEx, $storage, $path_helper, $dispatcher, $files_factory, $cache)) ->getMock(); } $cur_avatar->expects($this->any()) From ee094dd0de5e2fff1d47ca82f0d07065e97466fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 21 Jul 2017 10:51:24 +0200 Subject: [PATCH 06/34] [ticket/15276] Remove annotation PHPBB3-15276 --- phpBB/phpbb/avatar/driver/upload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 829aee6a72..753daf2d05 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -261,7 +261,6 @@ class upload extends \phpbb\avatar\driver\driver * Before deleting an existing avatar * * @event core.avatar_driver_upload_delete_before - * @var string destination Destination directory where the file is going to be deleted * @var string prefix Prefix for the avatar filename * @var array row Array with avatar row data * @var array error Array of errors, if filled in by this event file will not be deleted From 5a25a6b69f538ef158ffbbd79708372aaba2d311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 21 Jul 2017 10:52:38 +0200 Subject: [PATCH 07/34] [ticket/15276] Remove empty line PHPBB3-15276 --- tests/avatar/manager_test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 2f2f753039..2360a48d8b 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -93,7 +93,6 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case { if ($driver !== 'upload') { - $cur_avatar = $this->getMockBuilder('\phpbb\avatar\driver\\' . $driver) ->setMethods(array('get_name')) ->setConstructorArgs(array($this->config, $imagesize, $phpbb_root_path, $phpEx, $path_helper, $cache)) From 89f4e12f855b5a0d4bccb0a6cfb3dbeae6166ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 24 Jul 2017 02:30:44 +0200 Subject: [PATCH 08/34] [ticket/15276] Add service to collection PHPBB3-15276 --- phpBB/config/default/container/services_storage.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index 618c1d6c16..6cb0aa20cf 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -6,6 +6,8 @@ services: arguments: - '@storage.adapter.factory' - 'avatar' + tags: + - { name: storage } # Factory storage.adapter.factory: From 286b1bbe33c949fc5a8e88394285f60f7ccc3424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Jul 2017 11:55:35 +0200 Subject: [PATCH 09/34] [ticket/15276] Change adapter to provider in config_name PHPBB3-15276 --- phpBB/install/schemas/schema_data.sql | 2 +- phpBB/phpbb/db/migration/data/v330/storage_avatar.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index b28d39a494..fbe36bee05 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -287,7 +287,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_json INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_vendor_dir', 'vendor-ext/'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_enable_on_install', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_purge_on_remove', '1'); -INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\adapter', 'phpbb\storage\provider\local'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\provider', 'phpbb\storage\provider\local'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload'); INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1); diff --git a/phpBB/phpbb/db/migration/data/v330/storage_avatar.php b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php index 3d415ee558..077904daa6 100644 --- a/phpBB/phpbb/db/migration/data/v330/storage_avatar.php +++ b/phpBB/phpbb/db/migration/data/v330/storage_avatar.php @@ -18,7 +18,7 @@ class storage_avatar extends \phpbb\db\migration\migration public function update_data() { return array( - array('config.add', array('storage\\avatar\\adapter', \phpbb\storage\provider\local::class)), + array('config.add', array('storage\\avatar\\provider', \phpbb\storage\provider\local::class)), array('config.add', array('storage\\avatar\\config\\path', $this->config['avatar_path'])), array('config.remove', array('avatar_path')), ); From 4c5114c14d4c7880740f9cbefaf5ef917ac2194f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 28 Jul 2017 14:36:03 +0200 Subject: [PATCH 10/34] [ticket/15276] Use storage to download avatar PHPBB3-15276 --- phpBB/includes/functions_download.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index cee7c39035..55bed7ea79 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -25,7 +25,9 @@ if (!defined('IN_PHPBB')) */ function send_avatar_to_browser($file, $browser) { - global $config, $phpbb_root_path; + global $config, $phpbb_container; + + $storage = $phpbb_container->get('storage.avatar'); $prefix = $config['avatar_salt'] . '_'; $image_dir = $config['avatar_path']; @@ -41,15 +43,12 @@ function send_avatar_to_browser($file, $browser) { $image_dir = ''; } - $file_path = $phpbb_root_path . $image_dir . '/' . $prefix . $file; + $file_path = $image_dir . '/' . $prefix . $file; - if ((@file_exists($file_path) && @is_readable($file_path)) && !headers_sent()) + if ($storage->exists($file_path) && !headers_sent()) { header('Cache-Control: public'); - $image_data = @getimagesize($file_path); - header('Content-Type: ' . image_type_to_mime_type($image_data[2])); - if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -69,12 +68,6 @@ function send_avatar_to_browser($file, $browser) header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); } - $size = @filesize($file_path); - if ($size) - { - header("Content-Length: $size"); - } - if (@readfile($file_path) == false) { $fp = @fopen($file_path, 'rb'); @@ -89,6 +82,8 @@ function send_avatar_to_browser($file, $browser) } } + echo $storage->get_contents($file_path); + flush(); } else From 946f0348a275f76dc24e78b9e42d97a4d971a107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 7 Aug 2017 19:54:11 +0200 Subject: [PATCH 11/34] [ticket/15276] Add methods to get file info PHPBB3-15276 --- phpBB/phpbb/storage/adapter/local.php | 15 +++++++ phpBB/phpbb/storage/file_info.php | 65 +++++++++++++++++++++++++++ phpBB/phpbb/storage/storage.php | 5 +++ 3 files changed, 85 insertions(+) create mode 100644 phpBB/phpbb/storage/file_info.php diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index de63d0f6a5..a614860030 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -235,4 +235,19 @@ class local implements adapter_interface, stream_interface throw new exception('STORAGE_CANNOT_COPY_RESOURCE'); } } + + public function get_file_info($path) + { + return []; + } + + public function get_size($path) + { + return filesize($this->root_path . $path); + } + + public function get_mimetype($path) + { + return mime_content_type($this->root_path . $path); + } } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php new file mode 100644 index 0000000000..a3bcfbabba --- /dev/null +++ b/phpBB/phpbb/storage/file_info.php @@ -0,0 +1,65 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + * For full copyright and license information, please see + * the docs/CREDITS.txt file. + * + */ + +namespace phpbb\storage; + +use phpbb\storage\exception\not_implemented; + +class file_info +{ + protected $adapter; + + protected $path; + + protected $properties; + + public function __construct($adapter, $path) + { + $this->adapter = $adapter; + $this->path = $path; + } + + protected function fill_properties($path) + { + if ($this->properties === null) + { + $this->properties = []; + + foreach($this->adapter->get_file_info($this->path) as $name => $value) { + $this->properties[$name] = $value; + } + } + } + + public function get($name) + { + $this->fill_properties(); + + if (!isset($this->properties[$name])) + { + if (!method_exists($this->adapter, 'get_' . $name)) + { + throw new not_implemented(); + } + + $this->properties[$name] = call_user_func($this->adapter, 'get_' . $name); + } + + return $this->properties[$name]; + } + + public function __get($name) + { + return $this->get($name); + } +} diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index a2eb89ecb3..3ecf0f97af 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -192,4 +192,9 @@ class storage $adapter->put_contents($path, stream_get_contents($resource)); } } + + public function get_fileinfo($path) + { + return new file_info($adapter, $path); + } } From 9e018e7c12c76264fcaa10e9d716f01a4b52681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 Aug 2017 12:25:24 +0200 Subject: [PATCH 12/34] [ticket/15276] Use streams PHPBB3-15276 --- phpBB/includes/functions_download.php | 28 ++++++++++++++++++++++++++- phpBB/phpbb/storage/adapter/local.php | 6 +++--- phpBB/phpbb/storage/file_info.php | 6 +++--- phpBB/phpbb/storage/storage.php | 4 ++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 55bed7ea79..1ad6dfc092 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -47,8 +47,17 @@ function send_avatar_to_browser($file, $browser) if ($storage->exists($file_path) && !headers_sent()) { + $file_info = $storage->file_info($file_path); + header('Cache-Control: public'); + try { + header('Content-Type: ' . $file_info->mimetype); + } catch (\phpbb\storage\exception\not_implemented $e) { + // Just dont send this header + } + + if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); @@ -68,6 +77,12 @@ function send_avatar_to_browser($file, $browser) header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); } + try { + header('Content-Type: ' . $file_info->size); + } catch (\phpbb\storage\exception\not_implemented $e) { + // Just dont send this header + } + if (@readfile($file_path) == false) { $fp = @fopen($file_path, 'rb'); @@ -82,7 +97,18 @@ function send_avatar_to_browser($file, $browser) } } - echo $storage->get_contents($file_path); + try { + $fp = $storage->read_stream($file_path); + + while (!feof($fp)) + { + echo fread($fp, 8192); + } + + fclose($fp); + } catch (\Exception $e) { + + } flush(); } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index a614860030..9e7dc7db79 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -236,17 +236,17 @@ class local implements adapter_interface, stream_interface } } - public function get_file_info($path) + public function file_properties($path) { return []; } - public function get_size($path) + public function file_size($path) { return filesize($this->root_path . $path); } - public function get_mimetype($path) + public function file_mimetype($path) { return mime_content_type($this->root_path . $path); } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index a3bcfbabba..f78bc88d10 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -35,7 +35,7 @@ class file_info { $this->properties = []; - foreach($this->adapter->get_file_info($this->path) as $name => $value) { + foreach($this->adapter->file_properties($this->path) as $name => $value) { $this->properties[$name] = $value; } } @@ -47,12 +47,12 @@ class file_info if (!isset($this->properties[$name])) { - if (!method_exists($this->adapter, 'get_' . $name)) + if (!method_exists($this->adapter, 'file_' . $name)) { throw new not_implemented(); } - $this->properties[$name] = call_user_func($this->adapter, 'get_' . $name); + $this->properties[$name] = call_user_func($this->adapter, 'file_' . $name); } return $this->properties[$name]; diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 3ecf0f97af..59181d2623 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -193,8 +193,8 @@ class storage } } - public function get_fileinfo($path) + public function file_info($path) { - return new file_info($adapter, $path); + return new file_info($this->adapter, $path); } } From 006990f1d039e46cb91520211e0282ec5d7fb717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 Aug 2017 12:32:23 +0200 Subject: [PATCH 13/34] [ticket/15276] Fix file_info errors PHPBB3-15276 --- phpBB/phpbb/storage/file_info.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index f78bc88d10..c0b5256f33 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -43,7 +43,7 @@ class file_info public function get($name) { - $this->fill_properties(); + $this->fill_properties($this->path); if (!isset($this->properties[$name])) { @@ -52,7 +52,7 @@ class file_info throw new not_implemented(); } - $this->properties[$name] = call_user_func($this->adapter, 'file_' . $name); + $this->properties[$name] = call_user_func([$this->adapter, 'file_' . $name], $this->path); } return $this->properties[$name]; From 8a47fd4120405ec45bdfd082847a275761a4693c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 Aug 2017 12:34:39 +0200 Subject: [PATCH 14/34] [ticket/15276] Remove old code PHPBB3-15276 --- phpBB/includes/functions_download.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 1ad6dfc092..830da2b90d 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -83,20 +83,6 @@ function send_avatar_to_browser($file, $browser) // Just dont send this header } - if (@readfile($file_path) == false) - { - $fp = @fopen($file_path, 'rb'); - - if ($fp !== false) - { - while (!feof($fp)) - { - echo fread($fp, 8192); - } - fclose($fp); - } - } - try { $fp = $storage->read_stream($file_path); From 8d7336e57cd910ca27a3f08ae4a921dca8c66ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 Aug 2017 12:36:33 +0200 Subject: [PATCH 15/34] [ticket/15276] Fix code style PHPBB3-15276 --- phpBB/includes/functions_download.php | 1 - phpBB/phpbb/storage/file_info.php | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 830da2b90d..b15b28ced8 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -57,7 +57,6 @@ function send_avatar_to_browser($file, $browser) // Just dont send this header } - if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) { header('Content-Disposition: attachment; ' . header_filename($file)); diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index c0b5256f33..04a6eb7e99 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -35,7 +35,8 @@ class file_info { $this->properties = []; - foreach($this->adapter->file_properties($this->path) as $name => $value) { + foreach ($this->adapter->file_properties($this->path) as $name => $value) + { $this->properties[$name] = $value; } } From 400e663347ad827807e7691e08a663baad1b5274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 8 Aug 2017 14:43:38 +0200 Subject: [PATCH 16/34] [ticket/15276] Update file_info PHPBB3-15276 --- .../storage/adapter/adapter_interface.php | 11 +++++++ phpBB/phpbb/storage/adapter/local.php | 29 ++++++++++++++++++- phpBB/phpbb/storage/file_info.php | 24 +++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/storage/adapter/adapter_interface.php b/phpBB/phpbb/storage/adapter/adapter_interface.php index b2f6043741..f9fb2438b6 100644 --- a/phpBB/phpbb/storage/adapter/adapter_interface.php +++ b/phpBB/phpbb/storage/adapter/adapter_interface.php @@ -85,4 +85,15 @@ interface adapter_interface * When the file cannot be copied */ public function copy($path_orig, $path_dest); + + /** + * Get file info. + * + * @param string $path The file + * + * @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method + * + * @return \phpbb\storage\file_info Returns file_info object + */ + public function file_properties($path); } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index 9e7dc7db79..34c2894569 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -236,16 +236,43 @@ class local implements adapter_interface, stream_interface } } + /** + * {@inheritdoc} + */ public function file_properties($path) { return []; } + /** + * Get file size. + * + * @param string $path The file + * + * @throws \phpbb\storage\exception\exception When cannot get size + * + * @return int File size in bytes + */ public function file_size($path) { - return filesize($this->root_path . $path); + $size = filesize($this->root_path . $path); + + if ($size === null) + { + throw new exception('STORAGE_CANNOT_GET_FILESIZE'); + } + + return $size; } + + /** + * Get file mimetype. + * + * @param string $path The file + * + * @return string Mime type + */ public function file_mimetype($path) { return mime_content_type($this->root_path . $path); diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index 04a6eb7e99..ec80eb3ccf 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -17,10 +17,19 @@ use phpbb\storage\exception\not_implemented; class file_info { + /** + * @var \phpbb\storage\adapter\adapter_interface + */ protected $adapter; + /** + * @var string + */ protected $path; + /** + * @var array + */ protected $properties; public function __construct($adapter, $path) @@ -29,6 +38,11 @@ class file_info $this->path = $path; } + /** + * Load propertys lazily. + * + * @param string path The file path. + */ protected function fill_properties($path) { if ($this->properties === null) @@ -42,6 +56,13 @@ class file_info } } + /** + * Load propertys lazily. + * + * @param string name The property name. + * + * @return string Returns the property value + */ public function get($name) { $this->fill_properties($this->path); @@ -59,6 +80,9 @@ class file_info return $this->properties[$name]; } + /** + * Alias of \phpbb\storage\file_info->get() + */ public function __get($name) { return $this->get($name); From 090ed9bf79e9f92f7287bcd2644e43e9cfd37de6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 02:42:22 +0200 Subject: [PATCH 17/34] [ticket/15276] Use finfo to get mimetype PHPBB3-15276 --- phpBB/phpbb/storage/adapter/local.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index 34c2894569..2855dcf7d1 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -275,6 +275,16 @@ class local implements adapter_interface, stream_interface */ public function file_mimetype($path) { - return mime_content_type($this->root_path . $path); + if (class_exists('finfo')) + { + $finfo = new \finfo(FILEINFO_MIME_TYPE); + $mimetype = $finfo->file($this->root_path . $path); + } + else + { + $mimetype = mime_content_type($this->root_path . $path); + } + + return $mimetype; } } From 0ff80fead88fb62dea6f51eba88e9cc4c16d5f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 12:39:15 +0200 Subject: [PATCH 18/34] [ticket/15276] Remove avatar_path from acp PHPBB3-15276 --- phpBB/cache/.htaccess | 4 ---- phpBB/cache/index.htm | 10 ---------- phpBB/phpbb/avatar/driver/upload.php | 1 - 3 files changed, 15 deletions(-) delete mode 100644 phpBB/cache/.htaccess delete mode 100644 phpBB/cache/index.htm diff --git a/phpBB/cache/.htaccess b/phpBB/cache/.htaccess deleted file mode 100644 index aa5afc1640..0000000000 --- a/phpBB/cache/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ - - Order Allow,Deny - Deny from All - \ No newline at end of file diff --git a/phpBB/cache/index.htm b/phpBB/cache/index.htm deleted file mode 100644 index ee1f723a7d..0000000000 --- a/phpBB/cache/index.htm +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 753daf2d05..5e5a6db228 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -242,7 +242,6 @@ class upload extends \phpbb\avatar\driver\driver return array( 'allow_avatar_remote_upload'=> array('lang' => 'ALLOW_REMOTE_UPLOAD', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'avatar_filesize' => array('lang' => 'MAX_FILESIZE', 'validate' => 'int:0', 'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']), - 'avatar_path' => array('lang' => 'AVATAR_STORAGE_PATH', 'validate' => 'rpath', 'type' => 'text:20:255', 'explain' => true), ); } From 2afada5a5a8122c0488a72e32fef9042e1883099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 13:43:22 +0200 Subject: [PATCH 19/34] [ticket/15276] Remove avatar_path PHPBB3-15276 --- phpBB/develop/adjust_avatars.php | 23 +++++++++------- phpBB/docs/coding-guidelines.html | 1 - phpBB/includes/acp/acp_main.php | 22 ++------------- phpBB/includes/functions.php | 2 -- phpBB/includes/functions_acp.php | 1 - phpBB/includes/functions_download.php | 15 +---------- phpBB/includes/functions_user.php | 28 ++++++++++++++------ phpBB/install/convert/convertor.php | 2 +- phpBB/install/convertors/convert_phpbb20.php | 2 +- 9 files changed, 39 insertions(+), 57 deletions(-) diff --git a/phpBB/develop/adjust_avatars.php b/phpBB/develop/adjust_avatars.php index dc4ae88f37..7313967c94 100644 --- a/phpBB/develop/adjust_avatars.php +++ b/phpBB/develop/adjust_avatars.php @@ -19,7 +19,7 @@ $auth->acl($user->data); $user->setup(); $echos = 0; - + if (!isset($config['avatar_salt'])) { $cache->purge(); @@ -30,6 +30,11 @@ if (!isset($config['avatar_salt'])) die('database not up to date'); } +if (!isset($config['storage\\avatar\\config\\path']) || $config['storage\\avatar\\config\\path'] != 'phpbb\\storage\\provider\\local') +{ + die('use local provider'); +} + // let's start with the users using a group_avatar. $sql = 'SELECT group_id, group_avatar FROM ' . GROUPS_TABLE . ' @@ -46,16 +51,16 @@ while ($row = $db->sql_fetchrow($result)) { $new_avatar_name = adjust_avatar($row['group_avatar'], 'g' . $row['group_id']); $group_avatars[] = $new_avatar_name; - + // failure is probably due to the avatar name already being adjusted if ($new_avatar_name !== false) { $sql = 'UPDATE ' . USERS_TABLE . " SET user_avatar = '" . $db->sql_escape($new_avatar_name) . "' - WHERE user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' + WHERE user_avatar = '" . $db->sql_escape($row['group_avatar']) . "' AND user_avatar_type = " . AVATAR_UPLOAD; $db->sql_query($sql); - + $sql = 'UPDATE ' . GROUPS_TABLE . " SET group_avatar = '" . $db->sql_escape($new_avatar_name) . "' WHERE group_id = {$row['group_id']}"; @@ -80,8 +85,8 @@ while ($row = $db->sql_fetchrow($result)) $db->sql_freeresult($result); $sql = 'SELECT user_id, username, user_avatar, user_avatar_type - FROM ' . USERS_TABLE . ' - WHERE user_avatar_type = ' . AVATAR_UPLOAD . ' + FROM ' . USERS_TABLE . ' + WHERE user_avatar_type = ' . AVATAR_UPLOAD . ' AND ' . $db->sql_in_set('user_avatar', $group_avatars, true, true); $result = $db->sql_query($sql); @@ -108,7 +113,7 @@ while ($row = $db->sql_fetchrow($result)) $db->sql_query($sql); echo '
Failed updating user ' . $row['user_id'] . "\n"; } - + if ($echos > 200) { echo '
' . "\n"; @@ -131,8 +136,8 @@ $db->sql_close(); function adjust_avatar($old_name, $midfix) { global $config, $phpbb_root_path; - - $avatar_path = $phpbb_root_path . $config['avatar_path']; + + $avatar_path = $phpbb_root_path . $config['storage\\avatar\\config\\path']; $extension = strtolower(substr(strrchr($old_name, '.'), 1)); $new_name = $config['avatar_salt'] . '_' . $midfix . '.' . $extension; diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 3e6919c88a..97feea71ec 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -264,7 +264,6 @@ PHPBB_QA (Set board to QA-Mode, which means the updater also c
  • {T_SUPER_TEMPLATE_PATH} - styles/xxx/template
  • {T_IMAGES_PATH} - images/
  • {T_SMILIES_PATH} - $config['smilies_path']/
  • -
  • {T_AVATAR_PATH} - $config['avatar_path']/
  • {T_AVATAR_GALLERY_PATH} - $config['avatar_gallery_path']/
  • {T_ICONS_PATH} - $config['icons_path']/
  • {T_RANKS_PATH} - $config['ranks_path']/
  • diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 4efa8c70b3..86ce84a4a1 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -502,26 +502,8 @@ class acp_main $upload_dir_size = get_formatted_filesize($config['upload_dir_size']); - $avatar_dir_size = 0; - - if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) - { - while (($file = readdir($avatar_dir)) !== false) - { - if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) - { - $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file); - } - } - closedir($avatar_dir); - - $avatar_dir_size = get_formatted_filesize($avatar_dir_size); - } - else - { - // Couldn't open Avatar dir. - $avatar_dir_size = $user->lang['NOT_AVAILABLE']; - } + // Couldn't open Avatar dir. + $avatar_dir_size = $user->lang['NOT_AVAILABLE']; if ($posts_per_day > $total_posts) { diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 5bf86276c8..9f7d4f02e2 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4434,7 +4434,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id = 'T_SUPER_TEMPLATE_PATH' => "{$web_path}styles/" . rawurlencode($user->style['style_path']) . '/template', 'T_IMAGES_PATH' => "{$web_path}images/", 'T_SMILIES_PATH' => "{$web_path}{$config['smilies_path']}/", - 'T_AVATAR_PATH' => "{$web_path}{$config['avatar_path']}/", 'T_AVATAR_GALLERY_PATH' => "{$web_path}{$config['avatar_gallery_path']}/", 'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/", @@ -4452,7 +4451,6 @@ function page_header($page_title = '', $display_online_list = false, $item_id = 'T_SUPER_TEMPLATE_NAME' => rawurlencode((isset($user->style['style_parent_tree']) && $user->style['style_parent_tree']) ? $user->style['style_parent_tree'] : $user->style['style_path']), 'T_IMAGES' => 'images', 'T_SMILIES' => $config['smilies_path'], - 'T_AVATAR' => $config['avatar_path'], 'T_AVATAR_GALLERY' => $config['avatar_gallery_path'], 'T_ICONS' => $config['icons_path'], 'T_RANKS' => $config['ranks_path'], diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index c79a84f8d4..b3bde79339 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -88,7 +88,6 @@ function adm_page_header($page_title) 'T_IMAGES_PATH' => "{$phpbb_root_path}images/", 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", - 'T_AVATAR_PATH' => "{$phpbb_root_path}{$config['avatar_path']}/", 'T_AVATAR_GALLERY_PATH' => "{$phpbb_root_path}{$config['avatar_gallery_path']}/", 'T_ICONS_PATH' => "{$phpbb_root_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$phpbb_root_path}{$config['ranks_path']}/", diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index b15b28ced8..eea64c3ab2 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -30,20 +30,7 @@ function send_avatar_to_browser($file, $browser) $storage = $phpbb_container->get('storage.avatar'); $prefix = $config['avatar_salt'] . '_'; - $image_dir = $config['avatar_path']; - - // Adjust image_dir path (no trailing slash) - if (substr($image_dir, -1, 1) == '/' || substr($image_dir, -1, 1) == '\\') - { - $image_dir = substr($image_dir, 0, -1) . '/'; - } - $image_dir = str_replace(array('../', '..\\', './', '.\\'), '', $image_dir); - - if ($image_dir && ($image_dir[0] == '/' || $image_dir[0] == '\\')) - { - $image_dir = ''; - } - $file_path = $image_dir . '/' . $prefix . $file; + $file_path = $prefix . $file; if ($storage->exists($file_path) && !headers_sent()) { diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f1e03869b4..75fb301c01 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2164,7 +2164,9 @@ function phpbb_style_is_active($style_id) */ function avatar_delete($mode, $row, $clean_db = false) { - global $phpbb_root_path, $config; + global $config, $phpbb_container; + + $storage = $phpbb_container->get('storage.avatar'); // Check if the users avatar is actually *not* a group avatar if ($mode == 'user') @@ -2181,13 +2183,16 @@ function avatar_delete($mode, $row, $clean_db = false) } $filename = get_avatar_filename($row[$mode . '_avatar']); - if (file_exists($phpbb_root_path . $config['avatar_path'] . '/' . $filename)) + try { - @unlink($phpbb_root_path . $config['avatar_path'] . '/' . $filename); + $storage->delete($filename); + return true; } - - return false; + catch (\phpbb\storage\exception\exception $e) + { + return false; + } } /** @@ -2505,7 +2510,9 @@ function group_create(&$group_id, $type, $name, $desc, $group_attributes, $allow */ function group_correct_avatar($group_id, $old_entry) { - global $config, $db, $phpbb_root_path; + global $config, $db, $phpbb_container; + + $storage = $phpbb_container->get('storage.avatar'); $group_id = (int) $group_id; $ext = substr(strrchr($old_entry, '.'), 1); @@ -2513,14 +2520,19 @@ function group_correct_avatar($group_id, $old_entry) $new_filename = $config['avatar_salt'] . "_g$group_id.$ext"; $new_entry = 'g' . $group_id . '_' . substr(time(), -5) . ".$ext"; - $avatar_path = $phpbb_root_path . $config['avatar_path']; - if (@rename($avatar_path . '/'. $old_filename, $avatar_path . '/' . $new_filename)) + try { + $this->storage->rename($old_filename, $new_filename); + $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_avatar = \'' . $db->sql_escape($new_entry) . "' WHERE group_id = $group_id"; $db->sql_query($sql); } + catch (\phpbb\storage\exception\exception $e) + { + + } } diff --git a/phpBB/install/convert/convertor.php b/phpBB/install/convert/convertor.php index 5118651b71..619fc73275 100644 --- a/phpBB/install/convert/convertor.php +++ b/phpBB/install/convert/convertor.php @@ -281,7 +281,7 @@ class convertor $bad_folders = array(); $local_paths = array( - 'avatar_path' => path($config['avatar_path']), + 'avatar_path' => path($config['storage\\avatar\\config\\path']), 'avatar_gallery_path' => path($config['avatar_gallery_path']), 'icons_path' => path($config['icons_path']), 'ranks_path' => path($config['ranks_path']), diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index d0885dc620..6476fe0f3a 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -311,7 +311,7 @@ if (!$get_info) $convertor = array( 'test_file' => 'viewtopic.php', - 'avatar_path' => get_config_value('avatar_path') . '/', + 'avatar_path' => get_config_value('storage\\avatar\\config\\path') . '/', 'avatar_gallery_path' => get_config_value('avatar_gallery_path') . '/', 'smilies_path' => get_config_value('smilies_path') . '/', 'upload_path' => (defined('MOD_ATTACHMENT')) ? phpbb_get_files_dir() . '/' : '', From 3c603337251f9905fed05609d176305ed3928ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 16:07:28 +0200 Subject: [PATCH 20/34] [ticket/15276] Update PHPBB3-15276 --- phpBB/includes/functions_user.php | 4 +++- phpBB/install/convertors/convert_phpbb20.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 75fb301c01..531dd6f687 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2191,8 +2191,10 @@ function avatar_delete($mode, $row, $clean_db = false) } catch (\phpbb\storage\exception\exception $e) { - return false; + // Fail is covered by return statement below } + + return false; } /** diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 6476fe0f3a..d0885dc620 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -311,7 +311,7 @@ if (!$get_info) $convertor = array( 'test_file' => 'viewtopic.php', - 'avatar_path' => get_config_value('storage\\avatar\\config\\path') . '/', + 'avatar_path' => get_config_value('avatar_path') . '/', 'avatar_gallery_path' => get_config_value('avatar_gallery_path') . '/', 'smilies_path' => get_config_value('smilies_path') . '/', 'upload_path' => (defined('MOD_ATTACHMENT')) ? phpbb_get_files_dir() . '/' : '', From 09856aeb26a781a91087e9375c757cd92cbcbbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Wed, 9 Aug 2017 22:08:45 +0200 Subject: [PATCH 21/34] [ticket/15276] Update file_info to get size of images PHPBB3-15276 --- phpBB/cache/.htaccess | 4 + phpBB/cache/index.htm | 10 +++ .../default/container/services_storage.yml | 1 + .../storage/adapter/adapter_interface.php | 11 --- phpBB/phpbb/storage/adapter/local.php | 73 +++++++++++++++---- phpBB/phpbb/storage/file_info.php | 23 +----- phpBB/phpbb/storage/storage.php | 9 +++ tests/avatar/manager_test.php | 2 +- tests/storage/adapter/local_test.php | 2 +- 9 files changed, 87 insertions(+), 48 deletions(-) create mode 100644 phpBB/cache/.htaccess create mode 100644 phpBB/cache/index.htm diff --git a/phpBB/cache/.htaccess b/phpBB/cache/.htaccess new file mode 100644 index 0000000000..aa5afc1640 --- /dev/null +++ b/phpBB/cache/.htaccess @@ -0,0 +1,4 @@ + + Order Allow,Deny + Deny from All + \ No newline at end of file diff --git a/phpBB/cache/index.htm b/phpBB/cache/index.htm new file mode 100644 index 0000000000..ee1f723a7d --- /dev/null +++ b/phpBB/cache/index.htm @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index 6cb0aa20cf..4e37ffbce0 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -38,6 +38,7 @@ services: shared: false arguments: - '@filesystem' + - '@upload_imagesize' - '%core.root_path%' tags: - { name: storage.adapter } diff --git a/phpBB/phpbb/storage/adapter/adapter_interface.php b/phpBB/phpbb/storage/adapter/adapter_interface.php index f9fb2438b6..b2f6043741 100644 --- a/phpBB/phpbb/storage/adapter/adapter_interface.php +++ b/phpBB/phpbb/storage/adapter/adapter_interface.php @@ -85,15 +85,4 @@ interface adapter_interface * When the file cannot be copied */ public function copy($path_orig, $path_dest); - - /** - * Get file info. - * - * @param string $path The file - * - * @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method - * - * @return \phpbb\storage\file_info Returns file_info object - */ - public function file_properties($path); } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index 2855dcf7d1..4004669e44 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -18,6 +18,7 @@ use phpbb\storage\exception\exception; use phpbb\filesystem\exception\filesystem_exception; use phpbb\filesystem\filesystem; use phpbb\filesystem\helper as filesystem_helper; +use FastImageSize\FastImageSize; /** * @internal Experimental @@ -31,6 +32,13 @@ class local implements adapter_interface, stream_interface */ protected $filesystem; + /** + * Filesystem component + * + * @var \FastImageSize\FastImageSize + */ + protected $imagesize; + /** * @var string path */ @@ -44,9 +52,10 @@ class local implements adapter_interface, stream_interface /** * Constructor */ - public function __construct(filesystem $filesystem, $phpbb_root_path) + public function __construct(filesystem $filesystem, FastImageSize $imagesize, $phpbb_root_path) { $this->filesystem = $filesystem; + $this->imagesize = $imagesize; $this->phpbb_root_path = $phpbb_root_path; } @@ -236,14 +245,6 @@ class local implements adapter_interface, stream_interface } } - /** - * {@inheritdoc} - */ - public function file_properties($path) - { - return []; - } - /** * Get file size. * @@ -251,7 +252,7 @@ class local implements adapter_interface, stream_interface * * @throws \phpbb\storage\exception\exception When cannot get size * - * @return int File size in bytes + * @return array Properties */ public function file_size($path) { @@ -262,16 +263,15 @@ class local implements adapter_interface, stream_interface throw new exception('STORAGE_CANNOT_GET_FILESIZE'); } - return $size; + return ['size' => $size]; } - /** * Get file mimetype. * * @param string $path The file * - * @return string Mime type + * @return array Properties */ public function file_mimetype($path) { @@ -285,6 +285,51 @@ class local implements adapter_interface, stream_interface $mimetype = mime_content_type($this->root_path . $path); } - return $mimetype; + return ['mimetype' => $mimetype]; + } + + /** + * Get image dimensions. + * + * @param string $path The file + * + * @return array Properties + */ + protected function image_dimensions($path) + { + $size = $this->imagesize->getImageSize($this->root_path . $path); + + // For not supported types like swf + if ($size === false) + { + $imsize = getimagesize($this->root_path . $path); + $size = ['width' => $imsize[0], 'height' => $imsize[1]]; + } + + return ['image_width' => $size['width'], 'image_height' => $size['height']]; + } + + /** + * Get image width. + * + * @param string $path The file + * + * @return array Properties + */ + public function file_image_width($path) + { + return $this->image_dimensions($path); + } + + /** + * Get image height. + * + * @param string $path The file + * + * @return array Properties + */ + public function file_image_height($path) + { + return $this->image_dimensions($path); } } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index ec80eb3ccf..3e0a1b1b5b 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -36,24 +36,7 @@ class file_info { $this->adapter = $adapter; $this->path = $path; - } - - /** - * Load propertys lazily. - * - * @param string path The file path. - */ - protected function fill_properties($path) - { - if ($this->properties === null) - { - $this->properties = []; - - foreach ($this->adapter->file_properties($this->path) as $name => $value) - { - $this->properties[$name] = $value; - } - } + $this->properties = []; } /** @@ -65,8 +48,6 @@ class file_info */ public function get($name) { - $this->fill_properties($this->path); - if (!isset($this->properties[$name])) { if (!method_exists($this->adapter, 'file_' . $name)) @@ -74,7 +55,7 @@ class file_info throw new not_implemented(); } - $this->properties[$name] = call_user_func([$this->adapter, 'file_' . $name], $this->path); + $this->properties = array_merge($this->properties, call_user_func([$this->adapter, 'file_' . $name], $this->path)); } return $this->properties[$name]; diff --git a/phpBB/phpbb/storage/storage.php b/phpBB/phpbb/storage/storage.php index 59181d2623..089ccce737 100644 --- a/phpBB/phpbb/storage/storage.php +++ b/phpBB/phpbb/storage/storage.php @@ -193,6 +193,15 @@ class storage } } + /** + * Get file info. + * + * @param string $path The file + * + * @throws \phpbb\storage\exception\not_implemented When the adapter doesnt implement the method + * + * @return \phpbb\storage\file_info Returns file_info object + */ public function file_info($path) { return new file_info($this->adapter, $path); diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 2360a48d8b..d0ff67b6e1 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -36,7 +36,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->will($this->returnArgument(0)); $filesystem = new \phpbb\filesystem\filesystem(); - $adapter = new \phpbb\storage\adapter\local($filesystem, $phpbb_root_path); + $adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); $adapter->configure(['path' => 'images/avatars/upload']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) diff --git a/tests/storage/adapter/local_test.php b/tests/storage/adapter/local_test.php index 6d3ba10bca..09b4568cd6 100644 --- a/tests/storage/adapter/local_test.php +++ b/tests/storage/adapter/local_test.php @@ -24,7 +24,7 @@ $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR; - $this->adapter = new \phpbb\storage\adapter\local($filesystem, $phpbb_root_path); + $this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); $this->adapter->configure(['path' => 'test_path']); $this->path = $phpbb_root_path . 'test_path/'; From c3e9aa1c18d29dbe2e9f23a40776e3d49dd1b816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 11 Aug 2017 00:50:19 +0200 Subject: [PATCH 22/34] [ticket/15276] Use mimetype guesser PHPBB3-15276 --- .../default/container/services_storage.yml | 1 + phpBB/phpbb/storage/adapter/local.php | 25 +++++++++---------- tests/avatar/manager_test.php | 2 +- tests/storage/adapter/local_test.php | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/phpBB/config/default/container/services_storage.yml b/phpBB/config/default/container/services_storage.yml index 4e37ffbce0..32b74687c9 100644 --- a/phpBB/config/default/container/services_storage.yml +++ b/phpBB/config/default/container/services_storage.yml @@ -39,6 +39,7 @@ services: arguments: - '@filesystem' - '@upload_imagesize' + - '@mimetype.guesser' - '%core.root_path%' tags: - { name: storage.adapter } diff --git a/phpBB/phpbb/storage/adapter/local.php b/phpBB/phpbb/storage/adapter/local.php index 4004669e44..1ef2516f4f 100644 --- a/phpBB/phpbb/storage/adapter/local.php +++ b/phpBB/phpbb/storage/adapter/local.php @@ -18,6 +18,7 @@ use phpbb\storage\exception\exception; use phpbb\filesystem\exception\filesystem_exception; use phpbb\filesystem\filesystem; use phpbb\filesystem\helper as filesystem_helper; +use phpbb\mimetype\guesser; use FastImageSize\FastImageSize; /** @@ -33,12 +34,19 @@ class local implements adapter_interface, stream_interface protected $filesystem; /** - * Filesystem component + * FastImageSize * * @var \FastImageSize\FastImageSize */ protected $imagesize; + /** + * Mimetype Guesser component + * + * @var \phpbb\mimetype\guesser + */ + protected $mimetype_guesser; + /** * @var string path */ @@ -52,10 +60,11 @@ class local implements adapter_interface, stream_interface /** * Constructor */ - public function __construct(filesystem $filesystem, FastImageSize $imagesize, $phpbb_root_path) + public function __construct(filesystem $filesystem, FastImageSize $imagesize, guesser $mimetype_guesser, $phpbb_root_path) { $this->filesystem = $filesystem; $this->imagesize = $imagesize; + $this->mimetype_guesser = $mimetype_guesser; $this->phpbb_root_path = $phpbb_root_path; } @@ -275,17 +284,7 @@ class local implements adapter_interface, stream_interface */ public function file_mimetype($path) { - if (class_exists('finfo')) - { - $finfo = new \finfo(FILEINFO_MIME_TYPE); - $mimetype = $finfo->file($this->root_path . $path); - } - else - { - $mimetype = mime_content_type($this->root_path . $path); - } - - return ['mimetype' => $mimetype]; + return ['mimetype' => $this->mimetype_guesser->guess($this->root_path . $path)]; } /** diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index d0ff67b6e1..c276281fee 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -36,7 +36,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case ->will($this->returnArgument(0)); $filesystem = new \phpbb\filesystem\filesystem(); - $adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); + $adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); $adapter->configure(['path' => 'images/avatars/upload']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) diff --git a/tests/storage/adapter/local_test.php b/tests/storage/adapter/local_test.php index 09b4568cd6..b478ce4009 100644 --- a/tests/storage/adapter/local_test.php +++ b/tests/storage/adapter/local_test.php @@ -24,7 +24,7 @@ $filesystem = new \phpbb\filesystem\filesystem(); $phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR; - $this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); + $this->adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path); $this->adapter->configure(['path' => 'test_path']); $this->path = $phpbb_root_path . 'test_path/'; From 87229e1a779db0118b64c538dd2d4d0b961f9885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Tue, 15 Aug 2017 14:37:10 +0200 Subject: [PATCH 23/34] [ticket/15276] Fix typo PHPBB3-15276 --- phpBB/includes/functions_download.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index eea64c3ab2..1503510fcf 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -64,7 +64,7 @@ function send_avatar_to_browser($file, $browser) } try { - header('Content-Type: ' . $file_info->size); + header('Content-Length: ' . $file_info->size); } catch (\phpbb\storage\exception\not_implemented $e) { // Just dont send this header } From 28060a84683b39f826f8fc64ab59ad9c4bd5d79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Fri, 18 Aug 2017 16:18:09 +0200 Subject: [PATCH 24/34] [ticket/15276] Use stream_copy_to_stream PHPBB3-15276 --- phpBB/includes/functions_download.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 1503510fcf..4cbf6e16ee 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -71,13 +71,10 @@ function send_avatar_to_browser($file, $browser) try { $fp = $storage->read_stream($file_path); - - while (!feof($fp)) - { - echo fread($fp, 8192); - } - + $output = fopen('php://output', 'w+b'); + stream_copy_to_stream($fp, $output); fclose($fp); + fclose($output); } catch (\Exception $e) { } From da3c9b3de7539af27e179eb2cb0e3fee0a5658ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Mon, 28 Aug 2017 15:11:12 +0200 Subject: [PATCH 25/34] [ticket/15276] Fix code and add phpdoc PHPBB3-15276 --- phpBB/develop/adjust_avatars.php | 2 +- phpBB/includes/functions_download.php | 23 +++++++++++++++------- phpBB/phpbb/files/types/remote_storage.php | 2 +- phpBB/phpbb/storage/file_info.php | 20 ++++++++++++++++--- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/phpBB/develop/adjust_avatars.php b/phpBB/develop/adjust_avatars.php index 7313967c94..a6b326109d 100644 --- a/phpBB/develop/adjust_avatars.php +++ b/phpBB/develop/adjust_avatars.php @@ -30,7 +30,7 @@ if (!isset($config['avatar_salt'])) die('database not up to date'); } -if (!isset($config['storage\\avatar\\config\\path']) || $config['storage\\avatar\\config\\path'] != 'phpbb\\storage\\provider\\local') +if (!isset($config['storage\\avatar\\config\\path']) || $config['storage\\avatar\\config\\path'] !== 'phpbb\\storage\\provider\\local') { die('use local provider'); } diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 4cbf6e16ee..2582d2e0d9 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -38,9 +38,12 @@ function send_avatar_to_browser($file, $browser) header('Cache-Control: public'); - try { + try + { header('Content-Type: ' . $file_info->mimetype); - } catch (\phpbb\storage\exception\not_implemented $e) { + } + catch (\phpbb\storage\exception\exception $e) + { // Just dont send this header } @@ -63,20 +66,26 @@ function send_avatar_to_browser($file, $browser) header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . ' GMT'); } - try { + try + { header('Content-Length: ' . $file_info->size); - } catch (\phpbb\storage\exception\not_implemented $e) { + } + catch (\phpbb\storage\exception\exception $e) + { // Just dont send this header } - try { + try + { $fp = $storage->read_stream($file_path); $output = fopen('php://output', 'w+b'); stream_copy_to_stream($fp, $output); fclose($fp); fclose($output); - } catch (\Exception $e) { - + } + catch (\Exception $e) + { + // Send nothing } flush(); diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 92dbfd1d8e..16c061655c 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -141,7 +141,7 @@ class remote_storage extends base return $this->factory->get('filespec')->set_error($this->language->lang($this->upload->error_prefix . 'WRONG_FILESIZE', $max_filesize['value'], $max_filesize['unit'])); } - if ($content_length == 0) + if ($content_length === 0) { return $this->factory->get('filespec')->set_error($this->upload->error_prefix . 'EMPTY_REMOTE_DATA'); } diff --git a/phpBB/phpbb/storage/file_info.php b/phpBB/phpbb/storage/file_info.php index 3e0a1b1b5b..ae2bd5169d 100644 --- a/phpBB/phpbb/storage/file_info.php +++ b/phpBB/phpbb/storage/file_info.php @@ -13,7 +13,8 @@ namespace phpbb\storage; -use phpbb\storage\exception\not_implemented; +use phpbb\storage\exception\exception; +use phpbb\storage\adapter\adapter_interface; class file_info { @@ -23,16 +24,29 @@ class file_info protected $adapter; /** + * Path of the file + * * @var string */ protected $path; /** + * Stores the properties of $path file, so dont have to be consulted multiple times. + * For example, when you need the width of an image, using getimagesize() you get + * both dimensions, so you store both here, and when you get the height, you dont have + * to call getimagesize() again. + * * @var array */ protected $properties; - public function __construct($adapter, $path) + /** + * Constructor + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $adapter + * @param string $path + */ + public function __construct(adapter_interface $adapter, $path) { $this->adapter = $adapter; $this->path = $path; @@ -52,7 +66,7 @@ class file_info { if (!method_exists($this->adapter, 'file_' . $name)) { - throw new not_implemented(); + throw new exception('STORAGE_METHOD_NOT_IMPLEMENTED'); } $this->properties = array_merge($this->properties, call_user_func([$this->adapter, 'file_' . $name], $this->path)); From fe20aa058f70141fd7b3d0fdc25c9579ed069fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 13:15:19 +0200 Subject: [PATCH 26/34] [ticket/15276] Fix comments PHPBB3-15276 --- phpBB/includes/functions_download.php | 4 ++-- phpBB/includes/functions_user.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index 2582d2e0d9..332a9c600f 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -44,7 +44,7 @@ function send_avatar_to_browser($file, $browser) } catch (\phpbb\storage\exception\exception $e) { - // Just dont send this header + // Just don't send this header } if ((strpos(strtolower($browser), 'msie') !== false) && !phpbb_is_greater_ie_version($browser, 7)) @@ -72,7 +72,7 @@ function send_avatar_to_browser($file, $browser) } catch (\phpbb\storage\exception\exception $e) { - // Just dont send this header + // Just don't send this header } try diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 531dd6f687..57f87a2b1e 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2533,7 +2533,7 @@ function group_correct_avatar($group_id, $old_entry) } catch (\phpbb\storage\exception\exception $e) { - + // If rename fail, dont execute the query } } From 354dda5cc827e40a24d1832e1125efe177451189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 13:29:35 +0200 Subject: [PATCH 27/34] [ticket/15276] Use InitGetWrapper PHPBB3-15276 --- phpBB/config/default/container/services_files.yml | 2 -- phpBB/phpbb/avatar/driver/upload.php | 12 ++++++++++-- phpBB/phpbb/files/types/form.php | 8 +------- phpBB/phpbb/files/types/form_storage.php | 8 +------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 96682d6713..72a22d5f00 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -42,7 +42,6 @@ services: arguments: - '@files.factory' - '@language' - - '@php_ini' - '@plupload' - '@request' @@ -52,7 +51,6 @@ services: arguments: - '@files.factory' - '@language' - - '@php_ini' - '@plupload' - '@request' diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 5e5a6db228..7c02f5993a 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -13,6 +13,7 @@ namespace phpbb\avatar\driver; +use bantu\IniGetWrapper\IniGetWrapper; use \phpbb\storage\exception\exception as storage_exception; /** @@ -35,6 +36,11 @@ class upload extends \phpbb\avatar\driver\driver */ protected $files_factory; + /** + * @var IniGetWrapper + */ + protected $php_ini; + /** * Construct a driver object * @@ -45,9 +51,10 @@ class upload extends \phpbb\avatar\driver\driver * @param \phpbb\path_helper $path_helper phpBB path helper * @param \phpbb\event\dispatcher_interface $dispatcher phpBB Event dispatcher object * @param \phpbb\files\factory $files_factory File classes factory + * @param IniGetWrapper $php_ini ini_get() wrapper * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\storage\storage $storage, \phpbb\path_helper $path_helper, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, \phpbb\cache\driver\driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\storage\storage $storage, \phpbb\path_helper $path_helper, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, IniGetWrapper $php_ini, \phpbb\cache\driver\driver_interface $cache = null) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; @@ -56,6 +63,7 @@ class upload extends \phpbb\avatar\driver\driver $this->path_helper = $path_helper; $this->dispatcher = $dispatcher; $this->files_factory = $files_factory; + $this->php_ini = $php_ini; $this->cache = $cache; } @@ -303,6 +311,6 @@ class upload extends \phpbb\avatar\driver\driver */ protected function can_upload() { - return (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on'); + return $this->php_ini->getBool('file_uploads'); } } diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index 2c3beb6e02..872c0f014c 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -13,7 +13,6 @@ namespace phpbb\files\types; -use bantu\IniGetWrapper\IniGetWrapper; use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; @@ -28,9 +27,6 @@ class form extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var plupload */ protected $plupload; @@ -45,15 +41,13 @@ class form extends base * * @param factory $factory Files factory * @param language $language Language class - * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request) { $this->factory = $factory; $this->language = $language; - $this->php_ini = $php_ini; $this->plupload = $plupload; $this->request = $request; } diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php index 09bd850538..b80be689c9 100644 --- a/phpBB/phpbb/files/types/form_storage.php +++ b/phpBB/phpbb/files/types/form_storage.php @@ -13,7 +13,6 @@ namespace phpbb\files\types; -use bantu\IniGetWrapper\IniGetWrapper; use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; @@ -28,9 +27,6 @@ class form_storage extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var plupload */ protected $plupload; @@ -45,15 +41,13 @@ class form_storage extends base * * @param factory $factory Files factory * @param language $language Language class - * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request) { $this->factory = $factory; $this->language = $language; - $this->php_ini = $php_ini; $this->plupload = $plupload; $this->request = $request; } From bb886667d24ed3c252c9946b63fb9f928034c8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 13:35:15 +0200 Subject: [PATCH 28/34] [ticket/15276] Add missing properties PHPBB3-15276 --- phpBB/phpbb/avatar/driver/upload.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 7c02f5993a..32a902604d 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -21,11 +21,31 @@ use \phpbb\storage\exception\exception as storage_exception; */ class upload extends \phpbb\avatar\driver\driver { + /** + * @var \phpbb\config\config + */ + protected $config; + + /** + * @var string + */ + protected $phpbb_root_path; + + /** + * @var string + */ + protected $php_ext; + /** * @var \phpbb\storage\storage */ protected $storage; + /** + * @var \phpbb\path_helper + */ + protected $path_helper; + /** * @var \phpbb\event\dispatcher_interface */ @@ -41,6 +61,11 @@ class upload extends \phpbb\avatar\driver\driver */ protected $php_ini; + /** + * @var \phpbb\cache\driver\driver_interface + */ + protected $cache; + /** * Construct a driver object * From b255209574a13721af526f9cee91463a74e23a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 13:36:25 +0200 Subject: [PATCH 29/34] [ticket/15276] Remove unused dependency PHPBB3-15276 --- phpBB/config/default/container/services_avatar.yml | 1 - phpBB/phpbb/avatar/driver/upload.php | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/phpBB/config/default/container/services_avatar.yml b/phpBB/config/default/container/services_avatar.yml index d5d17b54a0..5f58ed9f75 100644 --- a/phpBB/config/default/container/services_avatar.yml +++ b/phpBB/config/default/container/services_avatar.yml @@ -65,7 +65,6 @@ services: - '@path_helper' - '@dispatcher' - '@files.factory' - - '@cache.driver' calls: - [set_name, [avatar.driver.upload]] tags: diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index 32a902604d..f1ea533a89 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -61,11 +61,6 @@ class upload extends \phpbb\avatar\driver\driver */ protected $php_ini; - /** - * @var \phpbb\cache\driver\driver_interface - */ - protected $cache; - /** * Construct a driver object * @@ -77,9 +72,8 @@ class upload extends \phpbb\avatar\driver\driver * @param \phpbb\event\dispatcher_interface $dispatcher phpBB Event dispatcher object * @param \phpbb\files\factory $files_factory File classes factory * @param IniGetWrapper $php_ini ini_get() wrapper - * @param \phpbb\cache\driver\driver_interface $cache Cache driver */ - public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\storage\storage $storage, \phpbb\path_helper $path_helper, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, IniGetWrapper $php_ini, \phpbb\cache\driver\driver_interface $cache = null) + public function __construct(\phpbb\config\config $config, $phpbb_root_path, $php_ext, \phpbb\storage\storage $storage, \phpbb\path_helper $path_helper, \phpbb\event\dispatcher_interface $dispatcher, \phpbb\files\factory $files_factory, IniGetWrapper $php_ini) { $this->config = $config; $this->phpbb_root_path = $phpbb_root_path; @@ -89,7 +83,6 @@ class upload extends \phpbb\avatar\driver\driver $this->dispatcher = $dispatcher; $this->files_factory = $files_factory; $this->php_ini = $php_ini; - $this->cache = $cache; } /** From 5ff182ce25f86342dfeb797a8fdca702084b2018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 13:51:35 +0200 Subject: [PATCH 30/34] [ticket/15276] Add missing dependency PHPBB3-15276 --- phpBB/config/default/container/services_avatar.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/config/default/container/services_avatar.yml b/phpBB/config/default/container/services_avatar.yml index 5f58ed9f75..93a8cd0b62 100644 --- a/phpBB/config/default/container/services_avatar.yml +++ b/phpBB/config/default/container/services_avatar.yml @@ -65,6 +65,7 @@ services: - '@path_helper' - '@dispatcher' - '@files.factory' + - '@php_ini' calls: - [set_name, [avatar.driver.upload]] tags: From 9fcf30d504a92e19e71627eca3b52d60f36416ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 14:50:55 +0200 Subject: [PATCH 31/34] [ticket/15276] Use IniGetWrapper PHPBB3-15276 --- phpBB/config/default/container/services_files.yml | 2 ++ phpBB/phpbb/avatar/driver/driver.php | 1 + phpBB/phpbb/files/types/form.php | 8 +++++++- phpBB/phpbb/files/types/form_storage.php | 8 +++++++- tests/avatar/manager_test.php | 4 +++- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/phpBB/config/default/container/services_files.yml b/phpBB/config/default/container/services_files.yml index 72a22d5f00..96682d6713 100644 --- a/phpBB/config/default/container/services_files.yml +++ b/phpBB/config/default/container/services_files.yml @@ -42,6 +42,7 @@ services: arguments: - '@files.factory' - '@language' + - '@php_ini' - '@plupload' - '@request' @@ -51,6 +52,7 @@ services: arguments: - '@files.factory' - '@language' + - '@php_ini' - '@plupload' - '@request' diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 45681f3e59..7f8e3795fe 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -81,6 +81,7 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface * @param string $php_ext PHP file extension * @param \phpbb\path_helper $path_helper phpBB path helper * @param \phpbb\cache\driver\driver_interface $cache Cache driver + * @param \bantu\IniGetWrapper\IniGetWrapper $php_ini Init get wrapper */ public function __construct(\phpbb\config\config $config, \FastImageSize\FastImageSize $imagesize, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null) { diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index 872c0f014c..2c3beb6e02 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -13,6 +13,7 @@ namespace phpbb\files\types; +use bantu\IniGetWrapper\IniGetWrapper; use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; @@ -27,6 +28,9 @@ class form extends base /** @var language */ protected $language; + /** @var IniGetWrapper */ + protected $php_ini; + /** @var plupload */ protected $plupload; @@ -41,13 +45,15 @@ class form extends base * * @param factory $factory Files factory * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) { $this->factory = $factory; $this->language = $language; + $this->php_ini = $php_ini; $this->plupload = $plupload; $this->request = $request; } diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php index b80be689c9..09bd850538 100644 --- a/phpBB/phpbb/files/types/form_storage.php +++ b/phpBB/phpbb/files/types/form_storage.php @@ -13,6 +13,7 @@ namespace phpbb\files\types; +use bantu\IniGetWrapper\IniGetWrapper; use phpbb\files\factory; use phpbb\files\filespec; use phpbb\language\language; @@ -27,6 +28,9 @@ class form_storage extends base /** @var language */ protected $language; + /** @var IniGetWrapper */ + protected $php_ini; + /** @var plupload */ protected $plupload; @@ -41,13 +45,15 @@ class form_storage extends base * * @param factory $factory Files factory * @param language $language Language class + * @param IniGetWrapper $php_ini ini_get() wrapper * @param plupload $plupload Plupload * @param request_interface $request Request object */ - public function __construct(factory $factory, language $language, plupload $plupload, request_interface $request) + public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, plupload $plupload, request_interface $request) { $this->factory = $factory; $this->language = $language; + $this->php_ini = $php_ini; $this->plupload = $plupload; $this->request = $request; } diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index c276281fee..2866a1673d 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -89,6 +89,8 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case $files_factory = new \phpbb\files\factory($phpbb_container); + $php_ini = new \bantu\IniGetWrapper\IniGetWrapper; + foreach ($this->avatar_drivers() as $driver) { if ($driver !== 'upload') @@ -102,7 +104,7 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case { $cur_avatar = $this->getMockBuilder('\phpbb\avatar\driver\\' . $driver) ->setMethods(array('get_name')) - ->setConstructorArgs(array($this->config, $phpbb_root_path, $phpEx, $storage, $path_helper, $dispatcher, $files_factory, $cache)) + ->setConstructorArgs(array($this->config, $phpbb_root_path, $phpEx, $storage, $path_helper, $dispatcher, $files_factory, $php_ini)) ->getMock(); } $cur_avatar->expects($this->any()) From ed282199acc83ba6e598657e4427c541bf2a1d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 14:59:55 +0200 Subject: [PATCH 32/34] [ticket/15276] Revert some changes PHPBB3-15276 --- phpBB/phpbb/avatar/driver/upload.php | 20 -------------------- phpBB/phpbb/files/types/form.php | 3 --- phpBB/phpbb/files/types/form_storage.php | 3 --- phpBB/phpbb/files/types/local.php | 3 --- phpBB/phpbb/files/types/remote.php | 3 --- phpBB/phpbb/files/types/remote_storage.php | 3 --- 6 files changed, 35 deletions(-) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index f1ea533a89..a808e7b2a1 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -21,31 +21,11 @@ use \phpbb\storage\exception\exception as storage_exception; */ class upload extends \phpbb\avatar\driver\driver { - /** - * @var \phpbb\config\config - */ - protected $config; - - /** - * @var string - */ - protected $phpbb_root_path; - - /** - * @var string - */ - protected $php_ext; - /** * @var \phpbb\storage\storage */ protected $storage; - /** - * @var \phpbb\path_helper - */ - protected $path_helper; - /** * @var \phpbb\event\dispatcher_interface */ diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index 2c3beb6e02..81a4a29c92 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -28,9 +28,6 @@ class form extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var plupload */ protected $plupload; diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php index 09bd850538..eff474044a 100644 --- a/phpBB/phpbb/files/types/form_storage.php +++ b/phpBB/phpbb/files/types/form_storage.php @@ -28,9 +28,6 @@ class form_storage extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var plupload */ protected $plupload; diff --git a/phpBB/phpbb/files/types/local.php b/phpBB/phpbb/files/types/local.php index 4dfe4f7506..fc80052fac 100644 --- a/phpBB/phpbb/files/types/local.php +++ b/phpBB/phpbb/files/types/local.php @@ -27,9 +27,6 @@ class local extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var request_interface */ protected $request; diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index 1fdba0ca32..7caa871c18 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -31,9 +31,6 @@ class remote extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var request_interface */ protected $request; diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index 16c061655c..bf7ea1272b 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -31,9 +31,6 @@ class remote_storage extends base /** @var language */ protected $language; - /** @var IniGetWrapper */ - protected $php_ini; - /** @var request_interface */ protected $request; From a8ba4a99e32631ce1f581043dc08366c8abc2b4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 15:10:52 +0200 Subject: [PATCH 33/34] [ticket/15276] Remove unused code PHPBB3-15276 --- phpBB/phpbb/avatar/driver/driver.php | 1 - phpBB/phpbb/files/types/form.php | 6 ------ phpBB/phpbb/files/types/form_storage.php | 7 ------- phpBB/phpbb/files/types/local.php | 6 ------ phpBB/phpbb/files/types/remote.php | 6 ------ phpBB/phpbb/files/types/remote_storage.php | 7 ------- 6 files changed, 33 deletions(-) diff --git a/phpBB/phpbb/avatar/driver/driver.php b/phpBB/phpbb/avatar/driver/driver.php index 7f8e3795fe..45681f3e59 100644 --- a/phpBB/phpbb/avatar/driver/driver.php +++ b/phpBB/phpbb/avatar/driver/driver.php @@ -81,7 +81,6 @@ abstract class driver implements \phpbb\avatar\driver\driver_interface * @param string $php_ext PHP file extension * @param \phpbb\path_helper $path_helper phpBB path helper * @param \phpbb\cache\driver\driver_interface $cache Cache driver - * @param \bantu\IniGetWrapper\IniGetWrapper $php_ini Init get wrapper */ public function __construct(\phpbb\config\config $config, \FastImageSize\FastImageSize $imagesize, $phpbb_root_path, $php_ext, \phpbb\path_helper $path_helper, \phpbb\cache\driver\driver_interface $cache = null) { diff --git a/phpBB/phpbb/files/types/form.php b/phpBB/phpbb/files/types/form.php index 81a4a29c92..a915476191 100644 --- a/phpBB/phpbb/files/types/form.php +++ b/phpBB/phpbb/files/types/form.php @@ -25,18 +25,12 @@ class form extends base /** @var factory Files factory */ protected $factory; - /** @var language */ - protected $language; - /** @var plupload */ protected $plupload; /** @var request_interface */ protected $request; - /** @var \phpbb\files\upload */ - protected $upload; - /** * Construct a form upload type * diff --git a/phpBB/phpbb/files/types/form_storage.php b/phpBB/phpbb/files/types/form_storage.php index eff474044a..29bef283bd 100644 --- a/phpBB/phpbb/files/types/form_storage.php +++ b/phpBB/phpbb/files/types/form_storage.php @@ -25,18 +25,12 @@ class form_storage extends base /** @var factory Files factory */ protected $factory; - /** @var language */ - protected $language; - /** @var plupload */ protected $plupload; /** @var request_interface */ protected $request; - /** @var \phpbb\files\upload */ - protected $upload; - /** * Construct a form upload type * @@ -71,7 +65,6 @@ class form_storage extends base * @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified) * * @return filespec $file Object "filespec" is returned, all further operations can be done with this object - * @access public */ protected function form_upload($form_name) { diff --git a/phpBB/phpbb/files/types/local.php b/phpBB/phpbb/files/types/local.php index fc80052fac..67948ea6df 100644 --- a/phpBB/phpbb/files/types/local.php +++ b/phpBB/phpbb/files/types/local.php @@ -24,15 +24,9 @@ class local extends base /** @var factory Files factory */ protected $factory; - /** @var language */ - protected $language; - /** @var request_interface */ protected $request; - /** @var \phpbb\files\upload */ - protected $upload; - /** * Construct a form upload type * diff --git a/phpBB/phpbb/files/types/remote.php b/phpBB/phpbb/files/types/remote.php index 7caa871c18..e64e360b6a 100644 --- a/phpBB/phpbb/files/types/remote.php +++ b/phpBB/phpbb/files/types/remote.php @@ -28,15 +28,9 @@ class remote extends base /** @var factory Files factory */ protected $factory; - /** @var language */ - protected $language; - /** @var request_interface */ protected $request; - /** @var \phpbb\files\upload */ - protected $upload; - /** @var string phpBB root path */ protected $phpbb_root_path; diff --git a/phpBB/phpbb/files/types/remote_storage.php b/phpBB/phpbb/files/types/remote_storage.php index bf7ea1272b..3e6953703e 100644 --- a/phpBB/phpbb/files/types/remote_storage.php +++ b/phpBB/phpbb/files/types/remote_storage.php @@ -28,15 +28,9 @@ class remote_storage extends base /** @var factory Files factory */ protected $factory; - /** @var language */ - protected $language; - /** @var request_interface */ protected $request; - /** @var \phpbb\files\upload */ - protected $upload; - /** @var string phpBB root path */ protected $phpbb_root_path; @@ -75,7 +69,6 @@ class remote_storage extends base * * @param string $upload_url URL pointing to file to upload, for example http://www.foobar.com/example.gif * @return filespec $file Object "filespec" is returned, all further operations can be done with this object - * @access public */ protected function remote_upload($upload_url) { From 443c5034ce774ea6f8d0469f20c08eb9b92ec081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Calvo?= Date: Thu, 7 Sep 2017 16:34:50 +0200 Subject: [PATCH 34/34] [ticket/15276] Changed annotation PHPBB3-15276 --- phpBB/phpbb/avatar/driver/upload.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/phpbb/avatar/driver/upload.php b/phpBB/phpbb/avatar/driver/upload.php index a808e7b2a1..621164c765 100644 --- a/phpBB/phpbb/avatar/driver/upload.php +++ b/phpBB/phpbb/avatar/driver/upload.php @@ -270,6 +270,7 @@ class upload extends \phpbb\avatar\driver\driver * @var array row Array with avatar row data * @var array error Array of errors, if filled in by this event file will not be deleted * @since 3.1.6-RC1 + * @changed 3.3.0-a1 Remove destination */ $vars = array( 'prefix',