在Fckeditor中加入上传音频视频功能,办法是通过扩展原来的flash上传来实现。过程中出现了乱码问题,现在把调试的过程记录下来。部分内容参考了“玉树临风真情无限”的日志。
         软件版本:FckEditor2.6.2;平台:Windows XP;数据库:MySQL。
1.  分别打开editor/js文件夹下的fckeditorcode_ie.js、fckeditorcode_gecko.js文件。将代码:
 ||/\.swf($|#|\?)/i.test(A.src)
||/\.swf($|#|\?)/i.test(A.src) 

替换为:
1 ||/\.swf($|#|\?)/i.test(A.src)||/\.mpg($|#|\?)/i.test(A.src)||/\.asf($|#|\?)/i.test(A.src)||/\.wma($|#|\?)/i.test(A.src)
||/\.swf($|#|\?)/i.test(A.src)||/\.mpg($|#|\?)/i.test(A.src)||/\.asf($|#|\?)/i.test(A.src)||/\.wma($|#|\?)/i.test(A.src)
2
3 ||/\.wmv($|#|\?)/i.test(A.src)||/\.avi($|#|\?)/i.test(A.src)||/\.mov($|#|\?)/i.test(A.src)||/\.mp3($|#|\?)/i.test(A.src)
||/\.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)
||/\.rmvb($|#|\?)/i.test(A.src)||/\.mid($|#|\?)/i.test(A.src)
6
 
        这段代码用来判断文件后缀名,当然文件格式可以自定义,不过要考虑和其他地方相吻合。
2. 打开/editor/dialog/fck_flash/fck_flash.js文件。
2.1 增加以下程序代码,用来判断文件后缀名:
 1
 function WinPlayer(url)
function WinPlayer(url) {
{
 2
 3 var r, re;
var r, re;
 4
 5 re = /.(avi|wmv|asf|wma|mid|mp3|mpg)$/i;
re = /.(avi|wmv|asf|wma|mid|mp3|mpg)$/i;
 6
 7 r = url.match(re);
r = url.match(re);
 8
 9 return r;
return r;
10
11 }
}
12
13
 function RealPlayer(url)
function RealPlayer(url) {
{
14
15 var r, re;
var r, re;
16
17 re = /.(.rm|.ra|.rmvb|ram)$/i;
re = /.(.rm|.ra|.rmvb|ram)$/i;
18
19 r = url.match(re);
r = url.match(re);
20
21 return r;
return r;
22
23 }
}
24
25
 function QuickTime(url)
function QuickTime(url) {
{
26
27 var r, re;
var r, re;
28
29 re = /.(mov|qt)$/i;
re = /.(mov|qt)$/i;
30
31 r = url.match(re);
r = url.match(re);
32
33 return r;
return r;
34
35 }
}
36
37
 function FlashPlayer(url)
function FlashPlayer(url) {
{
38
39 var r, re;
var r, re;
40
41 re = /.swf$/i;
re = /.swf$/i;
42
43 r = url.match(re);
r = url.match(re);
44
45 return r;
return r;
46
47 }
}
48
 
2.2 替换两个地方的代码:一个在UpdatePreview()中,将:
 SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;

替换为:

 if(WinPlayer(GetE('txtUrl').value)!=null)
if(WinPlayer(GetE('txtUrl').value)!=null) {
{ 

 SetAttribute( e, 'type', 'application/x-mplayer2' ) ;
SetAttribute( e, 'type', 'application/x-mplayer2' ) ; 

 }
} 


 if(RealPlayer(GetE('txtUrl').value)!=null)
if(RealPlayer(GetE('txtUrl').value)!=null) {
{ 

 SetAttribute( e, 'type', 'audio/x-pn-realaudio-plugin' ) ;
SetAttribute( e, 'type', 'audio/x-pn-realaudio-plugin' ) ; 

 }
} 


 if(QuickTime(GetE('txtUrl').value)!=null)
if(QuickTime(GetE('txtUrl').value)!=null) {
{ 

 SetAttribute( e, 'type', 'application/video/quicktime' ) ;
SetAttribute( e, 'type', 'application/video/quicktime' ) ; 

 }
} 


 if(FlashPlayer(GetE('txtUrl').value)!=null)
if(FlashPlayer(GetE('txtUrl').value)!=null) {
{ 

 SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ; 

 SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ;
SetAttribute( e, 'pluginspage', 'http://www.macromedia.com/go/getflashplayer' ) ; 

 }
}

另一个地方在UpdateEmbed()中,将:
 SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;

 SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;

替换为:

 if(WinPlayer(GetE('txtUrl').value)!=null)
if(WinPlayer(GetE('txtUrl').value)!=null) {
{

 SetAttribute( e, 'type' , 'application/x-mplayer2' ) ;
SetAttribute( e, 'type' , 'application/x-mplayer2' ) ; 

 SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;

 }
}


 if(RealPlayer(GetE('txtUrl').value)!=null)
if(RealPlayer(GetE('txtUrl').value)!=null) {
{

 SetAttribute( e, 'type' , 'audio/x-pn-realaudio-plugin' ) ;
SetAttribute( e, 'type' , 'audio/x-pn-realaudio-plugin' ) ; 

 SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;

 }
}


 if(QuickTime(GetE('txtUrl').value)!=null)
if(QuickTime(GetE('txtUrl').value)!=null) {
{

 SetAttribute( e, 'type' , 'video/quicktime' ) ;
SetAttribute( e, 'type' , 'video/quicktime' ) ; 

 SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;

 }
}


 if(FlashPlayer(GetE('txtUrl').value)!=null)
if(FlashPlayer(GetE('txtUrl').value)!=null) {
{

 SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;

 SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;

 }
}

3.打开/fckconfig.js文件,将:
 FCKConfig.FlashUploadAllowedExtensions = ".(swf)$" ; // empty for all
FCKConfig.FlashUploadAllowedExtensions = ".(swf)$" ; // empty for all

替换为:
 FCKConfig.FlashUploadAllowedExtensions = ".(swf|fla|mpg|asf|wma|wmv|avi|mov|mp3|rmvb|mid)$" ; // empty for all
FCKConfig.FlashUploadAllowedExtensions = ".(swf|fla|mpg|asf|wma|wmv|avi|mov|mp3|rmvb|mid)$" ; // empty for all

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

 SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'false' : 'true' ) ;
SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'false' : 'true' ) ;posted on 2008-07-16 17:59 
matthew 阅读(5849) 
评论(88)  编辑  收藏