Пример #1
0
        public static string getStandardHtmlView(SingleImageDisplayInfo displayInfo)
        {
            StringBuilder html = new StringBuilder();

            if (displayInfo.ImagePath.Trim() == "")
            {
                return("");
            }

            string thumbUrl = showThumbPage.getThumbDisplayUrl(displayInfo.ImagePath, displayInfo.ThumbImageDisplayBox);

            System.Drawing.Size imgThumbSize = showThumbPage.getDisplayWidthAndHeight(displayInfo.ImagePath, displayInfo.ThumbImageDisplayBox);
            System.Drawing.Size imgLargeSize = showThumbPage.getDisplayWidthAndHeight(displayInfo.ImagePath, displayInfo.FullImageDisplayBox);

            int    popWidth  = -1;
            int    popHeight = -1;
            string popUrl    = displayInfo.FullImageDisplayUrl;

            string template       = displayInfo.ThumbDisplayWithLinkTemplate;
            string clickForLarger = "";

            if (imgLargeSize.IsEmpty || displayInfo.PopupDisplayBox.IsEmpty || imgThumbSize.Width > imgLargeSize.Width || imgThumbSize.Height > imgLargeSize.Height)
            {
                template = displayInfo.ThumbDisplayWithoutLinkTemplate;
            }
            else
            {
                popWidth       = displayInfo.PopupDisplayBox.Width;
                popHeight      = displayInfo.PopupDisplayBox.Height;
                clickForLarger = displayInfo.ClickToEnlargeText;
            }

            string creditPrefix = displayInfo.CreditsPromptPrefix;
            string credits      = displayInfo.Credits;

            if (credits.Trim() == "")
            {
                creditPrefix = "";
            }

            /// {0} = image thumbnail width
            /// {1} = image thumbnail height
            /// {2} = image thumbnail URL
            /// {3} = popup page width
            /// {4} = popup page height
            /// {5} = popup page URL
            /// {6} = Caption
            /// {7} = CreditsPrefix
            /// {8} = Credits
            /// {9} = ClickToEnlargeText
            string txt = String.Format(template, imgThumbSize.Width, imgThumbSize.Height, thumbUrl, popWidth, popHeight, popUrl, displayInfo.Caption, creditPrefix, credits, clickForLarger);

            html.Append("<div class=\"SingleImagePlaceholder View\">");
            html.Append(txt);
            html.Append("</div>");

            return(html.ToString());
        }
Пример #2
0
        /*
         * public static string getStandardHtmlView_Old(SingleImageData image, FullSizeImageLinkMode fullSizeLinkMode, string fullSizeDisplayUrl)
         * {
         *  StringBuilder html = new StringBuilder();
         *  if (image.ImagePath != "")
         *  {
         *      bool linkToLarger = false;
         *      if (image.FullSizeDisplayBoxHeight > 0 || image.FullSizeDisplayBoxWidth > 0)
         *          linkToLarger = true;
         *
         *      string thumbUrl = showThumbPage.getThumbDisplayUrl(image.ImagePath, image.ThumbnailDisplayBoxWidth, image.ThumbnailDisplayBoxHeight);
         *      System.Drawing.Size ThumbSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, image.ThumbnailDisplayBoxWidth, image.ThumbnailDisplayBoxHeight);
         *
         *      html.Append("<div class=\"SingleImagePlaceholder View\">");
         *      if (linkToLarger)
         *      {
         *          bool useSubmodal = CmsConfig.getConfigValue("SingleImagePlaceHolderUseSubModal", false);
         *          bool useMultibox = CmsConfig.getConfigValue("SingleImagePlaceHolderUseMultibox", false);
         *
         *
         *          int popupPaddingWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupPaddingWidth", 50);
         *          int popupPaddingHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupPaddingHeight", 60);
         *
         *          int maxPopWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMaxWidth", 700 - popupPaddingWidth);
         *          int maxPopHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMaxHeight", 500 - popupPaddingHeight);
         *
         *
         *          int minPopWidth = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMinWidth", 200);
         *          int minPopHeight = CmsConfig.getConfigValue("SingleImagePlaceHolderPopupMinHeight", 200);
         *
         *
         *          string showLargerPagePath = CmsConfig.getConfigValue("SingleImage.DisplayPath", "/_internal/showImage");
         *
         *          NameValueCollection largerParams = new NameValueCollection();
         *          largerParams.Add("i", image.SingleImageId.ToString());
         *          string showLargerPageUrl = CmsContext.getUrlByPagePath(showLargerPagePath, largerParams);
         *
         *          System.Drawing.Size imgLargeSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, image.FullSizeDisplayBoxWidth, image.FullSizeDisplayBoxHeight);
         *
         *          if (ThumbSize.Width > imgLargeSize.Width || ThumbSize.Height > imgLargeSize.Height)
         *          {
         *              linkToLarger = false;
         *          }
         *          else
         *          {
         *
         *              int popWidth = imgLargeSize.Width + popupPaddingWidth;
         *              int popHeight = imgLargeSize.Height + popupPaddingHeight;
         *
         *              if (popWidth < minPopWidth)
         *                  popWidth = minPopWidth;
         *              if (popHeight < minPopHeight)
         *                  popHeight = minPopHeight;
         *
         *              if (popWidth > maxPopWidth)
         *                  popWidth = maxPopWidth;
         *              if (popHeight > maxPopHeight)
         *                  popHeight = maxPopHeight;
         *
         *              if (useSubmodal &&
         *                  (fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig || fullSizeLinkMode == FullSizeImageLinkMode.SubModalWindow))
         *              {
         *                  string submodalCssClass = "class=\"submodal-" + popWidth.ToString() + "-" + popHeight.ToString() + "\"";
         *                  html.Append("<a " + submodalCssClass + " href=\"" + showLargerPageUrl + "\" >");
         *              }
         *              else if (useMultibox && (fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig || fullSizeLinkMode == FullSizeImageLinkMode.SubModalWindow))
         *              {
         *                  string submodalCssClass = "class=\"mb\"";
         *                  html.Append("<a " + submodalCssClass + " href=\"" + showLargerPageUrl + "\" rel=\"width:" + popWidth + ",height:" + popHeight + "\" >");
         *              }
         *              else if (fullSizeLinkMode == FullSizeImageLinkMode.SingleImagePopup || fullSizeLinkMode == FullSizeImageLinkMode.SubModalOrPopupFromConfig)
         *              {
         *                  string onclick = "var w = window.open(this.href, 'popupLargeImage', 'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,height=" + popWidth.ToString() + ",width=" + popWidth.ToString() + "'); ";
         *                  onclick += " return false;";
         *                  html.Append("<a href=\"" + showLargerPageUrl + "\" onclick=\"" + onclick + "\">");
         *              }
         *              else if (fullSizeLinkMode == FullSizeImageLinkMode.ProvidedUrl)
         *                  html.Append("<a href=\"" + fullSizeDisplayUrl + "\">");
         *              else
         *                  linkToLarger = false;
         *          } // else
         *      } // if link to larger
         *
         *      string width = "";
         *      string height = "";
         *      if (!ThumbSize.IsEmpty)
         *      {
         *          width = " width=\"" + ThumbSize.Width + "\"";
         *          height = " height=\"" + ThumbSize.Height.ToString() + "\"";
         *      }
         *
         *      html.Append("<img src=\"" + thumbUrl + "\"" + width + "" + height + ">");
         *      if (linkToLarger)
         *      {
         *          html.Append("</a>");
         *      }
         *
         *      if (image.Caption.Trim() != "")
         *      {
         *          html.Append("<div class=\"caption\">");
         *          html.Append(image.Caption);
         *          html.Append("</div>"); // caption
         *      }
         *
         *      if (image.Credits.Trim() != "")
         *      {
         *          html.Append("<div class=\"credits\">");
         *          string creditsPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPrefix", "");
         *          html.Append(creditsPrefix + image.Credits);
         *          html.Append("</div>"); // credits
         *      }
         *
         *      if (linkToLarger)
         *      {
         *          string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");
         *          if (clickToEnlargeText != "")
         *          {
         *              html.Append("<div class=\"clickToEnlarge\">");
         *              html.Append(clickToEnlargeText);
         *              html.Append("</div>"); // clickToEnlarge
         *          }
         *      }
         *
         *      html.Append("</div>");
         *  }
         *
         *  return html.ToString();
         * }
         */

        public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList)
        {
            // -- all rendering in View mode is handled by getStandardHtmlView()
            SingleImageDb   db    = (new SingleImageDb());
            SingleImageData image = db.getSingleImage(page, identifier, langToRenderFor, true);

            int fullWidth  = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayWidth", -1);
            int fullHeight = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayHeight", -1);

            int thumbWidth  = getThumbDisplayWidth(page, paramList);
            int thumbHeight = getThumbDisplayHeight(page, paramList);

            int popupPaddingWidth  = CmsConfig.getConfigValue("SingleImage.PopupPaddingWidth", 50);
            int popupPaddingHeight = CmsConfig.getConfigValue("SingleImage.PopupPaddingHeight", 60);

            int maxPopWidth  = CmsConfig.getConfigValue("SingleImage.PopupMaxWidth", 700 - popupPaddingWidth);
            int maxPopHeight = CmsConfig.getConfigValue("SingleImage.PopupMaxHeight", 500 - popupPaddingHeight);


            int minPopWidth  = CmsConfig.getConfigValue("SingleImage.PopupMinWidth", 200);
            int minPopHeight = CmsConfig.getConfigValue("SingleImage.PopupMinHeight", 200);

            string withLinkTemplate    = CmsConfig.getConfigValue("SingleImage.WithLinkTemplate", "<a href=\"{5}\"><img src=\"{2}\" width=\"{0}\" height=\"{1}\" /></a>");
            string withoutLinkTemplate = CmsConfig.getConfigValue("SingleImage.WithoutLinkTemplate", "<img src=\"{2}\" width=\"{0}\" height=\"{1}\" />");

            string showLargerPagePath = CmsConfig.getConfigValue("SingleImage.DisplayPath", "/_internal/showImage");

            NameValueCollection largerParams = new NameValueCollection();

            largerParams.Add("i", image.SingleImageId.ToString());
            string showLargerPageUrl = CmsContext.getUrlByPagePath(showLargerPagePath, largerParams);

            System.Drawing.Size imgLargeSize = showThumbPage.getDisplayWidthAndHeight(image.ImagePath, fullWidth, fullHeight);

            int popWidth  = imgLargeSize.Width + popupPaddingWidth;
            int popHeight = imgLargeSize.Height + popupPaddingHeight;

            if (popWidth < minPopWidth)
            {
                popWidth = minPopWidth;
            }
            if (popHeight < minPopHeight)
            {
                popHeight = minPopHeight;
            }

            if (popWidth > maxPopWidth)
            {
                popWidth = maxPopWidth;
            }
            if (popHeight > maxPopHeight)
            {
                popHeight = maxPopHeight;
            }


            // -- create the SingleImageDisplayInfo object
            SingleImageDisplayInfo displayInfo = new SingleImageDisplayInfo();

            displayInfo.ImagePath = image.ImagePath;

            displayInfo.FullImageDisplayBox  = new System.Drawing.Size(fullWidth, fullHeight);
            displayInfo.ThumbImageDisplayBox = new System.Drawing.Size(thumbWidth, thumbHeight);
            displayInfo.PopupDisplayBox      = new System.Drawing.Size(popWidth, popHeight);

            displayInfo.FullImageDisplayUrl = showLargerPageUrl;

            displayInfo.ThumbDisplayWithLinkTemplate    = withLinkTemplate;
            displayInfo.ThumbDisplayWithoutLinkTemplate = withoutLinkTemplate;

            displayInfo.Caption = image.Caption;
            displayInfo.Credits = image.Credits;

            // -- Multilingual CreditsPromptPrefix
            string creditPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPromptPrefix", "");

            string[] creditPrefixParts = creditPrefix.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (creditPrefixParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    creditPrefix = creditPrefixParts[index];
                }
            }

            // -- Multilingual ClickToEnlargeText
            string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");

            string[] clickToEnlargeTextParts = clickToEnlargeText.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (clickToEnlargeTextParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    clickToEnlargeText = clickToEnlargeTextParts[index];
                }
            }

            displayInfo.CreditsPromptPrefix = creditPrefix;
            displayInfo.ClickToEnlargeText  = clickToEnlargeText;

            string html = getStandardHtmlView(displayInfo);

            writer.WriteLine(html.ToString());
        } // RenderView
        private string renderThumbnail(SingleImageGalleryPlaceholderData placeholderData, SingleImageData img, CmsLanguage langToRenderFor)
        {
            string fullDisplayUrl = "";
            Dictionary <string, string> pageParams = new Dictionary <string, string>();

            pageParams.Add("galleryimage", img.SingleImageId.ToString());
            fullDisplayUrl = CmsContext.currentPage.getUrl(pageParams);

            SingleImageDisplayInfo displayInfo = new SingleImageDisplayInfo();

            displayInfo.FullImageDisplayUrl = fullDisplayUrl;

            displayInfo.PopupDisplayBox = new System.Drawing.Size(-1, -1);
            displayInfo.ImagePath       = img.ImagePath;

            displayInfo.ThumbImageDisplayBox = new System.Drawing.Size(placeholderData.ThumbImageDisplayBoxWidth, placeholderData.ThumbImageDisplayBoxHeight);
            displayInfo.Caption = img.Caption;
            displayInfo.Credits = img.Credits;

            int fullImageBoxWidth  = -1;
            int fullImageBoxHeight = -1;

            if (placeholderData.OverrideFullDisplayBoxSize)
            {
                fullImageBoxWidth  = placeholderData.FullSizeDisplayBoxWidth;
                fullImageBoxHeight = placeholderData.FullSizeDisplayBoxHeight;
            }
            else
            {
                fullImageBoxWidth  = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayWidth", -1);
                fullImageBoxHeight = CmsConfig.getConfigValue("SingleImage.FullSizeDisplayHeight", -1);
            }
            displayInfo.FullImageDisplayBox = new System.Drawing.Size(fullImageBoxWidth, fullImageBoxHeight);

            // -- Multilingual CreditsPromptPrefix
            string creditPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPromptPrefix", "");

            string[] creditPrefixParts = creditPrefix.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (creditPrefixParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    creditPrefix = creditPrefixParts[index];
                }
            }

            // -- Multilingual ClickToEnlargeText
            string clickToEnlargeText = CmsConfig.getConfigValue("SingleImage.ClickToEnlargeText", "");

            string[] clickToEnlargeTextParts = clickToEnlargeText.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
            if (clickToEnlargeTextParts.Length >= CmsConfig.Languages.Length)
            {
                int index = CmsLanguage.IndexOf(langToRenderFor.shortCode, CmsConfig.Languages);
                if (index >= 0)
                {
                    clickToEnlargeText = clickToEnlargeTextParts[index];
                }
            }

            displayInfo.CreditsPromptPrefix = creditPrefix;
            displayInfo.ClickToEnlargeText  = clickToEnlargeText;

            string displayTemplate = "<a href=\"{5}\"><img src=\"{2}\" width=\"{0}\" height=\"{1}\" /></a>";

            displayTemplate = CmsConfig.getConfigValue("SingleImage.WithLinkTemplate", displayTemplate);

            displayInfo.ThumbDisplayWithLinkTemplate    = displayTemplate;
            displayInfo.ThumbDisplayWithoutLinkTemplate = displayTemplate;

            return(SingleImage.getStandardHtmlView(displayInfo));
        }