You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.0 KiB

  1. using CookComputing.XmlRpc;
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Web;
  6. [XmlRpcMissingMapping(MappingAction.Ignore)]
  7. public class Post
  8. {
  9. public Post()
  10. {
  11. ID = Guid.NewGuid().ToString();
  12. Title = "My new post";
  13. Author = HttpContext.Current.User.Identity.Name;
  14. Content = "the content";
  15. PubDate = DateTime.UtcNow;
  16. LastModified = DateTime.UtcNow;
  17. Categories = new string[0];
  18. Comments = new List<Comment>();
  19. IsPublished = true;
  20. }
  21. [XmlRpcMember("postid")]
  22. public string ID { get; set; }
  23. [XmlRpcMember("title")]
  24. public string Title { get; set; }
  25. [XmlRpcMember("author")]
  26. public string Author { get; set; }
  27. [XmlRpcMember("wp_slug")]
  28. public string Slug { get; set; }
  29. [XmlRpcMember("description")]
  30. public string Content { get; set; }
  31. [XmlRpcMember("dateCreated")]
  32. public DateTime PubDate { get; set; }
  33. [XmlRpcMember("dateModified")]
  34. public DateTime LastModified { get; set; }
  35. public bool IsPublished { get; set; }
  36. [XmlRpcMember("categories")]
  37. public string[] Categories { get; set; }
  38. public List<Comment> Comments { get; private set; }
  39. public Uri AbsoluteUrl
  40. {
  41. get
  42. {
  43. Uri requestUrl = HttpContext.Current.Request.Url;
  44. return new Uri(requestUrl.Scheme + "://" + requestUrl.Authority + Url, UriKind.Absolute);
  45. }
  46. }
  47. public Uri Url
  48. {
  49. get
  50. {
  51. return new Uri(VirtualPathUtility.ToAbsolute("~/post/" + Slug), UriKind.Relative);
  52. }
  53. }
  54. public bool AreCommentsOpen(HttpContextBase context)
  55. {
  56. return PubDate > DateTime.UtcNow.AddDays(-Blog.DaysToComment) || context.User.Identity.IsAuthenticated;
  57. }
  58. public int CountApprovedComments(HttpContextBase context)
  59. {
  60. return (Blog.ModerateComments && !context.User.Identity.IsAuthenticated) ? this.Comments.Count(c => c.IsApproved) : this.Comments.Count;
  61. }
  62. }