CKEditor插件 - 插入PHP,不包括变量

时间:2010-04-23 21:04:59

标签: php javascript variables ckeditor

我遇到了CKEditor插件的问题。 我需要PHP代码来使用MySQL数据库和CMS(WebsiteBaker)给我的几个变量。 CKEditor插件应该打开一个新的对话框,给出你可以选择的PHP部分中定义的几个链接。 在plugin.js代码中

CKEDITOR.dialog.add('wbdropletsdlg', this.path + 'dialogs/wbdroplets.php');

运行良好 - 但不适用于“真正的”UNIX服务器,仅适用于XAMPP(Windows7)。在wblink.php中有PHP部分和CKEditor所需的JavaScript部分。

我尝试将plugin.js中的代码更改为

CKEDITOR.dialog.add('wbdropletsdlg', this.path + 'dialogs/wbdroplets.js');

放入JavaScript

CKEDITOR.dialog.add( 'wbdropletsdlg', function( editor ) {
CKEDITOR.scriptLoader.load(this.path + "wbdroplets.php");
return {
    title: editor.lang.wbdroplets.name,
    minWidth: 280,
    minHeight: 80,
    contents: [ 
        {
            id: 'tab1',
            label: 'Tab1',        
            title: 'Tab1',
            elements : [{
                    id: 'wbdroplets',
                    type: 'select',
                    label: "Droplets",
                    labelLayout:'horizontal',
                    widths:['20%','80%'],
                    style: 'width: 150px; margin-left: 10px; margin-top:-3px;',
                    validate : function() { },
                    items: list,
                    onMouseUp: function() { 
                        /** 
                         *    code to display the description of the droplets ... 
                         *
                         */
                        desc_list;
                        var droplet_name = this.getValue();
                        var ref = document.getElementById("droplet_info");
                        ref.innerHTML = info[droplet_name];
                    },
                    onShow: function() { 
                        this.onMouseUp();
                    }
                } , {
                    id: 'droplet_info_box',
                    type: 'html',
                    label: 'Info',
                    labelLayout:'horizontal',
                    widths:['20%','80%'],
                    style:    "display: inline; " +
                            "float: left; " +
                            "margin-left: 0; " +
                            "padding-left: 10px; " +
                            "width: 250px !important; " +
                            "height: 100px;" +
                            "white-space: normal !important;",
                    html: "<div id='droplet_info'>Hello</div>"
                } ] 
        }
        ],
     onOk: function() {

         /**
          *    Getting the value of our droplet-select
          *
          */
         var droplet_name = this.getContentElement("tab1", "wbdroplets").getInputElement().getValue();

         editor = this.getParentEditor();
         editor.fire('paste', { 'text' : droplet_name } );

        return true;
     },

     resizable: 2
};
} );

在PHP文件中的代码

require(WB_PATH.'/framework/class.admin.php');
admin = new admin('Pages', 'pages_modify', false);

global $database;
$get_droplet = $database->query("SELECT * FROM `".TABLE_PREFIX."mod_droplets` where `active`=1 ORDER BY `name`");

$list = "[";
$desc_list = "var info = new Array();";

if($get_droplet->numRows() > 0) {

while($droplet = $get_droplet->fetchRow()) {

    $title  = stripslashes($droplet['name']);
    $desc   = stripslashes($droplet['description']);
    $comm   = stripslashes($droplet['comments']);

    $list .= "\n['".$title."', '[[".$title."]]'],";
    $desc_list .= "info['[[".$title."]]']='".trim($desc)."<br /><br />".trim($comm)."';"; 

}
$list = substr( $list, 0, -1 );
 }
 $list .= "]";
 $desc_list .= "\n";

function script($list)
{
    $out = "<script type=\"text/javascript\">";
    $out .= "//<![CDATA[\n";
    $out .= $list;
    $out .= $desc_list;
    $out .= "\n//]]>";
    $out .= "</script>\n";

    return $out;
}

但是CKEditor插件没有打开 - Firefox控制台说“列表没有定义”。

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

scriptLoader有第二个参数,它是在加载请求的脚本时执行的回调函数。如果您在计算机中进行开发,它可能会足够快地返回数据,但在生产环境中,预计会有一些延迟,因此可以解释为什么它在一种情况下工作而在另一种情况下失败。

相关问题