blog_post.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/engine/wrapper"
  6. "golang-fave/utils"
  7. )
  8. type BlogPost struct {
  9. wrap *wrapper.Wrapper
  10. object *utils.MySql_blog_post
  11. user *User
  12. }
  13. func (this *BlogPost) load() *BlogPost {
  14. return this
  15. }
  16. func (this *BlogPost) Id() int {
  17. if this == nil {
  18. return 0
  19. }
  20. return this.object.A_id
  21. }
  22. func (this *BlogPost) User() *User {
  23. if this == nil {
  24. return nil
  25. }
  26. if this.user != nil {
  27. return this.user
  28. }
  29. this.user = &User{wrap: this.wrap}
  30. this.user.loadById(this.object.A_user)
  31. return this.user
  32. }
  33. func (this *BlogPost) Name() string {
  34. if this == nil {
  35. return ""
  36. }
  37. return this.object.A_name
  38. }
  39. func (this *BlogPost) Alias() string {
  40. if this == nil {
  41. return ""
  42. }
  43. return this.object.A_alias
  44. }
  45. func (this *BlogPost) Briefly() template.HTML {
  46. if this == nil {
  47. return template.HTML("")
  48. }
  49. return template.HTML(this.object.A_briefly)
  50. }
  51. func (this *BlogPost) Content() template.HTML {
  52. if this == nil {
  53. return template.HTML("")
  54. }
  55. return template.HTML(this.object.A_content)
  56. }
  57. func (this *BlogPost) DateTimeUnix() int {
  58. if this == nil {
  59. return 0
  60. }
  61. return this.object.A_datetime
  62. }
  63. func (this *BlogPost) DateTimeFormat(format string) string {
  64. if this == nil {
  65. return ""
  66. }
  67. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  68. }
  69. func (this *BlogPost) Active() bool {
  70. if this == nil {
  71. return false
  72. }
  73. return this.object.A_active > 0
  74. }
  75. func (this *BlogPost) Permalink() string {
  76. if this == nil {
  77. return ""
  78. }
  79. return "/blog/" + this.object.A_alias + "/"
  80. }