/// <summary> /// Initialize this BOItem. /// </summary> /// <param name="source">Current processed source.</param> /// <param name="item">Current processed RSS-item from given source.</param> private void Initialize(String source, THashtable item) { this.source = source; this.item = item; this.link = ((String)item["link"]).Trim(); // Pre-process full description & title // Trick to eliminate non-UTF-8 characters this.fullTitle = Strings.CleanChars((String)item["title"]); if (item.ContainsKey("description") && !BLANK(item["description"])) { this.fullDescription = Strings.CleanChars((String)item["description"]); this.fullDescription = Strings.Replace("\n", "\r\n", this.fullDescription); this.fullDescription = Strings.Replace("\r\r", "\r", this.fullDescription); } this.PreProcessLink(); }
/// <summary> /// Fetch info from RSS-feed. /// </summary> /// <param name="url">Feed url</param> /// <returns>Resulting array of items</returns> public static Object[] FetchRss(String url) { var items = new TArrayList(); XmlDocument rssXmlDoc = new XmlDocument(); XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssXmlDoc.NameTable); nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); // Load the RSS file from the RSS URL try { rssXmlDoc.Load(url); } catch (Exception ex1) { var matchCollection = Regex.Matches(ex1.Message, "'([^']+)' is an undeclared prefix. Line [0-9]+, position [0-9]+."); if (matchCollection.Count > 0) { var prefix = matchCollection[0].Groups[1].Value; try { var client = new System.Net.WebClient(); var content = (new System.Net.WebClient()).DownloadString(url); byte[] bytes = Encoding.Default.GetBytes(content); content = Encoding.UTF8.GetString(bytes); //content = System.Text.Encoding.UTF8.GetBytes(content).ToString(); var pattern = CAT("<", prefix, ":[^>]+>[^<]+</", prefix, ":[^>]+>"); content = Regex.Replace(content, pattern, ""); rssXmlDoc.LoadXml(content); } catch (Exception ex2) { return(null); } } else { return(null); } } // Parse the Items in the RSS file XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item"); // Iterate through the items in the RSS file foreach (XmlNode rssNode in rssNodes) { var item = new THashtable(); XmlNodeList itemNodes = rssNode.SelectNodes("*"); foreach (XmlNode itemNode in itemNodes) { String name = itemNode.Name; String text = itemNode.InnerXml; if (text.StartsWith("<![CDATA[")) { text = text.Replace("<![CDATA[", "").Replace("]]>", ""); } if (name == "category") { if (item[name] == null) { item[name] = text; } else { item[name] += ", " + text; } } else if (name == "dc:creator") { THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable(); dc["creator"] = text; item["dc"] = dc; } else if (name == "dc:date") { THashtable dc = item.ContainsKey("dc") ? (THashtable)item["dc"] : new THashtable(); dc["date"] = text; item["dc"] = dc; } else { item[name] = text; } } items.Add(item); } return(items.ToArray()); }
/// <summary> /// Fill Row from Item. /// </summary> /// <param name="oItem">Original Item.</param> /// <param name="idField">Name of ID field.</param> /// <param name="count">The number of inserted Row in HTML table.</param> /// <returns>Resulting Row.</returns> protected THashtable FillItemRow(THashtable oItem, String idField, int count) { var row = new THashtable(); var itemId = INT(oItem[idField]); var urlTitle = STR(oItem["s_Url"]); var itemHref = this.context.ImmediateRedirect ? GetRedirectItemLink(itemId, urlTitle) : GetViewItemLink(itemId, urlTitle); row["[#Link]"] = itemHref; if ((count % 2) == 0) { row["[#Shade]"] = "1"; } if (Config.SHOW_FROM) { row["[#Show_From]"] = 1; } if (Config.SHOW_IMAGES) { row["[#Show_Images]"] = 1; } var sourceName = STR(oItem["s_SourceName"]); row["[#SourceName]"] = sourceName; row["[#ExtImages]"] = Config.EXT_IMAGES; row["[#Title]"] = Util.Show(STR(oItem["s_Title"])); row["[#SourceLink]"] = this.GetLink(Config.INDEX_PAGE, "?p=items&source=", "items/source/", sourceName); if (this.context.Contains("Name_Category") && oItem.ContainsKey("s_Category") && !NUL(oItem["s_Category"])) { row["[#Category]"] = STR(oItem["s_Category"]); } if (this.context.Contains("Name_Creator") && oItem.ContainsKey("s_Creator") && !NUL(oItem["s_Creator"])) { var s_Creator = STR(oItem["s_Creator"]); if (s_Creator != null) { if (s_Creator.IndexOf("(") != -1) { s_Creator = s_Creator.Replace("(", "<br/>("); } } else { s_Creator = (String)" "; //TODO -- "" doesn't works somehow, need to investigate } row["[#Creator]"] = s_Creator; } if (this.context.Contains("Name_Custom1") && oItem.ContainsKey("s_Custom1") && !NUL(oItem["s_Custom1"])) { row["[#Custom1]"] = oItem["s_Custom1"]; } if (this.context.Contains("Name_Custom2") && oItem.ContainsKey("s_Custom2") && !NUL(oItem["s_Custom2"])) { row["[#Custom2]"] = oItem["s_Custom2"]; } var d_Date = Util.ShowTime(STR(oItem["d_Date"])); if (this.context.IsMobile) { d_Date = Strings.Replace("-", " ", d_Date); } else { if (BLANK(this.context.Api)) { d_Date = Strings.ReplaceFirst(" ", "<br/>", d_Date); } } row["[#Date]"] = d_Date; return(row); }