From a1617548cfe650fe1420822f1764d5debe2691be Mon Sep 17 00:00:00 2001
From: KYPREO <58344533+KYPREO@users.noreply.github.com>
Date: Mon, 20 Jan 2020 15:19:56 +1100
Subject: [PATCH] [ticket/16329] Add configuration options for Plupload

PHPBB3-16329
PHPBB3-16330
---
 phpBB/includes/acp/acp_attachments.php        |  2 ++
 phpBB/install/schemas/schema_data.sql         |  2 ++
 phpBB/language/en/acp/attachments.php         |  4 +++
 .../data/v32x/enable_plupload_config.php      | 32 +++++++++++++++++++
 phpBB/phpbb/plupload/plupload.php             | 23 ++++++++++---
 5 files changed, 58 insertions(+), 5 deletions(-)
 create mode 100644 phpBB/phpbb/db/migration/data/v32x/enable_plupload_config.php

diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php
index 94e3660de8..b3a1f9dc73 100644
--- a/phpBB/includes/acp/acp_attachments.php
+++ b/phpBB/includes/acp/acp_attachments.php
@@ -169,6 +169,8 @@ class acp_attachments
 						'img_max_thumb_width'		=> array('lang' => 'MAX_THUMB_WIDTH',		'validate' => 'int:0:999999999999999',	'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
 						'img_min_thumb_filesize'	=> array('lang' => 'MIN_THUMB_FILESIZE',	'validate' => 'int:0:999999999999999',	'type' => 'number:0:999999999999999', 'explain' => true, 'append' => ' ' . $user->lang['BYTES']),
 						'img_max'					=> array('lang' => 'MAX_IMAGE_SIZE',		'validate' => 'int:0:9999',	'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
+						'img_strip_metadata'		=> array('lang' => 'IMAGE_STRIP_METADATA',	'validate' => 'bool',	'type' => 'radio:yes_no', 'explain' => true),
+						'img_quality'				=> array('lang' => 'IMAGE_QUALITY',			'validate' => 'int:1:100',	'type' => 'number:1:100', 'explain' => true, 'append' => '&nbsp;&percnt;'),
 						'img_link'					=> array('lang' => 'IMAGE_LINK_SIZE',		'validate' => 'int:0:9999',	'type' => 'dimension:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
 					)
 				);
diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql
index 86c8f00a24..d301efd556 100644
--- a/phpBB/install/schemas/schema_data.sql
+++ b/phpBB/install/schemas/schema_data.sql
@@ -155,6 +155,8 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_height', '
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_thumb_width', '400');
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_max_width', '0');
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_min_thumb_filesize', '12000');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_quality', '90');
+INSERT INTO phpbb_config (config_name, config_value) VALUES ('img_strip_metadata', '1');
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('ip_check', '3');
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('ip_login_limit_max', '50');
 INSERT INTO phpbb_config (config_name, config_value) VALUES ('ip_login_limit_time', '21600');
diff --git a/phpBB/language/en/acp/attachments.php b/phpBB/language/en/acp/attachments.php
index 86430f46bd..b3e568b277 100644
--- a/phpBB/language/en/acp/attachments.php
+++ b/phpBB/language/en/acp/attachments.php
@@ -111,6 +111,10 @@ $lang = array_merge($lang, array(
 
 	'IMAGE_LINK_SIZE'			=> 'Image link dimensions',
 	'IMAGE_LINK_SIZE_EXPLAIN'	=> 'Display image attachment as an inline text link if image is larger than this. To disable this behaviour, set the values to 0px by 0px.',
+	'IMAGE_QUALITY'				=> 'Quality for image compression',
+	'IMAGE_QUALITY_EXPLAIN'		=> 'Higher value means lower compression/larger file size. Default 90%. Setting is only effective if max image dimensions set to value other than 0px v 0px, but will then apply to all uploaded JPEG images',
+	'IMAGE_STRIP_METADATA'		=> 'Strip image metadata',
+	'IMAGE_STRIP_METADATA_EXPLAIN'	=> 'Strip Exif metadata eg author name, GPS coordinates & camera details (JPEG only). Setting is only effective if max image dimensions set to value other than 0px v 0px.',
 
 	'MAX_ATTACHMENTS'				=> 'Maximum number of attachments per post',
 	'MAX_ATTACHMENTS_PM'			=> 'Maximum number of attachments per private message',
diff --git a/phpBB/phpbb/db/migration/data/v32x/enable_plupload_config.php b/phpBB/phpbb/db/migration/data/v32x/enable_plupload_config.php
new file mode 100644
index 0000000000..a1405e55a0
--- /dev/null
+++ b/phpBB/phpbb/db/migration/data/v32x/enable_plupload_config.php
@@ -0,0 +1,32 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @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\v32x;
+
+class enable_plupload_config extends \phpbb\db\migration\migration
+{
+	static public function depends_on()
+	{
+		return array(
+			'\phpbb\db\migration\data\v32x\v329',
+		);
+	}
+
+	public function update_data()
+	{
+		return array(
+			array('config.add', array('img_quality', '90')),
+			array('config.add', array('img_strip_metadata', '1')),
+		);
+	}
+}
diff --git a/phpBB/phpbb/plupload/plupload.php b/phpBB/phpbb/plupload/plupload.php
index 5a5b8a1874..b3484911a4 100644
--- a/phpBB/phpbb/plupload/plupload.php
+++ b/phpBB/phpbb/plupload/plupload.php
@@ -263,11 +263,24 @@ class plupload
 		$resize = '';
 		if ($this->config['img_max_height'] > 0 && $this->config['img_max_width'] > 0)
 		{
-			$resize = sprintf(
-				'resize: {width: %d, height: %d, quality: 85},',
-				(int) $this->config['img_max_width'],
-				(int) $this->config['img_max_height']
-			);
+			if ($this->config['img_strip_metadata'] == 1)
+			{
+				$resize = sprintf(
+					'resize: {width: %d, height: %d, quality: %d, preserve_headers: false},',
+					(int) $this->config['img_max_width'],
+					(int) $this->config['img_max_height'],
+					(int) $this->config['img_quality']
+				);
+			}
+			else
+			{
+				$resize = sprintf(
+					'resize: {width: %d, height: %d, quality: %d},',
+					(int) $this->config['img_max_width'],
+					(int) $this->config['img_max_height'],
+					(int) $this->config['img_quality']
+				);
+			}
 		}
 
 		return $resize;