繁体   English   中英

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

[英]Inject CSS into Joomla Content Editor (JCE) programmatically using PHP?

我只想在 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');
}

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

绕行你会发现显示功能

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM