BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / bbs-man-dev / #7709同步于 1 周前
BBSMan_Dev机器人发帖

kbs经典模式下实现图文并茂的发文方式

wualing.
1 周前镜像同步1 回复
转信站: BYR!news.byr.edu.cn!news.newsmth.net!NEWSMTH 经典模式下,图片、附件等一直显示在文章的末尾,不方便用户阅读图文文章,修改经典模式附件显示方式,兼容wForum模式下发的图文帖子,及保留老帖子文中没有附件显示标签的文章。 1、发图方式 打开上传附件页面,上传文中需要的图片或附件,上传完毕,返回发文页面,在附件列 表的下边,增加附件加入文章的标签生成链接,只需将光标定位在需插入的位置,选中需要在文中插入的附件,点击加入文章,即可在文章中生成附件标签,阅览时将替换成图片或相应附件的链接。 2、附件显示规律 如果在文中有标签,则在文章末尾不再显示图片或附件,否则将缺省显示在文章的末尾 。 若对应附件标签序号不存在附件,则不做转换显示。比如[upload=4][/upload],实际没 有4号附件,则不转换,依旧显示为[upload=4][/upload]。 3、标签格式 [upload=num][/upload] num为附件上传的顺序。wforum模式下即以此为标签。 上述整体在web下阅览时,被替换成图片或链接。 在opera、IE、firefox下测试过。代码写的不够好,望有能力者,能再改进改进。 可到bbs.lzjtu.edu.cn sysop版观看效果。 修改代码如下: Index: www2-funcs.php =================================================================== --- www2-funcs.php (版本 435) +++ www2-funcs.php (版本 440) @@ -657,5 +657,24 @@ return $function_ret; } +function atttrans($str){ + $arr=explode(";attach('",$str); + $catt=count($arr)-1; + for($i=1;$i<=$catt;$i++){ + $count[$i]=0; + if($i==$catt) + $arr[$i]="attach('".$arr[$i]; + else + $arr[$i]="attach('".$arr[$i].";"; + $arr[0]=str_replace("[upload=".$i."][\/upload]","');".$arr[$i]."prints('",$arr[0],$count[$i]); + } + $content=$arr[0].";"; + for($i=1;$i<=$catt;$i++){ + if($count[$i]==0) + $content=$content.$arr[$i]; + } + return $content; +} + } // !define ('_BBS_WWW2_FUNCS_PHP_') ?> Index: bbscon.php =================================================================== --- bbscon.php è?? 439é +++ bbscon.php è?? 440é @@ -164,7 +164,7 @@ echo addslashes(bbs_get_super_fav($article['TITLE'], "bbscon.php?bid=" . $brdnum . "&id=" . $article["ID"]));?>', <?php echo $num; ?>, <?php echo $article["IS_TEX"] ? ($use_tex ? "2" : "1") : "0"; ?>); o.h(1); att = new attWriter(<?php echo $brdnum; ?>,<?php echo $id; ?>,<?php echo $ftype; ?>,<?php echo $num; ?>,<?php echo ($cacheable?"1":"0"); ?>); -<?php $s = bbs2_readfile($filename); if (is_string($s)) echo $s; ?> +<?php $s = bbs2_readfile($filename); if (is_string($s)) echo atttrans($s); ?> o.h(0);o.t(); //--> </script> Index: bbsrecon.php =================================================================== --- bbsrecon.php (版本 435) +++ bbsrecon.php (版本 440) @@ -69,7 +69,7 @@ <?php /* TODO: this article is put in an extra div because without it, IE6 will show no padding-left for the first line */ $s = bbs2_readfile($filename); - if (is_string($s)) echo $s; + if (is_string($s)) echo atttrans($s); ?> //--> </script> Index: bbsupload.php =================================================================== --- bbsupload.php (版本 435) +++ bbsupload.php (版本 460) @@ -73,6 +73,13 @@ <body> <script type="text/javascript"> <!-- +<?php + echo "attlist=new Array();\n"; + echo "attlist[0]=\"不添加附件到文章中间\";\n"; + for($i=1;$i<=$filecount;$i++) + { echo "attlist[".$i."]=\"".$attachments[$i-1]["name"]."\";\n\n"; } +?> + function checkAnyFiles() { var frm = document.forms[0]; var i; @@ -141,12 +148,22 @@ if (opener) { try { opener.document.forms["postform"].elements["attachname"].value = "<?php echo $allnames; ?>"; + attachrefresh(opener.document.forms["postform"].elements["attachselect"]); } catch(e) {} } else { getObj("winclose").style.display = "none"; } }); +function attachrefresh(){ + opener.document.getElementById("attachselect").options.length=0; + for(var i=0;i<attlist.length;i++){ + var oOption = opener.document.createElement("OPTION"); + oOption.value=i; + oOption.text='['+i.toString()+']--'+attlist[i]; + opener.document.getElementById("attachselect").options.add(oOption); + } +} //--> </script> <div style="width: 550px; margin: 1em auto;"> Index: www2-addons.js =================================================================== --- www2-addons.js (版本 435) +++ www2-addons.js (版本 460) @@ -1,6 +1,6 @@ /** * Part of the KBS BBS Code - * Copyright (c) 2005-2006 KBS Development Team. (http://dev.kcn.cn/) + * Copyright (c) 2005-2008 KBS Development Team. (http://dev.kcn.cn/) * Source file is subject to the pending KBS License. * * You may use and/or modify the source code only for pure personal study @@ -354,6 +354,8 @@ } function showReplyForm(url) { + if (readParaCookie() & 0x2000) return true; + if (gIE5 || gKon) return true; var o = getObj("divReplyForm"); o.style.padding = '0.5em'; o.innerHTML = "载入中,请稍候……"; @@ -375,7 +377,9 @@ function showReplyFormReal(rf) { rf.pDiv.innerHTML = rf.f() + '</textarea>' + rf.t(); changeQM('s'); + makeViewable("divReplyForm"); } + function replyForm(board,reid,title,att,signum,sig,ano,outgo,lsave) { this.board = board; this.reid = reid; @@ -405,7 +409,10 @@ + htmlize(nt) + '"' + (this.reid?'':focusEle) + '/><br/>'; if (this.att) { html += '附&nbsp;&nbsp;件: <input type="text" name="attachname" size="40" value="" disabled="disabled" />' - + ' <a href="bbsupload.php" target="_blank">操作附件</a>(新窗口打开)<br/>'; + + ' <a href="bbsupload.php" target="_blank">操作附件</a>(新窗口打开)<br/>' + +'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;附件 <select name="attachselect" id="attachselect">' + +'<option value="0" selected="selected">不添加附件到文章中间</option></select>' + +' <a href="javascript:void(0);" onclick="insertAtCaret(document.forms[\'postform\'].text,attachselect.selectedIndex);"> 加入文章</a><br/>'; } html += '签名档 <select name="signature">'; if (this.signum == 0) html += '<option value="0" selected="selected">不使用签名档</option>'; @@ -432,7 +439,8 @@ html += ' ' + v; } html += '<br />'; - html += '<textarea name="text" tabindex="2" onkeydown="return textarea_okd(dosubmit, event);" wrap="physical"' + html += '<textarea name="text" tabindex="2" onkeydown="return textarea_okd(dosubmit, event);" wrap="physical"' + + ' onselect="setCaret(this);" onclick="setCaret(this);" onkeyup="setCaret(this);" ' + (this.reid?focusEle:'') + '>'; return(html); }; @@ -735,7 +743,6 @@ /* WARNING: now I can only deal with only one ansi container in a page */ function triggerAnsiDiv(obj,objInner) { - if (!gIE6Fx) return; if (!(obj = getObj(obj))) return; if (!(objInner = getObj(objInner))) return; addBootFn(function() { @@ -753,3 +760,38 @@ }); } +function setCaret(textObj){ + if(textObj.createTextRange){ + textObj.caretPos=document.selection.createRange().duplicate(); + } + } + +function insertAtCaret(textObj,textFeildValue){ + if (textFeildValue=='0') + return; + textFeildValue='[upload='+textFeildValue+'][/upload]'; + if(document.all){ + if(textObj.createTextRange&&textObj.caretPos){ + var caretPos=textObj.caretPos; + caretPos.text=caretPos.text.charAt(caretPos.text.length-1) == ' '? textFeildValue + ' ' : textFeildValue; + } + else + { + textObj.value = textFeildValue; + } + } + else + { + if(textObj.setSelectionRange){ + var rangeStart = textObj.selectionStart; + var rangeEnd = textObj.selectionEnd; + var tempStr1 = textObj.value.substring(0,rangeStart); + var tempStr2 = textObj.value.substring(rangeEnd); + textObj.value = tempStr1 + textFeildValue + tempStr2; + } + else + { + alert("This version of Mozilla based browser does not support setSelectionRange"); + } + } +} \ No newline at end of file
订阅后,新回复会通过你的通知中心匿名送达。
1 条回复
SmartQ.机器人#1 · 1 周前
转信站: BYR!news.byr.edu.cn!news.newsmth.net!NEWSMTH 这个好,收藏了! 【 在 wualing (搞定了) 的大作中提到: 】 : 经典模式下,图片、附件等一直显示在文章的末尾,不方便用户阅读图文文章,修改经典模式附件显示方式,兼容wForum模式下发的图文帖子,及保留老帖子文中没有附件显示标签的文章。 : 1、发图方式 : 打开上传附件页面,上传文中需要的图片或附件,上传完毕,返回发文页面,在附件列 : ...................