/
render_post.go
156 lines (128 loc) · 2.92 KB
/
render_post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package main
import (
"fmt"
"net/url"
"text/template"
"time"
)
// single post info
type postInfo struct {
parent *threadInfo
Id uint64
Name string
Trip string
Subject string
Email string
Date int64
Message string
File string
Original string
Thumb string
}
func (p *postInfo) Board() string {
return p.parent.Board()
}
func (p *postInfo) Thread() uint64 {
return p.parent.Id
}
func (p *postInfo) IsOp() bool {
return p.parent.Id == p.Id
}
func (p *postInfo) HasFile() bool {
return p.File != ""
}
func (p *postInfo) FullFile() string {
if p.HasFile() {
return "/" + p.Board() + "/src/" + p.File
}
return ""
}
func (p *postInfo) HasOriginal() bool {
return p.Original != ""
}
func (p *postInfo) StrOriginal() string {
if p.HasOriginal() {
return template.HTMLEscapeString(p.Original)
}
return template.HTMLEscapeString(p.File)
}
func (p *postInfo) FullOriginal() string {
if p.HasOriginal() {
var u = url.URL{Path: p.FullFile() + "/" + p.Original}
return u.EscapedPath()
}
return p.FullFile()
}
// whether thumb can be displayed for this file
func (p *postInfo) CanThumb() bool {
return p.Thumb != ""
}
// bit diferent.. whether thumb can be displayed AND is generated from file itself
func (p *postInfo) HasThumb() bool {
return len(p.Thumb) > 0 && p.Thumb[0] != '/'
}
func (p *postInfo) FullThumb() string {
if p.HasThumb() {
return urlThumb(p.Board(), p.Thumb)
} else {
return urlStaticThumb(p.Board(), p.Thumb)
}
}
func (p *postInfo) HasName() bool {
return p.Name != ""
}
func (p *postInfo) FName() string {
if p.HasName() {
return template.HTMLEscapeString(p.Name)
}
return "Anonymous"
}
func (p *postInfo) HasTrip() bool {
return p.Trip != ""
}
func (p *postInfo) HasSubject() bool {
return p.Subject != ""
}
func (p *postInfo) FSubject() string {
if p.HasSubject() {
return template.HTMLEscapeString(p.Subject)
}
return "None"
}
func (p *postInfo) HasEmail() bool {
return p.Email != ""
}
func (p *postInfo) FEmail() string {
return url.QueryEscape(p.Email)
}
func (p *postInfo) setMod(mod bool) {
p.parent.setMod(mod)
}
func (p *postInfo) IsMod() bool {
return p.parent.IsMod()
}
func (p *postInfo) setBoardView(bw bool) {
p.parent.setBoardView(bw)
}
func (p *postInfo) IsBoardView() bool {
return p.parent.IsBoardView()
}
// prints date in format browser understands
func (p *postInfo) FDate() string {
t := time.Unix(p.Date, 0)
return fmt.Sprintf("%d-%02d-%02dT%02d:%02d:%02dZ", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) // Z denotes UTC
}
// format user understands better
func (p *postInfo) StrDate() string {
t := time.Unix(p.Date, 0)
return fmt.Sprintf("%d-%02d-%02d %02d:%02d:%02d", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
}
func (p *postInfo) HasMessage() bool {
return p.Message != ""
}
type fullPostInfo struct {
postInfo
FMessage string
fparent *fullThreadInfo
References []postReference
}