使用PHP以编程方式将CSS注入Joomla Content Editor(JCE)吗?

问题描述 投票:3回答:1

我只想将样式表嵌入JCE编辑器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');
}
php css joomla editor joomla-component
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.