Search code examples
phpjavascriptcoding-stylewysiwygfckeditor

allowing style attribute in fckeditor 2 with php integration


I am yet to find an actual solution to this problem.

In FCKeditor 2, when using PHP integration method, any html element that is passed to the editor will have the css styling stripped form it.

Therefore this:

<div style="color:#000;background:blue">hello</div>

will end up as this:

<div>hello</div>

I can confirm that the editor will pass the styling correctly upon saving it, but if you load it into the editor, it is stripped out and thus on 2nd save, is removed.

The only 2 solutions, which unfortunately aren't solutions for me, are to either use Javascript Integration, which doesn't work with my coding structure or to turn off Magic Quotes. While I would like to turn off magic quotes as its not recommended to rely on it, I don't have the time at the moment to go through my rather large code base to ensure that doing this won't break something somewhere else.

So, I am asking how this can be resolved with FCKeditor 2 using PHP integration with magic quotes enabled? I have already removed 'style' from FCKConfig.RemoveAttributes in fckeditor.js

Please don't offer solutions like "upgrade to CKeditor", "use javascript integration" and "turn off magic quotes" as that would defeat the purpose of this post. Thank you for any help and hopefully it finding a solution will help many others with the same problem.

David


Solution

  • To be more direct than @Marek's answer -

    Instead of turning off magic quotes, on the PHP side you can detect if magic quotes are enabled using get_magic_quotes_gpc(), and use stripslashes() to undo them if they are.

    $html = $_POST['html']; // as an example
    if (get_magic_quotes_gpc()) $html = stripslashes($html);