Notifications
Clear all

wpForo 1.x.x [Closed] How to let user embed images while pasting them?

9 Posts
3 Users
3 Reactions
1,085 Views
Posts: 12
Topic starter
(@crescendo)
Eminent Member
Joined: 2 years ago

The title might not be clear, so let me quickly explain again.

 

What I need:

#1. An [upload image from local files] button

#2. When users copy a paragraph from another site (with text + images) and paste that into my wpForo forum, they should see the images are pasted correctly as well. By "correctly" I mean the user should be able to see the images while editing their post and move the images around, and of couse those images should display correctly after the post is posted.

 

After some quick search, it seems like #1 can be solved easily using the Advanced Attatchment or wpDiscuz plugin (I haven't tried either of those though). But is there a solution or workaround for #2? The closest I know is the Advanced Attatchment plugin as it allows users to insert the image correctly if the clipboard contains a single image only. But it won't work if I copy a paragraph [text + image + text]; the image for some reason is lost.

Topic Tags
8 Replies
dimalifragis
Posts: 2615
(@dimalifragis)
Famed Member
Joined: 4 years ago

I can help you with #1. Using the following script (posted somewhere in the forum by the admins) will auto make your image attachments appear in the body (embed). This snipet should be in your functions of your theme or use some snipet plugin for Wordpress.

 

add_filter('wpforo_content_after', function( $content ){
	return preg_replace_callback(
        '#<a[^><]*\sclass=[\'\"](?\s[^\'\"]*)?[\'\"][^><]*\shref=[\'\"]([^\"\']+)[\'\"][^><]*>.*?</a>#isu',
        function( $match ){
                $html     = $match[0];
	        $file     = $match[1];
	        $pathinfo = pathinfo( $file );
	        if( wpforo_is_image($pathinfo['extension']) ) {
                $html = sprintf(
                    '<a href="%1$s" target="_blank"><img class="wpforo-default-image-attachment" src="%1$s" alt="%2$s" title="%2$s"></a>',
	                esc_url($file),
	                esc_attr($pathinfo['basename'])
                );
	        }
            return $html;
        },
        $content
    );
}, 11);
1 Reply
(@crescendo)
Joined: 2 years ago

Eminent Member
Posts: 12

@dimalifragis Thank you for your help. I'll test it out.

Chris
Posts: 3649
(@chris)
Famed Member
Joined: 3 years ago

Hi @crescendo,

I have Created a Test topic in your website and added a post with text image text: https://forum.crescb.com/ize-composition/test-topic-by-wpforo-support-team/  

How you see, there are no issues in the First Post, however in the second Post you can see the same image 3 times with different sizes.

The First post content and second post content are copied from different websites, and the reason why the second post shows the same image 3 time with different sizes is the image HTML.

We cannot do anything in this case, this is not related to wpForo it's related to HTML used for that Image.

2 Replies
(@crescendo)
Joined: 2 years ago

Eminent Member
Posts: 12

@chris Thank you for your help. Could you perhpas provide the original url for both paragraphs? Just curious what's the difference in HTML that's causing this issue.

(@crescendo)
Joined: 2 years ago

Eminent Member
Posts: 12

@chris After some testing on other forum sites (non-wordpress ones), I noticed when I copy an image from outside that site, the image is automatically uploaded to the site's server and is displayed with that image source. Correct me if I'm wrong, but is this the reason why copying & pasting may not work for a wpForo forum?

Chris
Posts: 3649
(@chris)
Famed Member
Joined: 3 years ago

@crescendo,

Working HTML: https://cupofjo.com/2022/01/an-a-frame-cabin-in-minnesota-with-gorgeous-lake-views/

Not Working HTML: https://garconjon.com/mr-marcus-leatherdale-artist/

 

Posted by: @crescendo

After some testing on other forum sites (non-wordpress ones), I noticed when I copy an image from outside that site, the image is automatically uploaded to the site's server and is displayed with that image source. Correct me if I'm wrong, but is this the reason why copying & pasting may not work for a wpForo forum?

I Don't Follow you.

2 Replies
(@crescendo)
Joined: 2 years ago

Eminent Member
Posts: 12

@chris Thank you for providing the links; I'll look into them.

So what I meant was: for example at the site tieba.baidu.com (a Chinese forum), when you copy an image, paste there, and publish as a post at that forum, the image is uploaded to their server. When I right-click an image in a post, the url is at their forum's domain, meaning this image is retrieved from that forum's own server, as opposed to the original source. Just to be clear, I've checked some other forums and they all work this way; this is not a very special case. For those forums, there are no issues with HTML format or whatsoever; copying & pasting is all I need to do.

By the same means, I checked the first picture you posted in the test post, and its url still starts with "cupofjo.com/", meaning the image is only being referred, but not copied and uploaded to somewhere else. So I was wondering if this was the reason for the difference.

Chris
(@chris)
Joined: 3 years ago

Famed Member
Posts: 3649

@crescendo,

The reason is that thous forums have filters which clean the HTML attributes, and have feature to save external URL images in their server.