2012-11-02 50 views
3

我想嵌入JCE編輯器IFRAME樣式表僅適用於特定頁面,最好使用PHP。現在,JCE管理界面允許您爲管理控制面板中加載JCE的每個實例設置全局樣式表和個人用戶配置文件。不過,我創建加載編輯器顯示,像這樣的自定義組件:使用PHP以編程方式將CSS注入Joomla內容編輯器(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'); 
} 
+0

記錄你能否提供更多細節說明問題? –

+0

此外,糾正我,如果我錯了,但它似乎是JCE不採取任何使用'$ params'變量。 –

+0

已更新的問題。我不確定$ params數組接受什麼,或者即使JCE可能會使用它們。 – danronmoon

回答

0

我會建議你怎麼可以添加一些內嵌樣式,你可以用同樣的方法 編輯類移動位於根/庫/的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; 
... 
} 

現在我們要修改我們的jce.php文件位於根/插件/編輯/ JCE/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