允许 fckeditor 2 中的样式属性与 php 集成

发布于 2024-10-05 10:20:46 字数 709 浏览 0 评论 0原文

我还没有找到解决这个问题的实际方法。

在 FCKeditor 2 中,当使用 PHP 集成方法时,传递到编辑器的任何 html 元素都将剥离 css 样式。

因此,这:

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

最终会这样:

<div>hello</div>

我可以确认编辑器在保存时会正确传递样式,但是如果将其加载到编辑器中,它会被删除,因此在第二次保存时会被删除。

唯一的两个解决方案(不幸的是这不是我的解决方案)是使用 Javascript Integration(它不适合我的编码结构)或关闭 Magic Quotes。虽然我想关闭魔术引号,因为不建议依赖它,但我目前没有时间浏览我相当大的代码库以确保这样做不会破坏其他地方的东西。

所以,我想问如何使用启用了魔术引号的 PHP 集成通过 FCKeditor 2 来解决这个问题?我已经从 fckeditor.js 中的 FCKConfig.RemoveAttributes 中删除了“样式”。

请不要提供诸如“升级到 CKeditor”、“使用 javascript 集成”和“关闭魔术引号”之类的解决方案,因为这会违背本文的目的。感谢您的帮助,希望找到解决方案能够帮助许多其他遇到同样问题的人。

大卫

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╰ゝ天使的微笑 2024-10-12 10:20:46

比@Marek的答案更直接 -

在 PHP 端,您可以使用 检测是否启用了魔术引号,而不是关闭魔术引号get_magic_quotes_gpc(),并使用stripslashes() 撤消它们(如果存在)。

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

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);
独留℉清风醉 2024-10-12 10:20:46

您可以在运行时撤消魔术引号,请参阅示例#2:

http:// /www.php.net/manual/en/security.magicquotes.disabling.php

You can undo the magic quotes at runtime, see Example #2:

http://www.php.net/manual/en/security.magicquotes.disabling.php

↘紸啶 2024-10-12 10:20:46
function stripslashes_deep($value) {
    if (is_array($value)) {
        $value = array_map('stripslashes_deep', $value);
    } else {  
         $value = stripslashes($value);
    }
    return $value;
}

if (get_magic_quotes_gpc()) {
    $_POST  = stripslashes_deep($_POST);
    $_GET   = stripslashes_deep($_GET);
    $_COOKIE    = stripslashes_deep($_COOKIE);
    $_REQUEST   = stripslashes_deep($_REQUEST);
}
function stripslashes_deep($value) {
    if (is_array($value)) {
        $value = array_map('stripslashes_deep', $value);
    } else {  
         $value = stripslashes($value);
    }
    return $value;
}

if (get_magic_quotes_gpc()) {
    $_POST  = stripslashes_deep($_POST);
    $_GET   = stripslashes_deep($_GET);
    $_COOKIE    = stripslashes_deep($_COOKIE);
    $_REQUEST   = stripslashes_deep($_REQUEST);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文