public ElementModel(ICMSElement element) { Attributes = element.Attributes().Where(a => !AttributeExceptionList.Contains(a.AttributeName)).ToDictionary(a => a.AttributeName, a => a.Value); Name = element.RootElementName; Value = element.Value; Children = element.Descendants().Where(e => !ElementExceptionList.Contains(e.RootElementName)).Select(e => new ElementModel(e)); }
public static string GetAvailableView(this ControllerBase controller, ICMSElement elementToDisplay) { string fieldName = elementToDisplay.ViewName ?? elementToDisplay.Content.Name.LocalName; //check editable version first string viewName = "Editable/" + fieldName; if (!ViewExists(controller, viewName)) { viewName = fieldName; } if (!ViewExists(controller, viewName)) { string fieldType = elementToDisplay.Type; if (fieldType == "dhtml") { viewName = "Editable/_DefaultHtml"; } else if (fieldType == "string" || fieldType == string.Empty) { viewName = "Editable/_DefaultText"; } } return(viewName); }
/// <summary> /// if login is required, and not logged in, return redirect url /// </summary> /// <param name="pgRequest"></param> /// <returns>redirect url or null</returns> private string checkUserAuth(CMSPageRequest pgRequest) { bool authSucc = (Session["auth.success"] == null) ? false : (bool)Session["auth.success"]; int authLevel = (int?)Session["auth.accessLevel"] ?? 0; var authSet = pgRequest.GetNavigationItems("AncestorNavigation").Where(item => item.GetAttributeValue("Authorization") != ""); if (authSet.Any()) { string auth = authSet.LastOrDefault().GetAttributeValue("Authorization"); int requiredAuthLevel = auth.Split('-')[0].ToInt() ?? 0; bool accessGranted = (requiredAuthLevel == 0) || (authSucc && authLevel > 0 && authLevel >= requiredAuthLevel); if (!accessGranted && !pgRequest.IsPreview && pgRequest.RootElementName != "LoginPage") { ICMSElement loginElt = pgRequest.GetLinkItem("Login", true); String loginUrl = (loginElt != null) ? loginElt.URL : ""; if (!loginUrl.StartsWith("http")) { loginUrl = Url.Content("~/" + loginUrl); } return(loginUrl + "?returnURL=" + Request.Url); } } return(null); }
public static void RenderDisplay(this HtmlHelper helper, ICMSElement elementToDisplay) { string viewName = GetAvailableView(helper.ViewContext.Controller, elementToDisplay); if (!string.IsNullOrEmpty(viewName)) { helper.RenderPartial(viewName, elementToDisplay); } }
/// <summary> /// default fallback views to display text or html element. /// if the element is text or html element. Otherwise, return empty string /// </summary> /// <param name="helper"></param> /// <param name="elementToDisplay"></param> /// <returns></returns> public static MvcHtmlString Display(this HtmlHelper helper, ICMSElement elementToDisplay) { string viewName = GetAvailableView(helper.ViewContext.Controller, elementToDisplay); if (!string.IsNullOrEmpty(viewName)) { return(helper.Partial(viewName, elementToDisplay)); } else { return(MvcHtmlString.Empty); } }