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

I want to embed stylesheets in JCE Editor iframe only for specific pages, preferably using PHP. Right now, JCE admin interface allows you to set stylesheets globally and by individual user profile for every instance where JCE is loaded in the admin control panel. However, I am creating custom components that load the editor for display like so:

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

I want to be able to load different stylesheets based on different sections of my components. As far as I know, this doesn't exist out of the box, so I'd like to see if there's some API method that could help me achieve this.

Something like:

<?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');
}

I will suggest how you can add some inline styles, you can move on using the same method Editor class is located in root/libraries/joomla/html/editor.php

Around line you will find display function

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';
                ...
}

I will try to pass my inline styles

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

Now we have to edit our jce.php file located in root/plugins/editors/jce/jce.php

As you can see in the paramaters event we will change onDisplay event

Around line 108

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

Now we will change this function and use JDocument to parse our styles

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

Now in your component, you have to call your editor as it is documented in Joomla's docs

$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