index.go 1.5 KB

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