说明:
1、支持[img ]attach=2[/img]格式来引用图片附件,使用方法同D3
2、支持[div=left|right,width,border]内容[/div]代码,使用方法同D3
3、支持[block]、[hr ]代码,使用方法同D3
4、支持同一附件的多次引用,当附件不存在时,会用一个?来替换,而不是显示XX
5、目前仅支持图片附件,对于其它格式的文件,当用点击这里 [ /url]时无效
6、编辑贴子,再上传附件时,附件编号需要手动设置,不然会有重复
7、黑色部分为正常修改部分,绿色为可选部分,蓝色部分是当安装过其它插件,不方便覆盖文件时的对应修改部分
演示地址:[url]http://bbs.snowcn.com/viewthread.php?tid=2392&extra=page%3D1
或者参见附件中的图
安装难度:一般
升级数据:有,其实本来是D3的表,升级到D4后自动删除了,我们再把它找回来
后台升级数据库- ALTER TABLE `cdb_attachments` ADD `displayorder` TINYINT( 3 ) UNSIGNED DEFAULT '0' NOT NULL AFTER `filename` ;
复制代码
继续:
viewthred.php
查找
- $attach['attachimg'] = $attachimgpost && in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp')) && (!$attach['readperm'] || $readaccess >= $attach['readperm']) ? 1 : 0;
- $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;
复制代码
替换为
- /*$attach['attachimg'] = $attachimgpost && in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp')) && (!$attach['readperm'] || $readaccess >= $attach['readperm']) ? 1 : 0;
- $postlist[$attach['pid']]['attachments'][$attach['aid']] = $attach;*/
-
- //图文混排删除上面内容,加入下面
- $isimage = in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp'));
-
- if ( $isimage && $attachimgpost && !$attach['permid'] ){
- $postlist[$attach['pid']]['attachimg'][$attach[aid]] = $attach;
- }else{
- $postlist[$attach['pid']]['attachments'][$attach[aid]] = $attach;
- }
-
- if ( $attach['permid'] && $isimage && $attachimgpost && !isset($postlist[$attach['pid']]['attachimg'][$attach[aid]]) && ($disablepermscheck || checkperms( $attach['permid'],$attach['readperm'],'attach')==1)){
- $postlist[$attach['pid']]['attachimg'][$attach[aid]] = $attach;
- }
-
- if (isset($postlist[$attach['pid']]['attachimg'][$attach[aid]]) && $forum['allowbbcode'] && $forum['allowimgcode'] && !$post['bbcodeoff']){
- $posmessage = str_replace( "images/common/attachnoperm.gif?{$attach[displayorder]}","$attachurl/$attach[attachment]",$postlist[$attach['pid']]['message']);
-
- if($postlist[$attach['pid']]['message']!=$posmessage){
- $postlist[$attach['pid']]['message']=$posmessage;
- unset($posmessage,$postlist[$attach['pid']]['attachimg'][$attach[aid]]);
- }else{
- unset($posmessage,$postlist[$attach['pid']]['attachments'][$attach[aid]]);
- }
- }//结束
复制代码
查找
- $query = $db->query("SELECT aid, pid, dateline, readperm, filename, description, filetype, attachment, filesize, downloads
- FROM {$tablepre}attachments WHERE pid IN ($attachpids) ORDER BY aid");
复制代码
替换为:
- //图文混排,删除上面内容,替换为下面内容
- $query = $db->query("SELECT aid, pid, displayorder, dateline, readperm, filename, description, filetype, attachment, filesize, downloads
- FROM {$tablepre}attachments WHERE pid IN ($attachpids) ORDER BY displayorder");
- //图文混排结束
复制代码
templates\default\viewthread.htm
查找:- <!--{loop $post['attachments'] $attach}-->
复制代码
改成:- <!--{loop $post['attachimg'] $attach}-->
复制代码
查找:- <!--{if $attach['attachimg']}-->
复制代码
删除
查找
- <img src="$attachurl/$attach[attachment]" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='{lang image_open_zoom}';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(!this.resized) {return false;} else {window.open('$attachurl/$attach[attachment]');}" onmousewheel="return imgzoom(this);">
- <!--{/if}-->
- <!--{else}-->
复制代码
替换成
- <img src="$attachurl/$attach[attachment]" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='{lang image_open_zoom}';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(!this.resized) {return false;} else {window.open('$attachurl/$attach[attachment]');}" onmousewheel="return imgzoom(this);">
- <!--{/if}-->
- <!--{/loop}--><!--{if ($post['attachments'])}--><!--{loop $post['attachments'] $attach}--><br><br>$attach['attachicon']
复制代码
查找:- $attach[dateline], $attach[attachsize]
复制代码
一共有两处,全部
替换成- $attach[dateline], $attach[attachsize], 编号: $attach[displayorder]
复制代码
查找:
- <!--{/if}-->
- <!--{/loop}-->
- <!--{/if}-->
- <!--{if $post['signature']}-->
复制代码
替换成- <!--{/loop}--><!--{/if}-->
- <!--{/if}-->
- <!--{if $post['signature']}-->
复制代码
include\post.func.php
查找- $attachdesc, $attachsave, $attachdir,
复制代码
在后面添加
查找- $attach['perm'] = $allowsetattachperm ? $attachperm[$key] : 0;
复制代码
在上面一行加入- $attach['order'] = intval($attachordernew[$key]);//图文混排加入这句
复制代码
include\newthread.inc.php
查找
- if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }
复制代码
替换为
- /*if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }*/
- //图文混排删除上面一段,加入下面
- if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, displayorder, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$attach[order]', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }//结束
复制代码
include\newreply.inc.php
查找
- if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }
复制代码
替换为
- /*if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }*/
- //图文混排删除上面内容,添加下面
- if($attachment) {
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid,displayorder, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid','$attach[order]', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
- updatecredits($discuz_uid, $creditspolicy['postattach'], count($attachments));
- }//结束
复制代码
include\editpost.inc.php
查找
-
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }
复制代码
替换为
- /*foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }*/
- foreach($attachments as $attach) {
- $db->query("INSERT INTO {$tablepre}attachments (tid, pid,displayorder, dateline, readperm, filename, description, filetype, filesize, attachment, downloads)
- VALUES ('$tid', '$pid', '$attach[order]', '$timestamp', '$attach[perm]', '$attach[name]', '$attach[description]', '$attach[type]', '$attach[size]', '$attach[attachment]', '0')");
- }//图文混排,加入了 ,displayorder 和 , '$attach[order]'
复制代码
查找
- while($attach = $db->fetch_array($query)) {
- if(($attachpermadd = $allowsetattachperm && $attach['readperm'] != $attachpermnew[$attach['aid']] ? ", readperm='{$attachpermnew[$attach['aid']]}'": '') || $attach['description'] != ($attachdescnew[$attach['aid']] = cutstr(dhtmlspecialchars($attachdescnew[$attach['aid']]), 100))) {
- $db->query("UPDATE {$tablepre}attachments SET description='{$attachdescnew[$attach['aid']]}' $attachpermadd WHERE aid='$attach[aid]'");
- }
- }
复制代码
替换为
- /*while($attach = $db->fetch_array($query)) {
- if(($attachpermadd = $allowsetattachperm && $attach['readperm'] != $attachpermnew[$attach['aid']] ? ", readperm='{$attachpermnew[$attach['aid']]}'": '') || $attach['description'] != ($attachdescnew[$attach['aid']] = cutstr(dhtmlspecialchars($attachdescnew[$attach['aid']]), 100))) {
- $db->query("UPDATE {$tablepre}attachments SET description='{$attachdescnew[$attach['aid']]}' $attachpermadd WHERE aid='$attach[aid]'");
- }
- }*/
- //附件混排删除上面一段,加入下面
-
- while($attach = $db->fetch_array($query)) {
- $orderadd = $attachorder[$attach['aid']] != (int)$attach['displayorder'] ? ", displayorder='{$attachorder[$attach[aid]]}'":'';
- if(($attachpermadd = $allowsetattachperm && $attach['readperm'] != $attachpermnew[$attach['aid']] ? ", readperm='{$attachpermnew[$attach['aid']]}'": '') || $attach['description'] != ($attachdescnew[$attach['aid']] = cutstr(dhtmlspecialchars($attachdescnew[$attach['aid']]), 100)) || $orderadd) {
-
- $db->query("UPDATE {$tablepre}attachments SET description='{$attachdescnew[$attach['aid']]}' $attachpermadd $orderadd WHERE aid='$attach[aid]'");
- }
- }//结束
复制代码
将附件中的discuzcode.func.php放到include目录下,覆盖原来的;post_editpost.htm和post_attachments.htm放到templates\default下,覆盖原来的; attachnoperm.gif放到images\common目录下,完成
如果安装了其它插件修改过这几个文件,请参考下面的修改方法进行修改
include\discuzcode.func.php
查找- "/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is",
复制代码
下面添加:
- "/\s*\[block\][\n\r]*(.+?)[\n\r]*\[\/block\]\s*/is",
- "/\s*\[block=([^\[\n\r]+?)\][\n\r]*(.+?)[\n\r]*\[\/block\]\s*/is",
- "/\s*\[div=(left|right|none)[\,](\d{1,3})[\,](\d{1})\][\n\r]*(.+?)[\n\r]*\[\/div\]\s*/is",
- "/\s*\[div=(left|right|none)\][\n\r]*(.+?)[\n\r]*\[\/div\]\s*/is",
复制代码
查找
- "<br><br><div class="smalltxt" style="margin-left: 2em; font-weight: bold">QUOTE:</div><div class="altbg2" style="margin: 2em; margin-top: 3px; padding: 10px; border: ".INNERBORDERWIDTH."px solid ".BORDERCOLOR."; word-break: break-all">\\1</div>",
复制代码
下面添加
- "<br><br><blockquote class="altbg2" style="margin: 2em; margin-top: 3px; padding: 10px; border: ".INNERBORDERWIDTH."px dashed ".BORDERCOLOR."; word-break: break-all">\\1</blockquote>",
- "<br><br><div class="smalltxt" style="margin-left: 2em; font-weight: bold">\\1 :</div><blockquote class="altbg2" style="margin: 2em; margin-top: 3px; padding: 10px; border: ".INNERBORDERWIDTH."px dashed ".BORDERCOLOR."; word-break: break-all">\\2</blockquote>",
- "<div style="float: \\1 ;margin: 1px; margin-top: 1px; padding: 2px;word-break: break-all;width:\\2 ;border: \\3"."px solid ".BORDERCOLOR.";">\\4</div>",
- "<div style="float: \\1 ;margin: 1px; margin-top: 1px; padding: 2px;word-break: break-all;border:1px solid ".BORDERCOLOR.";">\\2</div>",
复制代码
/*12.23 23:20添加了这句,不然 代码没有用,没有大的影响,呵呵*/查找后面添加
查找后面添加
查找
- function bbcodeurl($url, $tags) {
- if(!preg_match("/<.+?>/s", $url)) {
- if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'ftp://', 'rtsp:/', 'mms://'))) {
- $url = 'http://'.$url;
- }
- return str_replace('submit', '', sprintf($tags, $url, addslashes($url)));
- } else {
- return ' '.$url;
- }
- }
复制代码
替换为
- function bbcodeurl($url, $tags) {
- if(!preg_match("/<.+?>/s", $url)) {
- if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'ftp://', 'rtsp:/', 'mms://'))) {
- $url = 'http://'.$url;
- }
- return str_replace(array('submit','action=logout','http://attach=',),array('', '', 'images/common/attachnoperm.gif?'), sprintf($tags, $url, $url));
- //return str_replace('submit', '', sprintf($tags, $url, addslashes($url)));
- } else {
- return ' '.$url;
- }
- }
复制代码
templates\default\post_attachments.htm
这个修改比较麻烦,因为是每行两个附件,所没法用loop语法,修改方法:
查找
文件中一共有10处,在每一处后面依次添加:- 编号: <input type="text" name="attachordernew[]" value="1" size='1'>
复制代码 其中的值从1到10,即第一个<td width="50%">后面是- 编号: <input type="text" name="attachordernew[]" value="1" size='1'>
复制代码 第二个<td width="50%">后面是- 编号: <input type="text" name="attachordernew[]" value="2" size='1'>
复制代码
....
第10个<td width="50%">后面是- 编号: <input type="text" name="attachordernew[]" value="10" size='1'>
复制代码
templates\default\post_editpost.htm
查找
后面添加
查找- <td class="altbg1">$attach[aid]</td>
复制代码
下面添加- <td class="altbg2"><input type="text" name="attachorder[{$attach[aid]}]" size="3" value="$attach[displayorder]" ></td>
复制代码
查找共有三处,全部改成
如果你安装过其它插件,这里可能不是8,是9或者其它数字,只要在原来的基础上加1就行了,比如:如果是9,就改成10
此处为可选部分,是对附件的一些显示美化,与插件本身没有多大关系,如果喜欢可以安装,此处美化已经结合了本插件
viewthread.htm
将- <br><br><img src="images/attachicons/common.gif"> {lang attachment}: <i>{lang attach_nopermission}</i>
- <!--{else}-->
复制代码 和- <!--{if $post['signature']}--><br><br>[/color]之间的内容替换为
- [code]
- <!--{loop $post['attachimg'] $attach}-->
- <br><br>
- <!--{if $attach['attachimg']}--><div style="text-align:center">
- <!--{if $attachrefcheck}-->
- <img title="$attach[filename] ($attach[dateline], $attach[attachsize]) <!--{if $attach['readperm']}-->{lang readperm} $attach[readperm]<!--{/if}--> ({$attach[description]})" src="attachment.php?aid=$attach[aid]&noupdate=yes" border="0" onload="if(this.width>800) {this.resized=true; this.width=800;}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(!this.resized) {return false;} else {window.open('attachment.php?aid=$attach[aid]');}" onmousewheel="return imgzoom(this);" style="border:1px dashed {BORDERCOLOR};padding:4px;">
- <!--{else}-->
- <img title="$attach[filename] ($attach[dateline], $attach[attachsize]) <!--{if $attach['readperm']}-->{lang readperm} $attach[readperm]<!--{/if}--> ({$attach[description]})" src="$attachurl/$attach[attachment]" border="0" onload="if(this.width>800) {this.resized=true; this.width=800;}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(!this.resized) {return false;} else {window.open('$attachurl/$attach[attachment]');}" onmousewheel="return imgzoom(this);" style="border:1px dashed {BORDERCOLOR};padding:4px;">
- <!--{/if}--></div>
- <!--{/if}-->
- <!--{/loop}-->
- <!--{if ($post['attachments'])}--><br><br>
- <table cellspacing="{INNERBORDERWIDTH}" cellpadding="{TABLESPACE}" width="{TABLEWIDTH}" align="center" class="tableborder">
- <tr align="center"><td colspan="7">本贴包含附件</td></tr>
- <tr class="category" align="center"><td width="5%">NO.<td width="40%">附件<td width="15%">更新时间<td width="10%">文件大小<td width="5%">下载<td width="10%">附件限制<td width="15%">描述</td></tr>
- <!--{loop $post['attachments'] $attach}-->
- <!--{if !$attach['attachimg']}-->
- <tr class="altbg1" align="center" ><td>$attach[displayorder]</td><td align="left">
- $attach[attachicon] <!--{if !$discuz_uid}-->$attach[filename](<a href="logging.php?action=login">登录</a>后下载)<!--{else}--><a href="attachment.php?aid=$attach[aid]" target="_blank" class="bold">$attach[filename]</a><!--{/if}-->{template att_video}<td>
- $attach[dateline]<td>
- $attach[attachsize]<td>
- <span class="smalltxt">$attach[downloads]</span><td>
- <!--{if $attach['readperm']}-->{lang readperm} $attach[readperm]<!--{/if}--><td align="left">
- {$attach[description]}</tr>
- <!--{/if}-->
- <!--{/loop}--></table>
- <!--{/if}-->
复制代码
[ 本帖最后由 晶莹雪花 于 2005-12-23 23:20 编辑 ] |