在Fckeditor中加入上传音频视频功能,办法是通过扩展原来的flash上传来实现。过程中出现了乱码问题,现在把调试的过程记录下来。部分内容参考了“玉树临风真情无限”的日志。
软件版本:FckEditor2.6.2;平台:Windows XP;数据库:MySQL。
1. 分别打开editor/js文件夹下的fckeditorcode_ie.js、fckeditorcode_gecko.js文件。将代码:
替换为:
2
3 ||/ /.wmv($ | # | / ? ) / i.test(A.src) ||/ /.avi($ | # | / ? ) / i.test(A.src) ||/ /.mov($ | # | / ? ) / i.test(A.src) ||/ /.mp3($ | # | / ? ) / i.test(A.src)
4
5 ||/ /.rmvb($ | # | / ? ) / i.test(A.src) ||/ /.mid($ | # | / ? ) / i.test(A.src)
6
这段代码用来判断文件后缀名,当然文件格式可以自定义,不过要考虑和其他地方相吻合。
2. 打开/editor/dialog/fck_flash/fck_flash.js文件。
2.1 增加以下程序代码,用来判断文件后缀名:

2
3var r, re;
4
5re = /.(avi|wmv|asf|wma|mid|mp3|mpg)$/i;
6
7r = url.match(re);
8
9return r;
10
11}
12
13 function RealPlayer(url)

14
15var r, re;
16
17re = /.(.rm|.ra|.rmvb|ram)$/i;
18
19r = url.match(re);
20
21return r;
22
23}
24
25 function QuickTime(url)

26
27var r, re;
28
29re = /.(mov|qt)$/i;
30
31r = url.match(re);
32
33return r;
34
35}
36
37 function FlashPlayer(url)

38
39var r, re;
40
41re = /.swf$/i;
42
43r = url.match(re);
44
45return r;
46
47}
48
2.2 替换两个地方的代码:一个在UpdatePreview()中,将:
替换为:

SetAttribute( e, 'type', 'application/x-mplayer2' ) ;
}
if (RealPlayer(GetE('txtUrl').value) != null )

SetAttribute( e, 'type', 'audio/x-pn-realaudio-plugin' ) ;
}
if (QuickTime(GetE('txtUrl').value) != null )

SetAttribute( e, 'type', 'application/video/quicktime' ) ;
}
if (FlashPlayer(GetE('txtUrl').value) != null )

SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ;
}
另一个地方在UpdateEmbed()中,将:
SetAttribute( e, 'pluginspage' , 'http: // www.macromedia.com/go/getflashplayer' ) ;
替换为:

SetAttribute( e, 'type' , 'application/x-mplayer2' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
}
if (RealPlayer(GetE('txtUrl').value) != null )

SetAttribute( e, 'type' , 'audio/x-pn-realaudio-plugin' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
}
if (QuickTime(GetE('txtUrl').value) != null )

SetAttribute( e, 'type' , 'video/quicktime' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
}
if (FlashPlayer(GetE('txtUrl').value) != null )

SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
}
3.打开/fckconfig.js文件,将:
替换为:
到此,基本功能已经完成。剩下的是一些细节的设置。
4. 其他设置
4.1 编辑框中文字的设置:打开/editor/lang/zh-cn.js 文件,将flash替换成想要显示的文字。
4.2 默认的音频视频播放效果是循环、自动播放、带操作menu的样式,可以通过设置来显示成想要的效果。方法还是在/editor/dialog/fck_flash/fck_flash.js文件,在UpdateEmbed()方法中,将对应的文件格式中的,
替换为:
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? ' false ' : ' true ' ) ;