Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

附件图文混排 1.0 for 2.5 SP1 [即down=xxx]

[复制链接]
qqboy1017 发表于 2005-8-22 00:04:29 | 显示全部楼层 |阅读模式
最新更新:需要这功能的请用以下那插件,他的思路比我写的这个好,可以不用查询数据库,我这样写的方法比较笨
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

查找
  1. global $credit, $tid, $discuz_uid,
复制代码

在后加上
  1. $language, $ppid, $table_attachments, $downlist, $dateformat, $timeformat, $timeoffset,
复制代码

查找
  1. if(!$bbcodeoff && $allowimgcode)
复制代码

在上加上
  1.   if(preg_match_all("/\[down=([0-9]{1,2}).{0,7}]/is",$message,$matches)){
  2.     require_once DISCUZ_ROOT.'./include/attachment.php';
  3.     $attachcount = 1;
  4.     $query = $db->query("SELECT aid FROM $table_attachments WHERE tid='$tid' AND pid='$ppid' ORDER BY aid");
  5.     while($attachments = $db->fetch_array($query)) $attachid[$attachcount++] = $attachments[aid];
  6.     $attachcount--;
  7.     for($i=0;$i<count($matches[1]);$i++) {
  8.       if($matches[1][$i]>$attachcount) {
  9.         $message = preg_replace("/\[down=".$matches[1][$i].".*]/","",$message);
  10.         continue;
  11.       }
  12.       $aaid = $attachid[$matches[1][$i]];
  13.       $query = $db->query("SELECT * FROM $table_attachments WHERE aid='$aaid'");
  14.       $attachinfo = $db->fetch_array($query);
  15.       $extension = strtolower(fileext($attachinfo['filename']));
  16.       $isimage = in_array($extension, array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp')) ? 1 : 0;
  17.       $downlist[] = $aattachment = $attachinfo['attachment'];
  18.       preg_match_all("/\[down=[0-9]{1,2}.{0,7}]/is",$message, $extract);
  19.       $downmsg = $extract[0][0];
  20.       if(preg_match_all("/,.{0,6}/is",$downmsg,$downmatches) && $isimage){
  21.         ereg(",[A-Za-z]{0,6}",$downmsg, $downextract);
  22.         $downext = $downextract[0];
  23.         $downextract[0] = preg_replace("/,/","",$downextract[0]);
  24.         if($downextract[0]=="center") {
  25.           $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);
  26.         } else {
  27.           $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);
  28.         }
  29.       } else {
  30.         if(preg_match_all("/,.{0,6}/is",$downmsg,$downmatches)){
  31.           ereg(",[A-Za-z]{0,6}",$downmsg, $downextract);
  32.           $downext = $downextract[0];
  33.         } else {
  34.           $downext = "";
  35.         }
  36.         $checkid = substr(md5($attachinfo['filesize']),0,5);
  37.         $attachicon = attachtype($extension."\t".$attachinfo['filetype']);
  38.         $attachsize = sizecount($attachinfo['filesize']);
  39.         $attachdateline = gmdate("$dateformat $timeformat", $attachinfo['dateline'] + $timeoffset * 3600);
  40.         $replacemsg = "<blockquote>";
  41.         $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>" : "";
  42.         $replacemsg .= "<center>";
  43.         $replacemsg .= $isimage ? "" : $language['attachment']." : ";
  44.         $replacemsg .= "$attachicon <a href="attachment.php?aid=$aaid&checkid=$checkid&download=1" target="_blank">$attachinfo[filename]</a> ($attachdateline,&nbsp;$attachsize";
  45.         if($attachinfo['creditsrequire']) $replacemsg .= ", $language[creditsrequire_attach]$language[credit_title] $attachinfo[creditsrequire] $language[credit_unit]";
  46.         if($attachinfo['downloads']) $replacemsg .= ", $language[downloads] : $attachinfo[downloads]";
  47.         $replacemsg .=")</center></blockquote>";
  48.         $message = str_replace("[down=".$matches[1][$i].$downext."]",$replacemsg,$message);
  49.       }
  50.     }
  51.   }
复制代码


2. 修改 viewthread.php

查找
  1. $discuz_action = 3;
复制代码

在上加上
  1. $downlist = array();
复制代码


查找
  1. if($post['username']) {
复制代码

在下加上
  1. $ppid = $post['pid'];
复制代码

查找
  1. while($attach = $db->fetch_array($query)) {
复制代码

在下加上
  1. if(in_array($attach[attachment],$downlist)) continue;
复制代码


完成!



[ 本帖最后由 qqboy1017 于 2005-8-30 12:48 编辑 ]
 楼主| qqboy1017 发表于 2005-8-22 00:05:08 | 显示全部楼层
备注:
1、任何类型的附件都可以采用[down=xxx]这种方式引用,但是只有附件是图片的时候对齐参数可以起作用。如果图片附件使用[down=xxx]这种形式,没有加入对齐参数,那么会自动采用居中的方式显示,例如上贴中的第一个图片。

2、对于贴子中没有安排具体位置的附件,会和从前一样,显示在文章的最下方。

3、如果您删除了某个附件,那么您需要重新安排附件位置,否则引用的附件位置可能会错乱。

4、对于使用了[down=xxx,align]代码的图片附件,为了保持文章的美观,去掉了上传日期、大小、下载次数等信息。

5、如果[down=xxx] 当中的xxx 大于本贴含有的附件,那么贴子中会自动去掉[down=xxx]。
回复

使用道具 举报

winter0706 发表于 2005-8-22 00:05:09 | 显示全部楼层
出來了?支持~!
回复

使用道具 举报

 楼主| qqboy1017 发表于 2005-8-22 00:10:43 | 显示全部楼层
是啊,捉了一天的虫了,应该是比较完美的了 :)
回复

使用道具 举报

咕咕 发表于 2005-8-22 00:13:37 | 显示全部楼层
把FD的也修改下吧。。免得有人说AD~~
回复

使用道具 举报

 楼主| qqboy1017 发表于 2005-8-22 00:18:18 | 显示全部楼层
原帖由 咕咕 于 2005-8-22 00:13 发表
把FD的也修改下吧。。免得有人说AD~~


不明白,什么AD呀?
回复

使用道具 举报

咕咕 发表于 2005-8-22 00:19:35 | 显示全部楼层
~~汗。。你的FD上只有。。。文章。。。米修改方法。。。而且里面有你的论坛地址,,,
所有有人说你AD(广告)
呼去改改吧~
回复

使用道具 举报

 楼主| qqboy1017 发表于 2005-8-22 00:40:51 | 显示全部楼层
原帖由 咕咕 于 2005-8-22 00:19 发表
~~汗。。你的FD上只有。。。文章。。。米修改方法。。。而且里面有你的论坛地址,,,
所有有人说你AD(广告)
呼去改改吧~


早就在那边同步发布了啊
回复

使用道具 举报

hufanyun 发表于 2005-8-22 00:41:48 | 显示全部楼层
精华鼓励一下
回复

使用道具 举报

hufanyun 发表于 2005-8-22 00:52:49 | 显示全部楼层
发现一个BUG.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-3-28 21:59 , Processed in 0.114282 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表