1.淇敼fckeditor_controller.rb錛屾妸瀹冮偅鍑犱釜private鏂規硶淇敼濡備笅錛?br />聽聽
聽聽private
聽聽def聽current_directory_path
聽聽聽聽base_dir聽=聽"#{RAILS_ROOT}/public"
聽聽聽聽#TODO聽鍦ㄥ垱寤虹敤鎴鋒椂錛屽氨寤虹珛濂界洰褰曘傝繖鏃跺彲浠ュ幓鎺夎繖閮ㄤ喚浠g爜錛屾彁楂樿繍琛屾晥鐜囥?br />聽聽聽聽("#{params[:uploaded]||UPLOADED}/#{params[:Type]}").split('/').each聽do聽|s|
聽聽聽聽next聽if聽s==''
聽聽聽聽聽聽聽聽base_dir聽+=聽'/'聽+聽s
聽聽聽聽聽聽聽聽Dir.mkdir(base_dir,0775)聽unless聽File.exists?(base_dir)
聽聽聽聽end
聽聽聽聽
聽聽聽聽check_path("#{base_dir}#{params[:CurrentFolder]}")
聽聽end
聽聽
聽聽def聽upload_directory_path
聽聽聽聽uploaded聽=聽@request.relative_url_root.to_s+"#{params[:uploaded]||UPLOADED}/#{params[:Type]}"
聽聽聽聽"#{uploaded}#{params[:CurrentFolder]}"
聽聽end
聽聽
聽聽def聽check_file(file)
聽聽聽聽#聽check聽that聽the聽file聽is聽a聽tempfile聽object
聽聽聽聽unless聽"#{file.class}"聽==聽"Tempfile"聽||聽"#{file.class}"聽==聽"StringIO"
聽聽聽聽聽聽@errorNumber聽=聽403
聽聽聽聽聽聽throw聽Exception.new
聽聽聽聽end
聽聽聽聽file
聽聽end
聽聽
聽聽def聽check_path(path)
聽聽聽聽exp_path聽=聽File.expand_path聽path
聽聽聽聽if聽exp_path聽!~聽%r[^#{File.expand_path(RAILS_ROOT)}/public#{params[:uploaded]||UPLOADED}]
聽聽聽聽聽聽@errorNumber聽=聽403
聽聽聽聽聽聽throw聽Exception.new
聽聽聽聽end
聽聽聽聽path
聽聽end
鍙﹀錛屽畠鍓嶉潰鐨勫父閲廢PLOADED_ROOT涔熸病鐢ㄤ簡錛屽彲浠ュ垹鎺夈?br />
2. 鍦ㄤ笂闈㈢殑浠g爜涓?span style="color: rgb(0, 0, 0);">params[:uploaded]鏄叧閿紝瀹冨氨鏄垜浠姩鎬佸畾涔夌殑涓婁紶鐩綍銆傝鍊兼潵鑷簬FCKEditor鐨勪竴浜沨tml欏甸潰錛屽畠鏄氳繃get鍙傛暟浼犲叆鐨勩備慨鏀筨rowser.html鏂囦歡錛堝涓嬬矖浣撻儴浠斤級錛屽湪瀹冪殑url璇鋒眰涓妸鎴戜滑瀹氫箟鐩綍鍔犲叆鍒癵et鍙傛暟鍒椾腑錛岃繖鏍峰畠灝卞彲浠ヤ紶鍒?/span>fckeditor_controller.rb閲屼簡銆?br />
var聽sServerPath聽=聽GetUrlParam(聽'ServerPath'聽)聽;
if聽(聽sServerPath.length聽>聽0聽)
聽聽聽聽oConnector.ConnectorUrl聽+=聽'ServerPath='聽+聽escape(聽sServerPath聽)聽+聽'&'聽;
var聽sUploaded聽=聽GetUrlParam(聽'uploaded'聽)聽;
if聽(聽sUploaded.length聽>聽0聽)
聽聽聽聽oConnector.ConnectorUrl聽+=聽'uploaded='聽+聽escape(聽sUploaded聽)聽+聽'&'聽;
oConnector.ResourceType聽聽聽聽聽聽聽聽=聽GetUrlParam(聽'Type'聽)聽;
oConnector.ShowAllTypes聽聽聽聽聽聽聽聽=聽(聽oConnector.ResourceType.length聽==聽0聽)聽;
3.聽 涓婇潰鐨凣etUrlParam(聽'uploaded'聽) 鐨勫兼潵鑷簬fckcustom.js銆備慨鏀筬ckcustom.js錛堝涓嬬矖浣撻儴浠斤級錛屾妸uploaded鍔犲叆鍒癵et鍙傛暟鍒椾腑銆?br />
//聽CHANGE聽FOR聽APPS聽HOSTED聽IN聽SUBDIRECTORY
FCKRelativePath聽=聽'';
//聽DON'T聽CHANGE聽THESE
FCKConfig.LinkBrowserURL聽=聽FCKConfig.BasePath聽+聽'filemanager/browser/default/browser.html?Connector='+FCKRelativePath+'/fckeditor/command';
FCKConfig.ImageBrowserURL聽=聽FCKConfig.BasePath聽+聽'filemanager/browser/default/browser.html?uploaded='+FCKConfig.uploaded+'&Type=Image&Connector='+FCKRelativePath+'/fckeditor/command';
FCKConfig.FlashBrowserURL聽=聽FCKConfig.BasePath聽+聽'filemanager/browser/default/browser.html?uploaded='+FCKConfig.uploaded+'&Type=Flash&Connector='+FCKRelativePath+'/fckeditor/command';
FCKConfig.LinkUploadURL聽=聽FCKRelativePath+'/fckeditor/upload';
FCKConfig.ImageUploadURL聽=聽FCKRelativePath+'/fckeditor/upload?Type=Image&uploaded='+FCKConfig.uploaded;
FCKConfig.FlashUploadURL聽=聽FCKRelativePath+'/fckeditor/upload?Type=Flash&uploaded='+FCKConfig.uploaded;
FCKConfig.AllowQueryStringDebug聽=聽false;
FCKConfig.SpellChecker聽=聽'SpellerPages';
//聽ONLY聽CHANGE聽BELOW聽HERE
FCKConfig.SkinPath聽=聽FCKConfig.BasePath聽+聽'skins/silver/';
FCKConfig.AutoDetectLanguage聽=聽false聽;
FCKConfig.DefaultLanguage聽=聽'zh-cn'聽;
FCKConfig.FontNames聽=聽'寰蔣闆呴粦;瀹嬩綋;榛戜綋;闅朵功;妤蜂綋_GB2312;Arial;Comic聽Sans聽MS;Courier聽New;Tahoma;Times聽New聽Roman;Verdana'聽;
FCKConfig.ToolbarSets["Simple"]聽=聽[
聽聽聽聽['Source','-','FitWindow','Preview','-','Templates'],
聽聽聽聽['PasteText','PasteWord'],
聽聽聽聽['Undo','Redo','Find','Replace'],
聽聽聽聽'/',
聽聽聽聽['RemoveFormat','Bold','Italic','Underline','StrikeThrough'],
聽聽聽聽['OrderedList','UnorderedList','Outdent','Indent'],
聽聽聽聽['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
聽聽聽聽聽聽聽聽['TextColor','BGColor'],
聽聽聽聽['Link','Unlink','Anchor'],
聽聽聽聽['Image','Flash','Table','Rule','Smiley'],
聽聽聽聽'/',
聽聽聽聽['Style','FontFormat','FontName','FontSize']
]聽;
4. 涓婇潰FCKConfig.uploaded鐨勫兼潵鑷簬fckeditor.rb銆傚湪fckeditor.rb涓姞鍏ヤ竴鍙ワ紙濡備笅綺椾綋鎵紺猴級銆?br />聽聽聽聽聽聽javascript_tag(聽"var聽oFCKeditor聽=聽new聽FCKeditor('#{id}',聽'#{width}',聽'#{height}',聽'#{toolbarSet}');\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"oFCKeditor.BasePath聽=聽\"#{base_path}\"\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"oFCKeditor.Config['CustomConfigurationsPath']聽=聽'../../fckcustom.js';\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"oFCKeditor.Config['uploaded']聽=聽'#{options[:path]}';\n"+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽"oFCKeditor.ReplaceTextarea();\n")聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
5.涓嶈繃涓婇潰oFCKeditor.Config['uploaded']鐨勫艱浼犲埌fckcustom.js鐨凢CKConfig.uploaded閲岋紝榪橀渶瑕佷慨鏀筬ckeditorcode_gecko.js鍜宖ckeditorcode_ie.js錛堣繖涓や釜鏂囦歡瀵筳avascript榪涜浜嗗帇緙╁鐞嗭紝淇敼璧鋒潵杈冮毦鎿嶄綔錛夈傛垜鏄弬鑰冧簡oFCKeditor.Config['CustomConfigurationsPath'] 榪欎釜鍙傛暟鐨勮澆鍏ュ疄鐜幫紝鎵嶆壘鍒拌繖縐嶉笩涓嶇敓铔嬬殑鍦版柟銆傛悳绱㈣繖涓や釜鏂囦歡鐨勫叧閿瓧CustomConfigurationsPath錛屾壘鍒板涓嬩竴琛岋紝鐒跺悗鍔犲叆涓涓猠lse if鍒ゆ柇(濡備笅綺椾綋鎵紺猴級銆?br />if聽(D=='CustomConfigurationsPath')聽FCKConfig[D]=E;else聽if聽(D=='uploaded')聽FCKConfig[D]=E;else聽if聽(E.toLowerCase()=="true")聽this.PageConfig[D]=true;
6.鏈鍚庡湪fckeditor.rb閲岀殑#{options[:path]}鏉ヨ嚜浜庢垜浠墠鍙扮殑view浜嗐傚涓嬬矖浣撴墍紺猴紝鎶婃爣鍑嗙殑fckeditor_textarea鏂板鍔犱簡涓涓弬鏁幫紝鍏朵腑params[:user_id]鏄妸鐢ㄦ埛鐨処D鍊煎仛涓?/span>鐩綍鍚嶃傝繖鏍峰氨瀹炵幇浜嗗姩鎬佹敼鍙楩CKEditor鐨勪笂浼犵洰褰曘?/span>
<%=fckeditor_textarea(:topic,聽:content,聽:ajax聽=>聽true,聽:toolbarSet聽=>聽'Simple',聽:height聽=>聽'400px',聽 :path聽=>聽"/uploads/#{params[:user_id]}")聽%>
淇敼瀹屽悗闇瑕侀噸鍚疻EB鏈嶅姟錛屾渶鍚庡埆蹇樿鎶妏ublic/javascripts/fckeditor鍜寁endor/plugins/fckeditor/public/javascripts鍚屾涓涓嬶紝鍘熷洜瑙乭ttp://www.tkk7.com/chengang/archive/2007/09/24/147867.html

]]>