使用PHP以编程方式将CSS注入Joomla内容编辑器(JCE)?

时间:2012-11-02 18:54:29

标签: php css joomla editor joomla-component

我想在JCE Editor iframe中仅为特定页面嵌入样式表,最好是使用PHP。现在,JCE管理界面允许您在管理控制面板中为每个加载JCE的实例全局设置样式表,并按个人用户配置文件设置样式表。但是,我正在创建自定义组件来加载编辑器以进行显示:

<?php
$editor = JFactory::getEditor();  // JCE set by default
echo $editor->display();

我希望能够根据组件的不同部分加载不同的样式表。据我所知,这不是开箱即用的,所以我想看看是否有一些API方法可以帮助我实现这一点。

类似的东西:

<?php
$editor = JFactory::getEditor();  // JCE set by default

// calculate whether additional styles may be needed...
if (true === $needs_more_stylesheets_bool) {
   // Would be nice to do something like
   $editor->addStylesheet('specific_styles.css');
   // Or
   $editor->addInlineStyle('body{background:green}');
   // Or
   $editor->removeStylesheet('general_styles.css'); 

   // Or... with adding/editing user profiles... 
   $editor->loadUserProfile('user_2_with_different_stylesheets');
}

1 个答案:

答案 0 :(得分:0)

我将建议您如何添加一些内联样式,您可以继续使用相同的方法 编辑器类位于root / libraries / joomla / html / editor.php

在线附近你会找到显示功能

public function display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array())
    {
        ...
        ...
$width = str_replace(';', '', $width);
        $height = str_replace(';', '', $height);

        // Initialise variables.
        $return = null;

        $args['name'] = $name;
        $args['content'] = $html;
        $args['width'] = $width;
        $args['height'] = $height;
        $args['col'] = $col;
        $args['row'] = $row;
        $args['buttons'] = $buttons;
        $args['id'] = $id ? $id : $name;
        $args['event'] = 'onDisplay';
                ...
}

我会尝试传递我的内联样式

public function display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array(),$inlinestyles){
...
$args['inlinestyles'] = $inlinestyles;
...
}

现在我们必须编辑位于root / plugins / editors / jce / jce.php中的jce.php文件

正如您在paramaters事件中所见,我们将更改onDisplay事件

第108行

public function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null) {
... 
return $editor;
    }

现在我们将更改此函数并使用JDocument来解析我们的样式

public function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null,$inlines) {
//blah blah some code
//here comes the fun part
if($inlines){
$document =& JFactory::getDocument();
$document->addStyleDeclaration($inlines);
}

} //end of ondisplay

现在在您的组件中,您必须调用您的编辑器,因为它在Joomla的文档中有记录

$inlines= 'BODY {'
        . 'background: #00ff00;'
        . 'color: rgb(0,0,255);'
        . '}'; 
$editor = JFactory::getEditor();
echo $editor->display("jobdesc", ""/*$itemData['body']*/, "400", "100", "150", "10", 1, null, null, null, array('mode' => 'advanced'),$inlines);

http://docs.joomla.org/JFactory/getEditor