public void InitFromPlaceholderParamList(string[] paramList) { if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { string sLinkMode = ""; try { sLinkMode = PlaceholderUtils.getParameterValue("filelinks", Enum.GetName(typeof(FileLinkMode), fileLinkMode), paramList); fileLinkMode = (FileLinkMode)Enum.Parse(typeof(FileLinkMode), sLinkMode, true); // set the default link target based on the link mode. This can be overridden by the linktarget parameter. switch (fileLinkMode) { case FileLinkMode.LinkToFile: LinkTarget = "_blank"; break; case FileLinkMode.LinkToPage: LinkTarget = "_self"; break; } } catch { throw new Exception("Error: invalid FileLibraryAggregator2 filelinks parameter. Valid values: " + String.Join(", ", Enum.GetNames(typeof(FileLinkMode)))); } PageIdToGatherFilesFrom = PlaceholderUtils.getParameterValue("gatherfrompageid", Int32.MinValue, paramList); RecursiveGatherFiles = PlaceholderUtils.getParameterValue("gatherrecusive", RecursiveGatherFiles, paramList); ListingTitle = PlaceholderUtils.getParameterValue("listingtitle", ListingTitle, paramList); LinkTarget = PlaceholderUtils.getParameterValue("linktarget", LinkTarget, paramList); ShowByCategory = PlaceholderUtils.getParameterValue("showbycategory", ShowByCategory, paramList); IncludePageFiles = PlaceholderUtils.getParameterValue("includepagefiles", IncludePageFiles, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } }
} // resolveUrl private void RenderViewStatus(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { PageRedirectDb db = new PageRedirectDb(); string url = db.getPageRedirectUrl(page, identifier, langToRenderFor.shortCode, true); string resolvedUrl = resolveRedirectUrl(url); string width = "100%"; string height = "1.5em"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); } else { throw new NotImplementedException("Error: invalid TemplateEngine version"); } System.Text.StringBuilder html = new System.Text.StringBuilder(); html.Append("<div style=\"background: #CCC; padding: 0.2em;\">"); html.Append("Normal site viewers (people who are not site authors) will be automatically redirected to :"); html.Append("<a href=\"" + resolvedUrl + "\" style=\"font-size: " + height + ";\">"); html.Append(url); html.Append("</a>"); if (resolvedUrl != "") { StringBuilder js = new StringBuilder(); js.Append("var start=new Date();" + Environment.NewLine); js.Append("start=Date.parse(start)/1000;" + Environment.NewLine); js.Append("var counts=10;" + Environment.NewLine); js.Append("function CountDownToRedirect(){" + Environment.NewLine); js.Append(" var now=new Date();" + Environment.NewLine); js.Append(" now=Date.parse(now)/1000;" + Environment.NewLine); js.Append(" var x=parseInt(counts-(now-start),10);" + Environment.NewLine); js.Append(" document.getElementById('redirectCountDown').value = x;" + Environment.NewLine); js.Append(" if(x>0){" + Environment.NewLine); js.Append(" timerID=setTimeout(\"CountDownToRedirect()\", 100)"+ Environment.NewLine); js.Append(" }else{" + Environment.NewLine); js.Append(" location.href=\""+ resolvedUrl + "\"" + Environment.NewLine); js.Append(" }" + Environment.NewLine); js.Append("} // CountDownToRedirect" + Environment.NewLine); page.HeadSection.AddJSStatements(js.ToString()); page.HeadSection.AddJSOnReady("CountDownToRedirect();"); page.HeadSection.registerBlockForOutput("RedirectTimer"); int numSecondsToWait = CmsConfig.getConfigValue("RedirectPlaceholder_autoRedirectAfterSeconds", 10);; html.Append("<p>You are being redirected in <input type=\"text\" name=\"clock\" id=\"redirectCountDown\" size=\"2\" value=\"" + numSecondsToWait.ToString() + "\"> seconds.</p>" + Environment.NewLine); } html.Append("</div>"); writer.WriteLine(html); } // RenderViewStatus
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { PageRedirectDb db = new PageRedirectDb(); string formName = "PageRedirect_" + page.ID.ToString() + identifier.ToString() + langToRenderFor.shortCode; string width = "100%"; string height = "1.5em"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); } else { throw new NotImplementedException("Error: invalid TemplateEngine version"); } string pageRedirectUrl = db.getPageRedirectUrl(page, identifier, langToRenderFor.shortCode, true); // string Message = ""; // ------- CHECK THE FORM FOR ACTIONS string action = Hatfield.Web.Portal.PageUtils.getFromForm(formName + "_Action", ""); if (action.Trim().ToLower() == "saveUrl".ToLower()) { pageRedirectUrl = Hatfield.Web.Portal.PageUtils.getFromForm(formName + "_value", ""); if (!db.saveUpdatedPageRedirect(page, identifier, langToRenderFor.shortCode, pageRedirectUrl)) { throw new Exception("Problem with database: could not set redirect url"); } } // ------- START RENDERING // -- get the Javascript string html = ""; // -- render the Control // note: no need to put in the <form></form> tags. string id = formName + "_id"; html = html + "<div style=\"background: #CCC; padding: 0.2em;\">"; html = html + "URL to redirect to: <input style=\"font-size: " + height + "; font-weight: bold; width: " + width + "; height:" + height + " \" type=\"text\" id=\"" + id + "\" name=\"" + formName + "_value\" value=\"" + pageRedirectUrl + "\">"; //html = html + "<br><a href=\"#\" onclick=\"var url = document.getElementById('"+id+"').value; window.open(url,'"+id+"_window');\">test link</a>"; html = html + "<br>hint: use a '~' for a local link (eg: '~/' links to the home page, '~" + page.ParentPage.Path + "' links to the " + page.ParentPage.Title + " page )"; html = html + "<input type=\"hidden\" name=\"" + formName + "_Action\" value=\"saveUrl\">"; html = html + "</div>"; writer.WriteLine(html); } // RenderEdit
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { PlainTextContentDb db = new PlainTextContentDb(); string plainTextContent = ""; string width = "100%"; string height = "200px"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); } else { throw new NotImplementedException("Error: invalid TemplateEngine version"); } string editorId = "plaintextcontent_" + page.Id.ToString() + "_" + identifier.ToString() + langToRenderFor.shortCode; // ------- CHECK THE FORM FOR ACTIONS string action = Hatfield.Web.Portal.PageUtils.getFromForm(editorId + "_Action", ""); if (action.Trim().ToLower() == "update") { plainTextContent = Hatfield.Web.Portal.PageUtils.getFromForm("name_" + editorId, ""); db.saveUpdatedPlainTextContent(page, identifier, langToRenderFor, plainTextContent); } else { plainTextContent = db.getPlainTextContent(page, identifier, langToRenderFor, true); } // ------- START RENDERING StringBuilder html = new StringBuilder(); // -- render the Control // note: no need to put in the <form></form> tags. html.Append("<textarea name=\"name_" + editorId + "\" id=\"" + editorId + "\" style=\"WIDTH: " + width + "; HEIGHT: " + height + ";\">"); html.Append(plainTextContent); html.Append("</textarea>"); html.Append("<input type=\"hidden\" name=\"" + editorId + "_Action\" value=\"update\">"); writer.WriteLine(html.ToString()); }
public RenderParameters(string[] paramList) { if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { renderWidth = PlaceholderUtils.getParameterValue("width", renderWidth, paramList); renderHeight = PlaceholderUtils.getParameterValue("height", renderHeight, paramList); renderTemplate = PlaceholderUtils.getParameterValue("OutputTemplate", renderTemplate, paramList); outputOnlyIfHasContent = PlaceholderUtils.getParameterValue("OutputOnlyIfHasContent", outputOnlyIfHasContent, paramList); outputOnlyInEditMode = PlaceholderUtils.getParameterValue("OutputOnlyInEditMode", outputOnlyInEditMode, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } }
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { // -- output the text in the parameters if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { string text = PlaceholderUtils.getParameterValue("text", "", paramList); if (text.Trim() != "") { writer.Write("<div class=\"EditModeComment\">" + text + "</div>"); } } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } } // RenderEdit
private int getThumbDisplayHeight(CmsPage page, string[] paramList) { int forceDefaultThumbHeight = Int32.MinValue; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { forceDefaultThumbHeight = PlaceholderUtils.getParameterValue("height", forceDefaultThumbHeight, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } if (forceDefaultThumbHeight < -1) { throw new TemplateExecutionException(page.TemplateName, "SingleImage placeholder must have a \"height\" parameter."); } return(forceDefaultThumbHeight); }
private static void doRender(string PlaceholderType, string RenderFunction, HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] subParamsArray, string templateFilename) { try { // Render() parameters are set in BaseCmsPlaceholder PlaceholderUtils.InvokePlaceholderFunction(PlaceholderType, RenderFunction, new object[] { writer, page, identifier, langToRenderFor, subParamsArray }); } catch (Exception ex) { if (ex is System.Threading.ThreadAbortException) { // the placeholder or control did a Response.End return; } else if (ex is CmsPageNotFoundException || ex.InnerException is CmsPageNotFoundException) { CmsContext.HandleNotFoundException(); } else if (ex is CmsPlaceholderNeedsRedirectionException || ex.InnerException is CmsPlaceholderNeedsRedirectionException) { // due to the dynamic nature of placeholders, // placeholders can not redirect on their own, so must raise an Exception to do so. if (HttpContext.Current != null && HttpContext.Current.Response != null) { System.Web.HttpResponse resp = System.Web.HttpContext.Current.Response; resp.Clear(); resp.ClearContent(); resp.ClearHeaders(); string targetUrl = (ex.InnerException as CmsPlaceholderNeedsRedirectionException).TargetUrl; resp.StatusCode = 301; // Moved Permanently resp.AddHeader("Location", targetUrl); resp.Redirect(targetUrl, true); } } else { throw new TemplateExecutionException(ex.InnerException, templateFilename, "Error in Placeholder, or Unknown Placeholder in " + PlaceholderType + " Template<p>root exception: " + ex.Message); } } } // callExternalPlaceholderRender
} // RenderView private int getThumbDisplayWidth(CmsPage page, string[] paramList) { int width = Int32.MinValue; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); // -- do checks of template parameters that are no longer used (and should be removed from templates). string notFound = Guid.NewGuid().ToString(); string popupWidth = PlaceholderUtils.getParameterValue("popupWidth", notFound, paramList); if (popupWidth != notFound) { throw new TemplateExecutionException(page.TemplateName, "SingleImage placeholders should no longer have a \"popupWidth\" parameter."); } string popupHeight = PlaceholderUtils.getParameterValue("popupHeight", notFound, paramList); if (popupHeight != notFound) { throw new TemplateExecutionException(page.TemplateName, "SingleImage placeholders should no longer have a \"popupHeight\" parameter."); } string tags = PlaceholderUtils.getParameterValue("tags", notFound, paramList); if (tags != notFound) { throw new TemplateExecutionException(page.TemplateName, "SingleImage placeholders should no longer have a \"tags\" parameter."); } } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } if (width < -1) { throw new TemplateExecutionException(page.TemplateName, "SingleImage placeholder must have a \"width\" parameter."); } return(width); }
} // RenderEdit public override void RenderInViewMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { string width = "400px"; string height = "200px"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } GoogleMapInfo mapInfo = (new GoogleMapDb()).getGoogleMap(page, identifier, true); StringBuilder html = new StringBuilder(); html.Append(getMapHtml(mapInfo, page, identifier, width, height)); writer.Write(html.ToString()); } // RenderView
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { string formName = "editTitle_" + page.Id.ToString() + identifier.ToString() + langToRenderFor.shortCode.ToLower(); // -- get the placeholder width and height parameters string width = "100%"; string height = "1.5em"; bool renamePageBasedOnTitle = false; bool hideNavigationMenuText = false; string pageTitlePrompt = "Page Title:"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); renamePageBasedOnTitle = PlaceholderUtils.getParameterValue("RenamePageBasedOnTitle", renamePageBasedOnTitle, paramList); hideNavigationMenuText = PlaceholderUtils.getParameterValue("HideNavigationMenuText", hideNavigationMenuText, paramList); pageTitlePrompt = PlaceholderUtils.getParameterValue("PageTitlePrompt", pageTitlePrompt, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } string pageTitle = ""; string menuTitle = ""; string searchEngineDescription = ""; string Message = ""; // ------- CHECK THE FORM FOR ACTIONS string action = Hatfield.Web.Portal.PageUtils.getFromForm(formName + "_PageTitleAction", ""); if (action.Trim().ToLower() == "savetitle") { // -- save the page title pageTitle = PageUtils.getFromForm(formName + "_value", ""); if ((pageTitle.CompareTo(page.Title) != 0 || renamePageBasedOnTitle) && page.setTitle(pageTitle, langToRenderFor)) { Message = "Page Title Updated"; // -- save the name based on the page title if (renamePageBasedOnTitle && page.Id != CmsContext.HomePage.Id) { string newPageName = getPageNameFromTitle(pageTitle, page); // -- rename the page to its new name bool renameSuccess = page.setName(newPageName, langToRenderFor); if (!renameSuccess) { Message = "Page did NOT rename successfully."; } } } else { Message = "Problem with database: could not set page title"; pageTitle = page.Title; } // -- save the menu title menuTitle = PageUtils.getFromForm(formName + "_menutitlevalue", ""); if (page.setMenuTitle(menuTitle, langToRenderFor)) { Message = "Navigation Menu Text Updated"; } else { Message = "Problem with database: could not set page's Menu title"; menuTitle = page.getMenuTitle(langToRenderFor); } searchEngineDescription = PageUtils.getFromForm(formName + "_searchEngineDescriptionvalue", ""); searchEngineDescription = StringUtils.StripHTMLTags(searchEngineDescription); if (page.setSearchEngineDescription(searchEngineDescription, langToRenderFor)) { Message = "Page Search Engine Description Updated"; } else { Message = "Problem with database: could not set page's search engine description"; searchEngineDescription = page.SearchEngineDescription; } } else { pageTitle = page.getTitle(langToRenderFor); menuTitle = page.getMenuTitle(langToRenderFor); searchEngineDescription = page.getSearchEngineDescription(langToRenderFor); } // ------- START RENDERING // -- get the Javascript StringBuilder html = new StringBuilder(); string EOL = Environment.NewLine; // -- render the Control // note: no need to put in the <form></form> tags. html.Append("<div class=\"PageTitlePlaceholder\">"); html.Append("<div class=\"PageTitleEdit\" style=\"background: #CCC; padding: 0.2em;\">"); html.Append(pageTitlePrompt + " <input style=\"font-size: " + height + "; font-weight: bold; width: " + width + "; height:" + height + " \" type=\"text\" name=\"" + formName + "_value\" value=\"" + pageTitle + "\"><br>"); html.Append("</div>" + Environment.NewLine); html.Append("<div class=\"PageMenuTextEdit\" style=\"background: #CCC; padding: 0.2em;\">"); html.Append("Navigation Menu Text: "); string onclickMenuText = "if ( $('#{0}').css('display') == 'none' ) { this.innerHTML = '(hide)'; $('#{0}').css('display','block'); } else { this.innerHTML = '(edit)'; $('#{0}').css('display','none'); } return false;"; onclickMenuText = onclickMenuText.Replace("{0}", formName + "_menutitlevalue"); string htmlLink = "<a href=\"#\" onclick=\"{0}\">({1})</a>"; htmlLink = String.Format(htmlLink, new string[] { onclickMenuText, (hideNavigationMenuText) ? "edit" : "hide" }); html.Append(htmlLink); html.Append("<input style=\"display: " + (hideNavigationMenuText ? "none" : "block") + "; font-size: " + height + "; font-weight: bold; width: " + width + "; height:" + height + " \" type=\"text\" id=\"" + formName + "_menutitlevalue\" name=\"" + formName + "_menutitlevalue\" value=\"" + menuTitle + "\"><br>"); html.Append("</div>" + Environment.NewLine); html.Append("<div style=\"background: #CCC; padding: 0.2em;\">"); html.Append("Search Engine Description: "); string onclickSearchEngine = "if ( $('#{0}').css('display') == 'none' ) { this.innerHTML = '(hide)'; $('#{0}').css('display','block'); } else { this.innerHTML = '(edit)'; $('#{0}').css('display','none'); } return false;"; onclickSearchEngine = onclickSearchEngine.Replace("{0}", formName + "_searchEngineDescriptionvalue"); string htmlLink2 = "<a href=\"#\" onclick=\"{0}\">({1})</a>"; htmlLink2 = String.Format(htmlLink2, new string[] { onclickSearchEngine, (searchEngineDescription == "") ? "edit" : "hide" }); html.Append(htmlLink2); html.Append("<textarea name=\"" + formName + "_searchEngineDescriptionvalue\" id=\"" + formName + "_searchEngineDescriptionvalue\" style=\"display: " + ((searchEngineDescription == "") ? "none" : "block") + "; width: " + width + ";\" rows=\"3\">"); html.Append(searchEngineDescription); html.Append("</textarea>"); html.Append("</div>" + Environment.NewLine); html.Append("<input type=\"hidden\" name=\"" + formName + "_PageTitleAction\" value=\"saveTitle\">"); html.Append("</div>" + Environment.NewLine); writer.WriteLine(html.ToString()); }
public override void RenderInEditMode(HtmlTextWriter writer, CmsPage page, int identifier, CmsLanguage langToRenderFor, string[] paramList) { string width = "400px"; string height = "200px"; if (CmsConfig.TemplateEngineVersion == CmsTemplateEngineVersion.v2) { width = PlaceholderUtils.getParameterValue("width", width, paramList); height = PlaceholderUtils.getParameterValue("height", height, paramList); } else { throw new ArgumentException("Invalid CmsTemplateEngineVersion"); } GoogleMapInfo mapInfo = (new GoogleMapDb()).getGoogleMap(page, identifier, true); string mapId = "GoogleMap_" + page.ID.ToString() + "_" + identifier.ToString(); string action = PageUtils.getFromForm(mapId + "Action", ""); if (action.Trim().ToLower() == "update") { mapInfo.APIKey = PageUtils.getFromForm(mapId + "API", mapInfo.APIKey); string PopupHtml = PageUtils.getFromForm(mapId + "PopupHtml", mapInfo.PopupHtml); PopupHtml = PopupHtml.Replace(Environment.NewLine, " "); PopupHtml = PopupHtml.Replace("\r", " "); PopupHtml = PopupHtml.Replace("\n", " "); mapInfo.PopupHtml = PopupHtml; mapInfo.Latitude = PageUtils.getFromForm(mapId + "Latitude", mapInfo.Latitude); mapInfo.Longitude = PageUtils.getFromForm(mapId + "Longitude", mapInfo.Longitude); mapInfo.intitialZoomLevel = PageUtils.getFromForm(mapId + "intitialZoomLevel", mapInfo.intitialZoomLevel); mapInfo.displayType = (GoogleMapInfo.MapDisplay)PageUtils.getFromForm(mapId + "type", typeof(GoogleMapInfo.MapDisplay), GoogleMapInfo.MapDisplay.G_NORMAL_MAP); mapInfo.KMLOverlayUrl = PageUtils.getFromForm(mapId + "KMLOverlayUrl", mapInfo.KMLOverlayUrl); (new GoogleMapDb()).saveUpdatedGoogleMap(page, identifier, mapInfo); } StringBuilder html = new StringBuilder(); html.Append("Google Maps API Key: "); html.Append(PageUtils.getInputTextHtml(mapId + "API", mapInfo + "API", mapInfo.APIKey, 30, 255)); html.Append("<br>"); html.Append("KML Overlay Url (specifying a KML will override Popup information below): "); html.Append(PageUtils.getInputTextHtml(mapId + "KMLOverlayUrl", mapInfo + "KMLOverlayUrl", mapInfo.KMLOverlayUrl.ToString(), 50, 255)); html.Append("<br>"); html.Append("Popup Html (max 255 chars):"); html.Append(PageUtils.getTextAreaHtml(mapId + "PopupHtml", mapInfo + "PopupHtml", mapInfo.PopupHtml, 50, 2)); html.Append("<br>"); html.Append("Popup Latitude (decimal degrees): "); html.Append(PageUtils.getInputTextHtml(mapId + "Latitude", mapInfo + "Latitude", mapInfo.Latitude.ToString(), 5, 255)); html.Append("<br>"); html.Append("Popup Longitude (decimal degrees): "); html.Append(PageUtils.getInputTextHtml(mapId + "Longitude", mapInfo + "Longitude", mapInfo.Longitude.ToString(), 5, 255)); html.Append("<br>"); html.Append("Display Type: " + PageUtils.getDropDownHtml(mapId + "type", mapInfo + "type", Enum.GetNames(typeof(GoogleMapInfo.MapDisplay)), Enum.GetName(typeof(GoogleMapInfo.MapDisplay), mapInfo.displayType))); html.Append("<br>"); string[] zoomLevels = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17" }; html.Append("Initial Zoom Level: " + PageUtils.getDropDownHtml(mapId + "intitialZoomLevel", mapInfo + "intitialZoomLevel", zoomLevels, mapInfo.intitialZoomLevel.ToString())); html.Append("<br>"); html.Append(PageUtils.getHiddenInputHtml(mapId + "Action", "update")); // -- Render the map html.Append(getMapHtml(mapInfo, page, identifier, width, height)); writer.Write(html.ToString()); } // RenderEdit