Closed 70hundert closed 4 years ago
Hello again!
I guess this is related to the Redactor-extra from modmore.
The way I described to add an image via drag'n'drop worked with Redactor 2, but both ways - the drag'n'drop-way and the FileManager-Upload - do not fire the plugin at all in Redactor 3.
I tested the use of your this extra on a modx-installation without Redactor, there the image upload via the FileManager does fire the plugin.
Even with the MoreGallery-extra from modmore I tried this. I edited the plugins systems-settings and added "MoreGallery_OnImageCreate", but this also does not work.
Do you have any idea how to solve these issues?
Hi @70hundert ,
the Plugin should work on every Upload that triggers the event "OnFileManagerUpload". That is the case using the File-Manager. I just tested it and it works as expected. The error Message tells us, that the Plugin is involved but there seems to be something wrong downloading the optimized image from the Server. So maybe that is just a temporarily problem by imageOptim?
The other Problem is, that moreGallery and may Redactor 3 may not trigger the action "OnFileManagerUpload" - that way the plugin will never be involved. I will try to check this.
Both extras use media sources to upload images; that should be triggering all the events.
It looks like the plugin is looking specifically for an upload name of file
in the files array:
$file = $modx->event->params['files']['file'];
In Redactor the name of upload is upload
, so $file
is going to be empty there.
I'm 99% sure it'll work consistently no matter the name of the upload if you'd change to this:
$modx->event->params['file']
In the media source (modFileMediaSource, line 851), it's already looping over all the files to trigger the event once per uploaded file.
Or even if you remove that line, because the way MODX runs events it will fill the params as "top level" properties. So the event will set a $files
, $file
and $directory
parameter already.
Tho I can't really make sense of that API error, I wouldn't expect it to even know the filename?
Hi @Mark-H,
thanks a lot for your support. I will check this and publish an Update of the extra.
Thank you guys for diving into this issue and trying to sort it out!
@Mark-H i just dived into this a little and checked that the var $files
will return an array. $file
does not exist. That way i receive different arrays:
In moreGallery i get:
(
[upload] => Array
(
[name] => 6_AdobeStock_63473115.jpeg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpyblire
[error] => 0
[size] => 4817368
)
)
And using the Filemanager i get the array:
(
[file] => Array
(
[name] => 6_AdobeStock_63473115.jpeg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpyblire
[error] => 0
[size] => 4817368
)
)
I can check if "file" does not exist and look for "upload". But that feels a bit dirty. Do you have a nice solution? Thanks a lot.
$file = (empty($files['file'])) ? $files['upload'] : $files['file'];
There should definitely be a $file
which just contains the inner array looking at the core code..
If that doesn't work, another way to do it without needing to know if it's called "file" or "upload" or whatever is to use reset()
to get the first element in the outer array:
$file = reset($files);
Or, as in theory there could be multiple files, iterate over the array:
foreach ($files as $file) {
// do your magic
}
(I don't think anything available today actually does multiple files once)
@70hundert i just updated the extra to version 1.0.3 with the help of @Mark-H . The extra should now support all the modmore extras.
I would be happy if you could also test it.
Will give it a try tomorrow, thanks for your great work ;)
Hi Jan!
Thanks again for your work on this - and of course to you too, Mark-H!
I just upgraded the extra and tested it - but with no effect.
I did try the Drag'n'Drop-way inside the content-input plus in the redactor image-modal, clicking in the redactor-image-modal for uploading and choosing my file through the windows-explorer, plus an upload via the Modx-Manager, but none of the ways i tried did resize the image, it has still it's original dimensions = 4001x2250px (sytem-setting: imageoptimonupload.options - "1920") and size 6.616 kb.
I even cleared the cache-folder manually and tried a different browser.
@70hundert that is very strange - because i tested it with CB, Redactor and moreGallery and everything worked as expected. Strange - maybe we can have a look on it together via TeamViewer or would you mind to grant us access?
Please just send us an email to support@quadro-system.de and i will try to fix this.
@70hundert just fixed the issue in the current Version 1.0.4
Hi there!
When I want to add an image (original dimensions = 4001x2250px) in a resource via drag'n'drop into the content-input-field, the extra/plugin is working as expected (sytem-setting: imageoptimonupload.options - "1920"; the image gets uploaded with the correct width of 1920px)
But when I'm using the File Manager Upload, the plugin does not work. The image keeps the original dimensions 4001x2250px.
I'm getting this error message:
I expected the plugin to work by using the file manager. What am I doing wrong?
MODX Version 2.7.2, imageoptimonupload-1.0.2-beta1