using System; using System.Linq; using System.Web; using Telligent.Evolution.Extensibility; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.Urls.Version1; namespace Telligent.Evolution.Examples { public class CustomBlogRawExample : IApplicationNavigable { Guid IApplicationNavigable.ApplicationTypeId { get { return Apis.Get().ApplicationTypeId; } } void IApplicationNavigable.RegisterUrls(IUrlController controller) { controller.AddRaw("blog-raw", "{WeblogApp}/raw", null, null, (a, p) => { var handler = new CustomBlogRawHttpHandler(); handler.ProcessRequest(a.ApplicationInstance.Context); }, new RawDefinitionOptions() { ParseContext = ParseBlogContext }); } private void ParseBlogContext(PageContext context) { var appKey = context.GetTokenValue("WeblogApp"); var blogsApi = Apis.Get(); var groupsApi = Apis.Get(); if (appKey != null) { var groupItem = context.ContextItems.GetAllContextItems().FirstOrDefault(a => a.ContentTypeId == groupsApi.ContentTypeId); if (groupItem != null) { var blog = blogsApi.Get(new BlogsGetOptions() { GroupId = int.Parse(groupItem.Id), Key = appKey.ToString() }); if (blog != null) { var contextItem = new ContextItem() { TypeName = "Blog", ApplicationId = blog.ApplicationId, ApplicationTypeId = blogsApi.ApplicationTypeId, ContainerId = blog.Group.ApplicationId, ContainerTypeId = groupsApi.ContentTypeId, ContentId = blog.ApplicationId, ContentTypeId = blogsApi.ApplicationTypeId, Id = blog.Id.ToString() }; context.ContextItems.Put(contextItem); } } } } public string Description { get { return "Define custom blog raw url"; } } public void Initialize() { } public string Name { get { return "Custom Blog Pages"; } } } public class CustomBlogRawHttpHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { var blog = PublicApi.Url.CurrentContext.ContextItems.GetAllContextItems() .FirstOrDefault(b => b.ContentTypeId == PublicApi.Blogs.ContentTypeId); if (blog != null) { var posts = Apis.Get().List(new BlogPostsListOptions() { BlogId = int.Parse(blog.Id)} ); foreach (var post in posts) context.Response.Write(post.Title + "
"); } context.Response.End(); } } }