Joomla编辑剥离标签

时间:2013-03-02 15:04:59

标签: joomla joomla2.5

我正在尝试在Joomla 2.5中创建一个自定义组件,并努力让它阻止它从编辑器字段中删除所有html标签 - 链接,新行,p标签 - 全部工作。表格字段如下:

<field
    name="post"
    type="editor"
    label="COM_HELLO_WORLD_EDITOR_LABEL"
    description="COM_HELLO_WORLD_EDITOR_DESC"
    class="inputbox"
    filter="JComponentHelper::filterText"
    required="true"
    default=""
/>

显然,在SO和Joomla论坛上有很多关于此的帖子。然而,它们通常似乎有两个明确的主题。

  1. 微小的MCE设置。我将默认编辑器设置为“无”(即只是文本区域)并且标签仍然被剥离后我已经检查过
  2. Joomla文本过滤器设置。我以全局管理员身份登录,超级用户设置为“无过滤”
  3. 我用以下方法覆盖模型的保存功能:

    function store()
    {
        $row =& $this->getTable();
        $input = new JInput();
        $data = $input->getArray($_POST);
    
        //Sets Users id as current logged in user if not set
        if(!$data['jform']['post_user']) {
            $data['jform']['post_user']=JFactory::getUser()->id;
        }
    
        // Bind the form fields to the post table
        if (!$row->bind($data['jform'])) {
            $this->setError($this->_db->getErrorMsg());
            return false;
        }
    
        // Make sure the hello is valid
        if (!$row->check()) {
            $this->setError($this->_db->getErrorMsg());
            return false;
        }
    
        // Store the hello table to the database
        if (!$row->store()) {
            $this->setError($this->_db->getErrorMsg());
            return false;
        }
        return true;
    }
    

    我的直觉是它与JInput剥离HTML标签有关。但即使将额外的行添加到保存文件$data['jform']['post']=$input->getHTML('post');也没有发生任何事情。所以我不确定从哪里开始。有什么想法吗?


    更新

    只是为了快速澄清问题 - 我想在“全局配置”下使用预设的Joomla'文本过滤器'设置,而不是手动设置组件中的每个标签!


    更新2

    我在编辑器表单字段中添加了filter =“raw”。我现在在转储变量<p>时看到html $_POST['jform']['post'], null, 'HTML')标记。然而,当只应用一个简单的JInput Filter函数时 - 更不用说应用Joomla Config值了 - 我得到了null。

        $input = new JInput();
        $data = $input->getArray($_POST);
        $data['jform']['post']=$input->get($_POST['jform']['post'], null, 'HTML');
    

    句子是here“HTML - 返回一个包含HTML实体和标签的字符串,完全符合过滤器中的白色或黑色列表。”描述引用全局配置文本过滤器设置的JInput HTML过滤器?只是为了确认?

3 个答案:

答案 0 :(得分:1)

尝试这样的事情

$input_options = JFilterInput::getInstance(
        array(
            'img','p','a','u','i','b','strong','span','div','ul','li','ol','h1','h2','h3','h4','h5',
            'table','tr','td','th','tbody','theader','tfooter','br'
        ),
        array(
            'src','width','height','alt','style','href','rel','target','align','valign','border','cellpading',
            'cellspacing','title','id','class'
        )
    );

    $postData = new JInput($_POST,array('filter' => $input_options));

第一个数组是允许标记,第二个数组是允许属性。

答案 1 :(得分:0)

这是什么意思?过滤器= “JComponentHelper :: filterText”?你写过自定义过滤器了吗?

像Joomla中的大多数事情(例如也是acl)的默认过滤是非常严格的,因此如果你从不过滤它得到xss是一个慎重的选择,你在核心中没有带来安全风险。但是应该应用你的核心过滤...除了你似乎已经覆盖了未知的过滤器。所以我怀疑这个未知的过滤器它会回到非常串的状态。

答案 2 :(得分:0)

很久以后,但仅仅是为了记录,对于遇到同样问题的人来说,这是我的解决方案。

对我来说,使用JRequest而不是JInput立即解决了这个问题。我相信它已被弃用,但在JControllerForm的save()函数中仍然被Joomla 2.5.14(此时最新的Joomla 2.5)使用。