예제 #1
0
        private bool FindIDFile()
        {
            if (m_ID != 0)
            {
                // try to locate by id.htm
                m_URL = Path.Combine(m_Root, m_ID.ToString() + "." + m_LocaleSetting + ".htm");
                m_FN  = CommonLogic.SafeMapPath(m_URL);
                if (CommonLogic.FileExists(m_FN))
                {
                    return(true);
                }

                // try default store locale path:
                m_URL = Path.Combine(m_Root, m_ID.ToString() + "." + Localization.GetDefaultLocale() + ".htm");
                m_FN  = CommonLogic.SafeMapPath(m_URL);
                if (CommonLogic.FileExists(m_FN))
                {
                    return(true);
                }

                // try skin (NULL) path:
                m_URL = Path.Combine(m_Root, m_ID.ToString() + ".htm");
                m_FN  = CommonLogic.SafeMapPath(m_URL);
                if (CommonLogic.FileExists(m_FN))
                {
                    return(true);
                }
            }
            m_URL = String.Empty;
            m_FN  = String.Empty;
            return(false);
        }
예제 #2
0
        private bool FindNameFile()
        {
            try
            {
                m_Name = AppLogic.GetEntityName(m_DescriptionType, m_ID, m_LocaleSetting);

                if (m_Name.Length != 0)
                {
                    // try specified locale
                    m_URL = Path.Combine(m_Root, m_Name + "." + m_LocaleSetting + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }

                    // try default store locale path:
                    m_URL = Path.Combine(m_Root, m_Name + "." + Localization.GetDefaultLocale() + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }

                    // try base (NULL) path:
                    m_URL = Path.Combine(m_Root, m_Name + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }
                }
                m_URL = String.Empty;
                m_FN  = String.Empty;
                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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());
            }
        }
        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);
        }
예제 #6
0
        private bool FindSKUFile()
        {
            try
            {
                if (m_ProductSKU.Length != 0)
                {
                    // try specified locale first
                    m_URL = Path.Combine(m_Root, m_ProductSKU + "." + m_LocaleSetting + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }

                    // try default store locale path:
                    m_URL = Path.Combine(m_Root, m_ProductSKU + "." + Localization.GetDefaultLocale() + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }

                    // try base (NULL) path:
                    m_URL = Path.Combine(m_Root, m_ProductSKU + ".htm");
                    m_FN  = CommonLogic.SafeMapPath(m_URL);
                    if (CommonLogic.FileExists(m_FN))
                    {
                        return(true);
                    }
                }
                m_URL = String.Empty;
                m_FN  = String.Empty;
                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #7
0
        public void LoadFromDB()
        {
            string suffix   = "_" + m_ProductID.ToString();
            string pvsuffix = "_" + m_ProductID.ToString() + "_" + m_VariantID.ToString();

            m_ImageNumbersSplit = m_ImageNumbers.Split(',');
            bool m_WatermarksEnabled = AppLogic.AppConfigBool("Watermark.Enabled");


            m_ColorsSplit = new String[1] {
                ""
            };
            if (m_Colors == String.Empty)
            {
                using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                {
                    dbconn.Open();
                    using (IDataReader rs = DB.GetRS("select Colors from productvariant   with (NOLOCK)  where VariantID=" + m_VariantID.ToString(), dbconn))
                    {
                        if (rs.Read())
                        {
                            m_Colors = DB.RSFieldByLocale(rs, "Colors", Localization.GetDefaultLocale());                             // remember to add "empty" color to front, for no color selected
                            if (m_Colors.Length != 0)
                            {
                                m_ColorsSplit = ("," + m_Colors).Split(',');
                            }
                        }
                    }
                }
            }
            else
            {
                m_ColorsSplit = ("," + m_Colors).Split(',');
            }
            if (m_Colors.Length != 0)
            {
                for (int i = m_ColorsSplit.GetLowerBound(0); i <= m_ColorsSplit.GetUpperBound(0); i++)
                {
                    String s2 = AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]);
                    m_ColorsSplit[i] = CommonLogic.MakeSafeFilesystemName(s2);
                }
            }

            if (AppLogic.AppConfigBool("MultiImage.UseProductIconPics"))
            {
                m_ImageUrlsicon = new String[m_ImageNumbersSplit.Length, m_ColorsSplit.Length];
                for (int x = m_ImageNumbersSplit.GetLowerBound(0); x <= m_ImageNumbersSplit.GetUpperBound(0); x++)
                {
                    int ImgIdx = Localization.ParseUSInt(m_ImageNumbersSplit[x]);
                    for (int i = m_ColorsSplit.GetLowerBound(0); i <= m_ColorsSplit.GetUpperBound(0); i++)
                    {
                        String Url = string.Empty;
                        if (m_ProductSKU == string.Empty)
                        {
                            Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "icon");
                        }
                        else
                        {
                            Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_ProductSKU, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "icon");
                        }
                        if (m_WatermarksEnabled && Url.Length != 0 && Url.IndexOf("nopicture") == -1)
                        {
                            if (Url.StartsWith("/"))
                            {
                                m_ImageUrlsicon[x, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length);
                            }
                            else
                            {
                                m_ImageUrlsicon[x, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length - 1);
                            }

                            if (m_ImageUrlsicon[x, i].StartsWith("/"))
                            {
                                m_ImageUrlsicon[x, i] = m_ImageUrlsicon[x, i].TrimStart('/');
                            }
                        }
                        else
                        {
                            m_ImageUrlsicon[x, i] = Url;
                        }
                    }
                }
                for (int x = m_ImageNumbersSplit.GetLowerBound(0); x <= m_ImageNumbersSplit.GetUpperBound(0); x++)
                {
                    int ImgIdx = Localization.ParseUSInt(m_ImageNumbersSplit[x]);
                    if (m_ImageUrlsicon[x, 0].IndexOf("nopicture") == -1)
                    {
                        m_MaxImageIndex = ImgIdx;
                    }
                }
            }

            m_ImageUrlsmedium = new String[m_ImageNumbersSplit.Length, m_ColorsSplit.Length];
            for (int j = m_ImageNumbersSplit.GetLowerBound(0); j <= m_ImageNumbersSplit.GetUpperBound(0); j++)
            {
                int ImgIdx = Localization.ParseUSInt(m_ImageNumbersSplit[j]);
                for (int i = m_ColorsSplit.GetLowerBound(0); i <= m_ColorsSplit.GetUpperBound(0); i++)
                {
                    String Url = string.Empty;
                    if (m_ProductSKU == string.Empty)
                    {
                        Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "medium");
                    }
                    else
                    {
                        Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_ProductSKU, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "medium");
                    }
                    if (m_WatermarksEnabled && Url.Length != 0 && Url.IndexOf("nopicture") == -1)
                    {
                        if (Url.StartsWith("/"))
                        {
                            m_ImageUrlsmedium[j, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length);
                        }
                        else
                        {
                            m_ImageUrlsmedium[j, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length - 1);
                        }

                        if (m_ImageUrlsmedium[j, i].StartsWith("/"))
                        {
                            m_ImageUrlsmedium[j, i] = m_ImageUrlsmedium[j, i].TrimStart('/');
                        }
                    }
                    else
                    {
                        m_ImageUrlsmedium[j, i] = Url;
                    }
                }
            }
            for (int j = m_ImageNumbersSplit.GetLowerBound(0); j <= m_ImageNumbersSplit.GetUpperBound(0); j++)
            {
                int ImgIdx = Localization.ParseUSInt(m_ImageNumbersSplit[j]);
                if (m_ImageUrlsmedium[j, 0].IndexOf("nopicture") == -1)
                {
                    m_MaxImageIndex = ImgIdx;
                }
            }

            m_ImageUrlslarge = new String[m_ImageNumbersSplit.Length, m_ColorsSplit.Length];
            for (int j = m_ImageNumbersSplit.GetLowerBound(0); j <= m_ImageNumbersSplit.GetUpperBound(0); j++)
            {
                int ImgIdx = Localization.ParseUSInt(m_ImageNumbersSplit[j]);
                for (int i = m_ColorsSplit.GetLowerBound(0); i <= m_ColorsSplit.GetUpperBound(0); i++)
                {
                    String Url = string.Empty;
                    if (m_ProductSKU == string.Empty)
                    {
                        Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "large");
                    }
                    else
                    {
                        Url = AppLogic.LookupProductImageByNumberAndColor(m_ProductID, m_SkinID, m_ProductSKU, m_LocaleSetting, ImgIdx, AppLogic.RemoveAttributePriceModifier(m_ColorsSplit[i]), "large");
                    }

                    if (m_WatermarksEnabled && Url.Length != 0 && Url.IndexOf("nopicture") == -1)
                    {
                        if (Url.StartsWith("/"))
                        {
                            m_ImageUrlslarge[j, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length);
                        }
                        else
                        {
                            m_ImageUrlslarge[j, i] = Url.Substring(HttpContext.Current.Request.ApplicationPath.Length - 1);
                        }

                        if (m_ImageUrlslarge[j, i].StartsWith("/"))
                        {
                            m_ImageUrlslarge[j, i] = m_ImageUrlslarge[j, i].TrimStart('/');
                        }

                        m_HasSomeLarge = true;
                    }
                    else if (Url.Length == 0 || Url.IndexOf("nopicture") != -1)
                    {
                        m_ImageUrlslarge[j, i] = String.Empty;
                    }
                    else
                    {
                        m_HasSomeLarge         = true;
                        m_ImageUrlslarge[j, i] = Url;
                    }
                }
            }

            if (!IsEmpty())
            {
                bool AttemptZoomify = AppLogic.AppConfigBool("Zoomify.Active") && (AppLogic.AppConfigBool("Zoomify.GalleryMedium") || AppLogic.AppConfigBool("Zoomify.ProductMedium"));
                bool GalleryZoomify = AttemptZoomify && AppLogic.AppConfigBool("Zoomify.GalleryMedium");

                StringBuilder tmpS = new StringBuilder(4096);
                tmpS.Append("<script type=\"text/javascript\">\n");
                tmpS.Append("var ProductPicIndex" + suffix + " = 1;\n");
                tmpS.Append("var ProductColor" + suffix + " = '';\n");
                tmpS.Append("var boardpics" + suffix + " = new Array();\n");
                tmpS.Append("var boardpicslg" + suffix + " = new Array();\n");
                tmpS.Append("var boardpicslgwidth" + suffix + " = new Array();\n");
                tmpS.Append("var boardpicslgheight" + suffix + " = new Array();\n");
                if (AttemptZoomify)
                {
                    tmpS.Append("var boardpicsZ" + suffix + " = new Array();\n");
                }
                for (int i = 1; i <= m_MaxImageIndex; i++)
                {
                    foreach (String c in m_ColorsSplit)
                    {
                        String MdUrl            = ImageUrl(i, c, "medium").ToLowerInvariant();
                        String MdWatermarkedUrl = MdUrl;

                        if (m_WatermarksEnabled)
                        {
                            if (MdUrl.Length > 0)
                            {
                                string[] split    = MdUrl.Split('/');
                                string   lastPart = split.Last();
                                MdUrl = AppLogic.LocateImageURL(lastPart, "PRODUCT", "medium", "");
                            }
                        }

                        tmpS.Append("boardpics" + suffix + "['" + i.ToString() + "," + c + "'] = '" + MdWatermarkedUrl + "';\n");

                        String LgUrl            = ImageUrl(i, c, "large").ToLowerInvariant();
                        String LgWatermarkedUrl = LgUrl;

                        if (m_WatermarksEnabled)
                        {
                            if (LgUrl.Length > 0)
                            {
                                string[] split    = LgUrl.Split('/');
                                string   lastPart = split.Last();
                                LgUrl = AppLogic.LocateImageURL(lastPart, "PRODUCT", "large", "");
                            }
                        }

                        tmpS.Append("boardpicslg" + suffix + "['" + i.ToString() + "," + c + "'] = '" + LgWatermarkedUrl + "';\n");

                        if (LgUrl.Length > 0)
                        {
                            System.Drawing.Size lgsz = CommonLogic.GetImagePixelSize(LgUrl);
                            tmpS.Append("boardpicslgwidth" + suffix + "['" + i.ToString() + "," + c + "'] = '" + lgsz.Width.ToString() + "';\n");
                            tmpS.Append("boardpicslgheight" + suffix + "['" + i.ToString() + "," + c + "'] = '" + lgsz.Height.ToString() + "';\n");
                        }

                        if (AttemptZoomify)
                        {
                            String ZMdUrl = string.Empty;

                            // Yes we use the large url here, because the Zoomify data is always in Large
                            if (LgUrl.Length > 0)
                            {
                                ZMdUrl = LgUrl.Remove(LgUrl.Length - 4);                                 // remove extension
                            }

                            if (GalleryZoomify && CommonLogic.FileExists(CommonLogic.SafeMapPath(LgUrl)))
                            {
                                tmpS.Append("boardpicsZ" + suffix + "['" + i.ToString() + "," + c + "'] = '" + AppLogic.RunXmlPackage("Zoomify.Medium", null, null, m_SkinID, "", "ImagePath=" + ZMdUrl + "&AltSrc=" + LgUrl, false, false).Replace("\r\n", " ").Replace("\r", " ").Replace("\n", " ").Replace("'", "\\'") + "';\n");                                 // the Replace's are to make the xmlpackage output consumable by javascript
                            }
                            else
                            {
                                tmpS.Append("boardpicsZ" + suffix + "['" + i.ToString() + "," + c + "'] = '';\n");
                            }
                        }
                    }
                }

                if (AttemptZoomify)
                {
                    tmpS.Append("function changeContent(markup)\n");
                    tmpS.Append("{\n");
                    tmpS.Append("	id='divProductPicZ"+ m_ProductID.ToString() + "';\n");
                    tmpS.Append("	if (document.getElementById || document.all)\n");
                    tmpS.Append("	{\n");
                    tmpS.Append("		var el = document.getElementById? document.getElementById(id): document.all[id];\n");
                    tmpS.Append("		if (el && typeof el.innerHTML != \"undefined\") el.innerHTML = markup;\n");
                    tmpS.Append("	}\n");
                    tmpS.Append("}\n");
                }

                tmpS.Append("function changecolorimg" + suffix + "()\n");
                tmpS.Append("{\n");
                tmpS.Append("	var scidx = ProductPicIndex"+ suffix + " + ',' + ProductColor" + suffix + ".toLowerCase();\n");

                if (AttemptZoomify)
                {
                    tmpS.Append("if (boardpicsZ" + suffix + "[scidx]!='') {\n");
                    tmpS.Append("  divProductPicZ" + m_ProductID.ToString() + ".style.display='inline';\n");
                    tmpS.Append("  divProductPic" + m_ProductID.ToString() + ".style.display='none';\n");
                    tmpS.Append("  changeContent(boardpicsZ" + suffix + "[scidx]); }\n");
                    tmpS.Append("else {\n");
                    tmpS.Append("  divProductPicZ" + m_ProductID.ToString() + ".style.display='none';\n");
                    tmpS.Append("  divProductPic" + m_ProductID.ToString() + ".style.display='inline';\n");
                    tmpS.Append("  document.ProductPic" + m_ProductID.ToString() + ".src=boardpics" + suffix + "[scidx]; }\n");
                }
                else
                {
                    tmpS.Append("	document.ProductPic"+ m_ProductID.ToString() + ".src=boardpics" + suffix + "[scidx];\n");
                }

                tmpS.Append("}\n");

                tmpS.Append("function popuplarge" + suffix + "()\n");
                tmpS.Append("{\n");
                tmpS.Append("	var scidx = ProductPicIndex"+ suffix + " + ',' + ProductColor" + suffix + ".toLowerCase();\n");
                tmpS.Append("	var LargeSrc = boardpicslg"+ suffix + "[scidx];\n");

                if (m_WatermarksEnabled)
                {
                    tmpS.AppendFormat("	var imageName = LargeSrc.split(\"/\").pop(-1);{0}", Environment.NewLine);
                    tmpS.AppendFormat("	LargeSrc = 'watermark.axd?size=large&imgurl=images/product/large/' + imageName;{0}", Environment.NewLine);
                }
                tmpS.Append("if(boardpicslg" + suffix + "[scidx] != '')\n");
                tmpS.Append("{\n");
                tmpS.Append("	window.open('popup.aspx?src=' + LargeSrc,'LargerImage"+ CommonLogic.GetRandomNumber(1, 100000) + "','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + CommonLogic.IIF(AppLogic.AppConfigBool("ResizableLargeImagePopup"), "yes", "no") + ",resizable=" + CommonLogic.IIF(AppLogic.AppConfigBool("ResizableLargeImagePopup"), "yes", "no") + ",copyhistory=no,width=' + boardpicslgwidth" + suffix + "[scidx] + ',height=' + boardpicslgheight" + suffix + "[scidx] + ',left=0,top=0');\n");
                tmpS.Append("}\n");
                tmpS.Append("else\n");
                tmpS.Append("{\n");
                tmpS.Append("	alert('There is no large image available for this picture');\n");
                tmpS.Append("}\n");
                tmpS.Append("}\n");

                tmpS.Append("function setcolorpicidx" + suffix + "(idx)\n");
                tmpS.Append("{\n");
                tmpS.Append("	ProductPicIndex"+ suffix + " = idx;\n");
                tmpS.Append("	changecolorimg"+ suffix + "();\n");
                tmpS.Append("}\n");

                tmpS.Append("function setActive(element)\n");
                tmpS.Append("{\n");
                tmpS.Append("	adnsf$('li.page-link').removeClass('active');\n");
                tmpS.Append("	adnsf$(element).parent().addClass('active');\n");
                tmpS.Append("}\n");

                tmpS.Append("function cleansizecoloroption" + suffix + "(theVal)\n");
                tmpS.Append("{\n");
                tmpS.Append("   if(theVal.indexOf('[') != -1){theVal = theVal.substring(0, theVal.indexOf('['))}");
                tmpS.Append("	theVal = theVal.replace(/[\\W]/g,\"\");\n");
                tmpS.Append("	theVal = theVal.toLowerCase();\n");
                tmpS.Append("	return theVal;\n");
                tmpS.Append("}\n");

                tmpS.Append("function setcolorpic" + suffix + "(color)\n");
                tmpS.Append("{\n");

                tmpS.Append("	while(color != unescape(color))\n");
                tmpS.Append("	{\n");
                tmpS.Append("		color = unescape(color);\n");
                tmpS.Append("	}\n");

                tmpS.Append("	if(color == '-,-' || color == '-')\n");
                tmpS.Append("	{\n");
                tmpS.Append("		color = '';\n");
                tmpS.Append("	}\n");

                tmpS.Append("	if(color != '' && color.indexOf(',') != -1)\n");
                tmpS.Append("	{\n");

                tmpS.Append("		color = color.substring(0,color.indexOf(',')).replace(new RegExp(\"'\", 'gi'), '');\n");                     // remove sku from color select value

                tmpS.Append("	}\n");
                tmpS.Append("	if(color != '' && color.indexOf('[') != -1)\n");
                tmpS.Append("	{\n");

                tmpS.Append("	    color = color.substring(0,color.indexOf('[')).replace(new RegExp(\"'\", 'gi'), '');\n");
                tmpS.Append("		color = color.replace(/[\\s]+$/g,\"\");\n");

                tmpS.Append("	}\n");
                tmpS.Append("	ProductColor"+ suffix + " = cleansizecoloroption" + suffix + "(color);\n");

                tmpS.Append("	changecolorimg"+ suffix + "();\n");
                tmpS.Append("	setcolorlisttoactiveitem"+ suffix + "(color);\n");
                tmpS.Append("	return (true);\n");
                tmpS.Append("}\n");

                // this one (without suffix) added back for backwards compatibility with older existing product data, where
                // the swatch map called to this js routine directly
                tmpS.Append("function setcolorpic(color)\n");
                tmpS.Append("{\n");

                tmpS.Append("	if(color == '-,-' || color == '-')\n");
                tmpS.Append("	{\n");
                tmpS.Append("		color = '';\n");
                tmpS.Append("	}\n");

                tmpS.Append("	if(color != '' && color.indexOf(',') != -1)\n");
                tmpS.Append("	{\n");

                tmpS.Append("		color = color.substring(0,color.indexOf(',')).replace(new RegExp(\"'\", 'gi'), '');\n");                     // remove sku from color select value

                tmpS.Append("	}\n");
                tmpS.Append("	if(color != '' && color.indexOf('[') != -1)\n");
                tmpS.Append("	{\n");

                tmpS.Append("	    color = color.substring(0,color.indexOf('[')).replace(new RegExp(\"'\", 'gi'), '');\n");
                tmpS.Append("		color = color.replace(/[\\s]+$/g,\"\");\n");

                tmpS.Append("	}\n");
                tmpS.Append("	ProductColor"+ suffix + " = cleansizecoloroption" + suffix + "(color);\n");

                tmpS.Append("	changecolorimg"+ suffix + "();\n");
                tmpS.Append("	setcolorlisttoactiveitem"+ suffix + "(color.toLowerCase());\n");
                tmpS.Append("	return (true);\n");
                tmpS.Append("}\n");

                tmpS.Append("function setcolorlisttoactiveitem" + suffix + "(color)\n");
                tmpS.Append("{\n");

                tmpS.Append("var lst = document.getElementById('Color" + pvsuffix + "');\n");

                tmpS.Append("var matchColor = cleansizecoloroption" + suffix + "(color);\n");

                tmpS.Append("for (var i=0; i < lst.length; i++)\n");
                tmpS.Append("   {\n");

                tmpS.Append("var value = lst[i].value;\n");
                tmpS.Append("var arrayValue = value.split(',');\n");
                tmpS.Append("var lstColor = cleansizecoloroption" + suffix + "(arrayValue[0]);\n");

                //tmpS.Append("	var lstColor = cleansizecoloroption" + suffix + "(lst[i].value);\n");

                tmpS.Append("   if (lstColor == matchColor)\n");
                tmpS.Append("      {\n");
                tmpS.Append("		lst.selectedIndex = i;\n");
                tmpS.Append("		return (true);\n");
                tmpS.Append("      }\n");
                tmpS.Append("   }\n");

                tmpS.Append("return (true);\n");
                tmpS.Append("}\n");

                tmpS.Append("</script>\n");
                m_ImgDHTML = tmpS.ToString();

                bool useMicros = AppLogic.AppConfigBool("UseImagesForMultiNav");

                bool microAction = CommonLogic.IIF(AppLogic.AppConfigBool("UseRolloverForMultiNav"), true, false);

                if (m_MaxImageIndex > 1)
                {
                    tmpS.Remove(0, tmpS.Length);

                    if (!AppLogic.AppConfigBool("MultiImage.UseProductIconPics") && !useMicros)
                    {
                        tmpS.Append("<ul class=\"pagination image-paging\">");
                        for (int i = 1; i <= m_MaxImageIndex; i++)
                        {
                            if (i == 1)
                            {
                                tmpS.Append("<li class=\"page-link active\">");
                            }
                            else
                            {
                                tmpS.Append("<li class=\"page-link\">");
                            }

                            tmpS.Append(string.Format("<a href=\"javascript:void(0);\" onclick='setcolorpicidx{0}({1});setActive(this);' class=\"page-number\">{1}</a>", suffix, i));
                            tmpS.Append("</li>");
                        }
                        tmpS.Append("</ul>");
                    }
                    else
                    {
                        tmpS.Append("<div class=\"product-gallery-items\">");
                        for (int i = 1; i <= m_MaxImageIndex; i++)
                        {
                            tmpS.Append("<div class=\"product-gallery-item\">");
                            tmpS.Append("	<div class=\"gallery-item-inner\">");
                            if (AppLogic.AppConfigBool("MultiImage.UseProductIconPics"))
                            {
                                string strImageTag = "<img class='product-gallery-image' onclick='setcolorpicidx{0}({1});setImageURL(\"{2}\")' alt='Show Picture {1}' src='{2}' border='0' />";
                                tmpS.AppendFormat(strImageTag, new object[] {
                                    suffix,
                                    i,
                                    m_ImageUrlsicon[i - 1, 0].ToString()
                                });
                            }
                            else
                            {
                                // check for different extensions but don't let the non existance leave a gap
                                // or crash because it can't find an image
                                String ImageLoc = String.Empty;
                                if (AppLogic.AppConfigBool("UseSKUForProductImageName"))
                                {
                                    using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
                                    {
                                        dbconn.Open();
                                        using (IDataReader skus = DB.GetRS("SELECT p.SKU FROM Product p  with (NOLOCK)  WHERE p.ProductID=" + m_ProductID.ToString(), dbconn))
                                        {
                                            try
                                            {
                                                String microSKU = String.Empty;
                                                if (skus.Read())
                                                {
                                                    microSKU = DB.RSField(skus, "SKU");
                                                }
                                                ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + ".gif");
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + "_" + ".gif");
                                                }
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + ".jpg");
                                                }
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + "_" + ".jpg");
                                                }
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + ".png");
                                                }
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + microSKU.ToString() + "_" + i.ToString() + "_" + ".png");
                                                }
                                                if (!CommonLogic.FileExists(ImageLoc))
                                                {
                                                    ImageLoc = AppLogic.LocateImageURL("App_Themes/skin_" + m_SkinID + "/images/nopicturemicro.gif");
                                                }
                                            }
                                            catch { }
                                        }
                                    }
                                }
                                else
                                {
                                    ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + ".gif");
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + "_" + ".gif");
                                    }
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + ".jpg");
                                    }
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + "_" + ".jpg");
                                    }
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + ".png");
                                    }
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("images/product/micro/" + m_ProductID.ToString() + "_" + i.ToString() + "_" + ".png");
                                    }
                                    if (!CommonLogic.FileExists(ImageLoc))
                                    {
                                        ImageLoc = AppLogic.LocateImageURL("App_Themes/skin_" + m_SkinID + "/images/nopicturemicro.gif");
                                    }
                                }

                                // if not using rollover to change the images
                                if (!microAction && ImageLoc.Length > 0)
                                {
                                    string strImageTag = string.Format("<img class='product-gallery-image' onclick='setcolorpicidx{0}({1});setImageURL(\"{2}\")' alt='Show Picture {1}' src='{2}' border='0' />",
                                                                       new object[]
                                    {
                                        suffix, i, ImageLoc
                                    });
                                    tmpS.Append(strImageTag);
                                }
                                else if (ImageLoc.Length > 0)
                                {
                                    string strImageTag = string.Format("<img class='product-gallery-image' onMouseOver='setcolorpicidx{0}({1});setImageURL(\"{2}\")' alt='Show Picture {1}' src='{2}' border='0' />",
                                                                       new object[]
                                    {
                                        suffix, i, ImageLoc
                                    });
                                    tmpS.Append(strImageTag);
                                }
                            }
                            tmpS.Append("	</div>");
                            tmpS.Append("</div>");
                        }
                        tmpS.Append("</div>");
                    }

                    m_ImgGalIcons = tmpS.ToString();
                }
            }
        }
예제 #8
0
        static void MakeMicroPic(string fileName, string tempImage, string microParams, string imageSize)
        {
            fileName = fileName.Replace("_.", ".");
            var spltConfig = new Hashtable();

            var microWidth  = AppLogic.AppConfigNativeInt("DefaultWidth_micro");
            var microHeight = AppLogic.AppConfigNativeInt("DefaultHeight_micro");

            var microMime = ".jpg";

            spltConfig = SplitConfig(microParams);

            if (spltConfig.ContainsKey("width"))
            {
                microWidth = int.Parse(spltConfig["width"].ToString());
            }

            if (spltConfig.ContainsKey("height"))
            {
                microHeight = int.Parse(spltConfig["height"].ToString());
            }

            if (spltConfig.ContainsKey("mime"))
            {
                microMime = spltConfig["mime"].ToString();
            }

            if (microHeight < 1)
            {
                microHeight = 40;
            }

            if (microWidth < 1)
            {
                microWidth = 40;
            }

            switch (microMime)
            {
            case "png":
                microMime = ".png";
                break;

            case "jpg":
            default:
                microMime = ".jpg";
                break;
            }

            if (imageSize == "large")
            {
                //check for large creates others and large overwrites others to create the micro image if desired
                var largeCreates    = false;
                var largeOverwrites = false;
                var globalCreate    = (AppLogic.AppConfigBool("LargeCreatesOthers"));
                var globalOverwrite = (AppLogic.AppConfigBool("LargeOverwritesOthers"));
                var localCreate     = string.Empty;
                var localOverwrite  = string.Empty;
                var configValues    = SplitConfig("Micro", "large", microParams);

                if (configValues.ContainsKey("largecreates"))
                {
                    localCreate = configValues["largecreates"].ToString();
                }

                if (configValues.ContainsKey("largeoverwrites"))
                {
                    localOverwrite = configValues["largeoverwrites"].ToString();
                }

                if (localCreate == "false")
                {
                    largeCreates = false;
                }
                else if (localCreate == "true")
                {
                    largeCreates = true;
                }
                else
                {
                    largeCreates = globalCreate;
                }

                if (localOverwrite == "false")
                {
                    largeOverwrites = false;
                }
                else if (localOverwrite == "true")
                {
                    largeOverwrites = true;
                }
                else
                {
                    largeOverwrites = globalOverwrite;
                }

                if (largeCreates)
                {
                    if (largeOverwrites)
                    {
                        try
                        {
                            foreach (string ss in CommonLogic.SupportedImageTypes)
                            {
                                System.IO.File.Delete(AppLogic.GetImagePath("Product", "micro", true) + fileName + ss);
                            }
                        }
                        catch { }

                        var newImageName = AppLogic.GetImagePath("Product", "micro", true) + fileName + microMime;

                        ResizeForMicro(tempImage, newImageName, microWidth, microHeight);
                    }
                    else
                    {
                        var microExists = false;
                        foreach (var imageType in CommonLogic.SupportedImageTypes)
                        {
                            if (CommonLogic.FileExists(AppLogic.GetImagePath("Product", "micro", true) + fileName + imageType))
                            {
                                microExists = true;
                            }
                        }

                        if (!microExists)
                        {
                            var newImageName = AppLogic.GetImagePath("Product", "micro", true) + fileName + microMime;

                            ResizeForMicro(tempImage, newImageName, microWidth, microHeight);
                        }
                    }
                }
            }
            else if (AppLogic.AppConfigBool("MultiMakesMicros") && imageSize == "medium")
            {
                // lets create micro images if using the medium multi image manager
                // since the medium icons are what show on the product pages
                var newImageName = AppLogic.GetImagePath("Product", "micro", true) + fileName + microMime;

                ResizeForMicro(tempImage, newImageName, microWidth, microHeight);
            }
        }
예제 #9
0
        public static void CreateOthersFromLarge(string objectName, string tempImage, string filename, string content)
        {
            var imgExt          = ".jpg";
            var largeCreates    = false;
            var largeOverwrites = false;
            var globalCreate    = (AppLogic.AppConfigBool("LargeCreatesOthers"));
            var globalOverwrite = (AppLogic.AppConfigBool("LargeOverwritesOthers"));
            var localCreate     = string.Empty;
            var localOverwrite  = string.Empty;
            var configValues    = SplitConfig(objectName, "large");

            if (configValues.ContainsKey("largecreates"))
            {
                localCreate = configValues["largecreates"].ToString();
            }

            if (configValues.ContainsKey("largeoverwrites"))
            {
                localOverwrite = configValues["largeoverwrites"].ToString();
            }

            if (localCreate == "false")
            {
                largeCreates = false;
            }
            else if (localCreate == "true")
            {
                largeCreates = true;
            }
            else
            {
                largeCreates = globalCreate;
            }

            if (localOverwrite == "false")
            {
                largeOverwrites = false;
            }
            else if (localOverwrite == "true")
            {
                largeOverwrites = true;
            }
            else
            {
                largeOverwrites = globalOverwrite;
            }

            switch (content)
            {
            case "image/png":
                imgExt = ".png";
                break;

            case "image/jpeg":
            default:
                imgExt = ".jpg";
                break;
            }

            filename = filename.Replace(".", "");
            if (largeCreates)
            {
                var microImage  = AppLogic.GetImagePath(objectName, "micro", true) + filename + imgExt;
                var iconImage   = AppLogic.GetImagePath(objectName, "icon", true) + filename + imgExt;
                var mediumImage = AppLogic.GetImagePath(objectName, "medium", true) + filename + imgExt;
                if (largeOverwrites)
                {
                    // delete any smaller image files first
                    try
                    {
                        foreach (var imageType in CommonLogic.SupportedImageTypes)
                        {
                            System.IO.File.Delete(AppLogic.GetImagePath(objectName, "icon", true) + filename + imageType);
                            System.IO.File.Delete(AppLogic.GetImagePath(objectName, "medium", true) + filename + imageType);
                        }
                    }
                    catch
                    { }

                    ResizeEntityOrObject(objectName, tempImage, iconImage, "icon", content);
                    ResizeEntityOrObject(objectName, tempImage, mediumImage, "medium", content);

                    if (objectName.Equals("PRODUCT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        foreach (string ss in CommonLogic.SupportedImageTypes)
                        {
                            System.IO.File.Delete(AppLogic.GetImagePath(objectName, "micro", true) + filename + ss);
                        }
                        ResizeEntityOrObject(objectName, tempImage, microImage.Replace("_.", "."), "micro", content);
                    }
                }
                else
                {
                    var iconExists   = false;
                    var mediumExists = false;
                    foreach (string imageType in CommonLogic.SupportedImageTypes)
                    {
                        if (CommonLogic.FileExists(AppLogic.GetImagePath(objectName, "icon", true) + filename + imageType))
                        {
                            iconExists = true;
                        }
                        if (CommonLogic.FileExists(AppLogic.GetImagePath(objectName, "medium", true) + filename + imageType))
                        {
                            mediumExists = true;
                        }
                    }

                    if (!iconExists)
                    {
                        ResizeEntityOrObject(objectName, tempImage, iconImage, "icon", content);
                    }

                    if (!mediumExists)
                    {
                        ResizeEntityOrObject(objectName, tempImage, mediumImage, "medium", content);
                    }

                    if (objectName.Equals("PRODUCT", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var microExists = false;

                        foreach (string imageType in CommonLogic.SupportedImageTypes)
                        {
                            if (CommonLogic.FileExists(AppLogic.GetImagePath(objectName, "micro", true) + filename + imageType))
                            {
                                microExists = true;
                            }
                        }

                        if (!microExists)
                        {
                            ResizeEntityOrObject(objectName, tempImage, microImage.Replace("_.", "."), "micro", content);
                        }
                    }
                }
            }
        }
예제 #10
0
        public static void MakeOtherMultis(string filename, string imageId, string color, string tempImage, string content)
        {
            var imgExt          = ".jpg";
            var largeCreates    = false;
            var largeOverwrites = false;
            var globalCreate    = (AppLogic.AppConfigBool("LargeCreatesOthers"));
            var globalOverwrite = (AppLogic.AppConfigBool("LargeOverwritesOthers"));
            var localCreate     = String.Empty;
            var localOverwrite  = String.Empty;
            var configValues    = SplitConfig("Product", "large");

            if (configValues.ContainsKey("largecreates"))
            {
                localCreate = configValues["largecreates"].ToString();
            }

            if (configValues.ContainsKey("largeoverwrites"))
            {
                localOverwrite = configValues["largeoverwrites"].ToString();
            }

            if (localCreate == "false")
            {
                largeCreates = false;
            }
            else if (localCreate == "true")
            {
                largeCreates = true;
            }
            else
            {
                largeCreates = globalCreate;
            }

            if (localOverwrite == "false")
            {
                largeOverwrites = false;
            }
            else if (localOverwrite == "true")
            {
                largeOverwrites = true;
            }
            else
            {
                largeOverwrites = globalOverwrite;
            }

            switch (content)
            {
            case "image/png":
                imgExt = ".png";
                break;

            case "image/jpeg":
            default:
                imgExt = ".jpg";
                break;
            }

            if (!largeCreates)
            {
                return;
            }

            var makeMicros  = AppLogic.AppConfigBool("MultiMakesMicros");
            var sizesToMake = new List <ProductImageSize>();

            sizesToMake.Add(ProductImageSize.icon);
            sizesToMake.Add(ProductImageSize.medium);

            if (makeMicros)
            {
                sizesToMake.Add(ProductImageSize.micro);
            }

            foreach (var size in sizesToMake)
            {
                var imagepath = AppLogic.GetImagePath("Product", size.ToString(), true) + filename + "_" + imageId.ToLowerInvariant() + "_" + color + imgExt;
                if (largeOverwrites)
                {
                    // delete any smaller image files first
                    foreach (var imageType in CommonLogic.SupportedImageTypes)
                    {
                        try
                        {
                            System.IO.File.Delete(AppLogic.GetImagePath("Product", size.ToString(), true) + filename + "_" + imageId.ToLowerInvariant() + "_" + color + imageType);
                        }
                        catch { }
                    }
                    ResizeEntityOrObject("Product", tempImage, imagepath, size.ToString(), content);
                }
                else
                {
                    var imageExists = false;
                    foreach (var imageType in CommonLogic.SupportedImageTypes)
                    {
                        if (CommonLogic.FileExists(AppLogic.GetImagePath("Product", size.ToString(), true) + filename + imageType))
                        {
                            imageExists = true;
                        }
                    }
                    if (!imageExists)
                    {
                        ResizeEntityOrObject("Product", tempImage, imagepath, size.ToString(), content);
                    }
                }
            }
        }
예제 #11
0
        public void ProcessRequest(HttpContext context)
        {
            if (!AppLogic.AppConfigBool("Watermark.Enabled"))
            {
                return;
            }

            string querystringImageURL = CommonLogic.QueryStringCanBeDangerousContent("imgurl");

            if (string.IsNullOrEmpty(querystringImageURL))
            {
                return;
            }

            context.Response.CacheControl = "private";
            context.Response.Expires      = 0;
            context.Response.AddHeader("pragma", "no-cache");

            string mappedImageUrl    = HttpContext.Current.Request.MapPath(querystringImageURL);
            bool   sourceImageExists = CommonLogic.FileExists(mappedImageUrl) && !mappedImageUrl.Contains("nopicture.gif") && !mappedImageUrl.Contains("nopictureicon.gif");

            if (sourceImageExists)
            {
                string imgSize           = CommonLogic.QueryStringCanBeDangerousContent("size");
                string copyrightText     = AppLogic.AppConfig("Watermark.CopyrightText");
                string copyrightImageUrl = string.Empty;

                if (string.IsNullOrEmpty(copyrightText))
                {
                    copyrightText = AppLogic.AppConfig("StoreName");
                }

                switch (imgSize.ToLower())
                {
                case "icon":
                    copyrightImageUrl = AppLogic.AppConfig("Watermark.CopyrightImage.Icon");
                    break;

                case "medium":
                    copyrightImageUrl = AppLogic.AppConfig("Watermark.CopyrightImage.Medium");
                    break;

                case "large":
                    copyrightImageUrl = AppLogic.AppConfig("Watermark.CopyrightImage.Large");
                    break;

                default:
                    copyrightImageUrl = AppLogic.AppConfig("Watermark.CopyrightImage.Icon");
                    break;
                }

                if (!CommonLogic.IsStringNullOrEmpty(copyrightImageUrl))
                {
                    copyrightImageUrl = CommonLogic.IIF(copyrightImageUrl.StartsWith("/"), copyrightImageUrl.Remove(0, 1), copyrightImageUrl);
                }



                // TODO: Image must be fully qualified (System.Drawing.Image) to support VB conversion
                // During conversion System.Drawing will be lost...must be re-added
                System.Drawing.Image imgPhoto = CommonLogic.LoadImage(mappedImageUrl);

                if (!string.IsNullOrEmpty(copyrightText) || !string.IsNullOrEmpty(copyrightImageUrl))
                {
                    //If a copyright image is used and exists on disk, clear copyright text
                    if (!string.IsNullOrEmpty(copyrightImageUrl) && CommonLogic.FileExists(copyrightImageUrl))
                    {
                        copyrightText = string.Empty;
                    }
                    try
                    {
                        imgPhoto = CommonLogic.AddWatermark(imgPhoto, copyrightText, copyrightImageUrl);
                    }
                    catch (Exception ex)
                    {
                        SysLog.LogException(ex, MessageTypeEnum.GeneralException, MessageSeverityEnum.Error);
                    }
                }

                if (mappedImageUrl.EndsWith(".jpeg", StringComparison.InvariantCultureIgnoreCase))
                {
                    context.Response.ContentType = "image/jpeg";
                    EncoderParameters encoderParameters = new EncoderParameters();
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    imgPhoto.Save(context.Response.OutputStream, ImageCodecInfo.GetImageEncoders()[1], encoderParameters);
                }
                if (mappedImageUrl.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase))
                {
                    context.Response.ContentType = "image/jpg";
                    EncoderParameters encoderParameters = new EncoderParameters();
                    encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    imgPhoto.Save(context.Response.OutputStream, ImageCodecInfo.GetImageEncoders()[1], encoderParameters);
                }
                if (mappedImageUrl.EndsWith(".gif", StringComparison.InvariantCultureIgnoreCase))
                {
                    context.Response.ContentType = "image/gif";
                    imgPhoto.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
                }
                if (mappedImageUrl.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase))
                {
                    context.Response.ContentType = "image/png";
                    imgPhoto.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
                }
                imgPhoto.Dispose();
            }
        }
예제 #12
0
파일: Topic.cs 프로젝트: lulzzz/BrandStore
        // 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());
                }
            }
        }
예제 #13
0
        // 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());
                }
            }
        }