public static string AppRelativeSkinUrl(this UrlHelper url, string path) { var skinId = (int)url.RequestContext.RouteData.Values[RouteDataKeys.SkinId]; var skinProvider = new SkinProvider(); var baseSkinUrl = string.Format("~/skins/{0}/", skinProvider.GetSkinNameById(skinId)); var virtualPath = VirtualPathUtility.Combine(baseSkinUrl, path); return(virtualPath); }
static public string BuildStarImages(decimal rating, int skinId) { var starTypes = new[] { rating < 0.25M ? StarType.Empty : rating >= 0.25M && rating < 0.75M ? StarType.Half : StarType.Full, rating < 1.25M ? StarType.Empty : rating >= 1.25M && rating < 1.75M ? StarType.Half : StarType.Full, rating < 2.25M ? StarType.Empty : rating >= 2.25M && rating < 2.75M ? StarType.Half : StarType.Full, rating < 3.25M ? StarType.Empty : rating >= 3.25M && rating < 3.75M ? StarType.Half : StarType.Full, rating < 4.25M ? StarType.Empty : rating >= 4.25M && rating < 4.75M ? StarType.Half : StarType.Full, }; var skinName = SkinProvider.GetSkinNameById(skinId); return(string.Join("", starTypes.Select((star, idx) => string.Format( "<img class='ratings-star-{0}-{1}' src='{2}' />", idx, star, AppLogic.LocateImageURL(string.Format("~/Skins/{0}/images/{1}", skinName, StarImage(star))))))); }
string GetXmlPackagePath(XmlPackageLocation location, int?skinId) { switch (location) { case XmlPackageLocation.Root: return("~/XmlPackages/"); case XmlPackageLocation.Skin: if (skinId != null) { return(String.Format("~/Skins/{0}/XmlPackages/", SkinProvider.GetSkinNameById(skinId.Value))); } else { throw new InvalidOperationException("A skinId must be provided when getting the location of a skin"); } case XmlPackageLocation.Admin: return(String.Format("~/{0}/XmlPackages/", AppLogic.GetAdminDir())); default: throw new NotSupportedException(String.Format("The XmlPackageLocation {0} is not supported", location)); } }
string GetImageUrl(string size, string identifier, int index) { var locale = HttpContext.Current.GetCustomer().LocaleSetting; var imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}.gif", identifier, index), "product", size, locale); if (!CommonLogic.FileExists(imageUrl)) { imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}_.gif", identifier, index), "product", size, locale); } if (!CommonLogic.FileExists(imageUrl)) { imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}.jpg", identifier, index), "product", size, locale); } if (!CommonLogic.FileExists(imageUrl)) { imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}_.jpg", identifier, index), "product", size, locale); } if (!CommonLogic.FileExists(imageUrl)) { imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}.png", identifier, index), "product", size, locale); } if (!CommonLogic.FileExists(imageUrl)) { imageUrl = AppLogic.LocateImageURL(string.Format("{0}_{1}_.png", identifier, index), "product", size, locale); } if (!CommonLogic.FileExists(imageUrl)) { if (StringComparer.OrdinalIgnoreCase.Equals(size, nameof(ProductImageSize.large)) || StringComparer.OrdinalIgnoreCase.Equals(size, nameof(ProductImageSize.medium))) { imageUrl = AppLogic.LocateImageURL(string.Format("skins/{0}/images/nopicture.gif", SkinProvider.GetSkinNameById(SkinId))); } else { imageUrl = AppLogic.LocateImageURL(string.Format("skins/{0}/images/nopicture{1}.gif", SkinProvider.GetSkinNameById(SkinId), size)); } } return(imageUrl); }
// 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()); } } }