Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oembed / CKeditor #302

Open
jawwadkalia opened this issue Sep 21, 2021 · 10 comments
Open

oembed / CKeditor #302

jawwadkalia opened this issue Sep 21, 2021 · 10 comments

Comments

@jawwadkalia
Copy link

Anyone found a way to allow oembed tag that comes with CKeditor media embed option?

@akf
Copy link

akf commented Nov 18, 2021

I'm working through this right now, so I thought I'd share. Here's what's working for me (this is partial; there's a lot in our config that isn't relevant and I haven't actually tested this subset:

        $config = HTMLPurifier_Config::createDefault();
        $config->set('HTML.TidyLevel', 'medium');

        /* You are probably already doing this, or something equivalent: */
	$config->set('HTML.AllowedElements', ['div' => true, 'iframe' => true]);
        $config->set('HTML.AllowedAttributes', [
                    'div.style'  => true,
                    'div.data-oembed-url'    => true,
                    'iframe.src'             => true,
                    'iframe.allowfullscreen' => true,
                    'iframe.tabindex'        => true,
                    'iframe.style'           => true,]);

         /* You also need this. */
         $def = $config->getHTMLDefinition(true);
         $def->addAttribute('div', 'data-oembed-url', 'URI');
         $def->addAttribute('div', 'style', 'Text');

         /* This is for the iframes you get if you pass omit_script=1. */
         $config->set('HTML.SafeIframe', TRUE);
         $config->set('URI.SafeIframeRegexp', '%^(https://cdn.iframe.ly/\S+)%');
         $def->addAttribute('iframe', 'allowfullscreen', 'Bool');
         $def->addAttribute('iframe', 'tabindex', 'Text');                                     
         $def->addAttribute('iframe', 'style', 'Text');

         $purifier = new HTMLPurifier($config);

I'm allowing iframes from cdn.iframe.ly as well as div with data-oembed-url because we've elected to configure our calls to iframely to give us the iframed version of the embed. You may not need that!

@jawwadkalia
Copy link
Author

jawwadkalia commented Nov 18, 2021

I will try this one and see on my side

Thanks

@AdamMiltonBarker
Copy link

Hi is there a solution to this? No matter what configuration I try oembed is always stripped out meaning the embed Youtube feature of CKEditor is useless.

@AdamMiltonBarker
Copy link

@ezyang please could you respond to this?

@ezyang
Copy link
Owner

ezyang commented Feb 15, 2023

oembed sounds like some new attribute, which means you have to teach HTML Purifier about the attribute (or reinsert it out of band, which is how some of the filters work)

@AdamMiltonBarker
Copy link

AdamMiltonBarker commented Feb 15, 2023

oembed sounds like some new attribute, which means you have to teach HTML Purifier about the attribute (or reinsert it out of band, which is how some of the filters work)

How exactly do we solve this issue? It is obvious that everyone that has tried here has been unable to find out how to.

@ezyang
Copy link
Owner

ezyang commented Feb 15, 2023

well, as a start, can someone post what the ckeditor oembed html looks like here

@AdamMiltonBarker
Copy link

well, as a start, can someone post what the ckeditor oembed html looks like here

Yer sure give me 5 minutes I will get it for you.

@AdamMiltonBarker
Copy link

well, as a start, can someone post what the ckeditor oembed html looks like here

<figure class="media"><oembed url="https://www.youtube.com/watch?v=nxLvxo0-NXs&amp;t=9s"></oembed></figure>

@AdamMiltonBarker
Copy link

well, as a start, can someone post what the ckeditor oembed html looks like here

Hi, please do you have an update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants