Exemple #1
0
        public Page Get(string id)
        {
            try {
                Models.PageModel pm = Models.PageModel.GetById(new Guid(id)) ;

                if (pm != null && (pm.Page.GroupId == Guid.Empty || HttpContext.Current.User.IsMember(pm.Page.GroupId))) {
                    // Page data
                    Page page = new Page() {
                        Id = pm.Page.Id,
                        Title = pm.Page.Title,
                        Permalink = pm.Page.Permalink,
                        IsHidden = ((Piranha.Models.Page)pm.Page).IsHidden,
                        Attachments = ((Models.Page)pm.Page).Attachments,
                        Created = pm.Page.Created.ToShortDateString(),
                        Updated = pm.Page.Updated.ToShortDateString(),
                        Published = pm.Page.Published.ToShortDateString(),
                        LastPublished = pm.Page.LastPublished.ToShortDateString()
                    } ;

                    // Regions
                    foreach (var key in ((IDictionary<string, object>)pm.Regions).Keys)
                        page.Regions.Add(new Region() { Name = key, Body =
                            ((HtmlString)((IDictionary<string, object>)pm.Regions)[key]).ToString() }) ;

                    // Properties
                    foreach (var key in ((IDictionary<string, object>)pm.Properties).Keys)
                        page.Properties.Add(new Property() { Name = key, Value = (string)
                            ((string)((IDictionary<string, object>)pm.Properties)[key]) }) ;

                    return page ;
                }
            } catch {}
            return null ;
        }
Exemple #2
0
		/// <summary>
		/// Gets the page specified by the given id.
		/// </summary>
		/// <param name="id">The page id</param>
		/// <returns>The page.</returns>
		internal Page GetInternal(string id) {
			try {
				Models.PageModel pm = Models.PageModel.GetById(new Guid(id)) ;

				if (pm != null && (pm.Page.GroupId == Guid.Empty || HttpContext.Current.User.IsMember(pm.Page.GroupId))) {
					// Page data
					Page page = new Page() {
						Id = pm.Page.Id,
						ParentId = ((Piranha.Models.Page)pm.Page).ParentId,
						Seqno = ((Piranha.Models.Page)pm.Page).Seqno,
						TemplateName = pm.Page.TemplateName,
						Title = pm.Page.Title,
						NavigationTitle = pm.Page.NavigationTitle,
						Permalink = pm.Page.Permalink,
						IsHidden = ((Piranha.Models.Page)pm.Page).IsHidden,
						Created = pm.Page.Created.ToString(),
						Updated = pm.Page.Updated.ToString(),
						Published = pm.Page.Published.ToString(),
						LastPublished = pm.Page.LastPublished.ToString()
					} ;

					// Regions
					foreach (var key in ((IDictionary<string, object>)pm.Regions).Keys) {
						if (((IDictionary<string, object>)pm.Regions)[key] is HtmlString) {
							page.Regions.Add(new Region() { Name = key, Body = 
								((HtmlString)((IDictionary<string, object>)pm.Regions)[key]).ToHtmlString() }) ;
						} else {
							page.Regions.Add(new Region() { Name = key, Body = 
								((IDictionary<string, object>)pm.Regions)[key] }) ;
						}
					}

					// Properties
					foreach (var key in ((IDictionary<string, object>)pm.Properties).Keys)
						page.Properties.Add(new Property() { Name = key, Value = (string)
							((string)((IDictionary<string, object>)pm.Properties)[key]) }) ;

					// Attachments
					foreach (var content in pm.Attachments)
						page.Attachments.Add(new Attachment() { Id = content.Id, IsImage = content.IsImage }) ;

					// Extensions
					page.ExpandedExtensions = pm.Extensions ;
					foreach (var key in ((IDictionary<string, object>)pm.Extensions).Keys) {
						if (((IDictionary<string, object>)pm.Extensions)[key] is HtmlString) {
							page.Extensions.Add(new Extension() { Name = key, Body = 
								((HtmlString)((IDictionary<string, object>)pm.Extensions)[key]).ToHtmlString() }) ;
						} else {
							page.Extensions.Add(new Extension() { Name = key, Body =
								((IDictionary<string, object>)pm.Extensions)[key] }) ;
						}
					}
					return page ;
				}
			} catch {}
			return null ;
		}