doskmc7870 2012-11-02 18:54
浏览 74

使用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');
}
  • 写回答

1条回答 默认 最新

  • dongzhao4036 2013-02-21 01:55
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。