示例#1
0
        protected string getText(CmsLanguage lang, string configKey, string dftValue)
        {
            string[]      msgArray  = CmsConfig.getConfigValue(configKey, dftValue).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            CmsLanguage[] langArray = CmsConfig.Languages;
            int           x         = CmsLanguage.IndexOf(lang.shortCode, langArray);

            if (msgArray.Length < langArray.Length || x < 0)
            {
                throw new Exception("Missing entry for " + configKey + "!");
            }

            return(msgArray[x]);
        }
        public string getLocationText(CmsLanguage forLanguage)
        {
            if (CmsConfig.Languages.Length < 2)
            {
                return(LocationText);
            }

            int index = CmsLanguage.IndexOf(forLanguage.shortCode, CmsConfig.Languages);

            if (index < 0)
            {
                throw new ArgumentException("Error: the joblocations table needs to be updated to make all LocationTexts multi-lingual");
            }

            string[] langParts = LocationText.Split(new char[] { CmsConfig.PerLanguageConfigSplitter });
            if (index > langParts.Length - 1)
            {
                throw new ArgumentException("Error: the joblocations table needs to be updated to make all LocationTexts multi-lingual");
            }

            return(langParts[index]);
        }
示例#3
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
示例#4
0
        public string RunInlineGlossaryFilter(CmsPage pageBeingFiltered, string placeholderHtml)
        {
            try
            {
                bool enabled = CmsConfig.getConfigValue("GlossaryHighlightFilter:Enable", false); // disabled by default

                if (!enabled || CmsContext.currentEditMode == CmsEditMode.Edit)
                {
                    return(placeholderHtml);
                }

#if DEBUG
                CmsContext.currentPage.HeadSection.AddCSSStyleStatements("span.InlineGlossaryTerm { border-bottom: 1px dotted red; }");
#endif

                // -- get the glossaryID to get data for (language specific)
                int    glossaryId  = 1;
                string glossaryIds = CmsConfig.getConfigValue("GlossaryHighlightFilter:GlossaryId", "");
                try
                {
                    string[] glossaryIdsParts = glossaryIds.Split(new char[] { CmsConfig.PerLanguageConfigSplitter }, StringSplitOptions.RemoveEmptyEntries);
                    if (glossaryIdsParts.Length >= CmsConfig.Languages.Length)
                    {
                        int index = CmsLanguage.IndexOf(CmsContext.currentLanguage.shortCode, CmsConfig.Languages);
                        if (index >= 0)
                        {
                            glossaryId = Convert.ToInt32(glossaryIdsParts[index]);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("Error: GlossaryHighlightFilter is incorrectly configured!");
                }

                // -- get the glossary data from the database. The data is cached so that we don't hit the database for this info every time.
                GlossaryData[] gData;
                string         cacheKey = "GlossaryHighlightFilter_Data_" + glossaryId;
                if (!CmsContext.currentUserIsLoggedIn && System.Web.Hosting.HostingEnvironment.Cache[cacheKey] != null)
                {
                    gData = (GlossaryData[])System.Web.Hosting.HostingEnvironment.Cache[cacheKey];
                }
                else
                {
                    GlossaryDb db = new GlossaryDb();

                    if (GlossaryPlaceholderData.DataSource == GlossaryPlaceholderData.GlossaryDataSource.RssFeed)
                    {
                        gData = db.FetchRssFeedGlossaryDataFromDatabase();
                    }
                    else
                    {
                        gData = db.getGlossaryData(glossaryId);
                    }

                    if (!CmsContext.currentUserIsLoggedIn)
                    {
                        System.Web.Hosting.HostingEnvironment.Cache.Insert(cacheKey, gData, null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration);
                    }

                    // go through longer words first (longer words/phrases are usually more specific than shorter ones)
                    gData = GlossaryData.SortByWordLength(gData, SortDirection.Descending);
                }

                // -- short-circuit processing if there aren't any glossary terms in the system.
                if (gData.Length == 0)
                {
                    return(placeholderHtml);
                }

                // -- process the placeholderHTML
                string html = placeholderHtml;

                List <string> toSurround = new List <string>();
                List <string> prefixs    = new List <string>();
                List <string> suffixs    = new List <string>();

                foreach (GlossaryData d in gData)
                {
                    int index = html.IndexOf(d.word.Trim(), StringComparison.CurrentCultureIgnoreCase);
                    if (index >= 0 && d.word.Trim().Length > 0)
                    {
                        // string safeDesc = StringUtils.AddSlashes(d.description);
                        string safeDesc = HttpUtility.HtmlEncode(d.word + ": " + d.description);
                        safeDesc = safeDesc.Replace("\n", " ");
                        safeDesc = safeDesc.Replace("\r", " ");
                        safeDesc = safeDesc.Replace("\t", " ");
                        safeDesc = safeDesc.Replace("  ", " ");

                        string prefix = "<span title=\"" + safeDesc + "\" class=\"InlineGlossaryTerm\">";
                        string suffix = "</span>";

                        toSurround.Add(d.word.Trim());
                        prefixs.Add(prefix);
                        suffixs.Add(suffix);
                    }
                } // foreach word

                html = SurroundInHtml(toSurround.ToArray(), prefixs.ToArray(), suffixs.ToArray(), html);

                return(html.ToString());
            }
            catch (Exception ex)
            {
                placeholderHtml += ("<!-- GlossaryHighlightingFilter Error: " + ex.Message + " -->");
            }

            return(placeholderHtml);
        }
        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));
        }
        /// <summary>
        /// Renders a template with all its controls and placeholders, and add these controls and placeholders to the parentUserControl.
        /// Note: do not use Render to HtmlWriter - Control events are not called properly.
        /// </summary>
        public override void CreateChildControls(System.Web.UI.UserControl parentUserControl)
        {
            // -- get the template file contents
            string templateText = getTemplateFileContents();

            // -- get the TemplateLayout statement
            string[] layouts = getCommandStatementParameters("TemplateLayout", templateText);
            if (layouts.Length == 0)
            {
                throw new TemplateExecutionException(templateName, "Template does not have a TemplateLayout statement.");
            }
            else if (layouts.Length > 1)
            {
                throw new TemplateExecutionException(templateName, "Template has more than one TemplateLayout statement - only one is allowed.");
            }

            // -- read the template layout file
            string layoutText = getTemplateLayoutFileContents(layouts[0]);

            // -- start with the first language if we are editing a page.
            currentLangIndex = 0;
            if (CmsContext.currentEditMode == CmsEditMode.View)
            {
                currentLangIndex = CmsLanguage.IndexOf(CmsContext.currentLanguage.shortCode, CmsConfig.Languages);
            }

            // -- make sure that StartPageBody and EndPageBody commands are included
            int start = layoutText.IndexOf("StartPageBody", StringComparison.CurrentCultureIgnoreCase);

            if (start < 0)
            {
                start = templateText.IndexOf("StartPageBody", StringComparison.CurrentCultureIgnoreCase);
            }

            if (start < 0)
            {
                throw new TemplateExecutionException(templateName, "You must include a StartPageBody and EndPageBody command in the template when multiple languages are used");
            }

            int end = layoutText.IndexOf("EndPageBody", StringComparison.CurrentCultureIgnoreCase);

            if (end < 0)
            {
                end = templateText.IndexOf("EndPageBody", StringComparison.CurrentCultureIgnoreCase);
            }
            if (end < 0)
            {
                throw new TemplateExecutionException(templateName, "You must include a StartPageBody and EndPageBody command in the template when multiple languages are used");
            }


            string startEditFormCommand = COMMAND_DELIMITER + "RenderControl(_system/StartEditForm)" + COMMAND_DELIMITER;
            string endEditFormCommand   = COMMAND_DELIMITER + "RenderControl(_system/EndEditForm)" + COMMAND_DELIMITER;

            if (layoutText.IndexOf(startEditFormCommand, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                templateText.IndexOf(startEditFormCommand, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                layoutText.IndexOf(endEditFormCommand, StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                templateText.IndexOf(endEditFormCommand, StringComparison.CurrentCultureIgnoreCase) >= 0)
            {
                throw new TemplateExecutionException(templateName, "Do not include the StartEditForm or EndEditForm controls");
            }


            templateLayoutFileContents = layoutText;
            templateFileContents       = templateText;

            // -- render the output
            RenderTextToPage(parentUserControl, templateLayoutFileContents);
        } // CreateChildControls