/// <summary> /// 设置RssItem /// </summary> /// <param name="list"></param> /// <param name="channel"></param> private void SetRssItems(List <Article> list, RssChannel channel) { List <RssItem> l = new List <RssItem>(); foreach (Article article in list) { FormatArticleUrl(article); RssItem item = new RssItem(); item.Author = article.Author; item.Link = article.LinkUrl; item.Title = article.Title; if (!string.IsNullOrEmpty(article.Description)) { item.Description = article.Description; } else { string content = We7Helper.RemoveHtml(article.Content); content = content.Replace(" ", ""); content = We7Helper.ConvertTextToHtml(content); if (content.Length > 200) { content = content.Substring(0, 200) + "..."; } item.Description = content; } item.PubDate = article.Created.ToString("yyyy-MM-dd"); l.Add(item); } channel.Rssitem = l; }
private List <Article> GetArtciles() { ShowFields = "ID,Title,Description,Updated,Source"; SearchResult result = QueryAdvance(); List <Article> items = new List <Article>(); if (result != null) { Pager.RecordCount = result.RecordCount; foreach (QueryArticle a in result.ArticleList) { Article article = new Article(); article.ID = a.ArcicleID; article.Title = a.ArticleTitle; article.Content = a.ArticleContent; string modelXml = a.ArticleModelXML; if (!string.IsNullOrEmpty(modelXml)) { modelXml = We7Helper.RemoveHtml(modelXml); } if (!string.IsNullOrEmpty(modelXml)) { modelXml = We7Helper.RemoveGUID(modelXml); } if (string.IsNullOrEmpty(article.Content)) { article.Content = modelXml; } else { article.Description = modelXml; } article.ChannelFullUrl = a.ArticleCategoryUrl; article.FullChannelPath = a.ArticleCategory; article.ContentUrl = a.ArticleUrl; article.ModelName = a.ArticleType; article.SiteName = a.SiteName; article.SiteUrl = a.SiteUrl; article.Created = Convert.ToDateTime(a.ArticleCreateTime); article.ContentType = (int)TypeOfArticle.LinkArticle; items.Add(article); } if (SummaryMaxLength == 0) { SummaryMaxLength = 200; } items = FormatArticlesData(items); } return(items); }
public static string RemoveHtml(object s) { string str = We7Helper.RemoveHtml(s != null ? s.ToString() : String.Empty); return(str.Replace(" ", "").Replace(" ", "").Replace(" ", "")); }
/// <summary> /// 获取没有html符号的字串 /// </summary> /// <param name="input"></param> /// <returns></returns> public virtual string GetClearHtml(string input) { return(We7Helper.RemoveHtml(input)); }
void FormatArticle(Article article) { if (IsImage) { article.TagThumbnail = article.GetTagThumbnail(ThumbnailTag); } if (!ChannelMap.ContainsKey(article.OwnerID)) { Channel ch = ChannelHelper.GetChannel(article.OwnerID, null); ChannelMap.Add(article.OwnerID, ch); } if (!String.IsNullOrEmpty(ShowChannel)) { Channel ch = ChannelMap[article.OwnerID]; string channelName = ch.Name; if (ChannelHasLink) { channelName = string.Format("<a href='{1}' target='{2}'>{0}</a>", ch.Name, article.ChannelFullUrl, LinkTarget); } article.FullChannelPath = string.Format(ShowChannel, channelName); } article.Icon = GetIcon(article.State); if (NoLink) { article.LinkUrl = ""; } else { if (article.ContentType == (int)TypeOfArticle.LinkArticle) { article.LinkUrl = article.ContentUrl; } else { if (We7Helper.IsEmptyID(article.OwnerID)) { string key = article.ModelName + "$modelchannelurl$const"; if (!ChannelMap.ContainsKey(key)) { List <Channel> chs = ChannelHelper.GetChannelByModelName(article.ModelName); article.LinkUrl = String.Format("{0}{1}", chs != null && chs.Count > 0?chs[0].FullUrl:"", article.FullUrl); } } else { article.LinkUrl = String.Format("{0}{1}", article.ChannelFullUrl, article.FullUrl); } } } if (DateFormat == null || DateFormat == "") { TimeSpan ts = DateTime.Now - article.Updated; article.TimeNote = GetTimeNote(ts); } else { article.TimeNote = article.Updated.ToString(DateFormat); } if (ShowField("ToolTip")) { article.FullTitle = article.Title; article.FullTitle += "," + article.TimeNote; if (article.Clicks > 0) { article.FullTitle += ",阅读量:" + article.Clicks; } } else { article.FullTitle = article.Title; } if (TitleMaxLength > 0 && article.Title.Length > TitleMaxLength) { article.Title = article.Title.Substring(0, TitleMaxLength) + "..."; } if (!string.IsNullOrEmpty(KeyWord)) { article.Title = article.Title.Replace(KeyWord, "<em>" + KeyWord + "</em>"); } if (Show("Description")) { if (SummaryMaxLength > 0 && article.Description != null && article.Description.Length > SummaryMaxLength) { article.Description = article.Description.Substring(0, SummaryMaxLength) + "..."; } if (string.IsNullOrEmpty(article.Description) && !string.IsNullOrEmpty(article.Content)) { string content = We7Helper.RemoveHtml(article.Content); if (content.Length > summaryMaxLength) { article.Description = content.Substring(0, SummaryMaxLength) + "..."; } else { article.Description = content; } } if (!string.IsNullOrEmpty(KeyWord) && !string.IsNullOrEmpty(article.Description)) { article.Description = article.Description.Replace(KeyWord, "<em>" + KeyWord + "</em>"); } } }
/// <summary> /// 格式化列表中的数据 /// </summary> /// <param name="list">文章列表</param> protected List <Article> FormatArticlesData(List <Article> list) { DateTime now = DateTime.Now; foreach (Article a in list) { if (ShowField("Thumbnail")) { a.TagThumbnail = GetTagThumbnail(a, ThumbnailTag); //a.GetTagThumbnail(ThumbnailTag); } //Channel ch = ChannelHelper.GetChannel(a.OwnerID, null); if (!String.IsNullOrEmpty(ShowChannel)) { string channelName = a.ChannelName; if (ChannelHasLink) { channelName = string.Format("<a href='{1}' target='{2}'>{0}</a>", a.ChannelName, a.ChannelFullUrl, LinkTarget); } a.FullChannelPath = string.Format(ShowChannel, channelName); } a.Icon = GetIcon(a.State); if (NoLink) { a.LinkUrl = ""; } else { if (a.ContentType == (int)TypeOfArticle.LinkArticle) { a.LinkUrl = a.ContentUrl; } else { if (String.IsNullOrEmpty(a.ChannelFullUrl) && !String.IsNullOrEmpty(a.ModelName)) { //这儿只能做一个容错处理 List <Channel> chs = ChannelHelper.GetChannelByModelName(a.ModelName); if (chs.Count > 0) { a.ChannelFullUrl = chs[0].FullUrl; } } a.LinkUrl = String.Format("{0}{1}", a.ChannelFullUrl, a.FullUrl); } } if (DateFormat == null || DateFormat == "") { TimeSpan ts = now - a.Updated; a.TimeNote = GetTimeNote(ts); } else { a.TimeNote = a.Updated.ToString(DateFormat); } if (ShowField("ToolTip")) { a.FullTitle = a.Title; a.FullTitle += "," + a.TimeNote; if (a.Clicks > 0) { a.FullTitle += ",阅读量:" + a.Clicks; } } else { a.FullTitle = a.Title; } if (TitleMaxLength > 0 && a.Title.Length > TitleMaxLength) { a.Title = a.Title.Substring(0, TitleMaxLength) + "..."; } if (!string.IsNullOrEmpty(KeyWord)) { a.Title = a.Title.Replace(KeyWord, "<em>" + KeyWord + "</em>"); } if (Show("Description")) { if (SummaryMaxLength > 0 && a.Description != null && a.Description.Length > SummaryMaxLength) { a.Description = a.Description.Substring(0, SummaryMaxLength) + "..."; } if (string.IsNullOrEmpty(a.Description) && !string.IsNullOrEmpty(a.Content)) { string content = We7Helper.RemoveHtml(a.Content); if (content.Length > summaryMaxLength) { a.Description = content.Substring(0, SummaryMaxLength) + "..."; } else { a.Description = content; } } if (!string.IsNullOrEmpty(KeyWord) && !string.IsNullOrEmpty(a.Description)) { a.Description = a.Description.Replace(KeyWord, "<em>" + KeyWord + "</em>"); } } if (AttachmentNum > 0) { a.Attachments = AttachmentHelper.GetAttachments(a.ID); } } return(list); }
/// <summary> /// 格式化列表中的数据 /// </summary> /// <param name="list">文章列表</param> List <Article> FormatArticlesData(List <Article> list) { DateTime now = DateTime.Now; foreach (Article a in list) { if (!String.IsNullOrEmpty(a.Thumbnail)) { a.TagThumbnail = GetTagThumbnail(a, ThumbnailTag); } if (!String.IsNullOrEmpty(ShowChannel)) { Channel ch = ChannelHelper.GetChannel(a.OwnerID, null); string channelName = ch.Name; if (ChannelHasLink) { channelName = string.Format("<a href='{1}' target='{2}'>{0}</a>", ch.Name, a.ChannelFullUrl, LinkTarget); } a.FullChannelPath = string.Format(ShowChannel, channelName); } a.Icon = GetIcon(a.State); if (NoLink) { a.LinkUrl = ""; } else { if (a.ContentType == (int)TypeOfArticle.LinkArticle) { a.LinkUrl = a.ContentUrl; } else { a.LinkUrl = String.Format("{0}{1}", a.ChannelFullUrl, a.FullUrl); } } if (DateFormat == null || DateFormat == "") { TimeSpan ts = now - a.Updated; a.TimeNote = GetTimeNote(ts); } else { a.TimeNote = a.Updated.ToString(DateFormat); } if (ShowField("ToolTip")) { a.FullTitle = a.Title; a.FullTitle += "," + a.TimeNote; if (a.Clicks > 0) { a.FullTitle += ",阅读量:" + a.Clicks; } } if (ArticleTitleMaxLength > 0 && a.Title.Length > ArticleTitleMaxLength) { a.Title = a.Title.Substring(0, ArticleTitleMaxLength) + "..."; } if (Show("Description")) { if (SummaryMaxLength > 0 && a.Description != null && a.Description.Length > SummaryMaxLength) { a.Description = a.Description.Substring(0, SummaryMaxLength) + "..."; } if (string.IsNullOrEmpty(a.Description)) { string content = We7Helper.RemoveHtml(a.Content); if (content.Length > summaryMaxLength) { a.Description = content.Substring(0, SummaryMaxLength) + "..."; } else { a.Description = content; } } } } return(list); }