在Fckeditor中加入上傳音頻視頻功能,辦法是通過擴展原來的flash上傳來實現。過程中出現了亂碼問題,現在把調試的過程記錄下來。部分內容參考了“玉樹臨風真情無限”的日志。
軟件版本:FckEditor2.6.2;平臺:Windows XP;數據庫:MySQL。
1. 分別打開editor/js文件夾下的fckeditorcode_ie.js、fckeditorcode_gecko.js文件。將代碼:
||/\.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)
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 增加以下程序代碼,用來判斷文件后綴名:
1
function WinPlayer(url)
{
2
3
var r, re;
4
5
re = /.(avi|wmv|asf|wma|mid|mp3|mpg)$/i;
6
7
r = url.match(re);
8
9
return r;
10
11
}
12
13
function RealPlayer(url)
{
14
15
var r, re;
16
17
re = /.(.rm|.ra|.rmvb|ram)$/i;
18
19
r = url.match(re);
20
21
return r;
22
23
}
24
25
function QuickTime(url)
{
26
27
var r, re;
28
29
re = /.(mov|qt)$/i;
30
31
r = url.match(re);
32
33
return r;
34
35
}
36
37
function FlashPlayer(url)
{
38
39
var r, re;
40
41
re = /.swf$/i;
42
43
r = url.match(re);
44
45
return r;
46
47
}
48
2.2 替換兩個地方的代碼:一個在UpdatePreview()中,將:
SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;

替換為:

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

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, 'type' , 'application/x-shockwave-flash' ) ;

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

替換為:

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

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文件,將:
FCKConfig.FlashUploadAllowedExtensions = ".(swf)$" ; // empty for all

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

到此,基本功能已經完成。剩下的是一些細節(jié)的設置。
4. 其他設置
4.1 編輯框中文字的設置:打開/editor/lang/zh-cn.js 文件,將flash替換成想要顯示的文字。
4.2 默認的音頻視頻播放效果是循環(huán)、自動播放、帶操作menu的樣式,可以通過設置來顯示成想要的效果。方法還是在/editor/dialog/fck_flash/fck_flash.js文件,在UpdateEmbed()方法中,將對應的文件格式中的,
SetAttribute( e, 'play', GetE('chkAutoPlay').checked ? 'true' : 'false' )
替換為:

SetAttribute( e, 'autostart', GetE('chkAutoPlay').checked ? 'false' : 'true' ) ;
posted on 2008-07-16 17:59
matthew 閱讀(5805)
評論(88) 編輯 收藏