Esempio n. 1
0
        private static string OnMatchAllAttach(Match match, AuthUser operatorUser, User postUser, int forumID, AttachmentCollection attachments, ForumSettingItem forumSetting
            , ref bool? hasViewAttachPermission, ref bool? canAlwaysViewContents, ref bool? allowImageTag, ref bool? allowAudioTag, ref bool? allowVideoTag, ref bool? allowFlashTag)
        {
            if (match.Success == false)
                return match.Value;

            string type = match.Groups["type"].Value;

            if (hasViewAttachPermission == null)
                hasViewAttachPermission = AllSettings.Current.ForumPermissionSet.Nodes.GetPermission(forumID).Can(operatorUser, ForumPermissionSetNode.Action.ViewAttachment);

            if (!hasViewAttachPermission.Value)
            {
                string message;
                if (operatorUser.UserID == 0)
                {
                    message = "您是游客";
                }
                else
                {
                    message = string.Empty;
                }

                if (StringUtil.EqualsIgnoreCase(type, "img"))
                    return GetNopermissionStyle(string.Concat(message, "您没有权限查看该图片"));
                else if (StringUtil.EqualsIgnoreCase(type, "media"))
                    return GetNopermissionStyle(string.Concat(message, "您没有权限查看该多媒体"));
                else
                {
                    int attachID = int.Parse(match.Groups["id"].Value);
                    Attachment attachment = attachments.GetValue(attachID);
                    if (attachment != null)
                        return GetNoPermissonfileStyle(attachment.FileName, operatorUser.UserID == 0);
                    else
                        return match.Value;
                }
            }
            else
            {
                int attachID = int.Parse(match.Groups["id"].Value);
                Attachment attachment = attachments.GetValue(attachID);

                if (attachment == null)
                    return match.Value;

                if (canAlwaysViewContents == null)
                {
                    ForumPermissionSetNode forumPermission = AllSettings.Current.ForumPermissionSet.Nodes.GetPermission(forumID);
                    canAlwaysViewContents = forumPermission.Can(operatorUser, ForumPermissionSetNode.Action.AlwaysViewContents);
                }

                if (StringUtil.EqualsIgnoreCase(type, "img"))
                {
                    if (allowImageTag == null)
                    {
                        allowImageTag = forumSetting.CreatePostAllowImageTag.GetValue(postUser);
                    }
                    if (allowImageTag.Value)
                    {
                        if (attachment.Price == 0 || attachment.UserID == operatorUser.UserID || canAlwaysViewContents.Value || attachment.IsBuyed(operatorUser) || attachment.IsOverSellDays(forumSetting))
                        {
                            //string info = string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" /><a href=\"", BbsUrlHelper.GetAttachmentUrl(attachment.AttachmentID), "\">", attachment.FileName, "</a>  <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:", attachment.TotalDownloads.ToString(), ")</span><br />");

                            string[] param = StringUtil.Split(match.Groups["param"].Value);
                            string width, height;
                            if (param.Length > 1)
                            {
                                width = param[0];
                                height = param[1];
                            }
                            else
                            {
                                width = string.Empty;
                                height = string.Empty;
                            }
                            return GetImageUrl(attachment.AttachmentID, false, width, height);
                        }
                        else
                        {
                            return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", attachment.FileName, " <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:" + attachment.TotalDownloads.ToString(), ")</span><br />", GetNopermissionStyle("您需要购买后才能查看该图片"));
                        }
                    }
                    else
                        return ProcessAttach(attachment, operatorUser, forumSetting, canAlwaysViewContents.Value);
                }
                else if (StringUtil.EqualsIgnoreCase(type, "media"))
                {
                    if (attachment.Price == 0 || canAlwaysViewContents.Value || attachment.UserID == operatorUser.UserID || attachment.IsBuyed(operatorUser)
                        || attachment.IsOverSellDays(forumSetting))
                    {
                        string[] param = StringUtil.Split(match.Groups["param"].Value);
                        string width, height;
                        bool auto = false;
                        if (param.Length > 1)
                        {
                            width = param[0];
                            height = param[1];
                            if (param.Length > 2)
                            {
                                if (string.Compare(param[2], "1") == 0)
                                {
                                    auto = true;
                                }
                            }
                        }
                        else
                        {
                            width = string.Empty;
                            height = string.Empty;
                        }

                        //return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", "<a href=\"", BbsUrlHelper.GetAttachmentUrl(attachment.AttachmentID), "\">", attachment.FileName
                        //    , "</a>  <span class=\"filesize gray\">(大小:", attachment.FileSizeFormat, "    下载次数:", attachment.TotalDownloads, ")</span><br />"
                        //    , GetMediaContent(attachment, false, width, height, auto, forumSetting, user, ref allowAudioTag, ref allowVideoTag, ref allowFlashTag));

                        return GetMediaContent(attachment, false, width, height, auto, forumSetting, operatorUser, ref allowAudioTag, ref allowVideoTag, ref allowFlashTag);

                    }
                    else
                    {
                        return string.Concat("<br /><img src=\"", attachment.FileIcon, "\" alt=\"\" />", attachment.FileName, "<span class=\"filesize gray\">(大小:", attachment.FileSizeFormat
                            , "    下载次数:", attachment.TotalDownloads, ")</span><br />", GetNopermissionStyle("您需要购买后才能查看该多媒体"));
                    }
                }
                else
                {
                    return ProcessAttach(attachment, operatorUser, forumSetting, canAlwaysViewContents.Value);
                }
            }
        }