/// <summary> /// Gets the SEO list for the given internal id. /// </summary> /// <param name="internalId">The internal id.</param> /// <returns>The SEO list</returns> public static ListModel GetSEO(string internalId = "") { if (String.IsNullOrEmpty(internalId)) { internalId = Config.SiteTree; } ListModel m = new ListModel(); m.Pages = Sitemap.GetStructure(internalId, false).Flatten() .Where(s => s.Published != DateTime.MinValue && (String.IsNullOrEmpty(s.Keywords) || String.IsNullOrEmpty(s.Description))).ToList(); m.ActiveSite = internalId.ToUpper(); using (var db = new DataContext()) { m.ActiveSiteId = db.SiteTrees.Where(s => s.InternalId == internalId).Select(s => s.Id).Single(); m.NewSeqno = db.Pages.Where(p => p.ParentId == null).Count() + 1; } // Check completion warnings foreach (var page in m.Pages) { m.PageWarnings[page.Id] = 0 + (String.IsNullOrEmpty(page.Keywords) ? 1 : 0) + (String.IsNullOrEmpty(page.Description) ? 1 : 0); } m.IsSeoList = true; return(m); }
/// <summary> /// Gets the list model for all available pages. /// </summary> /// <param name="internalId">Optional internal id of the site tree</param> /// <returns>The model.</returns> public static ListModel Get(string internalId = "") { if (String.IsNullOrEmpty(internalId)) { internalId = Config.SiteTree; } ListModel m = new ListModel(); m.SiteMap = Sitemap.GetStructure(internalId, false); m.Pages = Sitemap.GetStructure(internalId, false).Flatten(); m.ActiveSite = internalId.ToUpper(); m.NewSeqno = m.SiteMap.Count + 1; using (var db = new DataContext()) { m.ActiveSiteId = db.SiteTrees.Where(s => s.InternalId == internalId).Select(s => s.Id).Single(); } // Check completion warnings foreach (var page in m.Pages) { m.PageWarnings[page.Id] = 0 + (String.IsNullOrEmpty(page.Keywords) ? 1 : 0) + (String.IsNullOrEmpty(page.Description) ? 1 : 0); } return(m); }
/// <summary> /// Refreshes the model from the database. /// </summary> public virtual void Refresh() { if (Page != null) { if (!Page.IsNew) // Page.Id != Guid.Empty) { { Page = Page.GetSingle(Page.Id, true); CanDelete = Page.GetScalar("SELECT count(*) FROM page WHERE page_parent_id = @0", Page.Id) == 0; GetRelated(); } else { Template = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId); // Get placement ref title if (Page.ParentId != Guid.Empty || Page.Seqno > 1) { Page refpage = null; if (Page.Seqno > 1) { if (Page.ParentId != Guid.Empty) { refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1); } else { refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1); } } else { refpage = Page.GetSingle(Page.ParentId, true); } PlaceRef = refpage.Title; } // Get page position Parents = BuildParentPages(Sitemap.GetStructure(Page.SiteTreeInternalId, false), Page); Parents.Insert(0, new PagePlacement() { Level = 1, IsSelected = Page.ParentId == Guid.Empty }); Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId, Page.SiteTreeInternalId); // Initialize regions foreach (var reg in Regions) { if (Extend.ExtensionManager.ExtensionTypes.ContainsKey(reg.Type)) { var m = Extend.ExtensionManager.ExtensionTypes[reg.Type].GetMethod("Init"); if (m != null) { m.Invoke(reg.Body, new object[] { this }); } } } } } }
/// <summary> /// Gets the list model for all available pages. /// </summary> /// <returns>The model.</returns> public static ListModel Get() { ListModel m = new ListModel(); m.SiteMap = Sitemap.GetStructure(false); m.Pages = Sitemap.GetStructure(false).Flatten(); return(m); }
/// <summary> /// Gets the model for the given site. /// </summary> /// <param name="siteid">The site id</param> /// <returns>The model</returns> public static LinkDialogModel GetBySiteId(Guid siteid) { var m = new LinkDialogModel(); m.ActiveSite = siteid; using (var db = new DataContext()) { var site = db.SiteTrees.Where(s => s.Id == m.ActiveSite).Single(); m.Pages = Sitemap.GetStructure(site.InternalId); } return(m); }
/// <summary> /// Refreshes the model from the database. /// </summary> public virtual void Refresh() { if (Page != null) { if (!Page.IsNew) // Page.Id != Guid.Empty) { { Page = Page.GetSingle(Page.Id, true); CanDelete = Page.GetScalar("SELECT count(*) FROM page WHERE page_parent_id = @0", Page.Id) == 0; GetRelated(); } else { Template = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId); // Get placement ref title if (Page.ParentId != Guid.Empty || Page.Seqno > 1) { Page refpage = null; if (Page.Seqno > 1) { if (Page.ParentId != Guid.Empty) { refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1); } else { refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0 AND page_sitetree_id = @1", Page.Seqno - 1, Page.SiteTreeId); //ÖS 2015-03-18 added siteid to the query } } else { refpage = Page.GetSingle(Page.ParentId, true); } PlaceRef = refpage.Title; } // Get page position Parents = BuildParentPages(Sitemap.GetStructure(Page.SiteTreeInternalId, false), Page); Parents.Insert(0, new PagePlacement() { Level = 1, IsSelected = Page.ParentId == Guid.Empty }); Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId, Page.SiteTreeInternalId); // Initialize regions foreach (var reg in Regions) { reg.Body.Init(this); } } } }
/// <summary> /// Handles the sitemap request. /// </summary> /// <param name="context">The current http context</param> /// <param name="args">Optional url params</param> public virtual void HandleRequest(HttpContext context, params string[] args) { var sitemap = Sitemap.GetStructure(); var posts = Post.GetFields("post_last_published, permalink_name", "post_draft = 0"); context.Response.StatusCode = 200; context.Response.ContentType = "text/xml"; context.Response.Write(xmlStart); WriteNodes(context, sitemap); WritePosts(context, posts); context.Response.Write(xmlEnd); context.Response.EndClean(); }
/// <summary> /// Return the site structure as an ul/li list with the current page selected. /// </summary> /// <param name="StartLevel">The start level of the menu</param> /// <param name="StopLevel">The stop level of the menu</param> /// <param name="Levels">The number of levels. Use this if you don't know the start level</param> /// <returns>A html string</returns> public IHtmlString Menu(int StartLevel = 1, int StopLevel = Int32.MaxValue, int Levels = 0, string RootNode = "", string CssClass = "menu", bool RenderParent = false) { StringBuilder str = new StringBuilder(); List <Sitemap> sm = null; Page Current = CurrentPage; if (Current != null || StartLevel == 1) { if (Current == null) { Current = new Page(); } if (RootNode != "") { Permalink pr = Models.Permalink.GetSingle("permalink_name = @0 AND permalink_namespace_id = @1", RootNode, WebPiranha.CurrentSite.NamespaceId); if (pr != null) { Page p = Page.GetByPermalinkId(pr.Id); Sitemap page = Sitemap.GetStructure(true).GetRootNode(p.Id); if (page != null) { sm = new List <Sitemap>(); if (RenderParent) { sm.Add(Mapper.Map <Sitemap, Sitemap>(page)); } sm.AddRange(page.Pages); } } } else { sm = GetStartLevel(Sitemap.GetStructure(true), Current.Id, StartLevel, RenderParent); } if (sm != null) { if (StopLevel == Int32.MaxValue && Levels > 0 && sm.Count > 0) { StopLevel = sm[0].Level + Math.Max(0, Levels - 1); } RenderUL(Current, sm, str, StopLevel, CssClass); } } return(new HtmlString(str.ToString())); }
/// <summary> /// Refreshes the model from the database. /// </summary> public virtual void Refresh() { if (Page != null) { if (!Page.IsNew) // Page.Id != Guid.Empty) { { Page = Page.GetSingle(Page.Id, true); GetRelated(); } else { Template = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId); // Get placement ref title if (Page.ParentId != Guid.Empty || Page.Seqno > 1) { Page refpage = null; if (Page.Seqno > 1) { if (Page.ParentId != Guid.Empty) { refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1); } else { refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1); } } else { refpage = Page.GetSingle(Page.ParentId, true); } PlaceRef = refpage.Title; } // Get page position Parents = BuildParentPages(Sitemap.GetStructure(false), Page); Parents.Insert(0, new PagePlacement() { Level = 1, IsSelected = Page.ParentId == Guid.Empty }); Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId); } } }
/// <summary> /// Renders the current breadcrumb. /// </summary> /// <param name="StartLevel">Optional start level</param> /// <param name="RootNode">Optional root node</param> /// <returns>The breadcrumb</returns> public IHtmlString Breadcrumb(int StartLevel = 1, string RootNode = "") { StringBuilder str = new StringBuilder(); List <Sitemap> sm = null; Page Current = CurrentPage; if (Current != null) { if (RootNode != "") { Permalink pr = Models.Permalink.GetSingle("permalink_name = @0", RootNode); if (pr != null) { Page p = Page.GetByPermalinkId(pr.Id); Sitemap page = Sitemap.GetStructure(true).GetRootNode(p.Id); if (page != null) { sm = page.Pages; } } } else { sm = sm = GetStartLevel(Sitemap.GetStructure(true), Current.Id, StartLevel); } if (sm != null) { if (Hooks.Breadcrumb.RenderStart != null) { Hooks.Breadcrumb.RenderStart(this, str); } RenderBreadcrumb(Current, sm, str); if (Hooks.Breadcrumb.RenderEnd != null) { Hooks.Breadcrumb.RenderEnd(this, str); } } } return(new HtmlString(str.ToString())); }
/// <summary> /// Return the site structure as an ul/li list with the current page selected. /// </summary> /// <param name="StartLevel">The start level of the menu</param> /// <param name="StopLevel">The stop level of the menu</param> /// <returns>A html string</returns> public IHtmlString Menu(int StartLevel = 1, int StopLevel = Int32.MaxValue, string RootNode = "", string CssClass = "menu") { StringBuilder str = new StringBuilder(); List <Sitemap> sm = null; Page Current = CurrentPage; if (Current != null || StartLevel == 1) { if (Current == null) { Current = new Page(); } if (RootNode != "") { Permalink pr = Models.Permalink.GetSingle("permalink_name = @0", RootNode); if (pr != null) { Page p = Page.GetByPermalinkId(pr.Id); Sitemap page = Sitemap.GetStructure(true).GetRootNode(p.Id); if (page != null) { sm = page.Pages; } } } else { sm = GetStartLevel(Sitemap.GetStructure(true), Current.Id, StartLevel); } if (sm != null) { RenderUL(Current, sm, str, StopLevel, CssClass); } } return(new HtmlString(str.ToString())); }
private void GetRelated() { // Clear related Regions.Clear(); Properties.Clear(); AttachedContent.Clear(); // Get group parents DisableGroups = SysGroup.GetParents(Page.GroupId); DisableGroups.Reverse(); // Get template & permalink Template = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId); Permalink = Permalink.GetSingle(Page.PermalinkId); if (Permalink == null) { // Get the site tree using (var db = new DataContext()) { var sitetree = db.SiteTrees.Where(s => s.Id == Page.SiteTreeId).Single(); Permalink = new Permalink() { Id = Guid.NewGuid(), Type = Permalink.PermalinkType.PAGE, NamespaceId = sitetree.NamespaceId }; Page.PermalinkId = Permalink.Id; } } // Get placement ref title if (!IsSite) { if (Page.ParentId != Guid.Empty || Page.Seqno > 1) { Page refpage = null; if (Page.Seqno > 1) { if (Page.ParentId != Guid.Empty) { refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1); } else { refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1); } } else { refpage = Page.GetSingle(Page.ParentId, true); } PlaceRef = refpage.Title; } } if (Template != null) { // Only load regions & properties if this is an original if (Page.OriginalId == Guid.Empty) { // Get regions var regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id, new Params() { OrderBy = "regiontemplate_seqno" }); foreach (var rt in regions) { var reg = Region.GetSingle("region_regiontemplate_id = @0 AND region_page_id = @1 and region_draft = @2", rt.Id, Page.Id, Page.IsDraft); if (reg != null) { Regions.Add(reg); } else { Regions.Add(new Region() { InternalId = rt.InternalId, Name = rt.Name, Type = rt.Type, PageId = Page.Id, RegiontemplateId = rt.Id, IsDraft = Page.IsDraft, IsPageDraft = Page.IsDraft }); } } // Get Properties foreach (string name in Template.Properties) { Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2", name, Page.Id, Page.IsDraft); if (prp != null) { Properties.Add(prp); } else { Properties.Add(new Property() { Name = name, ParentId = Page.Id, IsDraft = Page.IsDraft }); } } } } else { throw new ArgumentException("Could not find page template for page {" + Page.Id.ToString() + "}"); } // Only load attachments if this is an original if (Page.OriginalId == Guid.Empty) { // Get attached content if (Page.Attachments.Count > 0) { // Content meta data is actually memcached, so this won't result in multiple queries Page.Attachments.ForEach(a => { Models.Content c = Models.Content.GetSingle(a, true); if (c != null) { AttachedContent.Add(c); } }); } } // Get page position Parents = BuildParentPages(Sitemap.GetStructure(Page.SiteTreeInternalId, false), Page); Parents.Insert(0, new PagePlacement() { Level = 1, IsSelected = Page.ParentId == Guid.Empty }); Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId, Page.SiteTreeInternalId); // Only load extensions if this is an original if (Page.OriginalId == Guid.Empty) { // Get extensions Extensions = Page.GetExtensions(true); } // Initialize regions foreach (var reg in Regions) { reg.Body.InitManager(this); } // Get whether comments should be enabled EnableComments = Areas.Manager.Models.CommentSettingsModel.Get().EnablePages; if (!Page.IsNew && EnableComments) { using (var db = new DataContext()) { Comments = db.Comments. Where(c => c.ParentId == Page.Id && c.ParentIsDraft == false). OrderByDescending(c => c.Created).ToList(); } } // Get the site if this is a site page if (Permalink.Type == Models.Permalink.PermalinkType.SITE) { using (var db = new DataContext()) { SiteTree = db.SiteTrees.Where(s => s.Id == Page.SiteTreeId).Single(); } } // Check if the page can be published if (Page.OriginalId != Guid.Empty) { CanPublish = Page.GetScalar("SELECT count(*) FROM page WHERE page_id=@0 AND page_draft=0", Page.OriginalId) > 0; } }
private void GetRelated() { // Clear related Regions.Clear(); Properties.Clear(); AttachedContent.Clear(); // Get group parents DisableGroups = SysGroup.GetParents(Page.GroupId); DisableGroups.Reverse(); // Get placement ref title if (Page.ParentId != Guid.Empty || Page.Seqno > 1) { Page refpage = null; if (Page.Seqno > 1) { if (Page.ParentId != Guid.Empty) { refpage = Page.GetSingle("page_parent_id = @0 AND page_seqno = @1", Page.ParentId, Page.Seqno - 1); } else { refpage = Page.GetSingle("page_parent_id IS NULL AND page_seqno = @0", Page.Seqno - 1); } } else { refpage = Page.GetSingle(Page.ParentId, true); } PlaceRef = refpage.Title; } // Get template & permalink Template = PageTemplate.GetSingle("pagetemplate_id = @0", Page.TemplateId); Permalink = Permalink.GetSingle(Page.PermalinkId); if (Permalink == null) { Permalink = new Permalink() { Id = Guid.NewGuid(), Type = Permalink.PermalinkType.PAGE, NamespaceId = new Guid("8FF4A4B4-9B6C-4176-AAA2-DB031D75AC03") }; Page.PermalinkId = Permalink.Id; } if (Template != null) { // Get regions var regions = RegionTemplate.Get("regiontemplate_template_id = @0", Template.Id, new Params() { OrderBy = "regiontemplate_seqno" }); foreach (var rt in regions) { var reg = Region.GetSingle("region_regiontemplate_id = @0 AND region_page_id = @1 and region_draft = @2", rt.Id, Page.Id, Page.IsDraft); if (reg != null) { Regions.Add(reg); } else { Regions.Add(new Region() { InternalId = rt.InternalId, Name = rt.Name, Type = rt.Type, PageId = Page.Id, RegiontemplateId = rt.Id, IsDraft = Page.IsDraft, IsPageDraft = Page.IsDraft }); } } // Get Properties foreach (string name in Template.Properties) { Property prp = Property.GetSingle("property_name = @0 AND property_parent_id = @1 AND property_draft = @2", name, Page.Id, Page.IsDraft); if (prp != null) { Properties.Add(prp); } else { Properties.Add(new Property() { Name = name, ParentId = Page.Id, IsDraft = Page.IsDraft }); } } } else { throw new ArgumentException("Could not find page template for page {" + Page.Id.ToString() + "}"); } // Get attached content if (Page.Attachments.Count > 0) { // Content meta data is actually memcached, so this won't result in multiple queries Page.Attachments.ForEach(a => { Models.Content c = Models.Content.GetSingle(a); if (c != null) { AttachedContent.Add(c); } }); } // Get page position Parents = BuildParentPages(Sitemap.GetStructure(false), Page); Parents.Insert(0, new PagePlacement() { Level = 1, IsSelected = Page.ParentId == Guid.Empty }); Siblings = BuildSiblingPages(Page.Id, Page.ParentId, Page.Seqno, Page.ParentId); }