This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
handle_postsby.go
79 lines (71 loc) · 1.96 KB
/
handle_postsby.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
// This code is in Public Domain. Take all the code you want, I'll just write more.
package main
import (
"fmt"
"html/template"
"net/http"
"strings"
)
// url: /{forum}/postsBy?[user=${userNameInternal}][ip=${ipInternal}]
func handlePostsBy(w http.ResponseWriter, r *http.Request) {
forum := mustGetForum(w, r)
if forum == nil {
return
}
store := forum.Store
var posts []*Post
userInternal := strings.TrimSpace(r.FormValue("user"))
ipAddrInternal := strings.TrimSpace(r.FormValue("ip"))
if userInternal == "" && ipAddrInternal == "" {
logger.Noticef("handlePostsBy(): missing both user and ip")
http.Redirect(w, r, fmt.Sprintf("/%s/", forum.ForumUrl), 302)
return
}
var total int
if userInternal != "" {
posts, total = store.GetPostsByUserInternal(userInternal, 50)
} else {
posts, total = store.GetPostsByIPInternal(ipAddrInternal, 50)
}
var ipAddr string
ipBlocked := false
if ipAddrInternal != "" {
ipAddr = ipAddrInternalToOriginal(ipAddrInternal)
ipBlocked = store.IsIPBlocked(ipAddrInternal)
}
isAdmin := userIsAdmin(forum, getSecureCookie(r))
displayPosts := make([]*PostDisplay, 0)
for _, p := range posts {
pd := NewPostDisplay(p, forum, isAdmin)
if pd != nil {
displayPosts = append(displayPosts, pd)
}
}
sidebar := DoSidebarTemplate(forum, isAdmin)
model := struct {
Forum
SidebarHtml template.HTML
Posts []*PostDisplay
TotalCount int
IsAdmin bool
Nick string
IpAddr string
IpAddrInternal string
IpBlocked bool
AnalyticsCode *string
LogInOut template.HTML
}{
Forum: *forum,
SidebarHtml: template.HTML(sidebar),
Posts: displayPosts,
TotalCount: total,
IsAdmin: isAdmin,
Nick: userInternal,
IpAddr: ipAddr,
IpAddrInternal: ipAddrInternal,
IpBlocked: ipBlocked,
AnalyticsCode: config.AnalyticsCode,
LogInOut: getLogInOut(r, getSecureCookie(r)),
}
ExecTemplate(w, tmplPosts, model)
}