public DescriptionFile(String DescriptionType, int ID, String LocaleSetting, int SkinID) { m_DescriptionType = DescriptionType.Trim().ToLowerInvariant(); m_ID = ID; m_LocaleSetting = LocaleSetting; m_SkinID = SkinID; // Find the description file content. will be in /{descriptiontype}descriptions or some locale subdir. find by ID m_Root = CommonLogic.IIF(AppLogic.IsAdminSite, "../", "") + "descriptions/" + m_DescriptionType.ToLowerInvariant() + "/"; m_Contents = String.Empty; m_ContentsRAW = String.Empty; m_FN = String.Empty; if (AppLogic.AppConfigBool("UseNameForSectionDescriptionName")) { //Try SKU version first if (!FindNameFile()) { FindIDFile(); } } else { FindIDFile(); } if (m_FN.Length != 0 && CommonLogic.FileExists(m_FN)) { m_URL = Path.Combine(AppLogic.GetStoreHTTPLocation(false), m_URL); m_Contents = CommonLogic.ReadFile(m_FN, true); m_ContentsRAW = m_Contents; m_Contents = CommonLogic.ExtractBody(m_Contents); m_Contents = m_Contents.Replace("(!SKINID!)", SkinID.ToString()); } else { m_URL = String.Empty; m_FN = String.Empty; } }
public ProductSpecFile(int ProductID, String LocaleSetting, int SkinID, string SKU) { m_ProductID = ProductID; m_LocaleSetting = LocaleSetting; m_SkinID = SkinID; m_ProductSKU = SKU; m_Contents = String.Empty; m_ContentsRAW = String.Empty; m_FN = String.Empty; // Find the Specified ProductSpec content. will be in /descriptions/productspecs or some locale subdir. find by productid or SKU, whichever is provided. m_Root = CommonLogic.IIF(AppLogic.IsAdminSite, "../", "") + "descriptions/productspecs/"; if (AppLogic.AppConfigBool("UseSKUForProductDescriptionName")) { //Try SKU version first if (m_ProductSKU.Length == 0) { m_ProductSKU = AppLogic.GetProductSKU(ProductID); } if (!FindSKUFile()) { FindIDFile(); } } else { FindIDFile(); } if (FN.Length != 0 && CommonLogic.FileExists(FN)) { m_URL = Path.Combine(AppLogic.GetStoreHTTPLocation(false), m_URL); m_Contents = CommonLogic.ReadFile(FN, true); m_ContentsRAW = m_Contents; m_Contents = CommonLogic.ExtractBody(m_Contents); m_Contents = m_Contents.Replace("(!SKINID!)", SkinID.ToString()); } }
// Find the specified topic content. note, we try to find content even if it doesn't exactly match the input specs, by doing an ordered lookup in various areas // we want to show SOME topic content if it is at all possible, even if the language is not right, etc... // Note: site id only used for file based topic _contents // Search Order is (yes, other orderings are possible, but this is the one we chose, where ANY db topic match overrides file content): // the other option would be to match on locales in the order of DB/File (Customer Locale), DB/File (Store Locale), DB/File (Null locale) // DB (customer locale) // DB (store locale) // DB (null locale) // File (customer locale) // File (store locale) // File (null locale) void LoadFromDB(int StoreID) { m_FromDB = false; m_DisplayOrder = 1; m_SkinID = ThisCustomer.SkinID; m_StoreID = StoreID; m_LocaleSetting = CommonLogic.IIF(m_LocaleSetting.Length > 0, m_LocaleSetting, Localization.GetDefaultLocale()); m_Contents = String.Empty; m_ContentsRAW = String.Empty; m_SectionTitle = String.Empty; m_RequiresSubscription = false; m_RequiresDisclaimer = false; m_ShowInSiteMap = true; m_Password = String.Empty; m_SETitle = m_TopicName; m_SEKeywords = String.Empty; m_SEDescription = String.Empty; m_SENoScript = String.Empty; m_FN = String.Empty; m_MasterLocale = m_LocaleSetting; m_Children = new List <int>(); m_HasChildren = false; if (m_TopicID == 0) { m_TopicID = Topic.GetTopicID(m_TopicName, CommonLogic.IIF(AppLogic.IsAdminSite, m_MasterLocale, m_LocaleSetting), AppLogic.StoreID()); } if (m_TopicID != 0) { String sql = String.Format("SELECT * from Topic with (NOLOCK) where Deleted=0 and Published=1 and TopicID={1} and (SkinID IS NULL or SkinID=0 or SkinID={2}) order by DisplayOrder, Name ASC", CommonLogic.IIF(AppLogic.GlobalConfigBool("AllowTopicFiltering") == true, 1, 0), m_TopicID.ToString(), m_SkinID.ToString()); using (SqlConnection con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (IDataReader rs = DB.GetRS(sql, con)) { if (rs.Read()) { m_FromDB = true; m_TopicID = DB.RSFieldInt(rs, "TopicID"); m_TopicName = DB.RSField(rs, "Name"); m_Contents = DB.RSFieldByLocale(rs, "Description", m_LocaleSetting); m_Password = DB.RSField(rs, "Password"); m_RequiresSubscription = DB.RSFieldBool(rs, "RequiresSubscription"); m_RequiresDisclaimer = DB.RSFieldBool(rs, "RequiresDisclaimer"); m_GraphicsColor = DB.RSField(rs, "GraphicsColor"); m_ContentsBGColor = DB.RSField(rs, "ContentsBGColor"); m_PageBGColor = DB.RSField(rs, "PageBGColor"); m_DisplayOrder = DB.RSFieldInt(rs, "DisplayOrder"); m_ShowInSiteMap = DB.RSFieldBool(rs, "ShowInSiteMap"); m_SkinID = DB.RSFieldInt(rs, "SkinID"); if (m_Contents.Length != 0) { m_ContentsRAW = m_Contents; m_SectionTitle = DB.RSFieldByLocale(rs, "Title", m_LocaleSetting); m_SETitle = DB.RSFieldByLocale(rs, "SETitle", m_LocaleSetting); m_SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", m_LocaleSetting); m_SEDescription = DB.RSFieldByLocale(rs, "SEDescription", m_LocaleSetting); m_SENoScript = DB.RSFieldByLocale(rs, "SENoScript", m_LocaleSetting); } else // nothing found, try master locale: { m_Contents = DB.RSFieldByLocale(rs, "Description", m_MasterLocale); m_ContentsRAW = m_Contents; m_SectionTitle = DB.RSFieldByLocale(rs, "Title", m_MasterLocale); m_SETitle = DB.RSFieldByLocale(rs, "SETitle", m_MasterLocale); m_SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", m_MasterLocale); m_SEDescription = DB.RSFieldByLocale(rs, "SEDescription", m_MasterLocale); m_SENoScript = DB.RSFieldByLocale(rs, "SENoScript", m_MasterLocale); } // if an html tag is present, extract just the body of the content if (m_Contents.IndexOf("<html", StringComparison.InvariantCultureIgnoreCase) != -1) { m_Contents = CommonLogic.ExtractBody(m_ContentsRAW); } } } } // loads the child topics m_HasChildren = DB.GetSqlN("select count(tm.TopicID) as N from dbo.TopicMapping tm with(NOLOCK) left join dbo.Topic t with(NOLOCK) on t.TopicID = tm.ParentTopicID where t.TopicID =" + m_TopicID.ToString() + " and t.Deleted=0") > 0; if (m_HasChildren) { LoadChildren(); } } if (!m_FromDB) // did not find anything in db, try file based topic content (in skins folder as topicname.htm) { string appdir = HttpContext.Current.Request.PhysicalApplicationPath; List <string> possibleFileNames = new List <string> { Path.Combine(appdir, string.Format("App_Templates\\Skin_{0}\\Topics\\{1}.{2}.htm", SkinID.ToString(), m_TopicName, m_LocaleSetting)), //Skin specific, localized Path.Combine(appdir, String.Format("App_Templates\\Skin_{0}\\Topics\\{1}.htm", SkinID.ToString(), m_TopicName)), //Skin specific, unlocalized Path.Combine(appdir, string.Format("Topics\\{0}.{1}.htm", m_TopicName, m_LocaleSetting)), //Root folder, localized Path.Combine(appdir, string.Format("Topics\\{0}.htm", m_TopicName)), //Root folder, unlocalized Path.Combine(appdir, string.Format("App_Templates\\Skin_{0}\\Topics\\{1}.{2}.html", SkinID.ToString(), m_TopicName, m_LocaleSetting)), //Skin specific, localized HTML Path.Combine(appdir, String.Format("App_Templates\\Skin_{0}\\Topics\\{1}.html", SkinID.ToString(), m_TopicName)), //Skin specific, unlocalized HTML Path.Combine(appdir, string.Format("Topics\\{0}.{1}.html", m_TopicName, m_LocaleSetting)), //Root folder, localized HTML Path.Combine(appdir, string.Format("Topics\\{0}.html", m_TopicName)) //Root folder, unlocalized HTML }; foreach (string fileNametoCheck in possibleFileNames) { m_FN = CommonLogic.SafeMapPath(fileNametoCheck); if (CommonLogic.FileExists(m_FN)) { break; } } if (m_FN.Length != 0 && CommonLogic.FileExists(m_FN)) { m_Contents = CommonLogic.ReadFile(m_FN, true); m_ContentsRAW = m_Contents; m_SectionTitle = CommonLogic.ExtractToken(m_ContentsRAW, "<title>", "</title>"); m_Contents = CommonLogic.ExtractBody(m_Contents); // try old token formats first, for backwards compatibility: m_SETitle = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGETITLE>", "</PAGETITLE>"); m_SEKeywords = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGEKEYWORDS>", "</PAGEKEYWORDS>"); m_SEDescription = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGEDESCRIPTION>", "</PAGEDESCRIPTION>"); m_SENoScript = CommonLogic.ExtractToken(m_ContentsRAW, "<NOSCRIPT>", "</NOSCRIPT>"); // if regular HTML tokens found, try to parse it out in regular HTML syntax meta tag format and they take precedence over the old tokens (above): String t = Regex.Match(m_ContentsRAW, @"(?<=<title[^\>]*>).*?(?=</title>)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture).Value; if (t.Length != 0) { m_SETitle = t; } String MK = String.Empty; String MV = String.Empty; foreach (Match metamatch in Regex.Matches(m_ContentsRAW, @"<meta\s*(?:(?:\b(\w|-)+\b\s*(?:=\s*(?:""[^""]*""|'[^']*'|[^""'<> ]+)\s*)?)*)/?\s*>", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)) { MK = String.Empty; MV = String.Empty; // Loop through the attribute/value pairs inside the tag foreach (Match submatch in Regex.Matches(metamatch.Value.ToString(), @"(?<name>\b(\w|-)+\b)\s*=\s*(""(?<value>[^""]*)""|'(?<value>[^']*)'|(?<value>[^""'<> ]+)\s*)+", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)) { if ("http-equiv".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { MV = submatch.Groups[2].ToString(); } if (("name".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) && MK == String.Empty) // if it's already set, HTTP-EQUIV takes precedence { MV = submatch.Groups[2].ToString(); } if ("content".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { MV = submatch.Groups[2].ToString(); } } switch (MK.ToLowerInvariant()) { case "description": m_SEDescription = MV; break; case "keywords": case "keyword": m_SEKeywords = MV; break; } } } if (m_CommandHashtable.Contains("contentsbgcolor")) { m_ContentsBGColor = m_CommandHashtable["contentsbgcolor"].ToString(); } if (m_CommandHashtable.Contains("pagebgcolor")) { m_PageBGColor = m_CommandHashtable["pagebgcolor"].ToString(); } if (m_CommandHashtable.Contains("graphicscolor")) { m_GraphicsColor = m_CommandHashtable["graphicscolor"].ToString(); } } if (m_SETitle.Length == 0) { m_SETitle = m_SectionTitle; } if (AppLogic.ReplaceImageURLFromAssetMgr) { while (m_Contents.IndexOf("../images") != -1) { m_Contents = m_Contents.Replace("../images", "images"); } } if (m_UseParser != null) { m_Contents = m_UseParser.ReplaceTokens(m_Contents); } else { if (SkinID > 0) { m_Contents = m_Contents.Replace("(!SKINID!)", SkinID.ToString()); } } }
// Find the specified topic content. note, we try to find content even if it doesn't exactly match the input specs, by doing an ordered lookup in various areas // we want to show SOME topic content if it is at all possible, even if the language is not right, etc... // Note: site id only used for file based topic _contents // Search Order is (yes, other orderings are possible, but this is the one we chose, where ANY db topic match overrides file content): // the other option would be to match on locales in the order of DB/File (Customer Locale), DB/File (Store Locale), DB/File (Null locale) // DB (customer locale) // DB (store locale) // DB (null locale) // File (customer locale) // File (store locale) // File (null locale) void LoadFromDB(int StoreID) { m_FromDB = false; m_DisplayOrder = 1; m_SkinID = ThisCustomer.SkinID; m_StoreID = StoreID; m_LocaleSetting = CommonLogic.IIF(m_LocaleSetting.Length > 0, m_LocaleSetting, Localization.GetDefaultLocale()); m_Contents = String.Empty; m_ContentsRAW = String.Empty; m_SectionTitle = String.Empty; m_RequiresDisclaimer = false; m_ShowInSiteMap = true; m_Password = String.Empty; m_SETitle = m_TopicName; m_SEKeywords = String.Empty; m_SEDescription = String.Empty; m_FN = String.Empty; m_MasterLocale = m_LocaleSetting; m_HasChildren = false; if (m_TopicID == 0) { m_TopicID = Topic.GetTopicID(m_TopicName, CommonLogic.IIF(AppLogic.IsAdminSite, m_MasterLocale, m_LocaleSetting), AppLogic.StoreID()); } if (m_TopicID != 0) { var sql = string.Format("SELECT * from Topic with (NOLOCK) where Deleted=0 and Published=1 and TopicID={0} and (SkinID IS NULL or SkinID=0 or SkinID={1}) order by DisplayOrder, Name ASC", m_TopicID.ToString(), m_SkinID.ToString()); using (var con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (var rs = DB.GetRS(sql, con)) { if (rs.Read()) { m_FromDB = true; m_TopicID = DB.RSFieldInt(rs, "TopicID"); m_TopicName = DB.RSField(rs, "Name"); m_Contents = DB.RSFieldByLocale(rs, "Description", m_LocaleSetting); m_Password = DB.RSField(rs, "Password"); m_RequiresDisclaimer = DB.RSFieldBool(rs, "RequiresDisclaimer"); m_DisplayOrder = DB.RSFieldInt(rs, "DisplayOrder"); m_ShowInSiteMap = DB.RSFieldBool(rs, "ShowInSiteMap"); m_SkinID = DB.RSFieldInt(rs, "SkinID"); if (m_Contents.Length != 0) { m_ContentsRAW = m_Contents; m_SectionTitle = DB.RSFieldByLocale(rs, "Title", m_LocaleSetting); m_SETitle = DB.RSFieldByLocale(rs, "SETitle", m_LocaleSetting); m_SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", m_LocaleSetting); m_SEDescription = DB.RSFieldByLocale(rs, "SEDescription", m_LocaleSetting); } else // nothing found, try master locale: { m_Contents = DB.RSFieldByLocale(rs, "Description", m_MasterLocale); m_ContentsRAW = m_Contents; m_SectionTitle = DB.RSFieldByLocale(rs, "Title", m_MasterLocale); m_SETitle = DB.RSFieldByLocale(rs, "SETitle", m_MasterLocale); m_SEKeywords = DB.RSFieldByLocale(rs, "SEKeywords", m_MasterLocale); m_SEDescription = DB.RSFieldByLocale(rs, "SEDescription", m_MasterLocale); } // if an html tag is present, extract just the body of the content if (m_Contents.IndexOf("<html", StringComparison.InvariantCultureIgnoreCase) != -1) { m_Contents = CommonLogic.ExtractBody(m_ContentsRAW); } } } } } if (!m_FromDB) // did not find anything in db, try file based topic content (in skins folder as topicname.htm) { string appdir = HttpContext.Current.Request.PhysicalApplicationPath; List <string> possibleFileNames = new List <string> { Path.Combine(appdir, string.Format("Skins\\{0}\\Topics\\{1}.{2}.htm", SkinProvider.GetSkinNameById(SkinID), m_TopicName, m_LocaleSetting)), //Skin specific, localized Path.Combine(appdir, String.Format("Skins\\{0}\\Topics\\{1}.htm", SkinProvider.GetSkinNameById(SkinID), m_TopicName)), //Skin specific, unlocalized Path.Combine(appdir, string.Format("Topics\\{0}.{1}.htm", m_TopicName, m_LocaleSetting)), //Root folder, localized Path.Combine(appdir, string.Format("Topics\\{0}.htm", m_TopicName)), //Root folder, unlocalized Path.Combine(appdir, string.Format("Skins\\{0}\\Topics\\{1}.{2}.html", SkinProvider.GetSkinNameById(SkinID), m_TopicName, m_LocaleSetting)), //Skin specific, localized HTML Path.Combine(appdir, String.Format("Skins\\{0}\\Topics\\{1}.html", SkinProvider.GetSkinNameById(SkinID), m_TopicName)), //Skin specific, unlocalized HTML Path.Combine(appdir, string.Format("Topics\\{0}.{1}.html", m_TopicName, m_LocaleSetting)), //Root folder, localized HTML Path.Combine(appdir, string.Format("Topics\\{0}.html", m_TopicName)) //Root folder, unlocalized HTML }; foreach (string fileNametoCheck in possibleFileNames) { m_FN = CommonLogic.SafeMapPath(fileNametoCheck); if (CommonLogic.FileExists(m_FN)) { break; } } if (m_FN.Length != 0 && CommonLogic.FileExists(m_FN)) { m_Contents = CommonLogic.ReadFile(m_FN, true); m_ContentsRAW = m_Contents; m_SectionTitle = CommonLogic.ExtractToken(m_ContentsRAW, "<title>", "</title>"); m_Contents = CommonLogic.ExtractBody(m_Contents); // Throw a helpful error if the topic file is not formatted properly if (m_Contents.Length == 0 && m_ContentsRAW.Length > 0) { throw new Exception(@"Make sure to format your topic file like a normal html document. For Example: <!DOCTYPE html> <html> <head> <title>Your title</title> </head> <body> Your content here </body> </html>" ); } // try old token formats first, for backwards compatibility: m_SETitle = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGETITLE>", "</PAGETITLE>"); m_SEKeywords = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGEKEYWORDS>", "</PAGEKEYWORDS>"); m_SEDescription = CommonLogic.ExtractToken(m_ContentsRAW, "<PAGEDESCRIPTION>", "</PAGEDESCRIPTION>"); // if regular HTML tokens found, try to parse it out in regular HTML syntax meta tag format and they take precedence over the old tokens (above): String t = Regex.Match(m_ContentsRAW, @"(?<=<title[^\>]*>).*?(?=</title>)", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture).Value; if (t.Length != 0) { m_SETitle = t; } String MK = String.Empty; String MV = String.Empty; foreach (Match metamatch in Regex.Matches(m_ContentsRAW, @"<meta\s*(?:(?:\b(\w|-)+\b\s*(?:=\s*(?:""[^""]*""|'[^']*'|[^""'<> ]+)\s*)?)*)/?\s*>", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)) { MK = String.Empty; MV = String.Empty; // Loop through the attribute/value pairs inside the tag foreach (Match submatch in Regex.Matches(metamatch.Value.ToString(), @"(?<name>\b(\w|-)+\b)\s*=\s*(""(?<value>[^""]*)""|'(?<value>[^']*)'|(?<value>[^""'<> ]+)\s*)+", RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture)) { if ("http-equiv".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { MV = submatch.Groups[2].ToString(); } if (("name".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) && MK == String.Empty) // if it's already set, HTTP-EQUIV takes precedence { MV = submatch.Groups[2].ToString(); } if ("content".Equals(submatch.Groups[1].ToString(), StringComparison.InvariantCultureIgnoreCase)) { MV = submatch.Groups[2].ToString(); } } switch (MK.ToLowerInvariant()) { case "description": m_SEDescription = MV; break; case "keywords": case "keyword": m_SEKeywords = MV; break; } } } } if (m_SETitle.Length == 0) { m_SETitle = m_SectionTitle; } if (AppLogic.ReplaceImageURLFromAssetMgr) { while (m_Contents.IndexOf("../images") != -1) { m_Contents = m_Contents.Replace("../images", "images"); } } if (m_UseParser != null) { m_Contents = m_UseParser.ReplaceTokens(m_Contents); } else { if (SkinID > 0) { m_Contents = m_Contents.Replace("(!SKINID!)", SkinID.ToString()); } } }