【问题标题】:allowing style attribute in fckeditor 2 with php integration允许 fckeditor 2 中的样式属性与 php 集成
【发布时间】:2010-12-03 11:00:31
【问题描述】:

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

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

因此:

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

最终会变成这样:

<div>hello</div>

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

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

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

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

大卫

【问题讨论】:

    标签: php javascript coding-style wysiwyg fckeditor


    【解决方案1】:

    比@Marek 的回答更直接-

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:
        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);
        }
        

        【讨论】:

        • 看到这些解决方案而不是ini_set('magic_quotes_gpc', 0); 来禁用魔术引号标志,以防其他库也检测到它并再次删除输入,这总是让我感到困扰。
        猜你喜欢
        • 2016-12-27
        • 2014-11-08
        • 1970-01-01
        • 2017-07-09
        • 2011-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多