content.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package fetdata
  2. import (
  3. "html/template"
  4. "time"
  5. "golang-fave/utils"
  6. )
  7. func (this *FERData) Id() int {
  8. if this.dataRow != nil {
  9. if this.wrap.CurrModule == "index" {
  10. return this.dataRow.(*utils.MySql_page).A_id
  11. } else if this.wrap.CurrModule == "blog" {
  12. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  13. // Blog category
  14. return this.dataRow.(*utils.MySql_blog_category).A_id
  15. } else {
  16. // Blog post
  17. return this.dataRow.(*utils.MySql_blog_posts).A_id
  18. }
  19. }
  20. }
  21. return 0
  22. }
  23. func (this *FERData) Name() string {
  24. if this.dataRow != nil {
  25. if this.wrap.CurrModule == "index" {
  26. return this.dataRow.(*utils.MySql_page).A_name
  27. } else if this.wrap.CurrModule == "blog" {
  28. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  29. // Blog category
  30. return this.dataRow.(*utils.MySql_blog_category).A_name
  31. } else {
  32. // Blog post
  33. return this.dataRow.(*utils.MySql_blog_posts).A_name
  34. }
  35. }
  36. }
  37. return ""
  38. }
  39. func (this *FERData) Alias() string {
  40. if this.dataRow != nil {
  41. if this.wrap.CurrModule == "index" {
  42. return this.dataRow.(*utils.MySql_page).A_alias
  43. } else if this.wrap.CurrModule == "blog" {
  44. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  45. // Blog category
  46. return this.dataRow.(*utils.MySql_blog_category).A_alias
  47. } else {
  48. // Blog post
  49. return this.dataRow.(*utils.MySql_blog_posts).A_alias
  50. }
  51. }
  52. }
  53. return ""
  54. }
  55. func (this *FERData) Content() template.HTML {
  56. if this.dataRow != nil {
  57. if this.wrap.CurrModule == "index" {
  58. return template.HTML(this.dataRow.(*utils.MySql_page).A_content)
  59. } else if this.wrap.CurrModule == "blog" {
  60. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  61. // Blog category
  62. return template.HTML("")
  63. } else {
  64. // Blog post
  65. return template.HTML(this.dataRow.(*utils.MySql_blog_posts).A_content)
  66. }
  67. }
  68. }
  69. return template.HTML("")
  70. }
  71. func (this *FERData) DateTime() int {
  72. if this.dataRow != nil {
  73. if this.wrap.CurrModule == "index" {
  74. return this.dataRow.(*utils.MySql_page).A_datetime
  75. } else if this.wrap.CurrModule == "blog" {
  76. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  77. // Blog category
  78. return 0
  79. } else {
  80. // Blog post
  81. return this.dataRow.(*utils.MySql_blog_posts).A_datetime
  82. }
  83. }
  84. }
  85. return 0
  86. }
  87. func (this *FERData) DateTimeFormat(format string) string {
  88. if this.dataRow != nil {
  89. if this.wrap.CurrModule == "index" {
  90. return time.Unix(int64(this.dataRow.(*utils.MySql_page).A_datetime), 0).Format(format)
  91. } else if this.wrap.CurrModule == "blog" {
  92. if len(this.wrap.UrlArgs) >= 2 && this.wrap.UrlArgs[0] == "blog" && this.wrap.UrlArgs[1] == "category" {
  93. // Blog category
  94. return ""
  95. } else {
  96. // Blog post
  97. return time.Unix(int64(this.dataRow.(*utils.MySql_blog_posts).A_datetime), 0).Format(format)
  98. }
  99. }
  100. }
  101. return ""
  102. }