public override RevertToRevisionResult RevertToRevision(CmsPage oldPage, CmsPage currentPage, int[] identifiers, CmsLanguage language) { SingleImageDb imageDb = new SingleImageDb(); foreach (int identifier in identifiers) { SingleImageData oldData = imageDb.getSingleImage(oldPage, identifier, language, false); bool b = imageDb.saveUpdatedSingleImage(currentPage, identifier, language, oldData); if (!b) { return(RevertToRevisionResult.Failure); } } // foreach return(RevertToRevisionResult.Success); }
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { string formName = getEditFormName(page, identifier, langToRenderFor); SingleImageDb db = (new SingleImageDb()); SingleImageData image = db.getSingleImage(page, identifier, langToRenderFor, true); string[] possibleTags = (new SingleImageDb()).getAllPossibleTags(); StringBuilder html = new StringBuilder(); // ------- CHECK THE FORM FOR ACTIONS string action = Hatfield.Web.Portal.PageUtils.getFromForm(formName + "_SingleImageAction", ""); if (action.Trim().ToLower() == "saveimage") { image.ImagePath = PageUtils.getFromForm(formName + "ImagePath", ""); // remove the Application path from the file location if (image.ImagePath.StartsWith(CmsContext.ApplicationPath)) { image.ImagePath = image.ImagePath.Substring(CmsContext.ApplicationPath.Length); } image.Caption = PageUtils.getFromForm(formName + "Caption", ""); image.Credits = PageUtils.getFromForm(formName + "Credits", ""); image.Tags = PageUtils.getFromForm(formName + "Tags"); bool b = db.saveUpdatedSingleImage(page, identifier, langToRenderFor, image); if (!b) { html.Append("Error: Image not saved - database error"); } } string creditsPrefix = CmsConfig.getConfigValue("SingleImage.CreditsPrefix", "Credit:"); int thumbWidth = getThumbDisplayWidth(page, paramList); int thumbHeight = getThumbDisplayHeight(page, paramList); // ------- START RENDERING // note: no need to put in the <form></form> tags. html.Append("<div class=\"SingleImagePlaceholder Edit\">" + Environment.NewLine); string ImageRenderAreaId = formName + "ImageRendered"; html.Append("<div id=\"" + ImageRenderAreaId + "\"></div>"); html.Append(PageUtils.getHiddenInputHtml(formName + "ImagePath", formName + "ImagePath", image.ImagePath)); List <string> editParams = new List <string>(); editParams.Add("i=" + image.SingleImageId); editParams.Add("formName=" + formName); editParams.Add("tw=" + thumbWidth.ToString()); editParams.Add("th=" + thumbHeight.ToString()); string editUrl = CmsContext.ApplicationPath + "_system/tools/SingleImage/SingleImageEditor.aspx?" + string.Join("&", editParams.ToArray());; string jsResetFunctionName = formName + "Reset"; string jsUpdateRenderFunctionName = formName + "UpdateDisplay"; html.Append("<table>"); html.Append("<tr>" + Environment.NewLine); html.Append("<td colspan=\"2\">"); html.Append("<p>"); html.Append("<a id=\"" + formName + "OpenEditorLink\" href=\"" + editUrl + "\" onclick=\"window.open(this.href, 'SingleImageEdit','width=680,height=540'); return false;\">select image</a>"); html.Append(" | "); html.Append("<a href=\"#\" onclick=\"" + jsResetFunctionName + "(); return false;\">clear</a>"); if (CmsConfig.Languages.Length > 1) { html.Append(" | "); html.Append("copy from language: "); List <string> langCopyLinks = new List <string>(); foreach (CmsLanguage lang in CmsConfig.Languages) { if (lang != langToRenderFor) { string langClick = "document.getElementById('" + formName + "ImagePath').value = document.getElementById('" + getEditFormName(page, identifier, lang) + "ImagePath').value;" + jsUpdateRenderFunctionName + "(); if (document.getElementById('" + formName + "ImagePath').value == '') {alert('No image is selected because the source image is blank.');} return false;"; langCopyLinks.Add("<a href=\"#\" onclick=\"" + langClick + "\">" + lang.shortCode + "</a>"); } } // foreach html.Append(string.Join("; ", langCopyLinks.ToArray())); } html.Append("</p>"); html.Append("</td>"); html.Append("</tr>" + Environment.NewLine); html.Append("<tr><td>"); html.Append("Caption:"); html.Append("</td><td class=\"CaptionInputTD\">"); html.Append(PageUtils.getInputTextHtml(formName + "Caption", formName + "Caption", image.Caption.ToString(), 40, 250)); html.Append("</td></tr>"); html.Append("<tr><td>"); html.Append(creditsPrefix); html.Append("</td><td class=\"CreditInputTD\">"); html.Append(PageUtils.getInputTextHtml(formName + "Credits", formName + "Credits", image.Credits.ToString(), 40, 250)); html.Append("</td></tr>" + Environment.NewLine); if (possibleTags.Length > 0) { html.Append("<tr><td>"); html.Append("Tags:"); html.Append("</td><td>"); foreach (string t in possibleTags) { if (t != "") { html.Append(PageUtils.getCheckboxHtml(t.Trim(), formName + "Tags", formName + "tag_" + t, t.Trim(), Array.IndexOf(image.Tags, t) > -1)); html.Append("<br />"); } } // foreach html.Append("</td></tr>"); } html.Append("</table>"); html.Append("</div>" + Environment.NewLine); // -- hidden field actions html.Append("<input type=\"hidden\" name=\"" + formName + "_SingleImageAction\" value=\"saveImage\">"); // -- javascript StringBuilder js = new StringBuilder(); js.Append("function " + jsResetFunctionName + "() " + Environment.NewLine); js.Append("{ " + Environment.NewLine); js.Append("document.getElementById('" + formName + "ImagePath').value = '';" + Environment.NewLine); js.Append("document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<span style=\"margin: 10px; padding: 10px; background: #edff96; border: 1px solid #C00;\">no image is selected</span>';" + Environment.NewLine); js.Append("} " + Environment.NewLine); js.Append("function " + jsUpdateRenderFunctionName + "() " + Environment.NewLine); js.Append("{ " + Environment.NewLine); js.Append(" var ImagePath = document.getElementById('" + formName + "ImagePath').value;" + Environment.NewLine); js.Append(" if (ImagePath == '') { " + Environment.NewLine); js.Append(" document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<span style=\"margin: 10px; padding: 10px; background: #edff96; border: 1px solid #C00;\">no image is selected</span>';" + Environment.NewLine); js.Append(" } // if " + Environment.NewLine); js.Append(" else { " + Environment.NewLine); js.Append(" document.getElementById('" + ImageRenderAreaId + "').innerHTML = '<img src=\"" + CmsContext.ApplicationPath + "_system/tools/showThumb.aspx?file='+ImagePath+'&w=" + thumbWidth + "&h=" + thumbHeight + "&nocache='+((new Date()).getTime())+'\">';" + Environment.NewLine); js.Append(" } // else " + Environment.NewLine); js.Append(" document.getElementById('" + formName + "OpenEditorLink').href = '" + editUrl + "&SelImagePath='+ImagePath;" + Environment.NewLine); js.Append("} " + Environment.NewLine + Environment.NewLine); // add javascript to head section page.HeadSection.AddJSStatements(js.ToString()); page.HeadSection.AddJSOnReady(jsUpdateRenderFunctionName + "();"); writer.WriteLine(html.ToString()); }
/* * 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