index.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/engine/utils"
  6. "golang-fave/engine/wrapper"
  7. )
  8. type Page struct {
  9. wrap *wrapper.Wrapper
  10. object *utils.MySql_page
  11. user *User
  12. }
  13. func (this *Page) load() *Page {
  14. return this
  15. }
  16. func (this *Page) Id() int {
  17. if this == nil {
  18. return 0
  19. }
  20. return this.object.A_id
  21. }
  22. func (this *Page) 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 *Page) Name() string {
  34. if this == nil {
  35. return ""
  36. }
  37. return this.object.A_name
  38. }
  39. func (this *Page) Alias() string {
  40. if this == nil {
  41. return ""
  42. }
  43. return this.object.A_alias
  44. }
  45. func (this *Page) Content() template.HTML {
  46. if this == nil {
  47. return template.HTML("")
  48. }
  49. return template.HTML(this.object.A_content)
  50. }
  51. func (this *Page) MetaTitle() string {
  52. if this == nil {
  53. return ""
  54. }
  55. return this.object.A_meta_title
  56. }
  57. func (this *Page) MetaKeywords() string {
  58. if this == nil {
  59. return ""
  60. }
  61. return this.object.A_meta_keywords
  62. }
  63. func (this *Page) MetaDescription() string {
  64. if this == nil {
  65. return ""
  66. }
  67. return this.object.A_meta_description
  68. }
  69. func (this *Page) DateTimeUnix() int {
  70. if this == nil {
  71. return 0
  72. }
  73. return this.object.A_datetime
  74. }
  75. func (this *Page) DateTimeFormat(format string) string {
  76. if this == nil {
  77. return ""
  78. }
  79. return time.Unix(int64(this.object.A_datetime), 0).Format(format)
  80. }
  81. func (this *Page) Active() bool {
  82. if this == nil {
  83. return false
  84. }
  85. return this.object.A_active > 0
  86. }