public void BindDownloadAttachmentTip() { if (!Scoresets.IsSetDownLoadAttachScore()) { return; } float[] userExtCredits = Scoresets.GetUserExtCredits(CreditsOperationType.DownloadAttachment); string[] validScoreName = Scoresets.GetValidScoreName(); string[] validScoreUnit = Scoresets.GetValidScoreUnit(); for (int i = 0; i < userExtCredits.Length; i++) { if (userExtCredits[i] < 0f) { this.downloadattachmenttip += string.Format("{0}:{1} {2};", validScoreName[i + 1], Math.Abs(userExtCredits[i]), validScoreUnit[i + 1]); } } this.downloadattachmenttip = this.downloadattachmenttip.TrimEnd(';'); }
public void BindDownloadAttachmentTip() { if (!Scoresets.IsSetDownLoadAttachScore()) { return; } float[] extCredits = Scoresets.GetUserExtCredits(CreditsOperationType.DownloadAttachment); string[] extCreditNames = Scoresets.GetValidScoreName(); string[] extCreditUnits = Scoresets.GetValidScoreUnit(); for (int i = 0; i < extCredits.Length; i++) { if (extCredits[i] < 0)//只提示扣分的扩展积分信息 { downloadattachmenttip += string.Format("{0}:{1} {2};", extCreditNames[i + 1], System.Math.Abs(extCredits[i]), extCreditUnits[i + 1]); } } downloadattachmenttip = downloadattachmenttip.TrimEnd(';'); }
protected override void ShowPage() { pagetitle = "附件下载"; if (attachmentid == -1) { AddErrLine("无效的附件ID"); return; } // 如果当前用户非管理员并且论坛设定了禁止下载附件时间段,当前时间如果在其中的一个时间段内,则不允许用户下载附件 if (useradminid != 1 && usergroupinfo.Disableperiodctrl != 1) { string visitTime = ""; if (Scoresets.BetweenTime(config.Attachbanperiods, out visitTime)) { AddErrLine("在此时间段( " + visitTime + " )内用户不可以下载附件"); return; } } if (DNTRequest.GetString("goodsattach").ToLower() == "yes") GetGoodsAttachInfo(attachmentid); else { // 获取该附件的信息 attachmentinfo = Attachments.GetAttachmentInfo(attachmentid); if (attachmentinfo == null) { AddErrLine("不存在的附件ID"); return; } //当前用户已上传但是还没有绑定到帖子的附件需要特殊处理,直接输出图片 if ((userid > 0 || userid == -1) && userid == attachmentinfo.Uid && attachmentinfo.Tid == 0 && attachmentinfo.Filetype.StartsWith("image/")) { HttpContext.Current.Response.Clear(); if(attachmentinfo.Filename.IndexOf("http") < 0 ) HttpContext.Current.Response.TransmitFile(BaseConfigs.GetForumPath + "upload/" + attachmentinfo.Filename.Trim()); else HttpContext.Current.Response.Redirect(attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); return; } // 获取该主题的信息 topic = Topics.GetTopicInfo(attachmentinfo.Tid); if (topic == null) { AddErrLine("不存在的主题ID"); return; } ForumInfo forum = Forums.GetForumInfo(topic.Fid); pagetitle = Utils.RemoveHtml(forum.Name); if (!UserAuthority.VisitAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } //添加判断特殊用户的代码 if (!UserAuthority.CheckUsertAttachAuthority(forum, usergroupinfo, userid, ref msg)) { AddErrLine(msg); if (userid == -1) needlogin = true; return; } ismoder = Moderators.IsModer(useradminid, userid, forum.Fid); // 检查用户是否拥有足够的阅读权限 if ((attachmentinfo.Readperm > usergroupinfo.Readaccess) && (attachmentinfo.Uid != userid) && (!ismoder)) { AddErrLine("您的阅读权限不够"); if (userid == -1) needlogin = true; return; } //检查附件是否存在 if (attachmentinfo.Filename.IndexOf("http") < 0 && !File.Exists(Utils.GetMapPath(string.Format(@"{0}upload/{1}", BaseConfigs.GetForumPath, attachmentinfo.Filename)))) { AddErrLine("该附件文件不存在或已被删除"); return; } //(!Utils.IsImgFilename(attachmentinfo.Filename.Trim()) || config.Showimages != 1):判断文件是否是图片和图片是否允许在帖子中直接显示 //userid != attachmentinfo.Uid && !ismoder:判断当前下载用户是否是该附件的发布者和当前用户是否具有管理权限 //Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid))当前用户是否已经下载过该附件 if ((!Utils.IsImgFilename(attachmentinfo.Filename.Trim()) || config.Showimages != 1) && (userid != attachmentinfo.Uid && !ismoder && Utils.StrIsNullOrEmpty(Utils.GetCookie("dnt_attachment_" + attachmentid)))) { if (Scoresets.IsSetDownLoadAttachScore() && UserCredits.UpdateUserExtCreditsByDownloadAttachment(userid, 1) == -1) { string addExtCreditsTip = ""; if (EPayments.IsOpenEPayments()) addExtCreditsTip = "<br/><span><a href=\"usercpcreditspay.aspx\">点击充值积分</a></span>"; AddErrLine("您的积分不足" + addExtCreditsTip); return; } //设置该附件已经下载的cookie Utils.WriteCookie("dnt_attachment_" + attachmentid, "true", 5); } //检查附件是否存在 if (AttachPaymentLogs.HasBoughtAttach(userid, usergroupinfo.Radminid, attachmentinfo)) { AddErrLine("该附件为交易附件, 请先行购买!"); return; } //如果是图片就不更新下载次数 if (!Utils.IsImgFilename(attachmentinfo.Filename.Trim())) { Attachments.UpdateAttachmentDownloads(attachmentid); } EntLibConfigInfo entLibConfigInfo = EntLibConfigs.GetConfig(); //当使用企业版squid静态文件加速时 if (attachmentinfo.Filename.IndexOf("http") < 0 && entLibConfigInfo != null && !Utils.StrIsNullOrEmpty(entLibConfigInfo.Attachmentdir)) attachmentinfo.Filename = EntLibConfigs.GetConfig().Attachmentdir.TrimEnd('/') + "/" + attachmentinfo.Filename; if (attachmentinfo.Filename.IndexOf("http") < 0) { //当使用mongodb数据库存储附件及相关信息时 if (entLibConfigInfo != null && entLibConfigInfo.Cacheattachfiles.Enable && entLibConfigInfo.Cacheattachfiles.Attachpostid > 0 && entLibConfigInfo.Cacheattachfiles.Attachpostid < attachmentinfo.Pid) Discuz.Cache.Data.DBCacheService.GetAttachFilesService().ResponseFile(attachmentinfo.Filename, Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); else Utils.ResponseFile(Utils.GetMapPath(BaseConfigs.GetForumPath + @"upload/" + attachmentinfo.Filename), Path.GetFileName(attachmentinfo.Attachment), attachmentinfo.Filetype); } else { try //添加try语法, 以防止在并发访问情况下, 服务器端远程链接被关闭后出现应用程序 '警告'(事件查看器) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Redirect(attachmentinfo.Filename.Trim()); HttpContext.Current.Response.End(); } catch { } } } }
protected override void ShowPage() { this.pagetitle = "附件下载"; if (this.attachmentid == -1) { base.AddErrLine("无效的附件ID"); return; } if (this.useradminid != 1 && !this.usergroupinfo.DisablePeriodctrl) { string str = ""; if (Scoresets.BetweenTime(this.config.Attachbanperiods, out str)) { base.AddErrLine("在此时间段( " + str + " )内用户不可以下载附件"); return; } } var att = Attachment.FindByID(attachmentid); this.attachmentinfo = att; if (att == null) { base.AddErrLine("不存在的附件ID"); return; } if ((userid > 0 || userid == -1) && userid == att.Uid && att.Tid == 0 && att.FileType.StartsWith("image/")) { Response.Clear(); if (att.IsLocal) { Response.TransmitFile(att.FullFileName); } else { Response.Redirect(att.FileName); } Response.End(); return; } this.topic = Topic.FindByID(att.Tid); if (this.topic == null) { base.AddErrLine("不存在的主题ID"); return; } var fi = XForum.FindByID(this.topic.Fid); this.pagetitle = Utils.RemoveHtml(fi.Name); if (!UserAuthority.VisitAuthority(fi, this.usergroupinfo, userid, ref this.msg)) { base.AddErrLine(this.msg); if (userid == -1) { this.needlogin = true; } return; } if (!UserAuthority.CheckUsertAttachAuthority(fi, this.usergroupinfo, userid, ref this.msg)) { base.AddErrLine(this.msg); if (userid == -1) { this.needlogin = true; } return; } this.ismoder = Moderators.IsModer(this.useradminid, userid, fi.ID); var q = WebHelper.RequestInt("q"); if (att.ReadPerm > this.usergroupinfo.Readaccess && att.Uid != userid && !this.ismoder) { if (q != 1) { Response.Clear(); Response.Redirect("/images/common/imgerror2.png"); Response.End(); return; } base.AddErrLine("您的阅读权限不够"); if (userid == -1) { this.needlogin = true; } return; } if (att.IsLocal && !File.Exists(att.FullFileName)) { base.AddErrLine("该附件文件不存在或已被删除"); return; } var key = "attachment_" + attachmentid; if ((!att.ImgPost || config.Showimages != 1) && userid != att.Uid && !ismoder && Utils.GetCookie(key).IsNullOrEmpty()) { if (Scoresets.IsSetDownLoadAttachScore() && CreditsFacade.IsEnoughCreditsDownloadAttachment(userid, 1) && CreditsFacade.DowlnLoadAttachments(userid, 1) == -1) { string msg = ""; if (EPayments.IsOpenEPayments()) { msg = "<br/><span><a href=\"usercpcreditspay.aspx\">点击充值积分</a></span>"; } base.AddErrLine("您的积分不足" + msg); return; } Utils.WriteCookie(key, "true", 5); } if (AttachPaymentLog.HasBoughtAttach(userid, this.usergroupinfo.RadminID, att)) { if (q != 1) { Response.Clear(); Response.Redirect("/images/common/imgerror2.png"); Response.End(); return; } base.AddErrLine("该附件为交易附件, 请先行购买!"); return; } if (!attachmentinfo.ImgPost) { attachmentinfo.Downloads++; attachmentinfo.Save(); } if (!att.IsLocal) { try { Response.Clear(); Response.Redirect(att.FileName); Response.End(); } catch { } return; } Utils.ResponseFile(att.FullFileName, Path.GetFileName(att.Name), att.FileType); }