From be2afac60d1108408bfae674b1594aa983d6c254 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Jakobus=20Sch=C3=BCrz?= <jakobus.schuerz@schuerz.at>
Date: Mon, 13 Mar 2023 13:47:09 +0100
Subject: [PATCH] take maxFilesize from systemsettings

* does not work everywhere...
---
 mod/photos.php                             | 18 +++++++++++++++---
 src/Content/Conversation.php               |  5 +++++
 src/Module/Item/Compose.php                |  3 +++
 src/Module/Post/Edit.php                   |  5 +++++
 src/Object/Post.php                        |  4 +++-
 view/templates/item/compose.tpl            |  4 +++-
 view/theme/frio/templates/comment_item.tpl |  4 +++-
 view/theme/frio/templates/jot.tpl          |  5 +++--
 8 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/mod/photos.php b/mod/photos.php
index 050a254af3..a8b63d12df 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -1139,7 +1139,11 @@ function photos_content(App $a)
 						'$preview' => DI::l10n()->t('Preview'),
 						'$loading' => DI::l10n()->t('Loading...'),
 						'$qcomment' => $qcomment,
-						'$rand_num' => Crypto::randomDigits(12)
+						'$rand_num' => Crypto::randomDigits(12),
+						// Dropzone
+						//'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
+						// don't know, if DI::config.. does not work here, so it is set to a manual value
+						'$max_imagesize' => 100000,
 					]);
 				}
 			}
@@ -1194,7 +1198,11 @@ function photos_content(App $a)
 						'$submit' => DI::l10n()->t('Submit'),
 						'$preview' => DI::l10n()->t('Preview'),
 						'$qcomment' => $qcomment,
-						'$rand_num' => Crypto::randomDigits(12)
+						'$rand_num' => Crypto::randomDigits(12),
+						// Dropzone
+						//'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
+						// don't know, if DI::config.. does not work here, so it is set to a manual value
+						'$max_imagesize' => 200000
 					]);
 				}
 
@@ -1268,7 +1276,11 @@ function photos_content(App $a)
 							'$submit' => DI::l10n()->t('Submit'),
 							'$preview' => DI::l10n()->t('Preview'),
 							'$qcomment' => $qcomment,
-							'$rand_num' => Crypto::randomDigits(12)
+							'$rand_num' => Crypto::randomDigits(12),
+							// Dropzone
+							//'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
+							// don't know, if DI::config.. does not work here, so it is set to a manual value
+							'$max_imagesize' => 300000
 						]);
 					}
 				}
diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php
index 249190b1ad..586b0bc540 100644
--- a/src/Content/Conversation.php
+++ b/src/Content/Conversation.php
@@ -408,6 +408,11 @@ class Conversation
 
 			'$compose_link_title'  => $this->l10n->t('Open Compose page'),
 			'$always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose', false),
+			// Dropzone
+			//'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
+			// DI::config.. does not work here, so it is set to a manual value
+			'$max_imagesize'       => 600000,
+
 		]);
 
 
diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php
index f53158b1f7..30e2aa9d6b 100644
--- a/src/Module/Item/Compose.php
+++ b/src/Module/Item/Compose.php
@@ -240,6 +240,9 @@ class Compose extends BaseModule
 				'deny_cid'  => $contact_deny_list,
 				'deny_gid'  => $group_deny_list,
 			]),
+
+			// Dropzone
+			'$max_imagesize'    => DI::config()->get('system', 'maximagesize')
 		]);
 	}
 }
diff --git a/src/Module/Post/Edit.php b/src/Module/Post/Edit.php
index 5fb339e179..87a0c1b9c6 100644
--- a/src/Module/Post/Edit.php
+++ b/src/Module/Post/Edit.php
@@ -182,6 +182,11 @@ class Edit extends BaseModule
 			'$shortpermset' => $this->t('Permissions'),
 
 			'$compose_link_title' => $this->t('Open Compose page'),
+			// Dropzone
+			//'$max_imagesize'       => DI::config()->get('system', 'maximagesize'),
+			// DI::config.. does not work here, so it is set to a manual value
+			'$max_imagesize'       => 500000,
+
 		]);
 
 		return $output;
diff --git a/src/Object/Post.php b/src/Object/Post.php
index 17c0c1f68e..59617573e0 100644
--- a/src/Object/Post.php
+++ b/src/Object/Post.php
@@ -1068,7 +1068,9 @@ class Post
 				'$prompttext'  => DI::l10n()->t('Please enter a image/video/audio/webpage URL:'),
 				'$preview'     => DI::l10n()->t('Preview'),
 				'$indent'      => $indent,
-				'$rand_num'    => Crypto::randomDigits(12)
+				'$rand_num'    => Crypto::randomDigits(12),
+				// Dropzone
+				'$max_imagesize' => DI::config()->get('system', 'maximagesize'),
 			]);
 		}
 
diff --git a/view/templates/item/compose.tpl b/view/templates/item/compose.tpl
index 21d89d5c4e..16ba7b477b 100644
--- a/view/templates/item/compose.tpl
+++ b/view/templates/item/compose.tpl
@@ -97,9 +97,11 @@
 </div>
 <script>
 	Dropzone.autoDiscover = false;
+	console.log('compose.tpl', {{$max_imagesize}} / 100000);
+	var maxis = {{$max_imagesize}} / 100000;
 	var dropzoneCompose = new Dropzone( '#comment-edit-form-{{$id}}',  { 
 		paramName: "userfile", // The name that will be used to transfer the file
-		maxFilesize: 6, // MB - change this to use systemsettings
+		maxFilesize: maxis, // MB
 		previewsContainer: '#dz-previewsCompose',
 		preventDuplicates: true,
 		clickable: true,
diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl
index b57bf8a071..cfc44ceb2f 100644
--- a/view/theme/frio/templates/comment_item.tpl
+++ b/view/theme/frio/templates/comment_item.tpl
@@ -67,9 +67,11 @@
 
 <script>
 	Dropzone.autoDiscover = false;
+	console.log('comment_item.tpl', {{$max_imagesize}} / 100000);
+	var maxis = {{$max_imagesize}} / 100000;
 	var dropzone{{$id}} = new Dropzone( '#comment-edit-wrapper-{{$id}}', {
 		paramName: "userfile", // The name that will be used to transfer the file
-		maxFilesize: 6, // MB - change this to use systemsettings
+		maxFilesize: maxis, // MB
 		previewsContainer: '#dz-preview-{{$id}}',
 		preventDuplicates: true,
 		clickable: true,
diff --git a/view/theme/frio/templates/jot.tpl b/view/theme/frio/templates/jot.tpl
index 015d967bea..31db86f7cc 100644
--- a/view/theme/frio/templates/jot.tpl
+++ b/view/theme/frio/templates/jot.tpl
@@ -181,9 +181,11 @@ can load different content into the jot moadl (e.g. the item edit jot)
 </script>
 <script>
 	Dropzone.autoDiscover = false;
+	console.log('jot.tpl', {{$max_imagesize}} / 100000);
+	var maxis = {{$max_imagesize}} / 100000;
 	var dropzoneJot = new Dropzone( '#jot-modal-body', {
 		paramName: "userfile", // The name that will be used to transfer the file
-		maxFilesize: 6, // MB - change this to use systemsettings
+		maxFilesize: maxis, // MB
 		previewsContainer: '#dz-preview-jot',
 		url: "/media/photo/upload?response=url&album=",
 		accept: function(file, done) {
@@ -208,7 +210,6 @@ can load different content into the jot moadl (e.g. the item edit jot)
 		},
 	});
 
-	//  document.onpaste = function(event){
 	$('#jot-modal-body').on('paste', function(event){
 		const items = (event.clipboardData || event.originalEvent.clipboardData).items;
 		items.forEach((item) => {
-- 
2.39.5