My hook for Wordpress plugin FCKEditor
搬家到wordpress后,流量大跌。呵呵。
不过也好,可以自由控制程序体本身了。
今天说说我对wordpress的fckeditor插件的改动吧。
Wordpress插件下载:
http://wordpress.org/extend/plugins/deans-fckeditor-for-wordpress-plugin/
FCKeditor的官方下载地址:
http://www.fckeditor.net/
因为wordpress这里的这个插件的fckeditor的版本太低了,
官方版本是2.5.1,而这里才是2.4.3,
所以我用官方版本进行了覆盖。
不过貌似这样就多出了不少的冗余文件。呵呵。
1、让fckeditor兼容worprss的文件上传功能
wordpress自带的文件上传功能很不错,但是启用fckeditor后,就不能使用了。
这是个很严重的问题,究其原因,其实是wordpress的代码写的不够健壮,基本上在
调用编辑器的时候,就认为用的是MCEeditor了。所以我们只有稍稍改动一下,就可以使
这个功能在fckeditor里面使用了。
修改文件:/wordpress/wp-admin/js/upload.js
函数名称:sendToEditor
代码修改:(Line269)(红色部分为修改)
if ( !win )
win = top;
tinyMCE = win.tinyMCE;
if ( typeof tinyMCE != ‘undefined’ && tinyMCE.getInstanceById(’content’) ) {
tinyMCE.selectedInstance.getWin().focus();
tinyMCE.execCommand(’mceInsertContent’, false, h);
} else{
var oFCKeditor=win.oFCKeditor;
if (typeof oFCKeditor != ‘undefined’){
var oEditor = win.FCKeditorAPI.GetInstance(’content’);
oEditor.InsertHtml(h);
}
else{
win.edInsertContent(win.edCanvas, h);
}
}
不过这样改动的时候,需要父win提供一个全局对象。
所以这里还需要对插件调用的时候进行改动。
修改文件:/worpress/wp-content/plugins/deans-fckeditor-for-wordpress-plugin/deans_fckeditor_class.php
函数名称:load_fckeditor
代码修改:(Line260)(红色部分为修改)
<script type=”text/javascript”>
//<![CDATA[
var oFCKeditor;
function _deans_fckeditor_load(){
oFCKeditor = new FCKeditor( 'content' ) ;
oFCKeditor.Config["CustomConfigurationsPath"] = “<?php echo $this->plugin_path . ‘custom_config_js.php’;?>”;
oFCKeditor.BasePath = “<?php echo $this->fckeditor_path;?>” ;
oFCKeditor.Height = “<?php echo $this->EditorHeight;?>” ;
oFCKeditor.Config[ "BaseHref"] = “<?php echo get_settings(’siteurl’);?>” ;
oFCKeditor.ToolbarSet = ‘<?php echo $this->toolbar_set?>’;
oFCKeditor.ReplaceTextarea() ;
}
_deans_fckeditor_load();
//]]>
</script>
经过了如上的改动,就可以在fckeditor里面使用wordpress自带的文件上传功能了。
2、夺回被fckeditor剥脱的textarea编辑权
在fckeditor里面使用textarea是一件非常郁闷的事情,其实这也是我为什么不使用mceeditor的原因。
不过mce里面的textarea的表现实在太差,在编辑POST的时候会出现非常重大的问题。主要是由MCE的本身
机制导致的,hook的办法是把content的内容中的</textarea>replace成&rt;/textarea>。不过这样看上去非常不爽。
最终选择使用iframe作为编辑区的fckeditor作为编辑器也是无奈之举。
而在fckeditor中textarea根本就不能获得焦点,也无法用鼠标进行拖拽改变大小,这对我这个喜欢用
textarea的人真是很大的打击,我可不想每次都切换到代码页去进行修改。
在fckeditor官方网站上也没有得到确切的消息,而一个其他的网站上提到了一句,
fckeditor剥夺textarea的编辑权也是有原因的,反正我没有看出来是什么原因,
反正我想把textarea的编辑权给夺回来,于是有了下面的hook。
修改文件:/wordpress/wp-content/plugins/deans-fckeditor-for-wordpress-plugin/fckeditor/editor/js/fckeditorcode_ie.js
函数名称:未知
修改代码:(Line33)红色部分为删除部分。
C+=’INPUT,Textarea,SELECT,.FCK__Anchor,.FCK__PageBreak,.FCK__InputHidden’;
大家可以看到被剥夺编辑权的还有如上几个对象,
不过,我的目的就是拯救textarea,其它的大家如果有需要,就自己按需求修改吧。呵呵。
从函数名来看,这里的修改只是针对ie的,其它的浏览器里面大家就照猫画虎吧,基本上都是修改这里。
fckeditor用css的behavior加载了个htc文件,用来剥脱对应的元素的编辑(获得焦点)权。
3、写在最后
我的fckeditor for wordpress按照我的意愿修改完毕,很高兴。哈哈~。
如果过些日子deanlee再不update的话,我就自己把东西打包上传wordpress插件目录了。呵呵。
本文来自苏南的博客, 转载请注明网址:http://newsn.net, 谢谢!
我的淘宝小店:http://68zz.com
我的Sina圈子:http://q.blog.sina.com.cn/pctalk
