/// <summary> /// Creates a link for a thread page. Also has a max length for how big part of the PageName will be used in the link. /// </summary> /// <param name="page">The thread page.</param> /// <param name="previewLength">Length of the page name.</param> /// <param name="cssClass">Any CSS classes that should be added to the link.</param> /// <returns>A string containing the link.</returns> protected string CreatePageLink(PageData page, int previewLength, string additionalCssClasses) { string cssClass = String.Empty; PageReference reference = (PageReference)ForumStartPage["StickyThreadContainer"]; if (!PageReference.IsNullOrEmpty(reference) && page.ParentLink.CompareToIgnoreWorkID(reference)) { cssClass = "sticky"; } if (page["IsLocked"] != null) { cssClass += "locked"; } if (!String.IsNullOrEmpty(additionalCssClasses)) { cssClass += " " + additionalCssClasses; } string pageName = page.PageName; if (previewLength > 3) { pageName = pageName.Ellipsis(previewLength); } return(String.Format("<a class=\"{0}\" href=\"{1}\">{2}</a>", cssClass, page.LinkURL, Server.HtmlEncode(pageName))); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); SetFlash(); //change the css class for this page type Form.Attributes["class"] = "StartPage"; if (CurrentPage["MainLinksCount"] != null) { MainPageList.MaxCount = (int)CurrentPage["MainLinksCount"]; } if (CurrentPage["SecondaryLinksCount"] != null) { SecondaryPageList.MaxCount = (int)CurrentPage["SecondaryLinksCount"]; } DynamicProperty property = DynamicProperty.Load(CurrentPageLink, "StartPage"); if (property == null) { return; } PageReference reference = property.PropertyValue.Value as PageReference; if (PageReference.IsNullOrEmpty(reference) || (reference.ID != CurrentPageLink.ID)) { property.PropertyValue.Value = CurrentPageLink; property.Save(); } }
protected override IEnumerable <PageReference> GetContentReferences(string languageBranch) { RecentlyChangedPagesFinder finder = new RecentlyChangedPagesFinder(); IEnumerable <RecentlyChangedPage> recentPages = finder.Find(50) .Where(p => p.Status == VersionStatus.Published.ToString()); var pageReferenceList = new List <PageReference>(); foreach (RecentlyChangedPage recentlyChangedpage in recentPages) { int pageId; if (!int.TryParse(recentlyChangedpage.ID, out pageId)) { continue; } var pageReference = new PageReference(pageId); if (PageReference.IsNullOrEmpty(pageReference)) { continue; } var page = DataFactory.Instance.GetPage(pageReference, new LanguageSelector(languageBranch)); if (page == null) { continue; } pageReferenceList.Add(pageReference); } return(pageReferenceList); }
/// <summary> /// Enables moderator functions if the user is a moderator. /// Enable the possibility to add a thread if the user is a poster. /// Adds sticky threads to the top of the thread list. /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (IsModerator && !IsStartPage) { DeleteForumButton.Visible = true; DeleteForumButton.OnClientClick = string.Format("if(!confirm('{0}'))return false;", Translate("/common/messages/confirmdelete")); } ForumList.DataBind(); // Add sticky threads. PageReference stickyThreadContainer = (PageReference)CurrentPage["StickyThreadContainer"]; if (!PageReference.IsNullOrEmpty(stickyThreadContainer)) { ThreadList.DataSource = DataFactory.Instance.GetChildren(stickyThreadContainer); } else if (CurrentPage.Status == VersionStatus.Published) { // If there is no container pages, and we are viewing the published version, show the error panel. SwitchView(ViewMode.ErrorView); return; } if (!IsPostBack) { SwitchView(ViewMode.ListView); } }
/// <summary> /// Returns the full, public URL of a page. /// </summary> /// <param name="page">The page whose friendly URL should be returned.</param> /// <returns>The friendly URL including host of the page based on the current HTTP context.</returns> public static string GetExternalUrl(this PageData page) { if (page == null) { return(string.Empty); } if (HttpContext.Current.Request.ApplicationPath == null) { return(string.Empty); } var url = new UrlBuilder(page.LinkURL); if (!string.IsNullOrEmpty(url.Scheme)) { return(page.LinkURL); } Global.UrlRewriteProvider.ConvertToExternal( url, !PageReference.IsNullOrEmpty(page.PageLink) ? page.PageLink : null, Encoding.UTF8); return(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath.TrimEnd(new[] { '/' }) + url.ToString()); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { FileList.Visible = IsFileManagerVisibleInMenu(); NewsListUnit.Visible = !PageReference.IsNullOrEmpty((PageReference)CurrentPage["NewsRoot"]) && DataFactory.Instance.GetPage((PageReference)CurrentPage["NewsRoot"]).VisibleInMenu; CalendarList.Visible = !PageReference.IsNullOrEmpty((PageReference)CurrentPage["CalendarContainer"]) && DataFactory.Instance.GetPage((PageReference)CurrentPage["CalendarContainer"]).VisibleInMenu; FileList.DataBind(); } if (NewsListUnit.Visible) { NewsListUnit.DataSource = GetNewsListPages(); NewsListUnit.DataBind(); } if (CalendarList.Visible) { CalendarList.DataBind(); } }
public void Initialize(Framework.Initialization.InitializationEngine context) { if (_initialized || PageReference.IsNullOrEmpty(GlobalNewsContainer) || context.HostType != HostType.WebApplication) { return; } var providerManager = ServiceLocator.Current.GetInstance <IContentProviderManager>(); var startPages = DataFactory.Instance.GetChildren(PageReference.RootPage).OfType <StartPage>(); // Attach content provider to each site's global news container foreach (var startPage in startPages.Where(startPage => !PageReference.IsNullOrEmpty(startPage.GlobalNewsPageLink))) { try { _logger.DebugFormat("Attaching global news content provider to page {0} [{1}], global news will be retrieved from page {2} [{3}]", startPage.GlobalNewsPageLink.GetPage().Name, startPage.GlobalNewsPageLink.ID, GlobalNewsContainer.GetPage().PageName, GlobalNewsContainer.ID); var provider = new ClonedContentProvider(GlobalNewsContainer, startPage.GlobalNewsPageLink, startPage.Category); providerManager.ProviderMap.AddProvider(provider); } catch (Exception ex) { _logger.ErrorFormat("Unable to create global news content provider for start page with ID {0}: {1}", startPage.PageLink.ID, ex.Message); } } _initialized = true; }
public static string GetSimpleAddressIfExits(this PageReference pageLink) { if (PageReference.IsNullOrEmpty(pageLink)) { return(string.Empty); } var page = pageLink.GetPage(); if (page == null) { return(string.Empty); } var simpleaddress = page.GetPropertyValue("PageExternalURL"); string pageUrl; if (!string.IsNullOrEmpty(simpleaddress)) { pageUrl = string.Format("/{0}/", simpleaddress); } else { var urlResolver = ServiceLocator.Current.GetInstance <UrlResolver>(); pageUrl = urlResolver.GetUrl(pageLink); } return(pageUrl); }
/// <summary> /// Updates the changed date and number of replies on a thread when a reply is made. /// </summary> /// <param name="threadReference">A reference to the thread.</param> /// <param name="forumStartPage">A reference to the forum the thread belongs to.</param> /// <returns>Returns true if the page has been moved from the archive to the active container; Otherwise false.</returns> private static bool UpdateThread(PageReference threadReference, PageData forumStartPage) { PageData thread = DataFactory.Instance.GetPage(threadReference).CreateWritableClone(); thread["PageChangedOnPublish"] = true; thread.StopPublish = DateTime.Now.Add(_archiveTimeSpan); if (thread["NumberOfReplies"] == null) { thread["NumberOfReplies"] = 1; } else { thread["NumberOfReplies"] = (int)thread["NumberOfReplies"] + 1; } DataFactory.Instance.Save(thread, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); PageReference archiveThreadContainerReference = (PageReference)forumStartPage["ArchiveThreadContainer"]; if (PageReference.IsNullOrEmpty(archiveThreadContainerReference)) { throw new EPiServerException("ArchiveThreadContainer", "'Container for archived threads' property is not defined on a forum start page."); } if (thread.ParentLink.CompareToIgnoreWorkID(archiveThreadContainerReference)) { DataFactory.Instance.Move(thread.PageLink, (PageReference)forumStartPage["ActiveThreadContainer"]); return(true); } return(false); }
/// <summary> /// Changes left menu and breadcrumbs if page is in workroom /// Redirects to profile page if needed /// </summary> /// <param name="page">page for initialization</param> /// <param name="enableRedirect">If redirect is enabled</param> private static void InitializeWorkroomPage(PageBase page, bool enableRedirect) { //Check if page is in workroom PageReference start = GetWorkroomStartPageLink(page); if (PageReference.IsNullOrEmpty(start)) { return; } /// Redirect ot profile page if (enableRedirect) { RedirectToUserProfilePage(page); } ///Update left menu tree PageTree tree = page.Master.FindControl(_subMenuControlID) as PageTree; if (tree != null) { tree.PageLink = start; tree.NumberOfLevels = 3; tree.DataBind(); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (PageReference.IsNullOrEmpty(CalendarContainer)) { this.Visible = false; } switch (ViewMode) { case UpcomingListViewMode.ContainerView: { ContainerView.Visible = true; ListView.Visible = false; break; } case UpcomingListViewMode.ListView: { ContainerView.Visible = false; ListView.Visible = true; break; } } DataBind(); if (CalendarEventList.DataCount == 0 && this.HideIfEmpty) { this.Visible = false; } }
/// <summary> /// The find pages with criteria. /// </summary> /// <param name="pageLink"> /// The page link. /// </param> /// <param name="criterias"> /// The criterias. /// </param> /// <param name="languageBranch"> /// The language branch. /// </param> /// <param name="selector"> /// The selector. /// </param> /// <returns> /// The <see cref="PageDataCollection"/>. /// </returns> public PageDataCollection FindPagesWithCriteria( PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, ILanguageSelector selector) { if (PageReference.IsNullOrEmpty(pageLink)) { return(new PageDataCollection()); } // Any search beneath the entry root should in fact be performed under the clone root as that's where the original content resides if (pageLink.CompareToIgnoreWorkID(this.EntryRoot)) { pageLink = this.CloneRoot; } else if (!string.IsNullOrWhiteSpace(pageLink.ProviderName)) { // Any search beneath a cloned page should in fact be performed under the original page, so we use a page link without any provider information pageLink = new PageReference(pageLink.ID); } PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria( pageLink, criterias, languageBranch, selector); // Return cloned search result set return(new PageDataCollection(pages.Select(this.ClonePage))); }
/// <summary> /// Initializes a new instance of the <see cref="ClonedContentProvider"/> class. /// </summary> /// <param name="providerKey"> /// The provider key. /// </param> /// <param name="cloneRoot"> /// The clone root. /// </param> /// <param name="entryRoot"> /// The entry root. /// </param> /// <param name="categoryFilter"> /// The category filter. /// </param> /// <exception cref="System.ArgumentNullException"> /// Parameter "cloneRoot" cannot be null or empty /// </exception> /// <exception cref="System.NotSupportedException"> /// Entry root and clone root cannot be set to the same content reference /// or /// Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children) /// </exception> public ClonedContentProvider( string providerKey, PageReference cloneRoot, PageReference entryRoot, CategoryList categoryFilter) { if (PageReference.IsNullOrEmpty(cloneRoot)) { throw new ArgumentNullException("cloneRoot"); } if (cloneRoot.CompareToIgnoreWorkID(entryRoot)) { throw new NotSupportedException("Entry root and clone root cannot be set to the same content reference"); } if (DataFactory.Instance.GetChildren <IContent>(entryRoot).Any()) { throw new NotSupportedException( "Unable to create ClonedContentProvider, the EntryRoot property must point to leaf content (without children)"); } this.CloneRoot = cloneRoot; this.EntryRoot = entryRoot; this.Category = categoryFilter; this.providerKey = providerKey; // Set the entry point parameter this.Parameters.Add(PageProvider.EntryPointString, this.EntryRoot.ID.ToString(CultureInfo.InvariantCulture)); // Configure content store used to retrieve pages this.ContentStore = ServiceLocator.Current.GetInstance <ContentStore>(); }
public static List <PageData> ToPages(this EPiServer.SpecializedProperties.LinkItemCollection linkItemCollection) { List <PageData> pages = new List <PageData>(); var contentLoader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <EPiServer.IContentLoader>(); foreach (EPiServer.SpecializedProperties.LinkItem linkItem in linkItemCollection) { string linkUrl; if (!EPiServer.Web.PermanentLinkMapStore.TryToMapped(linkItem.Href, out linkUrl)) { continue; } if (string.IsNullOrEmpty(linkUrl)) { continue; } PageReference pageReference = PageReference.ParseUrl(linkUrl); if (PageReference.IsNullOrEmpty(pageReference)) { continue; } pages.Add(contentLoader.Get <PageData>(pageReference)); } return(pages); }
public ActionResult Index(BusinessProfilePage currentPage, BusinessProfileModel businessProfile) { if (string.IsNullOrEmpty(SiteUser?.SerialNumber)) { return(HttpNotFound()); } if (!ModelState.IsValid) { Response.StatusCode = 400; ViewBag.Message = "Some fields have invalid value. Please try again!"; return(View("~/Views/Organization/BusinessProfile.cshtml", new BusinessProfileViewModel(currentPage) { BusinessProfile = businessProfile, IsLoginBankId = !string.IsNullOrEmpty(SiteUser.SerialNumber) })); } var customer = UserManager.GetActiveCustomer(HttpContext); if (customer != null) { var result = _organizationRepository.UpdateBusinessProfile(new BusinessProfile { CustomerId = customer.CustomerId, Id = businessProfile.Id, Name = businessProfile.Name, Rows = businessProfile.Rows.ToArray() }, customer.CustomerNo); if (result) { var startPage = _contentRepo.Get <StartPage>(ContentReference.StartPage); if (startPage != null) { if (!PageReference.IsNullOrEmpty(startPage.SettingsPage)) { var settingPage = _contentRepo.Get <SettingsPage>(startPage.SettingsPage); if (settingPage != null) { //TempData["UpdateInfoSuccess"] = true; TempData["UpdateBusinessProfileSuccess"] = true; return(RedirectToAction("Index", new { node = settingPage.MyAccountLink })); } } } } } var viewModel = new BusinessProfileViewModel(currentPage) { BusinessProfile = businessProfile, IsLoginBankId = !string.IsNullOrEmpty(SiteUser.SerialNumber) }; ViewBag.Message = "Uppdateringen lyckades inte. Försök igen!"; return(View("~/Views/Organization/BusinessProfile.cshtml", viewModel)); }
protected override void CreateChildControls() { PageData page = PageReference.IsNullOrEmpty(base.RootLink) ? null : base.GetPage(base.RootLink); base.CreateTemplateControl(page, this.HeaderTemplate, 0, false); this.CreateItemsRecursive(1, string.Empty); base.CreateTemplateControl(page, this.FooterTemplate, 0, false); }
private IOrganizeChildren GetChildrenOrganizer(PageReference pageLink) { if (PageReference.IsNullOrEmpty(pageLink)) { return(null); } return(DataFactory.Instance.GetPage(pageLink) as IOrganizeChildren); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.PreRender" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnPreRender(EventArgs e) { if (this._isDirty || !PageReference.IsNullOrEmpty(this.PageLink) && !this._isBound) { this.DataBind(); } this.EnsureChildControls(); base.OnPreRender(e); }
/// <summary> /// Returns parent page of provided page. /// </summary> /// <param name="page">The page for which to find parent page.</param> /// <returns>Returns instance of parent page of PageData type or null if parent page not found./></returns> public static PageData GetParent(this PageData page) { if (page == null || PageReference.IsNullOrEmpty(page.ParentLink) || DataFactory.Instance.IsWastebasket(page.PageLink)) // TODO: Might be obsolete in EPi 7 - should verify { return(null); } return(page.ParentLink.GetPage()); }
/// <summary> /// Returns all contact pages beneath the main contacts container /// </summary> /// <returns></returns> public IEnumerable <ContactPage> GetContactPages() { var contactsRootPageLink = PageReference.StartPage.GetPage <StartPage>().ContactsPageLink; if (PageReference.IsNullOrEmpty(contactsRootPageLink)) { throw new ConfigurationErrorsException("No contact page root specified in site settings, unable to retrieve contact pages"); } return(DataFactory.Instance.GetChildren <ContactPage>(contactsRootPageLink).OrderBy(p => p.PageName)); }
protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); Response.ContentType = "text/xml"; Response.Clear(); if (!PageReference.IsNullOrEmpty(CurrentPage["RssSource"] as PageReference)) { WriteRssDocument(); } Response.End(); }
public IEnumerable <PageData> FindPagesByPageType(PageReference pageLink, bool recursive, int pageTypeId) { if (PageReference.IsNullOrEmpty(pageLink)) { throw new ArgumentNullException("pageLink", "No page link specified, unable to find pages"); } var pages = recursive ? FindPagesByPageTypeRecursively(pageLink, pageTypeId) : _contentLoader.GetChildren <PageData>(pageLink); return(pages); }
/// <summary> /// Finds a page in the supplied <c>pages</c> collection. /// </summary> /// <param name="pages">The collection of pages to search in.</param> /// <param name="pageLink">A <see cref="PageReference"/> to find.</param> /// <returns>The <see cref="PageData"/> for the page if one could be found; otherwise <c>null</c>.</returns> private static PageData FindPage(PageDataCollection pages, PageReference pageLink) { if (PageReference.IsNullOrEmpty(pageLink)) { return(null); } int index = pages.Find(pageLink); if (index != -1) { return(pages[index]); } return(null); }
/// <summary> /// If the thread is sticky it moves the page back to the active thread container. /// Otherwise, it moves the thread page to the sticky thread container. /// </summary> protected void Sticky_Click(object sender, EventArgs e) { string temp = IsSticky ? "ActiveThreadContainer" : "StickyThreadContainer"; PageReference targetPageRef = (PageReference)ForumStartPage[temp]; if (PageReference.IsNullOrEmpty(targetPageRef)) { return; } DataFactory.Instance.Move(CurrentPageLink, targetPageRef); // Since we moved the page we are currently loading, we need to redirect to reload it from it's new place. Response.Redirect(CurrentPage.LinkURL, true); }
public ActionResult Index(StartPage currentPage) { /* Implementation of action. You can create your own view model class that you pass to the view or * you can pass the page type for simpler templates */ DefaultPageViewModel <StartPage> model = new DefaultPageViewModel <StartPage>(currentPage); if (PageReference.IsNullOrEmpty(currentPage.SearchPageLink)) { model.IsSearchPageSet = false; model.SearchNotActiveMessage = _uiInfoSearchInactiveMessage; } return(View(model)); }
public static PageData GetPage(this PageReference pageReference, IContentLoader contentLoader = null) { if (PageReference.IsNullOrEmpty(pageReference)) { return(null); } if (contentLoader == null) { contentLoader = ServiceLocator.Current.GetInstance <IContentLoader>(); } return(contentLoader.Get <PageData>(pageReference)); }
public List <INavigationItem> GetNavigationItems(PageReference pageReference) { if (PageReference.IsNullOrEmpty(pageReference)) { return(new List <INavigationItem>()); } var navigationItems = new List <INavigationItem>(); var menuPages = _websiteDependencies.ContentRepository.GetChildren <MenuPage>(pageReference); navigationItems.AddRange(menuPages.Select(CreateNavigationItem)); return(navigationItems); }
/// <summary> /// Checks if a specific page is located beneath another page /// </summary> public static bool IsDescendantOf(this PageData page, PageData parent) { while (!PageReference.IsNullOrEmpty(page.ParentLink)) { if (page.ParentLink.CompareToIgnoreWorkID(parent.PageLink)) { return(true); } page = page.ParentLink.GetPage(); } return(false); }
/// <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); } } } }
/// <summary> /// Gets a page reference pointing out the root page for the page collection to toggle visibility for. /// It looks at <see cref="PageLink"/> property and <see cref="PageLinkProperty"/> in named order to find a <see cref="PageReference"/>. /// </summary> /// <returns>A <see cref="PageReference"/>; or <c>null</c> if none has been set.</returns> private PageReference GetListPageLink() { if (_pageLink == null) { if (!PageReference.IsNullOrEmpty(PageLink)) { _pageLink = PageLink; } else if (!String.IsNullOrEmpty(PageLinkProperty)) { _pageLink = CurrentPage[PageLinkProperty] as PageReference; } } return(_pageLink); }