HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
FileUpload "Insert Image" causing http/https problems
When you upload an image and click "Insert Image" it inserts
<img src="http://www.example.tld/uploads/FileUpload/..." />
or
<img src="https://www.example.tld/uploads/FileUpload/..." />
(depending if you are accessing the forum by http or https) into the text box, however it's better to have it insert only
<img src="/uploads/FileUpload/..." />
not not have is cause any issues afterwards when accessing the site either by http or https.
I thought there is an easy fix, I tracked it down to line 507+ of plugins/FileUpload/js/fileupload.js
:
// Add "insert image" button if (JResponse.MediaResponse.FinalImageLocation != '') { var ImageAnchor = jQuery(FileListing.find('a.InsertImage')); ImageAnchor.attr('href', JResponse.MediaResponse.FinalImageLocation); ImageAnchor.show(); ImageAnchor.live('click', function() { var insertimg = '<img src="'+ImageAnchor.attr('href')+'" />'; // Test if we're working with CLEditor var wysiwyg = jQuery(FileListing.parents('form').find('iframe')); if (wysiwyg) { // Insert into WYSIWYG iframe var editorbox = wysiwyg.contents().find('body'); editorbox.html(function(index, oldhtml) { return oldhtml+insertimg }); } else { // Normal textarea (no WYSIWYG) var txtbox = jQuery(FileListing.parents('form').find('textarea')); txtbox.val(txtbox.val()+insertimg); } return false; }); }
but me not knowing JavaScript couldn't solve that problem.
Anyone any idea for a quick patch?
0
Comments
Is this on 2.0.18 or 2.1b1?
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Sorry, I always forget to mention, it's on 2.1b1.
I don't mean to hassle you about it. I usually forget and like to see the number when I come back to threads.
It seems it adds the webroot by default, because this site is set up to use a CDN. I would straight up just truncate it in js.
I couldn't test it, but it should work.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@hgtonight
I always enjoy these words . but its a good practice to provide the caveat.
I didn't test your solution - but I like it (who can argue with split.slice, join). .
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@hgtonight
It's almost working, only the leading slash is missing:
<img src="uploads/FileUpload/..." />
I have played around and tried to insert the slash in the
var insertimg
line, but that didn't work for some reason:What's the proper way of inserting the slash in front of
truncatedLocation
?Just concatenate it.
var truncatedLocation = '/' + JResponse.MediaResponse.FinalImageLocation.split('/').slice(3).join('/');
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
@hgtonight
It's working!