您现在的位置是:首页 > cms教程 > phpcms教程phpcms教程

phpcms编辑器添加一键排版控件的方法

何望2025-05-21 11:22:39phpcms教程已有4人查阅

导读CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的

CKEditor添加一键排版插件实例,大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢增加好了后,效果图是这样的废话不多说,直接说步骤
第一步:config.js中statics\js\ckeditor\config.js中注册autoformat控件
config.extraPlugins = 'capture,videoforpc,flashplayer,autoformat';
第二步,在statics\js\ckeditor\plugins 新建文件夹autoformat
第三步,在statics\js\ckeditor\plugins\autoformat新建文件plugin.js
写入如下内容
(function() {
CKEDITOR.plugins.add('autoformat', {
requires: ['styles', 'button'],
init: function(a) {
a.addCommand('autoformat', CKEDITOR.plugins.autoformat.commands.autoformat);
a.ui.addButton('autoformat', {
label: "清除格式,一键排版",
command: 'autoformat',
//这个autoformat.gif是你的插件图标,放在同目录下
icon: this.path + "autoformat.gif"
});
}
});
CKEDITOR.plugins.autoformat = {
commands: {
autoformat: {
exec: function(a) {
var _html = a.getData();
//清除样式代码
_html = _html.replace(/<div/ig, '<p');
_html = _html.replace(/<\/div>/ig, '</p>');
_html = _html.replace(/<strong[^>]*>/ig, '');
_html = _html.replace(/<\/strong>/ig, '');
_html = _html.replace(/<em[^>]*>/ig, '');
_html = _html.replace(/<\/em>/ig, '');
_html = _html.replace(/<u[^>]*>/ig, '');
_html = _html.replace(/<\/u>/, '');
_html = _html.replace(/<li[^>]*>/ig, '');
_html = _html.replace(/<\/li>/ig, '');
_html = _html.replace(/<span[^>]*>/ig, '');
_html = _html.replace(/<\/span>/ig, '');
_html = _html.replace(/ /ig, '');
_html = _html.replace(/ /ig, '');
_html = _html.replace(/<p><\/p>/ig, '');
_html = _html.replace(/<a/ig, '<a rel="nofollow"');
//将p标签替换成<br />
_html = _html.replace(/<p[^>]*>/ig, '');
_html = _html.replace(/<\/p>/ig, '<br />');
_html = _html.replace(/<br \/><br \/>/ig, '<br />');
_html = _html.replace(/[\n]/ig, '');
//按<br />分组,将换行<br>全部替换成p标签
bb = _html.split("<br />");
aa = '';
for (var i = 0; i < bb.length; i++) {
aa = aa + '<p>' + bb + '</p>';
}
//首行缩进
_html = aa.replace(/<p[^>]*>/ig, '<p>  ');
_html = _html.replace(/<p>  <\/p>/ig, '');
_html = _html.replace(/<p><\/p>/ig, '');
//在这里执行你将_html中的空行替换掉的操作
a.setData(_html);
}
}
}
};
})();
写到这里,就完成啦,完成了CKEditor添加一键排版插件
但是,到这里再phpcms里面,还是不能直接用的,在别的系统里面是可以的。因为phpcms的编辑器控件是需要单独选择的,还需要修改phpcms文件
打开phpcms/libs/classes/form.class.php
搜索['Maximize'] 在它的后面加上 ['autoformat'],就可以了。

本文标签:

很赞哦! (0)

暂无内容
暂无内容
暂无内容
暂无内容
留言与评论 (共有 0 条评论)
昵称:
匿名发表 登录账号
         
验证码: