最新更新:需要这功能的请用以下那插件,他的思路比我写的这个好,可以不用查询数据库,我这样写的方法比较笨
http://www.freediscuz.net/dev/viewthread.php?tid=3136
使用方法:
[down=xxx,align]
xxx 为 附件编号
align 为 left, right, center 其中之一 或 留空不填上
测试和演示 http://www.54zgr.com/bbs/viewthread.php?tid=506
安装步骤:
1. 修改 iclude/discuzcode.php
查找
- global $credit, $tid, $discuz_uid,
复制代码
在后加上
- $language, $ppid, $table_attachments, $downlist, $dateformat, $timeformat, $timeoffset,
复制代码
查找
- if(!$bbcodeoff && $allowimgcode)
复制代码
在上加上
- if(preg_match_all("/\[down=([0-9]{1,2}).{0,7}]/is",$message,$matches)){
- require_once DISCUZ_ROOT.'./include/attachment.php';
- $attachcount = 1;
- $query = $db->query("SELECT aid FROM $table_attachments WHERE tid='$tid' AND pid='$ppid' ORDER BY aid");
- while($attachments = $db->fetch_array($query)) $attachid[$attachcount++] = $attachments[aid];
- $attachcount--;
- for($i=0;$i<count($matches[1]);$i++) {
- if($matches[1][$i]>$attachcount) {
- $message = preg_replace("/\[down=".$matches[1][$i].".*]/","",$message);
- continue;
- }
- $aaid = $attachid[$matches[1][$i]];
- $query = $db->query("SELECT * FROM $table_attachments WHERE aid='$aaid'");
- $attachinfo = $db->fetch_array($query);
- $extension = strtolower(fileext($attachinfo['filename']));
- $isimage = in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp')) ? 1 : 0;
- $downlist[] = $aattachment = $attachinfo['attachment'];
- preg_match_all("/\[down=[0-9]{1,2}.{0,7}]/is",$message, $extract);
- $downmsg = $extract[0][0];
- if(preg_match_all("/,.{0,6}/is",$downmsg,$downmatches) && $isimage){
- ereg(",[A-Za-z]{0,6}",$downmsg, $downextract);
- $downext = $downextract[0];
- $downextract[0] = preg_replace("/,/","",$downextract[0]);
- if($downextract[0]=="center") {
- $message =str_replace("[down=".$matches[1][$i].$downext."]","<p align="center"><a href="attachments/$aattachment" target="_blank"><img src="attachments/$aattachment" border="0" onload="if(this.width>screen.width*0.5) {this.resized=true; this.width=screen.width*0.4; this.alt='".$language['click_open_newwindow']."';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) window.open(this.src);" hspace="10" vspace="10" style="float:none"></a></p>",$message);
- } else {
- $message =str_replace("[down=".$matches[1][$i].$downext."]","<a href="attachments/$aattachment" target="_blank"><img src="attachments/$aattachment" border="0" onload="if(this.width>screen.width*0.5) {this.resized=true; this.width=screen.width*0.4; this.alt='".$language['click_open_newwindow']."';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) window.open(this.src);" hspace="10" vspace="10" style="float:$downextract[0]"></a>",$message);
- }
- } else {
- if(preg_match_all("/,.{0,6}/is",$downmsg,$downmatches)){
- ereg(",[A-Za-z]{0,6}",$downmsg, $downextract);
- $downext = $downextract[0];
- } else {
- $downext = "";
- }
- $checkid = substr(md5($attachinfo['filesize']),0,5);
- $attachicon = attachtype($extension."\t".$attachinfo['filetype']);
- $attachsize = sizecount($attachinfo['filesize']);
- $attachdateline = gmdate("$dateformat $timeformat", $attachinfo['dateline'] + $timeoffset * 3600);
- $replacemsg = "<blockquote>";
- $replacemsg .= $isimage ? "<p align="center"><a href="attachments/$aattachment" target="_blank"><img src="attachments/$aattachment" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.6; this.alt='".$language['click_open_newwindow']."';}" onmouseover="if(this.resized) this.style.cursor='hand';" onclick="if(this.resized) window.open(this.src);" hspace="10" vspace="10" style="float:none"></ay></p>" : "";
- $replacemsg .= "<center>";
- $replacemsg .= $isimage ? "" : $language['attachment']." : ";
- $replacemsg .= "$attachicon <a href="attachment.php?aid=$aaid&checkid=$checkid&download=1" target="_blank">$attachinfo[filename]</a> ($attachdateline, $attachsize";
- if($attachinfo['creditsrequire']) $replacemsg .= ", $language[creditsrequire_attach]$language[credit_title] $attachinfo[creditsrequire] $language[credit_unit]";
- if($attachinfo['downloads']) $replacemsg .= ", $language[downloads] : $attachinfo[downloads]";
- $replacemsg .=")</center></blockquote>";
- $message = str_replace("[down=".$matches[1][$i].$downext."]",$replacemsg,$message);
- }
- }
- }
复制代码
2. 修改 viewthread.php
查找
在上加上
查找
在下加上
查找
- while($attach = $db->fetch_array($query)) {
复制代码
在下加上
- if(in_array($attach[attachment],$downlist)) continue;
复制代码
完成!
[ 本帖最后由 qqboy1017 于 2005-8-30 12:48 编辑 ] |