public ActionResult Item(int blogId, PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); BlogPart blogPart = _blogService.Get(blogId, VersionOptions.Latest).As <BlogPart>(); if (blogPart == null) { return(HttpNotFound()); } var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize, VersionOptions.Latest).ToArray(); var blogPostsShapes = blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "SummaryAdmin")).ToArray(); dynamic blog = Services.ContentManager.BuildDisplay(blogPart, "DetailAdmin"); var list = Shape.List(); list.AddRange(blogPostsShapes); blog.Content.Add(Shape.Parts_Blogs_BlogPost_ListAdmin(ContentItems: list), "5"); var totalItemCount = _blogPostService.PostCount(blogPart, VersionOptions.Latest); blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after"); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)blog)); }
public void CreateBlogArchivesWidget() { var type = "BlogArchives"; // Check any custom parameters that could cause creating the widget to fail. blog = GetBlog(BlogId, BlogPath); if (blog == null) { Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type)); return; } // Create the widget using the standard parameters. var widget = _widgetCommandsService.CreateBaseWidget( Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null); if (widget == null) { return; } // Set the custom parameters. widget.As <BlogArchivesPart>().BlogId = blog.Id; // Publish the successfully created widget. _widgetCommandsService.Publish(widget); Context.Output.WriteLine(T("{0} widget created successfully.", type).Text); }
private XRpcArray MetaWeblogGetRecentPosts( UrlHelper urlHelper, string blogId, string userName, string password, int numberOfPosts, IEnumerable <IXmlRpcDriver> drivers) { IUser user = ValidateUser(userName, password); // User needs to at least have permission to edit its own blog posts to access the service _authorizationService.CheckAccess(Permissions.EditBlogPost, user, null); BlogPart blog = _contentManager.Get <BlogPart>(Convert.ToInt32(blogId)); if (blog == null) { throw new ArgumentException(); } var array = new XRpcArray(); foreach (var blogPost in _blogPostService.Get(blog, 0, numberOfPosts, VersionOptions.Latest)) { var postStruct = CreateBlogStruct(blogPost, urlHelper); foreach (var driver in drivers) { driver.Process(postStruct); } array.Add(postStruct); } return(array); }
public IEnumerable <BlogPostPart> Get(BlogPart blogPart, int skip, int count, VersionOptions versionOptions) { return(GetBlogQuery(blogPart, versionOptions) .Slice(skip, count) .ToList() .Select(ci => ci.As <BlogPostPart>())); }
public ActionResult ListByArchive(string blogPath, string archiveData) { //TODO: (erikpo) Move looking up the current blog up into a modelbinder BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) { return(HttpNotFound()); } var archive = new ArchiveData(archiveData); var list = Shape.List(); list.AddRange(_blogPostService.Get(blogPart, archive).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"))); _feedManager.Register(blogPart); dynamic viewModel = Shape.ViewModel() .ContentItems(list) .Blog(blogPart) .ArchiveData(archive); //todo: (heskew) add back //.ArchiveData(archive) <-- ?? // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
public int PostCount(BlogPart blogPart, VersionOptions versionOptions) { return(_contentManager.Query(versionOptions, "BlogPost") .Join <CommonPartRecord>().Where( cr => cr.Container.Id == blogPart.Id) .Count()); }
public IEnumerable <BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData) { var query = GetBlogQuery(blogPart, VersionOptions.Published); if (archiveData.Day > 0) { var dayDate = new DateTime(archiveData.Year, archiveData.Month, archiveData.Day); query = query.Where(cr => cr.CreatedUtc >= dayDate && cr.CreatedUtc < dayDate.AddDays(1)); } else if (archiveData.Month > 0) { var monthDate = new DateTime(archiveData.Year, archiveData.Month, 1); query = query.Where(cr => cr.CreatedUtc >= monthDate && cr.CreatedUtc < monthDate.AddMonths(1)); } else { var yearDate = new DateTime(archiveData.Year, 1, 1); query = query.Where(cr => cr.CreatedUtc >= yearDate && cr.CreatedUtc < yearDate.AddYears(1)); } return(query.List().Select(ci => ci.As <BlogPostPart>())); }
public ActionResult Item(int blogId, PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); BlogPart blogPart = _blogService.Get(blogId, VersionOptions.Latest).As <BlogPart>(); if (blogPart == null) { return(HttpNotFound()); } var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize, VersionOptions.Latest).ToArray(); var blogPostsShapes = blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "SummaryAdmin")).ToArray(); var blog = Services.ContentManager.BuildDisplay(blogPart, "DetailAdmin"); var list = Shape.List(); list.AddRange(blogPostsShapes); blog.Content.Add(Shape.Parts_Blogs_BlogPost_ListAdmin(ContentItems: list), "5"); var totalItemCount = _blogPostService.PostCount(blogPart, VersionOptions.Latest); blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after"); return(View(blog)); }
private IContentQuery <ContentItem, CommonPartRecord> GetBlogQuery(BlogPart blog, VersionOptions versionOptions) { return (_contentManager.Query(versionOptions, "BlogPost") .Join <CommonPartRecord>().Where( cr => cr.Container.Id == blog.Id).OrderByDescending(cr => cr.CreatedUtc) ); }
public static void Register(this IFeedManager feedManager, BlogPart blogPart) { feedManager.Register(blogPart.Name, "rss", new RouteValueDictionary { { "containerid", blogPart.Id } }); feedManager.Register(blogPart.Name + " - Comments", "rss", new RouteValueDictionary { { "commentedoncontainer", blogPart.Id } }); }
public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) { var postPath = blogPart.As <IRoutableAspect>().GetChildPath(slug); return (_contentManager.Query(versionOptions, "BlogPost").Join <RoutePartRecord>().Where(rr => rr.Path == postPath). Join <CommonPartRecord>().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List(). SingleOrDefault().As <BlogPostPart>()); }
public IEnumerable <KeyValuePair <ArchiveData, int> > GetArchives(BlogPart blogPart) { var query = from bar in _blogArchiveRepository.Table where bar.BlogPart.Id == blogPart.Id orderby bar.Year descending, bar.Month descending select bar; return (query.ToList().Select( bar => new KeyValuePair <ArchiveData, int>(new ArchiveData(string.Format("{0}/{1}", bar.Year, bar.Month)), bar.PostCount))); }
private void UpdateBlogPostCount(BlogPostPart blogPostPart) { CommonPart commonPart = blogPostPart.As <CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { BlogPart blogPart = blogPostPart.BlogPart ?? _blogService.Get(commonPart.Record.Container.Id, VersionOptions.Published).As <BlogPart>(); // Ensure the "right" set of published posts for the blog is obtained blogPart.PostCount = _blogPostService.PostCount(blogPart); } }
protected override DriverResult Display(BlogArchivesPart part, string displayType, dynamic shapeHelper) { return(ContentShape("Parts_Blogs_BlogArchives", () => { var path = _blogPathConstraint.FindPath(part.ForBlog); BlogPart blog = _blogService.Get(path); if (blog == null) { return null; } return shapeHelper.Parts_Blogs_BlogArchives(ContentItem: part.ContentItem, Blog: blog, Archives: _blogPostService.GetArchives(blog)); })); }
public ActionResult Create() { if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs"))) { return(new HttpUnauthorizedResult()); } BlogPart blog = Services.ContentManager.New <BlogPart>("Blog"); if (blog == null) { return(HttpNotFound()); } var model = Services.ContentManager.BuildEditor(blog); return(View(model)); }
public ActionResult Rsd(string path) { Logger.Debug("RSD requested"); var blogPath = _rsdConstraint.FindPath(path); if (blogPath == null) { return(HttpNotFound()); } BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) { return(HttpNotFound()); } const string manifestUri = "http://archipelago.phrasewise.com/rsd"; var urlHelper = new UrlHelper(ControllerContext.RequestContext, _routeCollection); var url = urlHelper.AbsoluteAction("", "", new { Area = "XmlRpc" }); var options = new XElement( XName.Get("service", manifestUri), new XElement(XName.Get("engineName", manifestUri), "Orchard CMS"), new XElement(XName.Get("engineLink", manifestUri), "http://orchardproject.net"), new XElement(XName.Get("homePageLink", manifestUri), "http://orchardproject.net"), new XElement(XName.Get("apis", manifestUri), new XElement(XName.Get("api", manifestUri), new XAttribute("name", "MetaWeblog"), new XAttribute("preferred", true), new XAttribute("apiLink", url), new XAttribute("blogID", blogPart.Id)))); var doc = new XDocument(new XElement( XName.Get("rsd", manifestUri), new XAttribute("version", "1.0"), options)); Response.Cache.SetCacheability(HttpCacheability.NoCache); return(Content(doc.ToString(), "text/xml")); }
public ActionResult Create() { if (!Services.Authorizer.Authorize(Permissions.ManageBlogs, T("Not allowed to create blogs"))) { return(new HttpUnauthorizedResult()); } BlogPart blog = Services.ContentManager.New <BlogPart>("Blog"); if (blog == null) { return(HttpNotFound()); } dynamic model = Services.ContentManager.BuildEditor(blog); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)model)); }
public ActionResult ListByArchive(string path) { var blogPath = _archiveConstraint.FindPath(path); var archive = _archiveConstraint.FindArchiveData(path); if (blogPath == null) { return(HttpNotFound()); } if (archive == null) { return(HttpNotFound()); } BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) { return(HttpNotFound()); } if (archive.ToDateTime() == DateTime.MinValue) { // render the archive data return(new ShapeResult(this, Shape.Parts_Blogs_BlogArchives(Blog: blogPart, Archives: _blogPostService.GetArchives(blogPart)))); } var list = Shape.List(); list.AddRange(_blogPostService.Get(blogPart, archive).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"))); _feedManager.Register(blogPart, _services.ContentManager.GetItemMetadata(blogPart).DisplayText); var viewModel = Shape.ViewModel() .ContentItems(list) .Blog(blogPart) .ArchiveData(archive); return(View(viewModel)); }
public static void Register(this IFeedManager feedManager, BlogPart blogPart, string blogTitle) { if (String.IsNullOrWhiteSpace(blogPart.FeedProxyUrl)) { feedManager.Register(blogTitle, "rss", new RouteValueDictionary { { "containerid", blogPart.Id } }); } else { feedManager.Register(blogTitle, "rss", blogPart.FeedProxyUrl); } if (blogPart.EnableCommentsFeed) { feedManager.Register(blogTitle + " - Comments", "rss", new RouteValueDictionary { { "commentedoncontainer", blogPart.Id } }); } }
public void CreateRecentBlogPostsWidget() { var type = "RecentBlogPosts"; // Check any custom parameters that could cause creating the widget to fail. blog = GetBlog(BlogId, BlogPath); if (blog == null) { Context.Output.WriteLine(T("Creating {0} widget failed: blog was not found.", type)); return; } // Create the widget using the standard parameters. var widget = _widgetCommandsService.CreateBaseWidget( Context, type, Title, Name, Zone, Position, Layer, Identity, RenderTitle, Owner, null, false, null); if (widget == null) { return; } // Publish the successfully created widget. widget.As <RecentBlogPostsPart>().BlogId = blog.Id; // Setting count to 0 means all posts. It's an optional parameter and defaults to 5. if (!string.IsNullOrWhiteSpace(Count)) { int CountAsNumber = 0; if (Int32.TryParse(Count, out CountAsNumber)) { widget.As <RecentBlogPostsPart>().Count = CountAsNumber; } } // Publish the successfully created widget. _widgetCommandsService.Publish(widget); Context.Output.WriteLine(T("{0} widget created successfully.", type).Text); }
private XRpcArray MetaWeblogGetUserBlogs(UrlHelper urlHelper, string userName, string password) { IUser user = ValidateUser(userName, password); XRpcArray array = new XRpcArray(); foreach (BlogPart blog in _blogService.Get()) { // User needs to at least have permission to edit its own blog posts to access the service if (_authorizationService.TryCheckAccess(Permissions.EditBlogPost, user, blog)) { BlogPart blogPart = blog; array.Add(new XRpcStruct() .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blogPart))) .Set("blogid", blog.Id) .Set("blogName", blog.Name)); } } return(array); }
public ActionResult ListByArchive(string path) { var blogPath = _archiveConstraint.FindPath(path); var archive = _archiveConstraint.FindArchiveData(path); if (blogPath == null) { return(HttpNotFound()); } if (archive == null) { return(HttpNotFound()); } BlogPart blogPart = _blogService.Get(blogPath); if (blogPart == null) { return(HttpNotFound()); } var list = Shape.List(); list.AddRange(_blogPostService.Get(blogPart, archive).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"))); _feedManager.Register(blogPart); dynamic viewModel = Shape.ViewModel() .ContentItems(list) .Blog(blogPart) .ArchiveData(archive); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) { var path = _blogPathConstraint.FindPath(part.ForBlog); BlogPart blog = _blogService.Get(path); if (blog == null) { return(null); } var blogPosts = _contentManager.Query(VersionOptions.Published, "BlogPost") .Join <CommonPartRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord) .OrderByDescending(cr => cr.CreatedUtc) .Slice(0, part.Count) .Select(ci => ci.As <BlogPostPart>()); var list = shapeHelper.List(); list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary"))); var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list); return(ContentShape(shapeHelper.Parts_Blogs_RecentBlogPosts(ContentItem: part.ContentItem, ContentItems: blogPostList))); }
public int PostCount(BlogPart blogPart) { return(PostCount(blogPart, VersionOptions.Published)); }
public IEnumerable <BlogPostPart> Get(BlogPart blogPart, int skip, int count) { return(Get(blogPart, skip, count, VersionOptions.Published)); }
public IEnumerable <BlogPostPart> Get(BlogPart blogPart, VersionOptions versionOptions) { return(GetBlogQuery(blogPart, versionOptions).List().Select(ci => ci.As <BlogPostPart>())); }
public IEnumerable <BlogPostPart> Get(BlogPart blogPart) { return(Get(blogPart, VersionOptions.Published)); }
public int PostCount(BlogPart blogPart, VersionOptions versionOptions) { return(GetBlogQuery(blogPart, versionOptions).Count()); }
public void RebuildArchive(BlogPart blogPart) { var first = _contentManager.Query <BlogPostPart>().Where <CommonPartRecord>(bp => bp.Container.Id == blogPart.Id).OrderBy <CommonPartRecord>(x => x.CreatedUtc).Slice(0, 1).FirstOrDefault(); if (first == null) { return; } var last = _contentManager.Query <BlogPostPart>().Where <CommonPartRecord>(bp => bp.Container.Id == blogPart.Id).OrderByDescending <CommonPartRecord>(x => x.CreatedUtc).Slice(0, 1).FirstOrDefault(); DateTime?start = DateTime.MaxValue; if (first.As <CommonPart>() != null) { start = first.As <CommonPart>().CreatedUtc; } DateTime?end = DateTime.MinValue; if (last.As <CommonPart>() != null) { end = last.As <CommonPart>().CreatedUtc; } // delete previous archive records foreach (var record in _blogArchiveRepository.Table.Where(x => x.BlogPart.Id == blogPart.Id)) { _blogArchiveRepository.Delete(record); } if (!start.HasValue || !end.HasValue) { return; } // get the time zone for the current request var timeZone = _workContextAccessor.GetContext().CurrentTimeZone; // build a collection of all the post dates var blogPostDates = new List <DateTime>(); var blogPosts = _contentManager.Query <BlogPostPart>().Where <CommonPartRecord>(bp => bp.Container.Id == blogPart.Id); foreach (var blogPost in blogPosts.List()) { if (blogPost.As <CommonPart>() != null) { if (blogPost.As <CommonPart>().CreatedUtc.HasValue) { DateTime timeZoneAdjustedCreatedDate = TimeZoneInfo.ConvertTimeFromUtc(blogPost.As <CommonPart>().CreatedUtc.Value, timeZone); blogPostDates.Add(timeZoneAdjustedCreatedDate); } } } for (int year = start.Value.Year; year <= end.Value.Year; year++) { for (int month = 1; month <= 12; month++) { var fromDateUtc = new DateTime(year, month, 1); var from = TimeZoneInfo.ConvertTimeFromUtc(fromDateUtc, timeZone); var to = TimeZoneInfo.ConvertTimeFromUtc(fromDateUtc.AddMonths(1), timeZone); // skip the first months of the first year until a month has posts // for instance, if started posting in May 2000, don't write counts for Jan 200 > April 2000... start May 2000 if (from < TimeZoneInfo.ConvertTimeFromUtc(new DateTime(start.Value.Year, start.Value.Month, 1), timeZone)) { continue; } // skip the last months of the last year if no posts // for instance, no need to have archives for months in the future if (to > end.Value.AddMonths(1)) { continue; } //var count = _contentManager.Query<BlogPostPart>().Where<CommonPartRecord>(x => x.CreatedUtc.Value >= from && x.CreatedUtc.Value < to).Count(); var count = blogPostDates.Count(bp => bp >= @from && bp < to); var newArchiveRecord = new BlogPartArchiveRecord { BlogPart = blogPart.ContentItem.Record, Year = year, Month = month, PostCount = count }; _blogArchiveRepository.Create(newArchiveRecord); } } }
public BlogPostPart Get(BlogPart blogPart, string slug) { return(Get(blogPart, slug, VersionOptions.Published)); }