コード例 #1
0
ファイル: WebPiranha.cs プロジェクト: rsaladrigas/Piranha
        /// <summary>
        /// Registers all of the hostnames configured in the database.
        /// </summary>
        public static void RegisterDefaultHostNames()
        {
            // Make sure we don't try to register the host names before
            // the database has been installed.
            if (SysParam.GetByName("SITE_VERSION") != null)
            {
                if (hostNames == null)
                {
                    hostNames = new Dictionary <string, Entities.SiteTree>();
                }

                HostNames.Clear();

                // We need to check version so we don't try to access the column sitetree_hostnames
                // before it's been created in the database.
                if (Data.Database.InstalledVersion > 26)
                {
                    using (var db = new DataContext()) {
                        var sites = db.SiteTrees.ToList();

                        foreach (var site in sites)
                        {
                            if (HttpContext.Current != null)
                            {
                                Page.InvalidateStartpage(site.Id);
                            }

                            if (!String.IsNullOrEmpty(site.HostNames))
                            {
                                var hostnames = site.HostNames.Split(new char[] { ',' });

                                foreach (var host in hostnames)
                                {
                                    if (HostNames.ContainsKey(host))
                                    {
                                        throw new Exception("Duplicates of the hostname [" + host + "] was found configured");
                                    }
                                    HostNames.Add(host.ToLower(), site);
                                }
                            }
                            if (site.Id == Config.DefaultSiteTreeId)
                            {
                                DefaultSite = site;
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: WebPiranha.cs プロジェクト: rajeshpillai/Piranha
		/// <summary>
		/// Registers all of the hostnames configured in the database.
		/// </summary>
		public static void RegisterDefaultHostNames() {
			// Make sure we don't try to register the host names before
			// the database has been installed.
			if (SysParam.GetByName("SITE_VERSION") != null) {
				if (hostNames == null)
					hostNames = new Dictionary<string,Entities.SiteTree>() ;

				HostNames.Clear() ;

				// We need to check version so we don't try to access the column sitetree_hostnames
				// before it's been created in the database.
				if (Data.Database.InstalledVersion > 26) {
					using (var db = new DataContext()) {
						var sites = db.SiteTrees.ToList() ;
					
						foreach (var site in sites) {
							if (HttpContext.Current != null)
								Page.InvalidateStartpage(site.Id) ;

							if (!String.IsNullOrEmpty(site.HostNames)) {
								var hostnames = site.HostNames.Split(new char[] { ',' }) ;

								foreach (var host in hostnames) {
									if (HostNames.ContainsKey(host))
										throw new Exception("Duplicates of the hostname [" + host + "] was found configured") ;
									HostNames.Add(host.ToLower(), site) ;
								}
							}
							if (site.Id == Config.DefaultSiteTreeId)
								DefaultSite = site ;
						}
					}
				}
			}
		}
コード例 #3
0
ファイル: EditModel.cs プロジェクト: ngnono/Piranha
		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 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;
				}
			}

			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.
						Include("CreatedBy").
						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;
			}
		}
コード例 #4
0
ファイル: EditModel.cs プロジェクト: scenicsoftware/Piranha
        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;
            }
        }