Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1599522
  • 博文数量: 1481
  • 博客积分: 26784
  • 博客等级: 上将
  • 技术积分: 17045
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-12 09:22
文章分类

全部博文(1481)

文章存档

2014年(10)

2013年(353)

2012年(700)

2011年(418)

分类: 系统运维

2012-05-14 10:14:15

来兄弟连快一个来月了,学习氛围杠杠的,教学环境也比想象中的要好,在完成每天课后作业之外,开始看brophp的源码,自己也用brophp框架动手做了一个小的应用,实现文章增加、删除、修改功能,在此过程中用到了一个富文本编辑的工具--ckeditor,经过一天时断时续的摸索,终于将该编辑器的 PHP版本和brophp框架做了整合。
brophp目录结构
---------------
|
|-----bases
| |
| |--structure.class.php
|
|------classes
| |
| |----ckeditor
| | |
| |---ckeditor.class.php
| |
|--commons
|
|--libs
|
|--brophp.php
步骤如下:

首先、将该编辑器的源文件夹整个拷贝到 brophp框架在的classes目录里边,修该其中ckeditor_php5.php文件名为ckeditor.class.php

其次、brophp.php添加如下
---->$GLOBALS["ckeditor_path"]=$GLOBALS["root"]."brophp/classes/ckeditor/"; //ckeditor根路径
| ---->自动类加载函数: 添加ckeditor类自动加载功能
| function __autoload($className){
| if($className=="memcache"){ //如果是系统的Memcache类则不包含
| return;
| }else if($className=="Smarty"){ //如果类名是Smarty类,则直接包含
| include "Smarty.class.php";
| }else if($className=="Ckeditor"){
| include "ckeditor/".strtolower($className).".class.php";//ckeditor类包含
|
| }else{ //如果是其他类,将类名转为小写
| include strtolower($className).".class.php";
| }
| Debug::addmsg(" $className 类", 1); //在debug中显示自动包含的类
| }
|
接下来修改、
structure.class.php------->这里边写入配置文件config.inc.php的字符串中添加如下ckeditor的默认配置项
|
| /*************************
| *ckeditor配置项
| **************************
| */
| \$config= array(
| 'language' => 'zh-cn',
| 'skin' => 'kama',
| 'width' => 650,
| 'height' => 300,
| 'toolbar' => array(
|
| array('Save', 'Source','-','NewPage','Preview','-','Templates' ),
| array( 'Cut','Copy','Paste','PasteText','PasteFromWord','-', 'SpellChecker', 'Scayt' ),
| array( 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'),
| array('Form',
| 'Checkbox',
| 'Radio',
| 'TextField',
| 'Textarea',
| 'Select',
| 'Button',
| 'ImageButton',
| 'HiddenField'),
| array( 'Bold','Italic','Underline','Strike','-','Subscript','Superscript'),
| array( 'NumberedList','BulletedList','-','Outdent','Indent','Blockquote'),
| array( 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'),
| array( 'Image','Flash','Table','HorizontalRule','SpecialChar','MyPage','Maximize'),
| array( 'TextColor','BGColor'),
| array('Styles','Format','Font','FontSize')
| ),
|
| 'uiColor' => '#373737',
| 'font_names' => '宋体;楷体_GB2312;新宋体;黑体;隶书;幼圆;微软雅黑;Arial;'.
| 'Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana;',
| 'font_defaultLabel' => '宋体',
| 'fontSize_defaultLabel' => '19px',
| 'extraPlugins' => 'mypage',
| );

最后说说、在控制器中调用方式:
1、不用全局配置文件config.inc.php里边的默认配置
$editor = new Ckeditor($GLOBALS["root"].'/brophp/classes/ckeditor/');
$config = array();
$config['uiColor'] = '#373737';
$config['width'] = 500;
$config['height'] = 100;
$config['toolbar'] = array(
array( 'Bold', 'Indent','Italic', 'Underline', 'Strike','Smiley' ),
array( 'TextColor','Font','FontSize','RemoveFormat')
);

$editor->returnOutput = true;
$code = $editor->editor("messsage", "留言内容",$config);
$this->assign('ckeditor',$code);


2、//声明使用全局配置文件config.inc.php里边的配置
$editor = new Ckeditor($GLOBALS["ckeditor_path"]);
global $config;//声明使用全局配置文件config.inc.php里边的配置
$editor->returnOutput = true;
$code = $editor->editor("content",'',$config);
$this->display('editor',$code)

----$code = $editor->editor("messsage", "留言内容",$config);

editor方法的使用,其中有三个参数:
第一个是,生成的textarea框的name值,可以通过此name值,使用$_GET[]和$_POST[]取到内容
第二个参数是:默认内容,就是平时写到'; tpl += '
'; tpl += '
'; tpl += '
'; tpl += ''; tpl += '
'; tpl += '
'; tpl += '
'; $('.z_move_comment').html(''); $(this).parents('.Blog_right1_8').find('.z_move_comment').html(tpl).show(); }); //引用的评论提交 $('#quota_sbumit').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var tid = $(this).attr('tid');//被引用人的id var qid = $(this).attr('cid');//引用的id var url = $(this).attr('url'); var text = $('#rmsg').val(); var tname = $(this).attr('tname'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : tid , 'qid' : qid , 'text': text , 'tname' : tname }, dataType: 'json', success: function(data){ if(data.code == 1){ var tpl = '
'; tpl+= ''; tpl+= '
'; tpl+= '

' + data.info.username + '' + data.info.dateline + '

'; tpl+= '

' + data.info.quota.username + ':'+ data.info.quota.content + '

'; tpl+= '

' + data.info.content + '

回复 |  删除 |  举报
'; tpl+= ''; tpl+= '
'; $('#replyList .Blog_right1_8:first').before(tpl); $('.z_move_comment').html('').hide(); } else if(data.code == -1){ //showErrorMsg(data.info , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); } }, error: function(){//请求出错处理 } }); }); //底部发表评论 $('#submitmsg').click(function(){ if(allowComment == 1) { showErrorMsg('该博文不允许评论' , '消息提示'); return false; } var bid = $(this).attr('bid'); var toid = $(this).attr('toid'); var text = $('#reply').val(); var url = $(this).attr('url'); if(text == '' || text=='文明上网,理性发言...') { showErrorMsg('评论内容不能为空!' , '消息提示'); return false; } else { if(mb_strlen(text) > 1000){ showErrorMsg('评论内容不能超过500个汉字' , '消息提示'); return false; } } $.ajax({ type: "post", url: url , data: {'bid': bid , 'to' : toid ,'text': text}, dataType: 'json', success: function(data){ if(data.code == 1) { var tpl = '
'; tpl += ''; tpl += '
'; tpl += '

' + data.info.username + '' + data.info.dateline + '

'; tpl += '

' + data.info.content + '

'; tpl += '
回复 |  删除 |  举报
'; tpl += ''; tpl += '
'; $('.Blog_tit3:first').after(tpl); $('#reply').val('文明上网,理性发言...'); } else if(data.code == -1) { showErrorMsg(data.info , '消息提示'); } }, error: function(){//请求出错处理 } }); }); //底部评论重置 $('#reset_comment').click(function(){ $('#reply').val('文明上网,理性发言...'); }); //取消回复 $('#qx_comment').live('click' , function(){ $('.z_move_comment').html('').hide(); }); $('#rmsg, #reply').live({ focus:function(){ if($(this).val() == '文明上网,理性发言...'){ $(this).val(''); } }, blur:function(){ if($(this).val() == ''){ $(this).val('文明上网,理性发言...'); } } }); //删除留言确认 $('.comment_del_mark').live('click' , function(){ var url = $(this).attr('url'); asyncbox.confirm('删除留言','确认', function(action){ if(action == 'ok') { location.href = url; } }); }); //删除时间确认 $('.del_article_id').click(function(){ var delurl = $(this).attr('delurl'); asyncbox.confirm('删除文章','确认', function(action){ if(action == 'ok') { location.href = delurl; } }); }); /* //字数限制 $('#rmsg, #reply').live('keyup', function(){ var id = $(this).attr('id'); var left = Util.calWbText($(this).val(), 500); var eid = '#errmsg'; if(id == 'reply') eid = '#rerrmsg'; if (left >= 0) $(eid).html('您还可以输入' + left + '字'); else $(eid).html('您已超出' + Math.abs(left) + ''); }); */ //加载表情 $('#face').qqFace({id : 'facebox1', assign : 'reply', path : '/image/qqface/'}); $('#mface').qqFace({id : 'facebox', assign : 'rmsg', path:'/image/qqface/'}); /* $('#class_one_id').change(function(){ alert(123213); var id = parseInt($(this).val() , 10); if(id == 0) return false; $('.hidden_son_class span').each(function( index , dom ){ if( dom.attr('cid') == id ) { } }); }); */ //转载文章 var turn_url = "/blog/viewClassPart.html"; $('#repost_bar').click(function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var id = $(this).attr('bid'); asyncbox.open({ id : 'turn_class_thickbox', url : turn_url, title : '转载文章', width : 330, height : 131, scroll : 'no', data : { 'id' : id }, callback : function(action){ if(action == 'close'){ $.cover(false); } } }); }); /* //转发文章 $('#repost_bar').live('click' , function(){ if(isOnLine == '' ) { //showErrorMsg('登录之后才能进行此操作' , '消息提示'); showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); return false; } var bid = $(this).attr('bid'); var url = $(this).attr('url'); asyncbox.confirm('转载文章','确认', function(action){ if(action == 'ok'){ $.ajax({ type:"POST", url:url, data: { 'bid' : bid }, dataType: 'json', success:function(msg){ if(msg.error == 0){ showSucceedMsg('转发成功!', '消息提示'); }else if(msg.error == 1){ //location.href = '/index.php?r=site/login'; showErrorMsg('操作失败,您需要先登录!', '消息提示', 'http://account.chinaunix.net/login'); }else{ showErrorMsg(msg.error_content, '消息提示'); } } }); } }); }); */ });