Exemplo n.º 1
0
        /// <summary>
        /// 文档显示页面
        /// </summary>
        /// <param name="id"></param>
        public void Show(string id)
        {
            Archive   archive;
            Member    member;
            Category  catalog;
            DataTable comments;
            string    user,          //发贴名称
                      replayContent; //评论列表


            StringBuilder sb = new StringBuilder();

            archive = bll.Get(id);
            if (archive == null || archive.IsSystem)
            {
                Render404(); return;
            }



            //增加评论

            new System.Threading.Thread(() =>
            {
                bll.AddViewCount(id, 1);
            }).Start();

            //获取分类
            catalog = cbll.Get(c => c.ID == archive.CatalogID);

            //获取作者昵称
            member = mbll.GetMember(archive.Author);
            user   = member == null ? "游客" : member.Nickname;

            //获取评论
            comments = cmbll.GetArchiveComments(archive.ID);
            string nickname, content;
            Match  match;

            for (int i = 0; i < comments.Rows.Count; i++)
            {
                content = comments.Rows[i]["content"].ToString();
                match   = Regex.Match(content, "\\(u:'(?<user>.+?)'\\)");

                if (match != null)
                {
                    nickname = match.Groups["user"].Value;
                    content  = Regex.Replace(content, "\\(u:'(.+?)'\\)", String.Empty);
                }
                else
                {
                    nickname = "游客";
                }

                sb.Append("<li><dl><!--<em><a href=\"#\">引用</a></em>--><span class=\"cDGray\">")
                .Append((i + 1).ToString()).Append("楼</span>&nbsp;<span class=\"cGray\">").Append(nickname)
                .Append("</span>&nbsp;于 <span class=\"cDGray\">")
                .Append(String.Format("{0:yyyy-MM-dd HH:mm:ss}", comments.Rows[i]["createDate"])).Append("</span> 说:</dl><dt><p>")
                .Append(content).Append("</p></dt></li>");
            }
            if (sb.Length == 0)
            {
                replayContent = "<li style=\"text-align:center\">暂无评论</li>";
            }
            else
            {
                replayContent = sb.ToString();
                sb.Remove(0, sb.Length);
            }


            string tagsLink = String.Empty;



            //如果关键词不为空
            if (!String.IsNullOrEmpty(archive.Tags))
            {
                sb.Remove(0, sb.Length);
                Array.ForEach(archive.Tags.Split(','), str =>
                {
                    sb.Append("<strong><a href=\"${domain}/tag/")
                    .Append(Server.UrlEncode(str)).Append("/\" title=\"")
                    .Append(str).Append("\">").Append(str).Append("</a></strong>");
                });

                tagsLink = sb.ToString();
            }


            //呈现页面
            PageUtility.Render("3d9e2da210eea3fb",
                               new
            {
                sitemap      = @"<a href=""${domain}/archive${suffix}/list/${catalogTag}/"">${catalogName}</a>",
                catalogName  = catalog.Name,
                catalogTag   = catalog.Tag,
                archiveTitle = archive.Title,
                author       = archive.Author,
                content      = archive.Content,
                keywords     = archive.Tags,
                click        = ++archive.ViewCount,
                user         = user,
                replays      = comments.Rows.Count,
                outline      = ArchiveUtility.GetOutline(archive, 190),
                source       = String.IsNullOrEmpty(archive.Source) ? "${site.shortname}" : archive.Source,
                publishdate  = string.Format("{0:yyyy-MM-dd HH:mm:ss}", archive.CreateDate),
                tagsLink     = tagsLink,

                guestName     = String.Format("游客:{0}", Request.UserHostAddress),
                replayContent = replayContent,


                h_topics      = hotTopics,
                r_topics      = recommendTopics,
                h_companyinfo = companyInfo
            });
        }