예제 #1
0
        /// <summary>
        /// Gets the associated regions for the current page
        /// </summary>
        protected void Init()
        {
            PageTemplate pt = PageTemplate.GetSingle(((Page)Page).TemplateId);

            // Regions
            var regions = RegionTemplate.GetByTemplateId(pt.Id);

            if (regions.Count > 0)
            {
                foreach (var rt in regions)
                {
                    ((IDictionary <string, object>)Regions).Add(rt.InternalId,
                                                                Activator.CreateInstance(ExtensionManager.RegionTypes[rt.Type]));
                }
                Region.GetContentByPageId(Page.Id, Page.IsDraft).ForEach(reg => {
                    if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId))
                    {
                        ((IDictionary <string, object>)Regions)[reg.InternalId] = reg.Body;
                    }
                });
            }
            // Properties
            if (pt.Properties.Count > 0)
            {
                foreach (string str in pt.Properties)
                {
                    ((IDictionary <string, object>)Properties).Add(str, "");
                }
                Property.GetContentByParentId(Page.Id, Page.IsDraft).ForEach(pr => {
                    if (((IDictionary <string, object>)Properties).ContainsKey(pr.Name))
                    {
                        ((IDictionary <string, object>)Properties)[pr.Name] = pr.Value;
                    }
                });
            }
            // Attachments
            foreach (var guid in ((Models.Page)Page).Attachments)
            {
                var a = Models.Content.GetSingle(guid);
                if (a != null)
                {
                    Attachments.Add(a);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the associated regions for the current page
        /// </summary>
        protected void Init()
        {
            var id = Page.Id;

            // Handle page copies
            if (((Models.Page)Page).OriginalId != Guid.Empty)
            {
                var copy = (Models.Page)Page;
                var org  = Models.Page.GetSingle(copy.OriginalId, copy.IsDraft);

                copy.Id             = org.Id;
                copy.GroupId        = org.GroupId;
                copy.DisabledGroups = org.DisabledGroups;
                copy.Keywords       = org.Keywords;
                copy.Description    = org.Description;
                copy.LastModified   = copy.LastModified > org.LastModified ? copy.LastModified : org.LastModified;
            }

            // Get the page template
            PageTemplate pt = PageTemplate.GetSingle(((Page)Page).TemplateId);

            // Regions
            var regions = RegionTemplate.GetByTemplateId(pt.Id);

            if (regions.Count > 0)
            {
                foreach (var rt in regions)
                {
                    if (rt.Type != "Piranha.Extend.Regions.PostRegion")
                    {
                        if (ExtensionManager.Current.HasType(rt.Type))
                        {
                            // Create empty region
                            object body = ExtensionManager.Current.CreateInstance(rt.Type);
                            // Initialize empty regions
                            if (body != null)
                            {
                                body = ((IExtension)body).GetContent(this);
                            }
                            ((IDictionary <string, object>)Regions).Add(rt.InternalId, body);
                        }
                        else
                        {
                            ((IDictionary <string, object>)Regions).Add(rt.InternalId, null);
                        }
                    }
                    else
                    {
                        ((IDictionary <string, object>)Regions).Add(rt.InternalId, new List <Piranha.Entities.Post>());
                    }
                }
                Piranha.Models.Region.GetContentByPageId(Page.Id, Page.IsDraft).ForEach(reg => {
                    string cachename = null;
                    if (!Page.IsDraft)
                    {
                        cachename = Extend.Regions.PostRegion.CacheName(Page, reg);
                    }

                    if (!(reg.Body is Extend.Regions.PostRegion))
                    {
                        object content = reg.Body;

                        // Initialize region
                        content = ((IExtension)content).GetContent(this);

                        if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId))
                        {
                            ((IDictionary <string, object>)Regions)[reg.InternalId] = content;
                        }
                    }
                    else
                    {
                        if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId))
                        {
                            ((IDictionary <string, object>)Regions)[reg.InternalId] =
                                ((Extend.Regions.PostRegion)reg.Body).GetMatchingPosts(cachename);
                        }
                    }
                });
            }
            // Properties
            if (pt.Properties.Count > 0)
            {
                foreach (string str in pt.Properties)
                {
                    ((IDictionary <string, object>)Properties).Add(str, "");
                }
                Property.GetContentByParentId(Page.Id, Page.IsDraft).ForEach(pr => {
                    if (((IDictionary <string, object>)Properties).ContainsKey(pr.Name))
                    {
                        ((IDictionary <string, object>)Properties)[pr.Name] = pr.Value;
                    }
                });
            }
            // Attachments
            foreach (var guid in ((Models.Page)Page).Attachments)
            {
                var a = Models.Content.GetSingle(guid, Page.IsDraft);
                if (a != null)
                {
                    Attachments.Add(a);
                }
            }
            // Extensions
            foreach (var ext in ((Page)Page).GetExtensions())
            {
                object body = ext.Body;
                if (body != null)
                {
                    var getContent = body.GetType().GetMethod("GetContent");
                    if (getContent != null)
                    {
                        body = getContent.Invoke(body, new object[] { this });
                    }
                }
                ((IDictionary <string, object>)Extensions)[ExtensionManager.Current.GetInternalIdByType(ext.Type)] = body;
            }
            // Reset the page id if we changed it to load a copy
            ((Models.Page)Page).Id = id;
        }
예제 #3
0
        /// <summary>
        /// Gets the associated regions for the current page
        /// </summary>
        protected void Init()
        {
            PageTemplate pt = PageTemplate.GetSingle(((Page)Page).TemplateId);

            // Regions
            var regions = RegionTemplate.GetByTemplateId(pt.Id);

            if (regions.Count > 0)
            {
                foreach (var rt in regions)
                {
                    if (rt.Type != "Piranha.Extend.Regions.PostRegion")
                    {
                        if (ExtensionManager.ExtensionTypes.ContainsKey(rt.Type))
                        {
                            // Create empty region
                            var body = Activator.CreateInstance(ExtensionManager.ExtensionTypes[rt.Type]);
                            // Initialize empty regions
                            if (body != null)
                            {
                                var getContent = body.GetType().GetMethod("GetContent");
                                if (getContent != null)
                                {
                                    body = getContent.Invoke(body, new object[] { this });
                                }
                            }
                            ((IDictionary <string, object>)Regions).Add(rt.InternalId, body);
                        }
                        else
                        {
                            ((IDictionary <string, object>)Regions).Add(rt.InternalId, null);
                        }
                    }
                    else
                    {
                        ((IDictionary <string, object>)Regions).Add(rt.InternalId, new List <Piranha.Entities.Post>());
                    }
                }
                Piranha.Models.Region.GetContentByPageId(Page.Id, Page.IsDraft).ForEach(reg => {
                    string cachename = null;
                    if (!Page.IsDraft)
                    {
                        cachename = Extend.Regions.PostRegion.CacheName(Page, reg);
                    }

                    if (!(reg.Body is Extend.Regions.PostRegion))
                    {
                        object content = reg.Body;

                        // Initialize region
                        var getContent = ExtensionManager.ExtensionTypes[reg.Type].GetMethod("GetContent");
                        if (getContent != null)
                        {
                            content = getContent.Invoke(reg.Body, new object[] { this });
                        }

                        if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId))
                        {
                            ((IDictionary <string, object>)Regions)[reg.InternalId] = content;
                        }
                    }
                    else
                    {
                        if (((IDictionary <string, object>)Regions).ContainsKey(reg.InternalId))
                        {
                            ((IDictionary <string, object>)Regions)[reg.InternalId] =
                                ((Extend.Regions.PostRegion)reg.Body).GetMatchingPosts(cachename);
                        }
                    }
                });
            }
            // Properties
            if (pt.Properties.Count > 0)
            {
                foreach (string str in pt.Properties)
                {
                    ((IDictionary <string, object>)Properties).Add(str, "");
                }
                Property.GetContentByParentId(Page.Id, Page.IsDraft).ForEach(pr => {
                    if (((IDictionary <string, object>)Properties).ContainsKey(pr.Name))
                    {
                        ((IDictionary <string, object>)Properties)[pr.Name] = pr.Value;
                    }
                });
            }
            // Attachments
            foreach (var guid in ((Models.Page)Page).Attachments)
            {
                var a = Models.Content.GetSingle(guid, Page.IsDraft);
                if (a != null)
                {
                    Attachments.Add(a);
                }
            }
            // Extensions
            foreach (var ext in ((Page)Page).GetExtensions())
            {
                object body = ext.Body;
                if (body != null)
                {
                    var getContent = body.GetType().GetMethod("GetContent");
                    if (getContent != null)
                    {
                        body = getContent.Invoke(body, new object[] { this });
                    }
                }
                ((IDictionary <string, object>)Extensions)[ExtensionManager.GetInternalIdByType(ext.Type)] = body;
            }
        }