21293 Posts in 5733 Topics by 2602 members
| Go to End | Next > | |
| Author | Topic: | 2599 Views |
-
iframes and tinyMCE

4 April 2011 at 2:07pm Last edited: 4 April 2011 2:08pm
Hi,
I've searched up and down all over this site and google and have seen a bunch of people with the same issue but no answer still (or answers that don't work).
When you put in an iframe (like google maps), SS will turn the <iframe></iframe> into a <iframe /> tag and it will break the layout.
I know this is SS doing it because looking back at tinyMCE shows the tags as <iframe></iframe>
I read in another post that a solution is to put a space between the tags, so it becomes <iframe> </iframe>, however, if you do that from the HTML editor in tinyMCE, it will strip out the blank space (and anything else you put between the iframe tags) putting me back in the same situation.
ive tried using these 3 settings in mysite/_config.php file but it doesn't fix it
HtmlEditorConfig::get('cms')->setOption('verify_html', 'false');
HtmlEditorConfig::get('cms')->setOption('element_format', 'html');
HtmlEditorConfig::get('cms')->setOption('cleanup', 'false');I can understand that the editors are trying to be as xhtml compliant as possible but we live in an IE do-your-own-thing dominated world so that's not good enough for now. Is there solution to this?
-
Re: iframes and tinyMCE

7 May 2011 at 10:16pm
You need to do something along the lines of this on the server-side, although I haven't had issues with the space being stripped out on the client side myself. Even if it doesn't strip it client side, doing this server-side is a good idea anyway in case you forget, or it's someone else editing content that doesn't know about it.
function onBeforeWrite() {
$this->Content = str_replace("></iframe>", "> </iframe>", $this->Content);
parent::onBeforeWrite();
} -
Re: iframes and tinyMCE

9 May 2011 at 11:20am
Now that I've actually tried this it doesn't work as expected because the content has already been loaded into the object using domdocument so it's already collapsed the iframe. I've used this regexp instead:
function onBeforeWrite() {
$this->Content = preg_replace('|<iframe(.*)/>|Uims', '<iframe\\1> </iframe>', $this->Content);
parent::onBeforeWrite();
} -
Re: iframes and tinyMCE

25 June 2011 at 8:43pm
Thanks a lot! Silverstripe used to move all html content after an iframe between the opening and closing iframe tags, so everything after an iframe would disappear. Your code fixes that issue.
Cheers!
Anatol -
Re: iframes and tinyMCE

5 July 2011 at 9:36pm
Thanks alot Chris,
This solved my problems of embedding Youtube videos in the editor
-
Re: iframes and tinyMCE

13 July 2011 at 10:57pm
This looks like it will be really helpful. But where do you put the onBeforeWrite() function? in mysite/_config.php?
-
Re: iframes and tinyMCE

13 July 2011 at 11:04pm
Oh, fixed it. I added it to my Page class in mysite/code/Page.php. See bellow:
<?php
class Page extends SiteTree {static $icon = "themes/default/images/icons/page";
public static $db = array(
);public static $has_one = array(
);
public function onBeforeWrite() {
$this->Content = preg_replace('|<iframe(.*)/>|Uims', '<iframe\\1> </iframe>', $this->Content);
parent::onBeforeWrite();
}}
-
Re: iframes and tinyMCE

12 November 2011 at 12:34pm
Any way to keep a class from being stripped as well? I'd like to allow the user to apply Left, LeftAlone, Center classes from the style drop down.
I hope that SS3 fixes these issues. It should be easy to add video to content.
Thanks
| 2599 Views | ||
| Go to Top | Next > |



