aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--post/util.go21
-rw-r--r--route/routes/actor.go9
-rw-r--r--route/routes/admin.go16
-rw-r--r--route/structs.go2
-rw-r--r--views/admin.html7
-rw-r--r--views/manage.html11
-rw-r--r--views/partials/posts.html5
7 files changed, 49 insertions, 22 deletions
diff --git a/post/util.go b/post/util.go
index 8db2d02..bc2580b 100644
--- a/post/util.go
+++ b/post/util.go
@@ -469,7 +469,7 @@ func ParseAttachment(obj activitypub.ObjectBase, catalog bool) template.HTML {
return template.HTML(media)
}
-func ParseContent(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase) (template.HTML, error) {
+func ParseContent(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase, id string, _type string) (template.HTML, error) {
// TODO: should escape more than just < and >, should also escape &, ", and '
nContent := strings.ReplaceAll(content, `<`, "&lt;")
nContent, err := ParseLinkComments(board, op, nContent, thread)
@@ -478,12 +478,31 @@ func ParseContent(board activitypub.Actor, op string, content string, thread act
return "", util.MakeError(err, "ParseContent")
}
+ if _type == "new" {
+ nContent = ParseTruncate(nContent, board, op, id)
+ }
nContent = ParseCommentQuotes(nContent)
nContent = strings.ReplaceAll(nContent, `/\&lt;`, ">")
return template.HTML(nContent), nil
}
+func ParseTruncate(content string, board activitypub.Actor, op string, id string) string {
+ if strings.Count(content, "\r") > 30 {
+ content = strings.ReplaceAll(content, "\r\n", "\r")
+ lines := strings.SplitAfter(content, "\r")
+ content = ""
+
+ for i := 0; i < 30; i++ {
+ content += lines[i]
+ }
+
+ content += fmt.Sprintf("<a href=\"%s\">(view full post...)</a>", board.Id+"/"+util.ShortURL(board.Outbox, op)+"#"+util.ShortURL(board.Outbox+"/outbox", id))
+ }
+
+ return content
+}
+
func ParseLinkComments(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase) (string, error) {
re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)(f[A-Za-z0-9_.\-~]+-)?([A-Za-z0-9_.\-~]+)?#?([A-Za-z0-9_.\-~]+)?)`)
match := re.FindAllStringSubmatch(content, -1)
diff --git a/route/routes/actor.go b/route/routes/actor.go
index 1072472..83cbca2 100644
--- a/route/routes/actor.go
+++ b/route/routes/actor.go
@@ -8,6 +8,7 @@ import (
"net/http"
"regexp"
"strconv"
+ "strings"
"github.com/FChannel0/FChannel-Server/activitypub"
"github.com/FChannel0/FChannel-Server/config"
@@ -238,7 +239,7 @@ func ActorPost(ctx *fiber.Ctx) error {
}
if ctx.FormValue("inReplyTo") == "" || file == nil {
- if ctx.FormValue("comment") == "" && ctx.FormValue("subject") == "" {
+ if strings.TrimSpace(ctx.FormValue("comment")) == "" && ctx.FormValue("subject") == "" {
return ctx.Render("403", fiber.Map{
"message": "Comment or Subject required",
})
@@ -251,6 +252,12 @@ func ActorPost(ctx *fiber.Ctx) error {
})
}
+ if strings.Count(ctx.FormValue("comment"), "\r\n") > 50 || strings.Count(ctx.FormValue("comment"), "\n") > 50 || strings.Count(ctx.FormValue("comment"), "\r") > 50 {
+ return ctx.Render("403", fiber.Map{
+ "message": "Too many new lines - try again.",
+ })
+ }
+
if len(ctx.FormValue("subject")) > 100 || len(ctx.FormValue("name")) > 100 || len(ctx.FormValue("options")) > 100 {
return ctx.Render("403", fiber.Map{
"message": "Name, Subject or Options limit 100 characters",
diff --git a/route/routes/admin.go b/route/routes/admin.go
index 31e8e8e..1576a3a 100644
--- a/route/routes/admin.go
+++ b/route/routes/admin.go
@@ -129,13 +129,19 @@ func AdminIndex(ctx *fiber.Ctx) error {
adminData.Board.Post.Actor = actor.Id
+ adminData.Instance, _ = activitypub.GetActorFromDB(config.Domain)
+
adminData.PostBlacklist, _ = util.GetRegexBlacklist()
+ adminData.Meta.Description = adminData.Title
+ adminData.Meta.Url = adminData.Board.Actor.Id
+ adminData.Meta.Title = adminData.Title
+
adminData.Themes = &config.Themes
return ctx.Render("admin", fiber.Map{
"page": adminData,
- })
+ }, "layouts/main")
}
func AdminFollow(ctx *fiber.Ctx) error {
@@ -255,6 +261,8 @@ func AdminActorIndex(ctx *fiber.Ctx) error {
data.Board.Post.Actor = actor.Id
+ data.Instance, _ = activitypub.GetActorFromDB(config.Domain)
+
data.AutoSubscribe, _ = actor.GetAutoSubscribe()
jannies, err := actor.GetJanitors()
@@ -263,6 +271,10 @@ func AdminActorIndex(ctx *fiber.Ctx) error {
return util.MakeError(err, "AdminActorIndex")
}
+ data.Meta.Description = data.Title
+ data.Meta.Url = data.Board.Actor.Id
+ data.Meta.Title = data.Title
+
data.Themes = &config.Themes
data.RecentPosts, _ = actor.GetRecentPosts()
@@ -274,7 +286,7 @@ func AdminActorIndex(ctx *fiber.Ctx) error {
return ctx.Render("manage", fiber.Map{
"page": data,
"jannies": jannies,
- })
+ }, "layouts/main")
}
func AdminAddJanny(ctx *fiber.Ctx) error {
diff --git a/route/structs.go b/route/structs.go
index 73371ae..601943c 100644
--- a/route/structs.go
+++ b/route/structs.go
@@ -44,6 +44,8 @@ type AdminPage struct {
PostBlacklist []util.PostBlacklist
AutoSubscribe bool
RecentPosts []activitypub.ObjectBase
+ Instance activitypub.Actor
+ Meta Meta
Themes *[]string
ThemeCookie string
diff --git a/views/admin.html b/views/admin.html
index e490704..2b733b5 100644
--- a/views/admin.html
+++ b/views/admin.html
@@ -72,8 +72,5 @@
{{ end }}
</div>
-<!-- <div id="reported" class="popup-box" style="margin-bottom: 25px; padding: 12px;"> -->
-<!-- <h4 style="margin: 0; margin-bottom: 5px;">Reported</h4> -->
-<!-- <ul style="display: inline-block; padding: 0; margin: 0; list-style-type: none;"> -->
-<!-- </ul> -->
-<!-- </div> -->
+{{ template "partials/footer" .page }}
+{{ template "partials/general_scripts" .page }}
diff --git a/views/manage.html b/views/manage.html
index e3c03a0..e51644e 100644
--- a/views/manage.html
+++ b/views/manage.html
@@ -80,14 +80,3 @@
{{ template "partials/footer" .page }}
{{ template "partials/general_scripts" .page }}
-
-<script>
- var reported = document.querySelectorAll('#rpost');
- var reportedArray = [].slice.call(reported);
-
- reportedArray.forEach(function(r, i){
- var id = r.getAttribute("post")
- r.innerText = "/" + {{ .page.Board.Name }} + "/" + shortURL("{{ .page.Board.Actor.Id }}", id)
- r.href = {{ .page.Domain }} + "/" + {{ .page.Board.Name }} + "/" + shortURL("{{ .page.Board.Actor.Id }}", id)
- })
-</script>
diff --git a/views/partials/posts.html b/views/partials/posts.html
index 67f3d27..8ae1745 100644
--- a/views/partials/posts.html
+++ b/views/partials/posts.html
@@ -1,5 +1,6 @@
{{ $board := .Board }}
{{ $len := len .Posts }}
+{{ $page := . }}
{{ range .Posts }}
{{ $thread := . }}
{{ $opId := .Id }}
@@ -48,7 +49,7 @@
<span class="name"><b>{{ if .AttributedTo }} {{.AttributedTo }} {{ else }} Anonymous {{ end }}</b></span>
<span class="tripcode"> {{ .TripCode }} </span>
<span class="timestamp" data-utc="{{.Published | timeToUnix}}">{{ .Published | timeToReadableLong }} <a id="{{ .Id }}-anchor" href="/{{ $board.Name }}/{{ shortURL $board.Actor.Outbox $opId }}#{{ shortURL $board.Actor.Outbox .Id }}">No.</a> <a id="{{ .Id }}-link" title="{{ .Id }}" {{ if eq .Type "Note" }} href="javascript:quote('{{ $board.Actor.Id }}', '{{ $opId }}', '{{ .Id }}')" {{ end }}>{{ shortURL $board.Actor.Outbox .Id }}</a> {{ if ne .Type "Tombstone" }}[<a href="javascript:report('{{ $board.Actor.Id }}', '{{ .Id }}')">Report</a>]{{ end }}</span>
- <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread }}</p>
+ <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}</p>
{{ if .Replies }}
{{ $replies := .Replies }}
{{ if gt $replies.TotalItems 5 }}
@@ -109,7 +110,7 @@
<span id="{{$parentId}}-replyto-{{.Id}}">{{ parseReplyLink $board.Actor.Id $opId .Id .Content }}</span>
{{ end }}
{{ end }}
- <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread }}</p>
+ <p id="{{ .Id }}-content" style="white-space: pre-wrap; margin: 10px 30px 10px 30px;">{{ parseContent $board.Actor $opId .Content $thread .Id $page.PostType }}</p>
</div>
</div>
</div>