源程序:
function form_wikitext($attrs) {
// mandatory attributes
unset($attrs['name']);
unset($attrs['id']);
return '<textarea name="wikitext" id="wiki__text" '
.buildAttributes($attrs,true).'>'.DOKU_LF
.formText($attrs['_text'])
.'</textarea>';
}
function form_wikitext($attrs) { // mandatory attributes unset($attrs['name']); unset($attrs['id']); return '<textarea id="elm1" rows="15" cols="80" style="width:100%" name="wikitext">'.DOKU_LF .formText($attrs['_text']) .'</textarea>'; }
2.3.3:在/lib/tpl/dokuwiki/main.php添加xheditor包
<script type="text/javascript" src="<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/xheditor-1.1.14-zh-cn.min.js"></script>
2.3.4.在/inc/parser/xhtml.php里更改cdata函数
源程序:function cdata($text) { $this->doc .= $this->_xmlEntities($text); }替换程序:
function cdata($text) { $this->doc.=$text; }替换原因是:因为以前是纯字符编辑器,会将一些特殊符号进行过滤,比如:<>等等.而替换之后的xheditor本身已经做了一次过滤了,再次过滤就会导致字符<变成<,因此去掉这段之后,就只过滤一次
2.3.5.添加js代码
$(function(){ $('#elm1').xheditor({ localUrlTest:/^https?:\/\/[^\/]*?(xheditor\.com)\//i, remoteImgSaveUrl:'<?php echo DOKU_BASE;?>lib/xheditor1-saveremoteimg.php?prefix=<?php echo DOKU_BASE;?>' }); });
2.3.6:配置php截图上传代码:
/lib/xheditor-1.1.14/demos/saveremoteimg.php.在文件底部修改代码:for($i=0;$i<$urlCount;$i++){ $localUrl=saveRemoteImg($arrUrls[$i]); if($localUrl)$arrUrls[$i]=$localUrl; } echo implode('|',$arrUrls);
for($i=0;$i<$urlCount;$i++){ $localUrl=saveRemoteImg($arrUrls[$i]); if($localUrl)$arrUrls[$i]=$localUrl; } foreach($arrUrls as $key=>$vo){ $arrUrls[$key]=$_GET['prefix'].'lib/xheditor-1.1.14/demos/'.$vo; } echo implode('|',$arrUrls);
2.3.7:将上传的图片去掉多余的”符号
图片上传,发布之后.在调用图片时,会多一个中文”符号,需要修改语言包/inc/lang/zh/lang.php$lang['doublequoteopening'] = '“'; $lang['doublequoteclosing'] = '”';
$lang['doublequoteopening'] = ''; $lang['doublequoteclosing'] = '';
<script type="text/javascript"> var editor; jQuery(pageInit); function pageInit() { var allPlugin={ Code:{c:'btnCode',t:'插入代码',h:1,e:function(){ var _this=this; var htmlCode='<div><select id="xheCodeType"><option value="html">HTML/XML</option><option value="js">Javascript</option><option value="css">CSS</option><option value="php">PHP</option><option value="java">Java</option><option value="py">Python</option><option value="pl">Perl</option><option value="rb">Ruby</option><option value="cs">C#</option><option value="c">C++/C</option><option value="vb">VB/ASP</option><option value="">其它</option></select></div><div><textarea id="xheCodeValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>'; var jCode=jQuery(htmlCode),jType=jQuery('#xheCodeType',jCode),jValue=jQuery('#xheCodeValue',jCode),jSave=jQuery('#xheSave',jCode); jSave.click(function(){ _this.loadBookmark(); _this.pasteHTML('<pre class="prettyprint lang-'+jType.val()+'">'+_this.domEncode(jValue.val())+'</pre>'); _this.hidePanel(); return false; }); _this.saveBookmark(); _this.showDialog(jCode); }} }; editor=jQuery('#elm1').xheditor({ plugins:allPlugin, tools:'Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Anchor,Img,Flash,Media,Hr,Emot,Table,|,Source,Print,Fullscreen,Code', loadCSS:'<style>pre{margin-left:2em;border-left:3px solid #CCC;padding:0 1em;}</style>', localUrlTest:/^https?:\/\/[^\/]*?(xheditor\.com)\//i, remoteImgSaveUrl:'lib/xheditor-1.1.14/demos/saveremoteimg.php?prefix=<?php echo DOKU_BASE;?>', upLinkUrl:"<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/upload.php?immediate=1&prefix=<?php echo DOKU_BASE;?>", upLinkExt:"zip,rar,txt", upImgUrl:"<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/upload.php?immediate=1&prefix=<?php echo DOKU_BASE;?>", upImgExt:"jpg,jpeg,gif,png", upFlashUrl:"<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/upload.php?immediate=1&prefix=<?php echo DOKU_BASE;?>", upFlashExt:"swf", upMediaUrl:"<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/upload.php?immediate=1&prefix=<?php echo DOKU_BASE;?>", upMediaExt:"wmv,avi,wma,mp3,mid" }); } </script>
.btnCode { background:transparent url(../images/code.gif) no-repeat 16px 16px; background-position:2px 2px;}
<script type="text/javascript" src="<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/prettify/prettify.js"></script> <link href="<?php echo DOKU_BASE;?>lib/xheditor-1.1.14/demos/prettify/prettify.css" type="text/css" rel="stylesheet">
<?php tpl_content() ?> <script type="text/javascript">prettyPrint();</script>
pre pre{box-shadow:none;border:0px;margin:0;padding:0;} span{font-style:normal;}
function split($subject, &$split) { if (count($this->_patterns) == 0) { return false; } if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) { if(function_exists('preg_last_error')){ $err = preg_last_error(); switch($err){ case PREG_BACKTRACK_LIMIT_ERROR: msg('A PCRE backtrack error occured. Try to increase the pcre.backtrack_limit in php.ini',-1); break; case PREG_RECURSION_LIMIT_ERROR: msg('A PCRE recursion error occured. Try to increase the pcre.recursion_limit in php.ini',-1); break; case PREG_BAD_UTF8_ERROR: msg('A PCRE UTF-8 error occured. This might be caused by a faulty plugin',-1); break; case PREG_INTERNAL_ERROR: msg('A PCRE internal error occured. This might be caused by a faulty plugin',-1); break; } } $split = array($subject, "", ""); return false; } $idx = count($matches)-2; list($pre, $post) = preg_split($this->_patterns[$idx].$this->_getPerlMatchingFlags(), $subject, 2); $split = array($pre, $matches[0], $post); return isset($this->_labels[$idx]) ? $this->_labels[$idx] : true; }
function split($subject, &$split) { if (count($this->_patterns) == 0) { return false; } if (! preg_match($this->_getCompoundedRegex(), $subject, $matches)) { if(function_exists('preg_last_error')){ $err = preg_last_error(); switch($err){ case PREG_BACKTRACK_LIMIT_ERROR: msg('A PCRE backtrack error occured. Try to increase the pcre.backtrack_limit in php.ini',-1); break; case PREG_RECURSION_LIMIT_ERROR: msg('A PCRE recursion error occured. Try to increase the pcre.recursion_limit in php.ini',-1); break; case PREG_BAD_UTF8_ERROR: msg('A PCRE UTF-8 error occured. This might be caused by a faulty plugin',-1); break; case PREG_INTERNAL_ERROR: msg('A PCRE internal error occured. This might be caused by a faulty plugin',-1); break; } } $split = array($subject, "", ""); return false; } $idx = count($matches)-2; list($pre, $post) = preg_split($this->_patterns[$idx].$this->_getPerlMatchingFlags(), $subject, 2); if(substr($this->_patterns[$idx].$this->_getPerlMatchingFlags(),0,5)=='(\/\/'){ $pre='//'.$pre; } $split = array($pre, $matches[0], $post); return isset($this->_labels[$idx]) ? $this->_labels[$idx] : true; }
function emphasis_open() { $this->doc .= '<em>'; } function emphasis_close() { $this->doc .= '</em>'; }
function emphasis_open() { //$this->doc .= '<em>'; } function emphasis_close() { //$this->doc .= '</em>'; }
4.1.1:插入界面
4.1.2:插入整体效果图
4.2.1:随意截图
4.2.2:发布效果
5.3.2:代码高亮那块是采用Google的prettify.js,那块实际上是用js来修改源代码,在一些关键字的地方加上一些标签和css属性,于是就产生了高亮,关于这块,我是比较担心兼容性问题的(单个页面不担心,但是wiki也引入一堆js,但是目前看来,我测试了几次,都没什么问题,那应该不会出现了)