From 16d5208d9aec0678b3295b0e14042991094197ba Mon Sep 17 00:00:00 2001
From: Marc Alexander <admin@m-a-styles.de>
Date: Sun, 20 Sep 2015 12:36:52 +0200
Subject: [PATCH] [ticket/14168] Use attachment upload class in message_parser

PHPBB3-14168
---
 phpBB/includes/message_parser.php | 27 +++++++--------------------
 phpBB/posting.php                 |  1 -
 2 files changed, 7 insertions(+), 21 deletions(-)

diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php
index 31fc1577a2..e0a0d69fba 100644
--- a/phpBB/includes/message_parser.php
+++ b/phpBB/includes/message_parser.php
@@ -1140,12 +1140,6 @@ class parse_message extends bbcode_firstpass
 	*/
 	protected $plupload;
 
-	/**
-	* The mimetype guesser object used for attachment mimetypes
-	* @var \phpbb\mimetype\guesser
-	*/
-	protected $mimetype_guesser;
-
 	/**
 	* Init - give message here or manually
 	*/
@@ -1541,6 +1535,7 @@ class parse_message extends bbcode_firstpass
 	function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false)
 	{
 		global $config, $auth, $user, $phpbb_root_path, $phpEx, $db, $request;
+		global $phpbb_container;
 
 		$error = array();
 
@@ -1576,7 +1571,9 @@ class parse_message extends bbcode_firstpass
 		{
 			if ($num_attachments < $cfg['max_attachments'] || $auth->acl_get('a_') || $auth->acl_get('m_', $forum_id))
 			{
-				$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
+				/** @var \phpbb\attachment\upload $attachment_upload */
+				$attachment_upload = $phpbb_container->get('attachment.upload');
+				$filedata = $attachment_upload->upload($form_name, $forum_id, false, '', $is_message);
 				$error = $filedata['error'];
 
 				if ($filedata['post_attach'] && !sizeof($error))
@@ -1692,7 +1689,9 @@ class parse_message extends bbcode_firstpass
 			{
 				if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id))
 				{
-					$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->mimetype_guesser, $this->plupload);
+					/** @var \phpbb\attachment\upload $attachment_upload */
+					$attachment_upload = $phpbb_container->get('attachment.upload');
+					$filedata = $attachment_upload->upload($form_name, $forum_id, false, '', $is_message);;
 					$error = array_merge($error, $filedata['error']);
 
 					if (!sizeof($error))
@@ -1980,18 +1979,6 @@ class parse_message extends bbcode_firstpass
 		$this->plupload = $plupload;
 	}
 
-	/**
-	* Setter function for passing the mimetype_guesser object
-	*
-	* @param \phpbb\mimetype\guesser $mimetype_guesser The mimetype_guesser object
-	*
-	* @return null
-	*/
-	public function set_mimetype_guesser(\phpbb\mimetype\guesser $mimetype_guesser)
-	{
-		$this->mimetype_guesser = $mimetype_guesser;
-	}
-
 	/**
 	* Function to perform custom bbcode validation by extensions
 	* can be used in bbcode_init() to assign regexp replacement
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 47fdb2d378..05a078ea39 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -571,7 +571,6 @@ $plupload = $phpbb_container->get('plupload');
 /* @var $mimetype_guesser \phpbb\mimetype\guesser */
 $mimetype_guesser = $phpbb_container->get('mimetype.guesser');
 $message_parser->set_plupload($plupload);
-$message_parser->set_mimetype_guesser($mimetype_guesser);
 
 if (isset($post_data['post_text']))
 {