前天写了半个小时却手快点错键,关闭了浏览器,记录全没了,伤心至极。如今重写,当作增强记忆吧。。。
首先在官网下载最新版的CKEditor和CKFinder放到网站下的同一个目录中,我把它们放在/inc里
1、配置CKEditor:
修改 /inc/ckeditor/config.js 文件内容:
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
config.language = 'zh-cn';
config.uiColor = '#AADC6E';
};
英文水平不是太差基本都能读懂吧,需要解释一下的:
config.extraPlugins='jwplayer'; //获取扩展插件jwplayer,jwplayer是作为一个文件夹名放在plugins文件夹里,它是视频播放器,下文会介绍到
config.toolbar 是菜单栏设置,它是一个二维数组,一维之间是外框分隔,二维里通过 '-' 在菜单中以 | 分隔。
其实自定义菜单,最好是找到预设的full,在其中删除不必要的功能。
2、配置CKFinder:
修改 /inc/ckfinder/config.php 文件内容:
(1)找到并修改 CheckAuthentication() 函数,它是权限验证函数,return true为允许上传,否则禁止
session_start();
function CheckAuthentication(){
}
(2)找到并修改 $baseUrl ,它指定上传文件的目录 (3)修改上传文件名的定义方式 对于上传文件名,ckfinder会按照原有的名字命名,中文的情况下可能会乱码,所以建议使用日期重命名。打开/ckfinder/core/connector/php/php5/CommandHandler/FileUpload.php 找到 修改为时间随机命名方式: $sUnsafeFileName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncod
$sExtension = CKFinder_Connector_Utils_FileSystem::getExtension($sUnsafeFileName);
$sUnsafeFileName=date('YmdHis').'.'.$sExtension;
当然你还可以加上rand()函数加一个随机值,把重名可能减至更小。
3、嵌入网页: require_once ROOTPATH . "inc/ckeditor/ckeditor.php";
require_once ROOTPATH . 'inc/ckfinder/ckfinder.php' ;
$CKEditor = new CKEditor();
$CKEditor->returnOutput = true;
$CKEditor->basePath = '/inc/ckeditor/';
CKFinder::SetupCKEditor($CKEditor, '/inc/ckfinder/') ;//注意这里是相对路径,相对于根目录,不能用绝对路径
$contentarea = $CKEditor->editor("content", $rs['contents']);//content是文件域的name,$rs['contents']是默认值 echo $contentarea; 4、加入“插入视频”功能(视频通过JWplayer播放): (1)下载jwplayer; (2)在ckeditor/plugins文件夹里建立jwplayer文件夹,并把jwplayer的内容放在里边去; (3)在ckeditor/plugins/jwplayer文件夹中建立plugin.js文件,内容参考: CKEDITOR.plugins.add('jwplayer',{requires:['dialog'],init:function(editor){var pluginName='jwplayer';CKEDITOR.dialog.add(pluginName,this.path+'dialogs/jwplayer.js');editor.addCommand(pluginName,new CKEDITOR.dialogCommand(pluginName));editor.ui.addButton('jwplayer',{label:'视频',command:pluginName,icon:this.path+'jwplayer/jwPlayer.gif',});}}); dialogs/jwplayer.js label:'视频' jwplayer/jwPlayer.gif (4)建立并设置详细功能配置文件:ckeditor/plugins/jwplayer/dialogs/jwplayer.js 以下贴上我的jwplayer.js的内容,需要咀嚼领悟: CKEDITOR.dialog.add('jwplayer', function(editor){
var escape = function(value){
return value;
};
return {
title: '插入视频',
resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
minWidth: 350,
contents: [{
id: 'info',
label: '视频宽度',
id: 'mywidth',
'default': '470px',
style: 'width:50px'
label: '视频高度',
id: 'myheight',
'default': '320px',
style: 'width:50px'
label: '自动播放',
id: 'myloop',
required: true,
'default': 'false',
items: [['是', 'true'], ['否', 'false']]
//style: 'width:300px;height:220px',
//label: '预览',
//id: 'code'
}],
onOk: function(){
mywidth = this.getValueOf('info', 'mywidth');
myheight = this.getValueOf('info', 'myheight');
myloop = this.getValueOf('info', 'myloop');
mysrc = this.getValueOf('info', 'src');
html = '' + escape(mysrc) + '';
//editor.insertHtml("<pre class="brush:" + lang + ";">" + html + "</pre>");
editor.insertHtml('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="'+mywidth+'" height="'+myheight+'" id="myjwplayer" ><param name="src" value="/inc/ckeditor/plugins/jwplayer/jwplayer/player.swf" /><param name="flashvars" value="file='+html+'&" /><param name="autostart" value='+myloop+' /><param name="PlayCount" value="1" />' + "<embed height=" + myheight + " width=" + mywidth + " flashvars="file=" + html + "&" allowfullscreen="true" allowscriptaccess="always" bgcolor="#ffffff" src="/inc/ckeditor/plugins/jwplayer/jwplayer/player.swf"></embed></object>");
},
onLoad: function(){
}
};
}); 注意:autostart是以参数的形式放在flashvars属性中传入播放器,外部的其他autostart均不起作用。 参考资料: http://www./php-ckeditor-ckfinder-studynotes.html http://www.360doc.com/content/10/0811/12/12569_45231367.shtml http:///forums/viewtopic.php?t=21290 http://77321660./blog/696269 |
|