CKEditor 插件 - 插入 PHP,不包括变量
我的 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控制台显示“列表未定义”。
非常感谢您的帮助。
I've got a problem with a CKEditor plugin.
I need PHP code to make use of a MySQL database and several variables the CMS (WebsiteBaker) gives me. The CKEditor plugin should open a new dialog, gives several links defined in the PHP part you can choose of.
In the plugin.js the code
CKEDITOR.dialog.add('wbdropletsdlg', this.path + 'dialogs/wbdroplets.php');
works good - but not on "real" UNIX server, only on XAMPP (Windows7). In the wblink.php there's the PHP part and the necessary JavaScript part for CKEditor.
I tried to change in the plugin.js the code to
CKEDITOR.dialog.add('wbdropletsdlg', this.path + 'dialogs/wbdroplets.js');
put in there the 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
};
} );
In the PHP-file the code
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;
}
But the CKEditor plugin is not opening - Firefox console says "list is not defined".
Thanks very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
scriptLoader 有第二个参数,它是在以下情况下执行的回调函数请求的脚本已加载。如果您在计算机中进行开发,它可能会足够快地返回数据,但在生产环境中,预计会有一些延迟,这就是为什么它在一种情况下有效而在另一种情况下失败的解释。
The scriptLoader has a second parameter that it's the callback function to execute when the requested script has been loaded. If you develop in your computer it might return the data fast enough, but in a production environment it's expected to have some delay so that's the explanation about why it works in one situation and fails in the other.