예제 #1
0
        /// <summary>
        /// 加载个人评论(个人中心:我的跟帖)
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public Stream LoadUserContent(string userId, string page, string pagesize)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            // 根据条件获得评论
            List <CommentInfo> cmtLst = DataAccess_News.Comments_SelectPaged(userId, page, pagesize);

            // 在评论里加上作者、发表时间、以及文章标题
            List <CommentInfoApp> cmtLst2 = new List <CommentInfoApp>();

            if (cmtLst != null)
            {
                for (int i = 0; i < cmtLst.Count; i++)
                {
                    var item    = cmtLst[i];
                    var infoApp = new CommentInfoApp();
                    infoApp.cmt_content      = item.cmt_content;
                    infoApp.cmt_id           = item.cmt_id;
                    infoApp.cmt_sourceId     = item.cmt_sourceId;
                    infoApp.cmt_sourceType   = item.cmt_sourceType;
                    infoApp.cmt_uid          = item.cmt_uid;
                    infoApp.cmt_sourceCateId = item.cmt_sourceCateId;

                    int catId = 0;
                    if (!int.TryParse(item.cmt_sourceCateId, out catId))
                    {
                        continue;
                    }

                    var cate = CacheMarker.GetNewsCatesBycat_id(catId.ToString());
                    if (cate == null)
                    {
                        continue;
                    }
                    NewsInfo news = CacheMarker.News_Selectbyn_gid(item.cmt_sourceId, "News_" + cate.cat_tableIndex.ToString());
                    if (news != null)
                    {
                        infoApp.n_authors = news.n_authors;
                        infoApp.n_date    = news.n_date;
                        infoApp.n_title   = news.n_title;
                    }

                    cmtLst2.Add(infoApp);
                }
            }
            var jsonSerialiser = new JavaScriptSerializer();

            json = "{\"list\":" + jsonSerialiser.Serialize(cmtLst2) + "}";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="list"></param>
        /// <param name="n_gid"></param>
        /// <param name="tableName"></param>
        /// <param name="imgs"></param>
        /// <param name="screen_resolution"></param>
        /// <returns></returns>
        private List <NewsContentInfo> CustomContent(List <NewsContentInfo> list, string n_gid, string tableName,
                                                     out List <ImgsInfo> imgs, string screen_resolution = "")
        {
            // 样式
            string tableStyle = "border-collapse:collapse;text-align:left;";
            string pStyle     = "font-size:18px;font-family:'Helvetica Neue','Helvetica','Heiti SC Regular',stheititc,sans-serif;font-color:#000;line-height:1.6;margin-top:19px;padding:0 6.5px"; //text-align:justify;

            if ((screen_resolution == "750x1334") || (screen_resolution == "1080x1920"))                                                                                                           // 6、6s
            {
                pStyle = "font-size:20px;font-family:'Helvetica Neue','Helvetica','Heiti SC Regular',stheititc,sans-serif;font-color:#000;line-height:1.6;margin-top:25px;padding:0 7.5px";        //text-align:justify;
            }
            string titleStyle  = "font-size:25px;font-weight:bold;line-height:1.25;font-family:'Helvetica Neue','Helvetica','Heiti SC',stheititc,sans-serif;color:#333;padding:0;margin:0;";
            string authorStyle = "font-size:12px;font-weight:400;font-family:'Helvetica Neue','Helvetica','Heiti SC',stheititc,sans-serif;color:#bbb;padding:0;margin:0;line-height:1.25;";

            // 获取文章题名,作者与时间
            string   html     = "";
            NewsInfo newsInfo = CacheMarker.News_Selectbyn_gid(n_gid, tableName); //DataAccess_News.News_Selectbyn_gid(n_gid, tableName);

            if (newsInfo != null)                                                 // 图集不需要将文章标题加入内容中
            {
                if (newsInfo.n_type != "images")
                {
                    string title  = newsInfo.n_title;
                    string author = string.IsNullOrEmpty(newsInfo.n_authors.Trim()) ? newsInfo.n_source : newsInfo.n_authors;
                    string date   = newsInfo.n_date;
                    html = string.Format("<p style=\"{0}\">{1}</p><p style=\"{2}\">{3} {4}</p>", titleStyle, title, authorStyle, date, author);
                }
                else
                {
                    list.RemoveAll(t => t.nc_order == -1);
                }
            }

            // 存放图片数据
            imgs = new List <ImgsInfo>();
            int first = 0;

            if (list != null)
            {
                foreach (var info in list)
                {
                    // 对新闻内容特殊字符做处理
                    info.nc_content = HtmlHelper.DecodeHTMLString(info.nc_content, false);

                    using (HtmlParser hp = new HtmlParser(string.Format("<q>{0}</q>", info.nc_content)))
                    {
                        hp.Parse();
                        // 链接集合
                        List <HtmlTag> anchorList = hp.HtmlElemnt.GetElementsByTagName("a");
                        foreach (var anchor in anchorList)
                        {
                            anchor.RemoveTagButKeepChildrenAndValue();  // 去掉新闻内容中的a标签
                        }
                        // 图片集合
                        List <HtmlTag> imgList = hp.HtmlElemnt.GetElementsByTagName("img");
                        foreach (var img in imgList)
                        {
                            img.SetAttribute("style", "width:100%;height:auto"); // 设置新闻内容的图片样式
                            img.RemoveAttribute("width");                        // 去除原来的width属性
                            img.RemoveAttribute("height");                       // 去除原来的height属性

                            string   src   = img.GetAttribute("src");
                            string   alt   = img.GetAttribute("alt");
                            ImgsInfo _info = new ImgsInfo();
                            _info.src = src;
                            _info.alt = alt;
                            imgs.Add(_info);
                        }
                        List <HtmlTag> pTags = hp.HtmlElemnt.GetElementsByTagName("p");
                        foreach (var p in pTags)
                        {
                            p.SetAttribute("style", pStyle); // 设置文章段落
                            foreach (var strong in p.GetElementsByTagName("strong"))
                            {
                                strong.SetAttribute("style", "color:#333");
                            }
                        }
                        // 设置表格样式
                        List <HtmlTag> tTags = hp.HtmlElemnt.GetElementsByTagName("table");
                        foreach (var table in tTags)
                        {
                            // 删除文章中的相关推荐
                            if (table.GetAttribute("style") == "float:right;margin-left:5px;border: 1px solid #C4D6EC;")
                            {
                                table.RemoveTag();
                                continue;
                            }

                            table.SetAttribute("style", tableStyle);
                        }

                        if (++first == 1)// 有些文章分成几篇,会出现多个标题情况
                        {
                            if (newsInfo != null && newsInfo.n_type != "images")
                            {
                                info.nc_content = html + hp.HtmlElemnt.InnerHTMLReBuild + "<br />"; // 重新组装新闻内容
                            }
                            else
                            {
                                info.nc_content = html + hp.HtmlElemnt.InnerHTMLReBuild;
                            }
                        }
                        else
                        {
                            if (newsInfo != null && newsInfo.n_type != "images")
                            {
                                info.nc_content = hp.HtmlElemnt.InnerHTMLReBuild + "<br />"; // 重新组装新闻内容
                            }
                            else
                            {
                                info.nc_content = hp.HtmlElemnt.InnerHTMLReBuild;
                            }
                        }
                    }
                }
            }
            return(list);
        }