/// <summary> /// Handles the AfterSubmitPostedData event of the XFormControl. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EPiServer.XForms.WebControls.SaveFormDataEventArgs"/> instance containing the event data.</param> public void XForm_AfterSubmitPostedData(object sender, SaveFormDataEventArgs e) { XFormControl control = (XFormControl)sender; if (control.FormDefinition.PageGuidAfterPost != Guid.Empty) { PermanentContentLinkMap pageMap = PermanentLinkMapStore.Find(control.FormDefinition.PageGuidAfterPost) as PermanentContentLinkMap; if (pageMap != null) { string internalUrl = pageMap.MappedUrl.ToString(); internalUrl = UriSupport.AddLanguageSelection(internalUrl, ContentLanguage.PreferredCulture.Name); UrlBuilder urlBuilder = new UrlBuilder(internalUrl); //Rewrite the url to make sure that it gets the friendly url if such a provider has been configured. Global.UrlRewriteProvider.ConvertToExternal(urlBuilder, null, Encoding.UTF8); //Always cast UrlBuilders to get a correctly encoded url since ToString() is for "human" readability. control.Page.Response.Redirect((string)urlBuilder); return; } } //After the form has been posted we remove the form elements and add a "thank you message". control.Controls.Clear(); Label label = new Label(); label.CssClass = "thankyoumessage"; label.Text = LocalizationService.Current.GetString("/form/postedmessage"); control.Controls.Add(label); }
public static IEnumerable <T> ToContentItems <T>(this LinkItemCollection links, IContentRepository repo) where T : ContentData { if (links == null) { yield break; } foreach (var link in links) { var linkUrl = new UrlBuilder(link.Href); if (!PermanentLinkMapStore.ToMapped(linkUrl)) { continue; } var contentLink = PermanentLinkUtility.GetContentReference(linkUrl); var item = repo.Get <T>(contentLink); if (item != null) { yield return(item); } } }
/// <summary> /// Returns ContentReference for provided LinkItem if it is EPiServer page otherwise returns EmptyReference. /// </summary> /// <param name="source">Source LinkItem for which to return content reference.</param> /// <returns>Returns ContentReference for provided LinkItem if it is EPiServer page otherwise returns EmptyReference.</returns> public static ContentReference ToContentReference(this LinkItem source) { var urlBuilder = new UrlBuilder(source.Href); return(PermanentLinkMapStore.ToMapped(urlBuilder) ? PermanentLinkUtility.GetContentReference(urlBuilder) : ContentReference.EmptyReference); }
public virtual string GetExportableLink(ContentReference contentLink) { var pageMap = PermanentLinkMapStore.Find(contentLink) as PermanentContentLinkMap; if (pageMap != null) { return(GetExportableLink(pageMap.Guid, string.Empty)); } return(""); }
public static T GetPageData <T>(this IndexResponseItem item) where T : PageData { var guid = new Guid(item.VirtualPathNodes.Last()); var map = PermanentLinkMapStore.Find(guid) as PermanentContentLinkMap; if (map != null) { return(ServiceLocator.Current.GetInstance <IContentLoader>().Get <T>(map.ContentReference)); } return(null); }
/// <summary> /// Gets the page data for the current search result /// </summary> /// <param name="result">The <see cref="IndexResponseItem"/> to operate on</param> /// <returns>A <see cref="PageData"/> for the result or null if the page cannot be found</returns> public static PageData GetPageData(this IndexResponseItem result) { var guid = new Guid(result.VirtualPathNodes.Last()); var map = PermanentLinkMapStore.Find(guid) as PermanentContentLinkMap; if (map != null) { return(DataFactory.Instance.Get <PageData>(map.ContentReference)); } return(null); }
public static string ToMappedLink(string url) { if (!string.IsNullOrEmpty(url)) { string str; if (PermanentLinkMapStore.TryToPermanent(url, out str)) { return(str); } } return(url); }
/// <summary> /// Prepares all links in a LinkItemCollection for output /// by filtering out inaccessible links and ensures all links are correct. /// </summary> /// <param name="linkItemCollection">The collection of links to prepare.</param> /// <param name="targetExternalLinksToNewWindow">True will set target to _blank if target is not specified for the LinkItem.</param> /// <returns>A prepared and filtered list of LinkItems</returns> public static IEnumerable <LinkItem> ToPreparedLinkItems(this LinkItemCollection linkItemCollection, bool targetExternalLinksToNewWindow) { var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); if (linkItemCollection != null) { foreach (var linkItem in linkItemCollection) { var url = new UrlBuilder(linkItem.Href); if (PermanentLinkMapStore.ToMapped(url)) { var pr = PermanentLinkUtility.GetContentReference(url); if (!PageReference.IsNullOrEmpty(pr)) { // page var page = contentLoader.Get <PageData>(pr); if (IsPageAccessible(page)) { linkItem.Href = page.LinkURL; yield return(linkItem); } } else { // document if (IsFileAccessible(linkItem.Href)) { Global.UrlRewriteProvider.ConvertToExternal(url, null, System.Text.Encoding.UTF8); linkItem.Href = url.Path; yield return(linkItem); } } } else if (!linkItem.Href.StartsWith("~")) { // external if (targetExternalLinksToNewWindow && string.IsNullOrEmpty(linkItem.Target)) { linkItem.Target = "_blank"; } if (linkItem.Href.StartsWith("mailto:") || linkItem.Target == "null") { linkItem.Target = string.Empty; } yield return(linkItem); } } } }
private static void AppendFiles(LinkItemCollection files, StringBuilder outputString, string formatString) { if (files == null || files.Count <= 0) { return; } foreach (var item in files.Where(item => !string.IsNullOrEmpty(item.Href))) { var map = PermanentLinkMapStore.Find(new UrlBuilder(item.Href)) as PermanentContentLinkMap; outputString.AppendLine(map == null ? string.Format(formatString, item.GetMappedHref()) : string.Format(formatString, UrlResolver.Current.GetUrl(map.ContentReference))); } }
/// <summary> /// Handles the AfterSubmitPostedData event of the XFormControl. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EPiServer.XForms.WebControls.SaveFormDataEventArgs"/> instance containing the event data.</param> public void XForm_AfterSubmitPostedData(object sender, SaveFormDataEventArgs e) { XFormControl control = (XFormControl)sender; if (control.FormDefinition.PageGuidAfterPost != Guid.Empty) { PermanentPageLinkMap pageMap = PermanentLinkMapStore.Find(control.FormDefinition.PageGuidAfterPost) as PermanentPageLinkMap; if (pageMap != null) { control.Page.Response.Redirect(pageMap.MappedUrl.ToString()); return; } } //After the form has been posted we remove the form elements and add a "thank you message". control.Controls.Clear(); Label label = new Label(); label.CssClass = "thankyoumessage"; label.Text = LanguageManager.Instance.Translate("/form/postedmessage"); control.Controls.Add(label); }
/// <summary> /// Converts a LinkItemCollection to typed pages. Any non-pages will be filtered out. (Not compatible with PageList - Use ToPageDataList) /// </summary> /// <typeparam name="T">PageType</typeparam> /// <param name="linkItemCollection">The collection of links to convert</param> /// <returns>An enumerable of typed PageData</returns> public static IEnumerable <T> ToPages <T>(this LinkItemCollection linkItemCollection) where T : PageData { var contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); if (linkItemCollection != null) { foreach (var linkItem in linkItemCollection) { var url = new UrlBuilder(linkItem.Href); if (PermanentLinkMapStore.ToMapped(url)) { var pr = PermanentLinkUtility.GetContentReference(url); if (!PageReference.IsNullOrEmpty(pr)) { var page = contentLoader.Get <PageData>(pr); if (page is T && IsPageAccessible(page)) { yield return((T)page); } } } } } }
public static ContentReference GetPageFromPageGuid(Guid pageGuid) { var map = PermanentLinkMapStore.Find(pageGuid) as PermanentContentLinkMap; return((map != null) ? map.ContentReference : PageReference.EmptyReference); }
public static string FromMappedLink(string url) { string str2; return(PermanentLinkMapStore.TryToMapped(url, out str2) ? str2 : url); }