mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-03 07:36:23 -07:00
Add bbcode, HTML reparsing function for imageboard admins
This commit is contained in:
parent
4d93f8bb98
commit
46a3e8ac77
9 changed files with 55 additions and 17 deletions
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ GOCHAN_DEBUG=1
|
|||
GOCHAN_VERBOSE=2
|
||||
GOCHAN_VERBOSITY=0 # This is set by "make release/debug/verbose"
|
||||
|
||||
GOCHAN_VERSION=1.8.2
|
||||
GOCHAN_VERSION=1.9.0
|
||||
GOCHAN_BUILDTIME=$(shell date +%y%m%d.%H%M)
|
||||
ifeq ($(GOOS), windows)
|
||||
GOCHAN_BIN=gochan.exe
|
||||
|
|
2
dist.sh
2
dist.sh
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
VERSION=1.8.2
|
||||
VERSION=1.9.0
|
||||
GOOS_ORIG=$GOOS
|
||||
|
||||
function copyStuff {
|
||||
|
|
|
@ -178,7 +178,6 @@ table#pages td {
|
|||
}
|
||||
|
||||
.post-text {
|
||||
white-space: pre-wrap;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
|
@ -232,8 +231,7 @@ table#pages td {
|
|||
}
|
||||
|
||||
.dropdown-button {
|
||||
display: inline;
|
||||
padding: 4px;
|
||||
padding: 4px 8px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
<h1>404: File not found</h1>
|
||||
<img src="/error/lol 404.gif" border="0" alt="">
|
||||
<p>The requested file could not be found on this server. Are you just typing random stuff in the address bar? If you followed a link from this site here, then post <a href="/site">here</a></p>
|
||||
<hr><address>http://gochan.org powered by Gochan v1.8.2</address>
|
||||
<hr><address>http://gochan.org powered by Gochan v1.9.0</address>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
<h1>500: Internal Server error</h1>
|
||||
<img src="/error/derpy server.gif" border="0" alt="">
|
||||
<p>The server encountered an error while trying to serve the page, and we apologize for the inconvenience. The <a href="https://en.wikipedia.org/wiki/Idiot">system administrator</a> will try to fix things as soon has he/she/it can.</p>
|
||||
<hr><address>http://gochan.org powered by Gochan v1.8.2</address>
|
||||
<hr><address>http://gochan.org powered by Gochan v1.9.0</address>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -150,13 +150,13 @@ var DropDownMenu = function(title,menu_html) {
|
|||
this.menuHTML = menu_html;
|
||||
this.button = new TopBarButton(title, function() {
|
||||
topbar.after("<div id=\""+title.toLowerCase()+"\" class=\"dropdown-menu\">"+menu_html+"</div>");
|
||||
$jq("a#"+title.toLowerCase()).children(0).html(title+up_arrow_symbol);
|
||||
$jq("a#"+title.toLowerCase() + "-menu").children(0).html(title+up_arrow_symbol);
|
||||
$jq("div#"+title.toLowerCase()).css({
|
||||
top:topbar.height()
|
||||
});
|
||||
}, function() {
|
||||
$jq("div#"+title.toLowerCase() + ".dropdown-menu").remove();
|
||||
$jq("a#"+title.toLowerCase()).children(0).html(title+down_arrow_symbol);
|
||||
$jq("a#"+title.toLowerCase() + "-menu").children(0).html(title+down_arrow_symbol);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -791,12 +791,13 @@ var manage_functions = map[string]ManageFunction{
|
|||
"<a href=\"javascript:void(0)\" id=\"announcements\" class=\"staffmenu-item\">Announcements</a><br />\n"
|
||||
if rank == 3 {
|
||||
html += "<b>Admin stuff</b><br />\n<a href=\"javascript:void(0)\" id=\"staff\" class=\"staffmenu-item\">Manage staff</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"purgeeverything\" class=\"staffmenu-item\">Purge everything!</a><br />\n" +
|
||||
//"<a href=\"javascript:void(0)\" id=\"purgeeverything\" class=\"staffmenu-item\">Purge everything!</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"executesql\" class=\"staffmenu-item\">Execute SQL statement(s)</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"cleanup\" class=\"staffmenu-item\">Run cleanup</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"rebuildall\" class=\"staffmenu-item\">Rebuild all</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"rebuildfront\" class=\"staffmenu-item\">Rebuild front page</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"rebuildboards\" class=\"staffmenu-item\">Rebuild board pages</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"reparsehtml\" class=\"staffmenu-item\">Reparse all posts</a><br />\n" +
|
||||
"<a href=\"javascript:void(0)\" id=\"boards\" class=\"staffmenu-item\">Add/edit/delete boards</a><br />\n"
|
||||
}
|
||||
if rank >= 2 {
|
||||
|
@ -832,6 +833,37 @@ var manage_functions = map[string]ManageFunction{
|
|||
initTemplates()
|
||||
return buildBoards(true, 0)
|
||||
}},
|
||||
"reparsehtml": {
|
||||
Permissions: 3,
|
||||
Callback: func() (html string) {
|
||||
posts, err := getPostArr(map[string]interface{}{
|
||||
"deleted_timestamp": nil_timestamp,
|
||||
}, "")
|
||||
if err != nil {
|
||||
html += err.Error() + "<br />"
|
||||
return
|
||||
}
|
||||
|
||||
for _, postInter := range posts {
|
||||
post := postInter.(PostTable)
|
||||
stmt, err := db.Prepare("UPDATE `" + config.DBprefix + "posts` SET `message` = ? WHERE `id` = ? AND `boardid` = ?")
|
||||
if err != nil {
|
||||
html += err.Error() + "<br />"
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if stmt != nil {
|
||||
stmt.Close()
|
||||
}
|
||||
}()
|
||||
stmt.Exec(formatMessage(post.MessageText), post.ID, post.BoardID)
|
||||
}
|
||||
html += "Done reparsing HTML<hr />" +
|
||||
buildFrontPage() + "<hr />\n" +
|
||||
buildBoardListJSON() + "<hr />\n" +
|
||||
buildBoards(true, 0) + "<hr />\n"
|
||||
return
|
||||
}},
|
||||
"recentposts": {
|
||||
Permissions: 1,
|
||||
Callback: func() (html string) {
|
||||
|
|
|
@ -1008,8 +1008,7 @@ func makePost(w http.ResponseWriter, r *http.Request, data interface{}) {
|
|||
serveErrorPage(w, "Post body is too long")
|
||||
return
|
||||
}
|
||||
post.MessageHTML = html.EscapeString(post.MessageText)
|
||||
formatMessage(&post)
|
||||
post.MessageHTML = formatMessage(post.MessageText)
|
||||
|
||||
post.Password = md5Sum(request.FormValue("postpassword"))
|
||||
|
||||
|
@ -1335,11 +1334,10 @@ func makePost(w http.ResponseWriter, r *http.Request, data interface{}) {
|
|||
benchmarkTimer("makePost", startTime, false)
|
||||
}
|
||||
|
||||
func formatMessage(post *PostTable) {
|
||||
message := post.MessageHTML
|
||||
|
||||
func formatMessage(message string) string {
|
||||
message = bbcompiler.Compile(message)
|
||||
// prepare each line to be formatted
|
||||
postLines := strings.Split(message, "\\r\\n")
|
||||
postLines := strings.Split(message, "<br>")
|
||||
for i, line := range postLines {
|
||||
trimmedLine := strings.TrimSpace(line)
|
||||
//lineWords := regexp.MustCompile("\\s").Split(trimmedLine, -1)
|
||||
|
@ -1377,5 +1375,5 @@ func formatMessage(post *PostTable) {
|
|||
}
|
||||
postLines[i] = line
|
||||
}
|
||||
post.MessageHTML = strings.Join(postLines, "<br />")
|
||||
return strings.Join(postLines, "<br />")
|
||||
}
|
||||
|
|
10
src/types.go
10
src/types.go
|
@ -7,6 +7,8 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/frustra/bbcode"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -16,6 +18,7 @@ var (
|
|||
errorLog *log.Logger
|
||||
modLog *log.Logger
|
||||
readBannedIPs []string
|
||||
bbcompiler bbcode.Compiler
|
||||
)
|
||||
|
||||
type RecentPost struct {
|
||||
|
@ -662,6 +665,13 @@ func initConfig() {
|
|||
println(0, "RandomSeed not set in gochan.json, halting.")
|
||||
os.Exit(2)
|
||||
}
|
||||
bbcompiler = bbcode.NewCompiler(true, true)
|
||||
bbcompiler.SetTag("center", nil)
|
||||
bbcompiler.SetTag("code", nil)
|
||||
bbcompiler.SetTag("color", nil)
|
||||
bbcompiler.SetTag("img", nil)
|
||||
bbcompiler.SetTag("quote", nil)
|
||||
bbcompiler.SetTag("size", nil)
|
||||
|
||||
config.Version = version
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue