diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 6d6f09da63..97263af5f9 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1086,6 +1086,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a global $template, $cache, $user, $phpbb_dispatcher; global $extensions, $config, $phpbb_root_path, $phpEx; + global $phpbb_container; + + $attachment_storage = $phpbb_container->get('storage.attachment'); // $compiled_attachments = array(); @@ -1219,18 +1222,16 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a { if ($config['img_link_width'] || $config['img_link_height']) { - // - $dimension = @getimagesize($filename); + try + { + $file_info = $storage_attachment->file_info($filename); - // If the dimensions could not be determined or the image being 0x0 we display it as a link for safety purposes - if ($dimension === false || empty($dimension[0]) || empty($dimension[1])) + $display_cat = ($file_info->image_width <= $config['img_link_width'] && $file_info->image_height <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE; + } + catch (\Exception $e) { $display_cat = ATTACHMENT_CATEGORY_NONE; } - else - { - $display_cat = ($dimension[0] <= $config['img_link_width'] && $dimension[1] <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE; - } } } else @@ -1284,8 +1285,18 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count_a // Macromedia Flash Files case ATTACHMENT_CATEGORY_FLASH: - // - list($width, $height) = @getimagesize($filename); + try + { + $file_info = $storage_attachment->file_info($filename); + + $width = $file_info->image_width; + $height = $file_info->image_height; + } + catch (\Exception $e) + { + $width = 0; + $height = 0; + } $block_array += array( 'S_FLASH_FILE' => true, diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 68980d79af..e6f328f102 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1442,7 +1442,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll_ary, &$data { global $db, $auth, $user, $config, $phpEx, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request; - $attachment_storage = $phpbb_container->get('storage.avatar'); + $attachment_storage = $phpbb_container->get('storage.attachment'); $poll = $poll_ary; $data = $data_ary; diff --git a/phpBB/phpbb/attachment/upload.php b/phpBB/phpbb/attachment/upload.php index b707921684..89c2b8d804 100644 --- a/phpBB/phpbb/attachment/upload.php +++ b/phpBB/phpbb/attachment/upload.php @@ -161,6 +161,15 @@ class upload // Make sure the image category only holds valid images... $this->check_image($is_image); + if (count($this->file->error)) + { + $this->file->remove($this->storage); + $this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error); + $this->file_data['post_attach'] = false; + + return $this->file_data; + } + $this->fill_file_data(); $filedata = $this->file_data; @@ -194,15 +203,6 @@ class upload // Only then perform additional image checks. $this->file->move_file($this->storage, false, !$is_image); - if (count($this->file->error)) - { - $this->file->remove($this->storage); - $this->file_data['error'] = array_merge($this->file_data['error'], $this->file->error); - $this->file_data['post_attach'] = false; - - return $this->file_data; - } - return $this->file_data; } diff --git a/tests/attachment/delete_test.php b/tests/attachment/delete_test.php index f5d307c5af..a22b31e1a0 100644 --- a/tests/attachment/delete_test.php +++ b/tests/attachment/delete_test.php @@ -55,7 +55,7 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case $this->filesystem->expects($this->any()) ->method('exists') ->willReturn(true); - $adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path); + $adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); $adapter->configure(['path' => 'files']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) @@ -110,6 +110,23 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case */ public function test_attachment_delete_success($remove_success, $exists_success, $expected, $throw_exception = false) { + $this->storage = $this->createMock('\phpbb\storage\storage', array('delete', 'exists')); + if ($throw_exception) + { + $this->storage->expects($this->any()) + ->method('delete') + ->willThrowException(new \phpbb\storage\exception\exception);; + } + else + { + $this->storage->expects($this->any()) + ->method('delete') + ->willReturn($remove_success); + } + $this->storage->expects($this->any()) + ->method('exists') + ->willReturn($exists_success); + $this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage); $this->assertSame($expected, $this->attachment_delete->unlink_attachment('foobar')); } diff --git a/tests/attachment/upload_test.php b/tests/attachment/upload_test.php index 11f862c277..0cb8fcc450 100644 --- a/tests/attachment/upload_test.php +++ b/tests/attachment/upload_test.php @@ -99,7 +99,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case $this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers); $this->plupload = new \phpbb\plupload\plupload($phpbb_root_path, $this->config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), $this->php_ini, $this->mimetype_guesser); - $adapter = new \phpbb\storage\adapter\local($this->filesystem, $phpbb_root_path); + $adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), $phpbb_root_path); $adapter->configure(['path' => 'files']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) diff --git a/tests/content_visibility/delete_post_test.php b/tests/content_visibility/delete_post_test.php index 46c2f05aab..054d5d6877 100644 --- a/tests/content_visibility/delete_post_test.php +++ b/tests/content_visibility/delete_post_test.php @@ -298,7 +298,7 @@ class phpbb_content_visibility_delete_post_test extends phpbb_database_test_case $db = $this->new_dbal(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); - $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), $phpbb_root_path); + $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), $phpbb_root_path); $adapter->configure(['path' => 'files']); $adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory'); $adapter_factory_mock->expects($this->any()) diff --git a/tests/functions_user/delete_user_test.php b/tests/functions_user/delete_user_test.php index 25042d9f1b..3f02bb53a5 100644 --- a/tests/functions_user/delete_user_test.php +++ b/tests/functions_user/delete_user_test.php @@ -34,8 +34,17 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + + $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), $phpbb_root_path); + $adapter->configure(['path' => 'files']); + $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, ''); + // Works as a workaround for tests - $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path)); + $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete($config, $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage)); $phpbb_container->set( 'auth.provider.db', new phpbb_mock_auth_provider() diff --git a/tests/notification/submit_post_base.php b/tests/notification/submit_post_base.php index baa90f29b1..5a25682b73 100644 --- a/tests/notification/submit_post_base.php +++ b/tests/notification/submit_post_base.php @@ -91,6 +91,15 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c // Language $lang = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); + // Storage + $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), $phpbb_root_path); + $adapter->configure(['path' => 'files']); + $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, ''); + // User $user = $this->createMock('\phpbb\user', array(), array( $lang, @@ -125,6 +134,7 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c $phpbb_container->set('cache', $cache); $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils()); $phpbb_container->set('dispatcher', $phpbb_dispatcher); + $phpbb_container->set('storage.attachment', $storage); $phpbb_container->setParameter('core.root_path', $phpbb_root_path); $phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications'); diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index 9d6ba7a917..0c3609207c 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -91,8 +91,17 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); + + $adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), $phpbb_root_path); + $adapter->configure(['path' => 'files']); + $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, ''); + // Works as a workaround for tests - $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path)); + $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage)); phpbb_delete_user_pms($delete_user);