Simplified adding variant hooks.

The benchmark now uses ten replies instead of one for a more relevant result.
Slices are now used instead of maps for itemLists.
The compiled template engine now supports slice loops.
More routes are compiled now.
Fixed a bug with the sorting of the itemLists in the templates.
Guests can no longer see the reply creation forms.
Fixed the notice system.
This commit is contained in:
Azareal 2016-12-18 12:56:06 +00:00
parent 2b9a9704fb
commit b9885e9d7a
30 changed files with 1115 additions and 703 deletions

View File

@ -18,12 +18,14 @@ In-memory static file, forum and group caches.
A profile system including profile comments and moderation tools for the profile owner.
A template engine which compiles templates down into machine code. Over ten times faster than html/templates.
A plugin system.
# Dependencies
Go. The programming language this program is written in, and the compiler which it requires. You will need to install this. https://golang.org/doc/install
Go 1.7. The programming language this program is written in, and the compiler which it requires. You will need to install this. https://golang.org/doc/install
MySQL Database. You will need to setup a MySQL Database somewhere. A MariaDB Database works equally well, and is much faster than MySQL.
If you're curious about how to install this, you might want to try the WNMP or XAMPP bundles on Windows.

View File

@ -23,4 +23,4 @@ var noavatar = "https://api.adorable.io/avatars/285/{id}@" + siteurl + ".png"
var items_per_page = 50
// Developer flag
var debug = true
var debug = false

View File

@ -11,6 +11,7 @@ CREATE TABLE `users`(
`createdAt` datetime not null,
`lastActiveAt` datetime not null,
`session` varchar(200) DEFAULT '' not null,
`last_ip` varchar(200) DEFAULT '0.0.0.0.0' not null,
`email` varchar(200) DEFAULT '' not null,
`avatar` varchar(20) DEFAULT '' not null,
`message` text not null,
@ -54,6 +55,7 @@ CREATE TABLE `topics`(
`is_closed` tinyint DEFAULT 0 not null,
`sticky` tinyint DEFAULT 0 not null,
`parentID` int DEFAULT 1 not null,
`ipaddress` varchar(200) DEFAULT '0.0.0.0.0' not null,
`data` varchar(200) DEFAULT '' not null,
primary key(`tid`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
@ -67,6 +69,7 @@ CREATE TABLE `replies`(
`createdBy` int not null,
`lastEdit` int not null,
`lastEditBy` int not null,
`ipaddress` varchar(200) DEFAULT '0.0.0.0.0' not null,
primary key(`rid`)
) CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;

View File

@ -0,0 +1,333 @@
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
body
{
font-family: arial;
}
@font-face {
font-family: 'EmojiFont';
src: url('https://github.com/Ranks/emojione/raw/master/assets/fonts/emojione-svg.woff2') format('woff2'),
url('https://github.com/Ranks/emojione/raw/master/assets/fonts/emojione-svg.woff') format('woff'), local("arial");
}
@supports (-ms-ime-align:auto) {
.user_content
{
font-family: EmojiFont, arial;
}
}
@-moz-document url-prefix() {
.user_content
{
font-family: EmojiFont, arial;
}
}
.move_left
{
float: left;
position: relative;
left: 50%;
}
.move_right
{
float: left;
position: relative;
left: -50%;
}
ul
{
padding-left: 0px;
padding-right: 0px;
height: 28px;
list-style-type: none;
}
li
{
height: 28px;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: bold;
text-transform: uppercase;
}
li a
{
text-decoration: none;
color: #515151;
}
li a:hover
{
color: #7a7a7a;
}
.menu_left
{
float: left;
border-right: 1px solid #ccc;
padding-right: 10px;
}
.menu_left:first-child
{
border-left: 1px solid #ccc
}
.menu_right
{
float: right;
border-left: 1px solid #ccc;
padding-right: 10px;
}
.container
{
width: 90%;
padding: 0px;
margin-left: auto;
margin-right: auto;
}
.rowblock
{
border: 1px solid #ccc;
width: 100%;
padding: 0px;
padding-top: 0px;
}
.rowblock:empty
{
display: none;
}
.colblock_left
{
border: 1px solid #ccc;
padding: 0px;
padding-top: 0px;
width: 30%;
float: left;
margin-right: 8px;
}
.colblock_right
{
border: 1px solid #ccc;
padding: 0px;
padding-top: 0px;
width: 65%;
overflow: hidden;
word-wrap: break-word;
}
.colblock_left:empty
{
display: none;
}
.colblock_right:empty
{
display: none;
}
.rowitem
{
width: 100%;
padding-left: 8px;
padding-right: 8px;
padding-top: 17px;
padding-bottom: 12px;
font-weight: bold;
text-transform: uppercase;
}
.rowitem.passive
{
font-weight: normal;
text-transform: none;
}
.rowitem:not(:last-child)/*:not(:only-child)*/
{
border-bottom: 1px dotted #ccc;
}
.rowitem a
{
text-decoration: none;
color: black;
}
.rowitem a:hover
{
color: silver;
}
.col_left
{
width: 30%;
float: left;
}
.col_right
{
width: 69%;
overflow: hidden;
}
.colitem
{
padding-left: 8px;
padding-right: 8px;
padding-top: 17px;
padding-bottom: 12px;
font-weight: bold;
text-transform: uppercase;
}
.colitem.passive
{
font-weight: normal;
text-transform: none;
}
.colitem a
{
text-decoration: none;
color: black;
}
.colitem a:hover
{
color: silver;
}
.formrow
{
/*height: 40px;*/
width: 100%;
}
/*Clearfix*/
.formrow:before,
.formrow:after {
content: " ";
display: table;
}
.formrow:after {
clear: both;
}
.formrow:not(:last-child)
{
border-bottom: 1px dotted #ccc;
}
.formitem
{
float: left;
padding-left: 8px;
padding-right: 8px;
padding-top: 13px;
padding-bottom: 8px;
font-weight: bold;
}
.formitem:first-child
{
font-weight: bold;
}
.formitem:not(:last-child)
{
border-right: 1px dotted #ccc;
}
.formitem.invisible_border
{
border: none;
}
/* Mostly for textareas */
.formitem:only-child
{
width: 97%;
}
.formitem textarea
{
width: 100%;
height: 100px;
}
.formitem:has-child()
{
margin: 0 auto;
float: none;
}
button
{
background: white;
border: 1px solid #8e8e8e;
}
/* Topics */
.topic_status
{
text-transform: none;
margin-left: 8px;
padding-left: 2px;
padding-right: 2px;
padding-top: 2px;
padding-bottom: 2px;
background-color: #E8E8E8; /* 232,232,232. All three RGB colours being the same seems to create a shade of gray */
color: #505050; /* 80,80,80 */
border-radius: 2px;
}
.topic_status:empty
{
display: none;
}
.username
{
text-transform: none;
margin-left: 0px;
padding-left: 4px;
padding-right: 4px;
padding-top: 2px;
padding-bottom: 2px;
color: #505050; /* 80,80,80 */
background-color: #FFFFFF;
border-style: dotted;
border-color: #505050; /* 232,232,232. All three RGB colours being the same seems to create a shade of gray */
border-width: 1px;
font-size: 15px;
}
button.username
{
position: relative;
top: -0.25px;
}
.show_on_edit
{
display: none;
}
.alert
{
display: block;
padding: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
.alert_success
{
display: block;
padding: 5px;
border: 1px solid A2FC00;
margin-bottom: 10px;
background-color: DAF7A6;
}
.alert_error
{
display: block;
padding: 5px;
border: 1px solid #FF004B;
margin-bottom: 8px;
background-color: #FEB7CC;
}

View File

@ -14,7 +14,7 @@ func init() {
}
func init_sendmail() {
add_vhook("email_send_intercept", send_sendmail)
add_hook("email_send_intercept", send_sendmail)
}
// Sendmail is only available on Linux

View File

@ -20,8 +20,19 @@ type Plugin struct
Deactivate func()
}
func add_hook(name string, handler func(interface{})interface{}) {
/*func add_hook(name string, handler func(interface{})interface{}) {
hooks[name] = handler
}*/
func add_hook(name string, handler interface{}) {
switch h := handler.(type) {
case func(interface{})interface{}:
hooks[name] = h
case func(...interface{}) interface{}:
vhooks[name] = h
default:
panic("I don't recognise this kind of handler!") // Should this be an error for the plugin instead of a panic()?
}
}
func remove_hook(name string) {
@ -32,10 +43,6 @@ func run_hook(name string, data interface{}) interface{} {
return hooks[name](data)
}
func add_vhook(name string, handler func(...interface{}) interface{}) {
vhooks[name] = handler
}
func remove_vhook(name string) {
delete(vhooks, name)
}

View File

@ -10,25 +10,45 @@ func BenchmarkTemplates(b *testing.B) {
noticeList[0] = "test"
topic := TopicUser{0,"Lol",template.HTML("Hey everyone!"),0,false,false,"",0,"","","",no_css_tmpl,0,"","","",""}
var replyList map[int]interface{} = make(map[int]interface{})
replyList[0] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
pi := Page{"Topic Blah","topic",user,noticeList,replyList,topic}
pi2 := Page{"Topic Blah","topic",admin,noticeList,replyList,topic}
replyList[1] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[2] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[3] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[4] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[5] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[6] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[7] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[8] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
replyList[9] = Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
var replyList2 []interface{}
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
replyList2 = append(replyList2, Reply{0,0,"Hey everyone!",template.HTML("Hey everyone!"),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
pi := Page2{"Topic Blah","topic",user,noticeList,replyList,topic}
pi2 := Page2{"Topic Blah","topic",admin,noticeList,replyList,topic}
pi3 := Page{"Topic Blah","topic",user,noticeList,replyList2,topic}
pi4 := Page{"Topic Blah","topic",admin,noticeList,replyList2,topic}
w := ioutil.Discard
b.Run("compiled_writer_collated_useradmin", func(b *testing.B) {
b.Run("compiled_sliceloop_useradmin", func(b *testing.B) {
for i := 0; i < b.N; i++ {
template_topic(pi2,w)
template_topic(pi4,w)
}
})
b.Run("compiled_writer_useradmin", func(b *testing.B) {
b.Run("compiled_maploop_useradmin", func(b *testing.B) {
for i := 0; i < b.N; i++ {
template_topic2(pi2,w)
}
})
b.Run("compiled_useradmin", func(b *testing.B) {
for i := 0; i < b.N; i++ {
w.Write([]byte(template_topic3(pi2)))
template_topic_maploop(pi2,w)
}
})
b.Run("interpreted_useradmin", func(b *testing.B) {
@ -36,19 +56,15 @@ func BenchmarkTemplates(b *testing.B) {
templates.ExecuteTemplate(w,"topic.html", pi2)
}
})
b.Run("compiled_writer_collated_userguest", func(b *testing.B) {
b.Run("compiled_sliceloop_userguest", func(b *testing.B) {
for i := 0; i < b.N; i++ {
template_topic(pi,w)
template_topic(pi3,w)
}
})
b.Run("compiled_writer_userguest", func(b *testing.B) {
b.Run("compiled_maploop_userguest", func(b *testing.B) {
for i := 0; i < b.N; i++ {
template_topic2(pi,w)
}
})
b.Run("compiled_userguest", func(b *testing.B) {
for i := 0; i < b.N; i++ {
w.Write([]byte(template_topic3(pi)))
template_topic_maploop(pi,w)
}
})
b.Run("interpreted_userguest", func(b *testing.B) {

Binary file not shown.

BIN
gosora.exe~ Normal file

Binary file not shown.

BIN
images/notices.PNG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

36
main.go
View File

@ -43,22 +43,43 @@ func compile_templates() {
log.Print("Compiling the templates")
topic := TopicUser{0,"",template.HTML(""),0,false,false,"",0,"","","",no_css_tmpl,0,"","","",""}
var replyList map[int]interface{} = make(map[int]interface{})
replyList[0] = Reply{0,0,"",template.HTML(""),0,"","",0,0,"",no_css_tmpl,0,"","","",""}
var replyList []interface{}
replyList = append(replyList, Reply{0,0,"",template.HTML(""),0,"","",0,0,"",no_css_tmpl,0,"","","",""})
var varList map[string]VarItem = make(map[string]VarItem)
varList["extra_data"] = VarItem{"extra_data","tmpl_topic_vars.Something.(TopicUser)","TopicUser"}
pi := Page{"Title","name",user,noticeList,replyList,topic}
topic_id := c.compile_template("topic.html","templates/","Page", pi, varList)
topic_id_tmpl := c.compile_template("topic.html","templates/","Page", pi, varList)
varList = make(map[string]VarItem)
varList["extra_data"] = VarItem{"extra_data","tmpl_profile_vars.Something.(User)","User"}
pi = Page{"Title","name",user,noticeList,replyList,user}
profile := c.compile_template("profile.html","templates/","Page", pi, varList)
profile_tmpl := c.compile_template("profile.html","templates/","Page", pi, varList)
var forumList []interface{}
for _, forum := range forums {
if forum.Active {
forumList = append(forumList, forum)
}
}
varList = make(map[string]VarItem)
pi = Page{"Forum List","forums",user,noticeList,forumList,0}
forums_tmpl := c.compile_template("forums.html","templates/","Page", pi, varList)
var topicList []interface{}
topicList = append(topicList, TopicUser{1,"Topic Title","The topic content.",1,false,false,"",1,"open","Admin","","",0,"","","",""})
pi = Page{"Topic List","topics",user,noticeList,topicList,""}
topics_tmpl := c.compile_template("topics.html","templates/","Page", pi, varList)
pi = Page{"General Forum","forum",user,noticeList,topicList,"There aren't any topics in this forum yet."}
forum_tmpl := c.compile_template("forum.html","templates/","Page", pi, varList)
log.Print("Writing the templates")
write_template("topic", topic_id)
write_template("profile", profile)
write_template("topic", topic_id_tmpl)
write_template("profile", profile_tmpl)
write_template("forums", forums_tmpl)
write_template("topics", topics_tmpl)
write_template("forum", forum_tmpl)
}
func write_template(name string, content string) {
@ -77,8 +98,8 @@ func write_template(name string, content string) {
func main(){
var err error
compile_templates()
init_database(err);
compile_templates()
log.Print("Loading the static files.")
err = filepath.Walk("./public", func(path string, f os.FileInfo, err error) error {
@ -167,6 +188,7 @@ func main(){
http.HandleFunc("/users/ban/", route_ban)
http.HandleFunc("/users/ban/submit/", route_ban_submit)
http.HandleFunc("/users/unban/", route_unban)
http.HandleFunc("/users/activate/", route_activate)
// Admin
http.HandleFunc("/panel/forums/", route_panel_forums)

View File

@ -454,7 +454,6 @@ func route_unban(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
if !user.Is_Mod && !user.Is_Admin {
NoPermissions(w,r,user)
return
@ -490,6 +489,46 @@ func route_unban(w http.ResponseWriter, r *http.Request) {
http.Redirect(w,r,"/users/" + strconv.Itoa(uid),http.StatusSeeOther)
}
func route_activate(w http.ResponseWriter, r *http.Request) {
user, ok := SimpleSessionCheck(w,r)
if !ok {
return
}
if !user.Is_Mod && !user.Is_Admin {
NoPermissions(w,r,user)
return
}
uid, err := strconv.Atoi(r.URL.Path[len("/users/activate/"):])
if err != nil {
LocalError("The provided User ID is not a valid number.",w,r,user)
return
}
var uname string
var active bool
err = db.QueryRow("SELECT `name`, `active` from users where `uid` = ?", uid).Scan(&uname, &active)
if err == sql.ErrNoRows {
LocalError("The account you're trying to activate no longer exists.",w,r,user)
return
} else if err != nil {
InternalError(err,w,r,user)
return
}
if active {
LocalError("The account you're trying to activate has already been activated.",w,r,user)
return
}
_, err = activate_user_stmt.Exec(uid)
if err != nil {
InternalError(err,w,r,user)
return
}
http.Redirect(w,r,"/users/" + strconv.Itoa(uid),http.StatusSeeOther)
}
func route_panel_forums(w http.ResponseWriter, r *http.Request){
user, noticeList, ok := SessionCheck(w,r)
if !ok {
@ -501,13 +540,10 @@ func route_panel_forums(w http.ResponseWriter, r *http.Request){
return
}
var forumList map[int]interface{} = make(map[int]interface{})
currentID := 0
var forumList []interface{}
for _, forum := range forums {
if forum.ID > -1 {
forumList[currentID] = forum
currentID++
forumList = append(forumList, forum)
}
}
@ -778,18 +814,14 @@ func route_panel_plugins(w http.ResponseWriter, r *http.Request){
if !ok {
return
}
if !user.Is_Admin {
NoPermissions(w,r,user)
return
}
var pluginList map[int]interface{} = make(map[int]interface{})
currentID := 0
var pluginList []interface{}
for _, plugin := range plugins {
pluginList[currentID] = plugin
currentID++
pluginList = append(pluginList, plugin)
}
pi := Page{"Plugin Manager","panel-plugins",user,noticeList,pluginList,0}
@ -911,9 +943,7 @@ func route_panel_users(w http.ResponseWriter, r *http.Request){
return
}
var userList map[int]interface{} = make(map[int]interface{})
currentID := 0
var userList []interface{}
rows, err := db.Query("SELECT `uid`, `name`, `group`, `active`, `is_super_admin`, `avatar` FROM users")
if err != nil {
InternalError(err,w,r,user)
@ -951,8 +981,7 @@ func route_panel_users(w http.ResponseWriter, r *http.Request){
puser.Tag = ""
}
userList[currentID] = puser
currentID++
userList = append(userList, puser)
}
err = rows.Err()
if err != nil {

View File

@ -28,6 +28,7 @@ var set_username_stmt *sql.Stmt
var register_stmt *sql.Stmt
var username_exists_stmt *sql.Stmt
var change_group_stmt *sql.Stmt
var activate_user_stmt *sql.Stmt
var create_profile_reply_stmt *sql.Stmt
var edit_profile_reply_stmt *sql.Stmt
var delete_profile_reply_stmt *sql.Stmt
@ -183,6 +184,12 @@ func init_database(err error) {
log.Fatal(err)
}
log.Print("Preparing activate_user statement.")
activate_user_stmt, err = db.Prepare("UPDATE users SET active = 1 WHERE uid = ?")
if err != nil {
log.Fatal(err)
}
log.Print("Preparing create_profile_reply statement.")
create_profile_reply_stmt, err = db.Prepare("INSERT INTO users_replies(uid,content,parsed_content,createdAt,createdBy) VALUES(?,?,?,NOW(),?)")
if err != nil {

View File

@ -3,6 +3,17 @@ import "strings"
//import "regexp"
type Page struct
{
Title string
Name string
CurrentUser User
NoticeList map[int]string
ItemList []interface{}
Something interface{}
}
/* For testing maps versus slices */
type Page2 struct
{
Title string
Name string

View File

@ -28,41 +28,56 @@ body
}
}
/*.move_left
{
float: left;
position: relative;
left: 50%;
}
.move_right
{
float: left;
position: relative;
left: -50%;
}*/
ul
{
border: 1px solid #ccc;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 0px;
padding-right: 0px;
height: 28px;
list-style-type: none;
border: 1px solid #ccc;
}
li
{
float: left;
height: 26px;
padding-left: 10px;
padding-top: 5px;
padding-bottom: 5px;
font-weight: bold;
text-transform: uppercase;
}
li a
{
text-decoration: none;
color: #515151;
}
li a:hover
{
color: #7a7a7a;
}
li:not(:last-child)
.menu_left
{
float: left;
border-right: 1px solid #ccc;
padding-right: 10px;
}
.menu_right
{
float: right;
border-left: 1px solid #ccc;
padding-right: 10px;
}
.container
{
@ -288,18 +303,26 @@ button.username
display: none;
}
.alert
{
display: block;
padding: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
.alert_success
{
display: block;
padding: 3px;
padding: 5px;
border: 1px solid A2FC00;
margin-bottom: 10px;
background-color: DAF7A6;
}
.alert_error
{
display: block;
padding: 3px;
padding: 5px;
border: 1px solid #FF004B;
margin-bottom: 8px;
background-color: #FEB7CC;
}

View File

@ -19,7 +19,7 @@ import _ "github.com/go-sql-driver/mysql"
import "golang.org/x/crypto/bcrypt"
// A blank list to fill out that parameter in Page for routes which don't use it
var tList map[int]interface{}
var tList []interface{}
var nList map[int]string
// GET functions
@ -80,7 +80,7 @@ func route_topics(w http.ResponseWriter, r *http.Request){
}
var(
topicList map[int]interface{}
topicList []interface{}
currentID int
tid int
@ -95,8 +95,6 @@ func route_topics(w http.ResponseWriter, r *http.Request){
name string
avatar string
)
topicList = make(map[int]interface{})
currentID = 0
rows, err := db.Query("select topics.tid, topics.title, topics.content, topics.createdBy, topics.is_closed, topics.sticky, topics.createdAt, topics.parentID, users.name, users.avatar from topics left join users ON topics.createdBy = users.uid order by topics.sticky DESC, topics.lastReplyAt DESC, topics.createdBy DESC")
if err != nil {
@ -125,12 +123,11 @@ func route_topics(w http.ResponseWriter, r *http.Request){
avatar = strings.Replace(noavatar,"{id}",strconv.Itoa(createdBy),1)
}
topicList[currentID] = TopicUser{tid,title,content,createdBy,is_closed,sticky, createdAt,parentID,status,name,avatar,"",0,"","","",""}
topicList = append(topicList, TopicUser{tid,title,content,createdBy,is_closed,sticky, createdAt,parentID,status,name,avatar,"",0,"","","",""})
if hooks["trow_assign"] != nil {
topicList[currentID] = run_hook("trow_assign", topicList[currentID])
}
currentID++
}
err = rows.Err()
if err != nil {
@ -146,10 +143,14 @@ func route_topics(w http.ResponseWriter, r *http.Request){
}
pi := Page{"Topic List","topics",user,noticeList,topicList,msg}
if ctemplates["topics"] != nil {
ctemplates["topics"](pi,w)
} else {
err = templates.ExecuteTemplate(w,"topics.html", pi)
if err != nil {
InternalError(err, w, r, user)
}
}
}
func route_forum(w http.ResponseWriter, r *http.Request){
@ -159,7 +160,7 @@ func route_forum(w http.ResponseWriter, r *http.Request){
}
var(
topicList map[int]interface{}
topicList []interface{}
currentID int
tid int
@ -174,8 +175,6 @@ func route_forum(w http.ResponseWriter, r *http.Request){
name string
avatar string
)
topicList = make(map[int]interface{})
currentID = 0
fid, err := strconv.Atoi(r.URL.Path[len("/forum/"):])
if err != nil {
@ -216,12 +215,11 @@ func route_forum(w http.ResponseWriter, r *http.Request){
avatar = strings.Replace(noavatar,"{id}",strconv.Itoa(createdBy),1)
}
topicList[currentID] = TopicUser{tid,title,content,createdBy,is_closed,sticky,createdAt,parentID,status,name,avatar,"",0,"","","",""}
topicList = append(topicList, TopicUser{tid,title,content,createdBy,is_closed,sticky,createdAt,parentID,status,name,avatar,"",0,"","","",""})
if hooks["trow_assign"] != nil {
topicList[currentID] = run_hook("trow_assign", topicList[currentID])
}
currentID++
}
err = rows.Err()
if err != nil {
@ -237,10 +235,14 @@ func route_forum(w http.ResponseWriter, r *http.Request){
}
pi := Page{forums[fid].Name,"forum",user,noticeList,topicList,msg}
if ctemplates["forum"] != nil {
ctemplates["forum"](pi,w)
} else {
err = templates.ExecuteTemplate(w,"forum.html", pi)
if err != nil {
InternalError(err, w, r, user)
}
}
}
func route_forums(w http.ResponseWriter, r *http.Request){
@ -249,13 +251,10 @@ func route_forums(w http.ResponseWriter, r *http.Request){
return
}
var forumList map[int]interface{} = make(map[int]interface{})
currentID := 0
var forumList []interface{}
for _, forum := range forums {
if forum.Active {
forumList[currentID] = forum
currentID++
forumList = append(forumList, forum)
}
}
@ -265,10 +264,14 @@ func route_forums(w http.ResponseWriter, r *http.Request){
}
pi := Page{"Forum List","forums",user,noticeList,forumList,0}
if ctemplates["forums"] != nil {
ctemplates["forums"](pi,w)
} else {
err := templates.ExecuteTemplate(w,"forums.html", pi)
if err != nil {
InternalError(err, w, r, user)
}
}
}
func route_topic_id(w http.ResponseWriter, r *http.Request){
@ -297,11 +300,8 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
is_super_admin bool
group int
currentID int
replyList map[int]interface{}
replyList []interface{}
)
replyList = make(map[int]interface{})
currentID = 0
topic := TopicUser{0,"","",0,false,false,"",0,"","","",no_css_tmpl,0,"","","",""}
topic.ID, err = strconv.Atoi(r.URL.Path[len("/topic/"):])
@ -398,12 +398,12 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){
}
}
replyList[currentID] = Reply{rid,topic.ID,replyContent,template.HTML(parse_message(replyContent)),replyCreatedBy,replyCreatedByName,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,replyURL,replyURLPrefix,replyURLName}
replyItem := Reply{rid,topic.ID,replyContent,template.HTML(parse_message(replyContent)),replyCreatedBy,replyCreatedByName,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,replyURL,replyURLPrefix,replyURLName}
if hooks["rrow_assign"] != nil {
replyList[currentID] = run_hook("rrow_assign", replyList[currentID])
replyItem = run_hook("rrow_assign", replyItem).(Reply)
}
currentID++
replyList = append(replyList, replyItem)
}
err = rows.Err()
if err != nil {
@ -444,11 +444,8 @@ func route_profile(w http.ResponseWriter, r *http.Request){
is_super_admin bool
group int
currentID int
replyList map[int]interface{}
replyList []interface{}
)
replyList = make(map[int]interface{})
currentID = 0
puser := User{0,"",0,false,false,false,false,false,false,"",false,"","","","",""}
puser.ID, err = strconv.Atoi(r.URL.Path[len("/user/"):])
@ -530,8 +527,7 @@ func route_profile(w http.ResponseWriter, r *http.Request){
replyTag = ""
}
replyList[currentID] = Reply{rid,puser.ID,replyContent,template.HTML(parse_message(replyContent)),replyCreatedBy,replyCreatedByName,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","",""}
currentID++
replyList = append(replyList, Reply{rid,puser.ID,replyContent,template.HTML(parse_message(replyContent)),replyCreatedBy,replyCreatedByName,replyCreatedAt,replyLastEdit,replyLastEditBy,replyAvatar,replyCss,replyLines,replyTag,"","",""})
}
err = rows.Err()
if err != nil {
@ -540,11 +536,14 @@ func route_profile(w http.ResponseWriter, r *http.Request){
}
pi := Page{puser.Name + "'s Profile","profile",user,noticeList,replyList,puser}
//w.Write([]byte(template_profile(pi)))
if ctemplates["profile"] != nil {
ctemplates["profile"](pi,w)
} else {
err = templates.ExecuteTemplate(w,"profile.html", pi)
if err != nil {
InternalError(err, w, r, user)
}
}
}
func route_topic_create(w http.ResponseWriter, r *http.Request){

104
template_forum.go Normal file
View File

@ -0,0 +1,104 @@
package main
import "strconv"
import "io"
func init() {
ctemplates["forum"] = template_forum
}
func template_forum(tmpl_forum_vars Page, w io.Writer) {
w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<title>` + tmpl_forum_vars.Title + `</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "` + tmpl_forum_vars.CurrentUser.Session + `";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_forum_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_forum_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_forum_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_forum_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_forum_vars.NoticeList) != 0 {
for _, item := range tmpl_forum_vars.NoticeList {
w.Write([]byte(`<div class="alert">` + item + `</div>`))
}
}
w.Write([]byte(`
<div class="rowblock">
<div class="rowitem"><a>` + tmpl_forum_vars.Title + `</a></div>
</div>
<div class="rowblock">
`))
if len(tmpl_forum_vars.ItemList) != 0 {
for _, item := range tmpl_forum_vars.ItemList {
w.Write([]byte(`<div class="rowitem passive" style="`))
if item.(TopicUser).Avatar != "" {
w.Write([]byte(`background-image: url(` + item.(TopicUser).Avatar + `);background-position: left;background-repeat: no-repeat;background-size: 64px;padding-left: 72px;`))
}
if item.(TopicUser).Sticky {
w.Write([]byte(`background-color: #FFFFCC;`))
}
w.Write([]byte(`">
<a href="/topic/` + strconv.Itoa(item.(TopicUser).ID) + `">` + item.(TopicUser).Title + `</a> `))
if item.(TopicUser).Is_Closed {
w.Write([]byte(`<span class="username topic_status_e topic_status_closed" style="float: right;">closed</span>
`))
} else {
w.Write([]byte(`<span class="username topic_status_e topic_status_open" style="float: right;">open</span>`))
}
w.Write([]byte(`
<span class="username" style="border-right: 0;float: right;">Status</span>
</div>`))
}
}
w.Write([]byte(`
</div>
`))
if tmpl_forum_vars.Something.(string) != "" {
w.Write([]byte(`
<div class="rowblock">
<div class="rowitem passive">` + tmpl_forum_vars.Something.(string) + `</div>
</div>
`))
}
w.Write([]byte(`
<!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`))
}

78
template_forums.go Normal file
View File

@ -0,0 +1,78 @@
package main
import "io"
import "strconv"
func init() {
ctemplates["forums"] = template_forums
}
func template_forums(tmpl_forums_vars Page, w io.Writer) {
w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<title>` + tmpl_forums_vars.Title + `</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "` + tmpl_forums_vars.CurrentUser.Session + `";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_forums_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_forums_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_forums_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_forums_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_forums_vars.NoticeList) != 0 {
for _, item := range tmpl_forums_vars.NoticeList {
w.Write([]byte(`<div class="alert">` + item + `</div>`))
}
}
w.Write([]byte(`
<div class="rowblock">
`))
if len(tmpl_forums_vars.ItemList) != 0 {
for _, item := range tmpl_forums_vars.ItemList {
w.Write([]byte(`<div class="rowitem">
<a href="/forum/` + strconv.Itoa(item.(Forum).ID) + `" style="font-size: 20px;position:relative;top: -2px;font-weight: normal;text-transform: none;">` + item.(Forum).Name + `</a>
<a href="/topic/` + strconv.Itoa(item.(Forum).LastTopicID) + `" style="font-weight: normal;text-transform: none;float: right;">` + item.(Forum).LastTopic + ` <small style="font-size: 12px;">` + item.(Forum).LastTopicTime + `</small></a>
</div>`))
}
}
w.Write([]byte(`
</div>
<!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`))
}

View File

@ -22,31 +22,36 @@ w.Write([]byte(`<!doctype html>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_overview"><a href="/">Overview</a></li>
<li class="menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_topics"><a href="/">Topics</a></li>
<li class="menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_profile_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_account"><a href="/user/` + strconv.Itoa(tmpl_profile_vars.CurrentUser.ID) + `">Profile</a></li>
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_profile_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_profile_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_account"><a href="/panel/forums/">Panel</a></li>`))
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_logout"><a href="/accounts/logout?session=` + tmpl_profile_vars.CurrentUser.Session + `">Logout</a></li>
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_profile_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_login"><a href="/accounts/login/">Login</a></li>
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_profile_vars.NoticeList) != 0 {

View File

@ -23,31 +23,36 @@ w.Write([]byte(`<!doctype html>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_overview"><a href="/">Overview</a></li>
<li class="menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_topics"><a href="/">Topics</a></li>
<li class="menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_topic_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_account"><a href="/user/` + strconv.Itoa(tmpl_topic_vars.CurrentUser.ID) + `">Profile</a></li>
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_topic_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_topic_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_account"><a href="/panel/forums/">Panel</a></li>`))
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_logout"><a href="/accounts/logout?session=` + tmpl_topic_vars.CurrentUser.Session + `">Logout</a></li>
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_topic_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_login"><a href="/accounts/login/">Login</a></li>
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_topic_vars.NoticeList) != 0 {
@ -158,7 +163,7 @@ w.Write([]byte(`
w.Write([]byte(`
</div>
`))
if !tmpl_topic_vars.CurrentUser.Is_Banned {
if !tmpl_topic_vars.CurrentUser.Is_Banned && tmpl_topic_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<div class="rowblock">
<form action="/reply/create/" method="post">

186
template_topic_maploop.go Normal file
View File

@ -0,0 +1,186 @@
package main
import "io"
import "strconv"
import "html/template"
func init() {
ctemplates["topic"] = template_topic
}
func template_topic_maploop(tmpl_topic_vars Page2, w io.Writer) {
var extra_data TopicUser = tmpl_topic_vars.Something.(TopicUser)
w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<title>` + tmpl_topic_vars.Title + `</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "` + tmpl_topic_vars.CurrentUser.Session + `";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_topic_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_topic_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_topic_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_topic_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_topic_vars.NoticeList) != 0 {
for _, item := range tmpl_topic_vars.NoticeList {
w.Write([]byte(`<div class="alert">` + item + `</div>`))
}
}
w.Write([]byte(`
<div class="rowblock">
<form action='/topic/edit/submit/` + strconv.Itoa(extra_data.ID) + `' method="post">
<div class="rowitem"`))
if extra_data.Sticky {
w.Write([]byte(` style="background-color: #FFFFEA;"`))
}
w.Write([]byte(`>
<a class='topic_name hide_on_edit'>` + extra_data.Title + `</a>
<span class='username topic_status_e topic_status_` + extra_data.Status + ` hide_on_edit' style="font-weight:normal;float: right;">` + extra_data.Status + `</span>
<span class="username" style="border-right: 0;font-weight: normal;float: right;">Status</span>
`))
if tmpl_topic_vars.CurrentUser.Is_Mod {
w.Write([]byte(`
<a href='/topic/edit/` + strconv.Itoa(extra_data.ID) + `' class="username hide_on_edit open_edit" style="font-weight: normal;margin-left: 6px;">Edit</a>
<a href='/topic/delete/submit/` + strconv.Itoa(extra_data.ID) + `' class="username" style="font-weight: normal;">Delete</a>
`))
if extra_data.Sticky {
w.Write([]byte(`<a href='/topic/unstick/submit/` + strconv.Itoa(extra_data.ID) + `' class="username" style="font-weight: normal;">Unpin</a>`))
} else {
w.Write([]byte(`<a href='/topic/stick/submit/` + strconv.Itoa(extra_data.ID) + `' class="username" style="font-weight: normal;">Pin</a>`))
}
w.Write([]byte(`
<input class='show_on_edit topic_name_input' name="topic_name" value='` + extra_data.Title + `' type="text" />
<select name="topic_status" class='show_on_edit topic_status_input' style='float: right;'>
<option>open</option>
<option>closed</option>
</select>
<button name="topic-button" class="formbutton show_on_edit submit_edit">Update</button>
`))
}
w.Write([]byte(`
<a href="/report/submit/` + strconv.Itoa(extra_data.ID) + `?session=` + tmpl_topic_vars.CurrentUser.Session + `&type=topic" class="username report_item" style="font-weight: normal;">Report</a>
</div>
</form>
</div>
<div class="rowblock">
<div class="rowitem passive editable_parent" style="border-bottom: none;`))
if extra_data.Avatar != "" {
w.Write([]byte(`background-image: url(` + extra_data.Avatar + `), url(/static/white-dot.jpg);background-position: 0px `))
if extra_data.ContentLines <= 5 {
w.Write([]byte(`-1`))
}
w.Write([]byte(`0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;` + string(extra_data.Css)))
}
w.Write([]byte(`">
<span class="hide_on_edit topic_content user_content">` + string(extra_data.Content.(template.HTML)) + `</span>
<textarea name="topic_content" class="show_on_edit topic_content_input">` + string(extra_data.Content.(template.HTML)) + `</textarea>
<br /><br />
<a href="/user/` + strconv.Itoa(extra_data.CreatedBy) + `" class="username">` + extra_data.CreatedByName + `</a>
`))
if extra_data.Tag != "" {
w.Write([]byte(`<a class="username" style="float: right;">` + extra_data.Tag + `</a>`))
} else {
if extra_data.URLName != "" {
w.Write([]byte(`<a href="` + extra_data.URL + `" class="username" style="color: #505050;float: right;">` + extra_data.URLName + `</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">` + extra_data.URLPrefix + `</a>`))
}
}
w.Write([]byte(`
</div>
</div><br />
<div class="rowblock" style="overflow: hidden;">
`))
if len(tmpl_topic_vars.ItemList) != 0 {
for _, item := range tmpl_topic_vars.ItemList {
w.Write([]byte(`
<div class="rowitem passive deletable_block editable_parent" style="`))
if item.(Reply).Avatar != "" {
w.Write([]byte(`background-image: url(` + item.(Reply).Avatar + `), url(/static/white-dot.jpg);background-position: 0px `))
if item.(Reply).ContentLines <= 5 {
w.Write([]byte(`-1`))
}
w.Write([]byte(`0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;` + string(item.(Reply).Css)))
}
w.Write([]byte(`">
<span class="editable_block user_content">` + string(item.(Reply).ContentHtml) + `</span>
<br /><br />
<a href="/user/` + strconv.Itoa(item.(Reply).CreatedBy) + `" class="username">` + item.(Reply).CreatedByName + `</a>
`))
if tmpl_topic_vars.CurrentUser.Is_Mod {
w.Write([]byte(`<a href="/reply/edit/submit/` + strconv.Itoa(item.(Reply).ID) + `"><button class="username edit_item">Edit</button></a>
<a href="/reply/delete/submit/` + strconv.Itoa(item.(Reply).ID) + `"><button class="username delete_item">Delete</button></a>`))
}
w.Write([]byte(`
<a href="/report/submit/` + strconv.Itoa(item.(Reply).ID) + `?session=` + tmpl_topic_vars.CurrentUser.Session + `&type=reply"><button class="username report_item">Report</button></a>
`))
if item.(Reply).Tag != "" {
w.Write([]byte(`<a class="username" style="float: right;">` + item.(Reply).Tag + `</a>`))
} else {
if item.(Reply).URLName != "" {
w.Write([]byte(`<a href="` + item.(Reply).URL + `" class="username" style="color: #505050;float: right;" rel="nofollow">` + item.(Reply).URLName + `</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">` + item.(Reply).URLPrefix + `</a>`))
}
}
w.Write([]byte(`
</div>`))
}
}
w.Write([]byte(`
</div>
`))
if !tmpl_topic_vars.CurrentUser.Is_Banned && tmpl_topic_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<div class="rowblock">
<form action="/reply/create/" method="post">
<input name="tid" value='` + strconv.Itoa(extra_data.ID) + `' type="hidden" />
<div class="formrow">
<div class="formitem"><textarea name="reply-content" placeholder="Insert reply here"></textarea></div>
</div>
<div class="formrow">
<div class="formitem"><button name="reply-button" class="formbutton">Create Reply</button></div>
</div>
</form>
</div>
`))
}
w.Write([]byte(`
<!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`))
}

View File

@ -1,262 +0,0 @@
package main
import "strconv"
import "html/template"
//func init() {
//ctemplates["topic2"] = template_topic2
//}
func template_topic3(tmpl_topic_vars Page) (tmpl string) {
var extra_data TopicUser = tmpl_topic_vars.Something.(TopicUser)
tmpl += `<!doctype html>
<html lang="en">
<head>
<title>`
tmpl += tmpl_topic_vars.Title
tmpl += `</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "`
tmpl += tmpl_topic_vars.CurrentUser.Session
tmpl += `";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
`
tmpl += `<div class="nav">
<ul>
<li class="menu_overview"><a href="/">Overview</a></li>
<li class="menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_topics"><a href="/">Topics</a></li>
<li class="menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`
if tmpl_topic_vars.CurrentUser.Loggedin {
tmpl += `
<li class="menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_account"><a href="/user/`
tmpl += strconv.Itoa(tmpl_topic_vars.CurrentUser.ID)
tmpl += `">Profile</a></li>
`
if tmpl_topic_vars.CurrentUser.Is_Super_Mod {
tmpl += `<li class="menu_account"><a href="/panel/forums/">Panel</a></li>`
}
tmpl += `
<li class="menu_logout"><a href="/accounts/logout?session=`
tmpl += tmpl_topic_vars.CurrentUser.Session
tmpl += `">Logout</a></li>
`
} else {
tmpl += `
<li class="menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_login"><a href="/accounts/login/">Login</a></li>
`
}
tmpl += `
</ul>
</div>`
tmpl += `
`
if len(tmpl_topic_vars.NoticeList) != 0 {
for _, item := range tmpl_topic_vars.NoticeList {
tmpl += `<div class="alert">`
tmpl += item
tmpl += `</div>`
}
}
tmpl += `
<div class="rowblock">
<form action='/topic/edit/submit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' method="post">
<div class="rowitem"`
if extra_data.Sticky {
tmpl += ` style="background-color: #FFFFEA;"`
}
tmpl += `>
<a class='topic_name hide_on_edit'>`
tmpl += extra_data.Title
tmpl += `</a>
<span class='username topic_status_e topic_status_`
tmpl += extra_data.Status
tmpl += ` hide_on_edit' style="font-weight:normal;float: right;">`
tmpl += extra_data.Status
tmpl += `</span>
<span class="username" style="border-right: 0;font-weight: normal;float: right;">Status</span>
`
if tmpl_topic_vars.CurrentUser.Is_Mod {
tmpl += `
<a href='/topic/edit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' class="username hide_on_edit open_edit" style="font-weight: normal;margin-left: 6px;">Edit</a>
<a href='/topic/delete/submit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' class="username" style="font-weight: normal;">Delete</a>
`
if extra_data.Sticky {
tmpl += `<a href='/topic/unstick/submit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' class="username" style="font-weight: normal;">Unpin</a>`
} else {
tmpl += `<a href='/topic/stick/submit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' class="username" style="font-weight: normal;">Pin</a>`
}
tmpl += `
<input class='show_on_edit topic_name_input' name="topic_name" value='`
tmpl += extra_data.Title
tmpl += `' type="text" />
<select name="topic_status" class='show_on_edit topic_status_input' style='float: right;'>
<option>open</option>
<option>closed</option>
</select>
<button name="topic-button" class="formbutton show_on_edit submit_edit">Update</button>
`
}
tmpl += `
<a href="/report/submit/`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `?session=`
tmpl += tmpl_topic_vars.CurrentUser.Session
tmpl += `&type=topic" class="username report_item" style="font-weight: normal;">Report</a>
</div>
</form>
</div>
<div class="rowblock">
<div class="rowitem passive editable_parent" style="border-bottom: none;`
if extra_data.Avatar != "" {
tmpl += `background-image: url(`
tmpl += extra_data.Avatar
tmpl += `), url(/static/white-dot.jpg);background-position: 0px `
if extra_data.ContentLines <= 5 {
tmpl += `-1`
}
tmpl += `0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;`
tmpl += string(extra_data.Css)
}
tmpl += `">
<span class="hide_on_edit topic_content user_content">`
tmpl += string(extra_data.Content.(template.HTML))
tmpl += `</span>
<textarea name="topic_content" class="show_on_edit topic_content_input">`
tmpl += string(extra_data.Content.(template.HTML))
tmpl += `</textarea>
<br /><br />
<a href="/user/`
tmpl += strconv.Itoa(extra_data.CreatedBy)
tmpl += `" class="username">`
tmpl += extra_data.CreatedByName
tmpl += `</a>
`
if extra_data.Tag != "" {
tmpl += `<a class="username" style="float: right;">`
tmpl += extra_data.Tag
tmpl += `</a>`
} else {
if extra_data.URLName != "" {
tmpl += `<a href="`
tmpl += extra_data.URL
tmpl += `" class="username" style="color: #505050;float: right;">`
tmpl += extra_data.URLName
tmpl += `</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">`
tmpl += extra_data.URLPrefix
tmpl += `</a>`
}
}
tmpl += `
</div>
</div><br />
<div class="rowblock" style="overflow: hidden;">
`
if len(tmpl_topic_vars.ItemList) != 0 {
for _, item := range tmpl_topic_vars.ItemList {
tmpl += `
<div class="rowitem passive deletable_block editable_parent" style="`
if item.(Reply).Avatar != "" {
tmpl += `background-image: url(`
tmpl += item.(Reply).Avatar
tmpl += `), url(/static/white-dot.jpg);background-position: 0px `
if item.(Reply).ContentLines <= 5 {
tmpl += `-1`
}
tmpl += `0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;`
tmpl += string(item.(Reply).Css)
}
tmpl += `">
<span class="editable_block user_content">`
tmpl += string(item.(Reply).ContentHtml)
tmpl += `</span>
<br /><br />
<a href="/user/`
tmpl += strconv.Itoa(item.(Reply).CreatedBy)
tmpl += `" class="username">`
tmpl += item.(Reply).CreatedByName
tmpl += `</a>
`
if tmpl_topic_vars.CurrentUser.Is_Mod {
tmpl += `<a href="/reply/edit/submit/`
tmpl += strconv.Itoa(item.(Reply).ID)
tmpl += `"><button class="username edit_item">Edit</button></a>
<a href="/reply/delete/submit/`
tmpl += strconv.Itoa(item.(Reply).ID)
tmpl += `"><button class="username delete_item">Delete</button></a>`
}
tmpl += `
<a href="/report/submit/`
tmpl += strconv.Itoa(item.(Reply).ID)
tmpl += `?session=`
tmpl += tmpl_topic_vars.CurrentUser.Session
tmpl += `&type=reply"><button class="username report_item">Report</button></a>
`
if item.(Reply).Tag != "" {
tmpl += `<a class="username" style="float: right;">`
tmpl += item.(Reply).Tag
tmpl += `</a>`
} else {
if item.(Reply).URLName != "" {
tmpl += `<a href="`
tmpl += item.(Reply).URL
tmpl += `" class="username" style="color: #505050;float: right;" rel="nofollow">`
tmpl += item.(Reply).URLName
tmpl += `</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">`
tmpl += item.(Reply).URLPrefix
tmpl += `</a>`
}
}
tmpl += `
</div>`
}
}
tmpl += `
</div>
`
if !tmpl_topic_vars.CurrentUser.Is_Banned {
tmpl += `
<div class="rowblock">
<form action="/reply/create/" method="post">
<input name="tid" value='`
tmpl += strconv.Itoa(extra_data.ID)
tmpl += `' type="hidden" />
<div class="formrow">
<div class="formitem"><textarea name="reply-content" placeholder="Insert reply here"></textarea></div>
</div>
<div class="formrow">
<div class="formitem"><button name="reply-button" class="formbutton">Create Reply</button></div>
</div>
</form>
</div>
`
}
tmpl += `
`
tmpl += ` <!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`
return tmpl
}

View File

@ -1,262 +0,0 @@
package main
import "io"
import "strconv"
import "html/template"
/*func init() {
ctemplates["topic"] = template_topic
}*/
func template_topic2(tmpl_topic_vars Page, w io.Writer) {
var extra_data TopicUser = tmpl_topic_vars.Something.(TopicUser)
w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<title>`))
w.Write([]byte(tmpl_topic_vars.Title))
w.Write([]byte(`</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "`))
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write([]byte(`";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
`))
w.Write([]byte(`<div class="nav">
<ul>
<li class="menu_overview"><a href="/">Overview</a></li>
<li class="menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_topics"><a href="/">Topics</a></li>
<li class="menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_topic_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_account"><a href="/user/`))
w.Write([]byte(strconv.Itoa(tmpl_topic_vars.CurrentUser.ID)))
w.Write([]byte(`">Profile</a></li>
`))
if tmpl_topic_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_logout"><a href="/accounts/logout?session=`))
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write([]byte(`">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>`))
w.Write([]byte(`
`))
if len(tmpl_topic_vars.NoticeList) != 0 {
for _, item := range tmpl_topic_vars.NoticeList {
w.Write([]byte(`<div class="alert">`))
w.Write([]byte(item))
w.Write([]byte(`</div>`))
}
}
w.Write([]byte(`
<div class="rowblock">
<form action='/topic/edit/submit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' method="post">
<div class="rowitem"`))
if extra_data.Sticky {
w.Write([]byte(` style="background-color: #FFFFEA;"`))
}
w.Write([]byte(`>
<a class='topic_name hide_on_edit'>`))
w.Write([]byte(extra_data.Title))
w.Write([]byte(`</a>
<span class='username topic_status_e topic_status_`))
w.Write([]byte(extra_data.Status))
w.Write([]byte(` hide_on_edit' style="font-weight:normal;float: right;">`))
w.Write([]byte(extra_data.Status))
w.Write([]byte(`</span>
<span class="username" style="border-right: 0;font-weight: normal;float: right;">Status</span>
`))
if tmpl_topic_vars.CurrentUser.Is_Mod {
w.Write([]byte(`
<a href='/topic/edit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' class="username hide_on_edit open_edit" style="font-weight: normal;margin-left: 6px;">Edit</a>
<a href='/topic/delete/submit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' class="username" style="font-weight: normal;">Delete</a>
`))
if extra_data.Sticky {
w.Write([]byte(`<a href='/topic/unstick/submit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' class="username" style="font-weight: normal;">Unpin</a>`))
} else {
w.Write([]byte(`<a href='/topic/stick/submit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' class="username" style="font-weight: normal;">Pin</a>`))
}
w.Write([]byte(`
<input class='show_on_edit topic_name_input' name="topic_name" value='`))
w.Write([]byte(extra_data.Title))
w.Write([]byte(`' type="text" />
<select name="topic_status" class='show_on_edit topic_status_input' style='float: right;'>
<option>open</option>
<option>closed</option>
</select>
<button name="topic-button" class="formbutton show_on_edit submit_edit">Update</button>
`))
}
w.Write([]byte(`
<a href="/report/submit/`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`?session=`))
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write([]byte(`&type=topic" class="username report_item" style="font-weight: normal;">Report</a>
</div>
</form>
</div>
<div class="rowblock">
<div class="rowitem passive editable_parent" style="border-bottom: none;`))
if extra_data.Avatar != "" {
w.Write([]byte(`background-image: url(`))
w.Write([]byte(extra_data.Avatar))
w.Write([]byte(`), url(/static/white-dot.jpg);background-position: 0px `))
if extra_data.ContentLines <= 5 {
w.Write([]byte(`-1`))
}
w.Write([]byte(`0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;`))
w.Write([]byte(string(extra_data.Css)))
}
w.Write([]byte(`">
<span class="hide_on_edit topic_content user_content">`))
w.Write([]byte(string(extra_data.Content.(template.HTML))))
w.Write([]byte(`</span>
<textarea name="topic_content" class="show_on_edit topic_content_input">`))
w.Write([]byte(string(extra_data.Content.(template.HTML))))
w.Write([]byte(`</textarea>
<br /><br />
<a href="/user/`))
w.Write([]byte(strconv.Itoa(extra_data.CreatedBy)))
w.Write([]byte(`" class="username">`))
w.Write([]byte(extra_data.CreatedByName))
w.Write([]byte(`</a>
`))
if extra_data.Tag != "" {
w.Write([]byte(`<a class="username" style="float: right;">`))
w.Write([]byte(extra_data.Tag))
w.Write([]byte(`</a>`))
} else {
if extra_data.URLName != "" {
w.Write([]byte(`<a href="`))
w.Write([]byte(extra_data.URL))
w.Write([]byte(`" class="username" style="color: #505050;float: right;">`))
w.Write([]byte(extra_data.URLName))
w.Write([]byte(`</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">`))
w.Write([]byte(extra_data.URLPrefix))
w.Write([]byte(`</a>`))
}
}
w.Write([]byte(`
</div>
</div><br />
<div class="rowblock" style="overflow: hidden;">
`))
if len(tmpl_topic_vars.ItemList) != 0 {
for _, item := range tmpl_topic_vars.ItemList {
w.Write([]byte(`
<div class="rowitem passive deletable_block editable_parent" style="`))
if item.(Reply).Avatar != "" {
w.Write([]byte(`background-image: url(`))
w.Write([]byte(item.(Reply).Avatar))
w.Write([]byte(`), url(/static/white-dot.jpg);background-position: 0px `))
if item.(Reply).ContentLines <= 5 {
w.Write([]byte(`-1`))
}
w.Write([]byte(`0px;background-repeat: no-repeat, repeat-y;background-size: 128px;padding-left: 136px;`))
w.Write([]byte(string(item.(Reply).Css)))
}
w.Write([]byte(`">
<span class="editable_block user_content">`))
w.Write([]byte(string(item.(Reply).ContentHtml)))
w.Write([]byte(`</span>
<br /><br />
<a href="/user/`))
w.Write([]byte(strconv.Itoa(item.(Reply).CreatedBy)))
w.Write([]byte(`" class="username">`))
w.Write([]byte(item.(Reply).CreatedByName))
w.Write([]byte(`</a>
`))
if tmpl_topic_vars.CurrentUser.Is_Mod {
w.Write([]byte(`<a href="/reply/edit/submit/`))
w.Write([]byte(strconv.Itoa(item.(Reply).ID)))
w.Write([]byte(`"><button class="username edit_item">Edit</button></a>
<a href="/reply/delete/submit/`))
w.Write([]byte(strconv.Itoa(item.(Reply).ID)))
w.Write([]byte(`"><button class="username delete_item">Delete</button></a>`))
}
w.Write([]byte(`
<a href="/report/submit/`))
w.Write([]byte(strconv.Itoa(item.(Reply).ID)))
w.Write([]byte(`?session=`))
w.Write([]byte(tmpl_topic_vars.CurrentUser.Session))
w.Write([]byte(`&type=reply"><button class="username report_item">Report</button></a>
`))
if item.(Reply).Tag != "" {
w.Write([]byte(`<a class="username" style="float: right;">`))
w.Write([]byte(item.(Reply).Tag))
w.Write([]byte(`</a>`))
} else {
if item.(Reply).URLName != "" {
w.Write([]byte(`<a href="`))
w.Write([]byte(item.(Reply).URL))
w.Write([]byte(`" class="username" style="color: #505050;float: right;" rel="nofollow">`))
w.Write([]byte(item.(Reply).URLName))
w.Write([]byte(`</a>
<a class="username" style="color: #505050;float: right;border-right: 0;">`))
w.Write([]byte(item.(Reply).URLPrefix))
w.Write([]byte(`</a>`))
}
}
w.Write([]byte(`
</div>`))
}
}
w.Write([]byte(`
</div>
`))
if !tmpl_topic_vars.CurrentUser.Is_Banned {
w.Write([]byte(`
<div class="rowblock">
<form action="/reply/create/" method="post">
<input name="tid" value='`))
w.Write([]byte(strconv.Itoa(extra_data.ID)))
w.Write([]byte(`' type="hidden" />
<div class="formrow">
<div class="formitem"><textarea name="reply-content" placeholder="Insert reply here"></textarea></div>
</div>
<div class="formrow">
<div class="formitem"><button name="reply-button" class="formbutton">Create Reply</button></div>
</div>
</form>
</div>
`))
}
w.Write([]byte(`
`))
w.Write([]byte(` <!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`))
}

104
template_topics.go Normal file
View File

@ -0,0 +1,104 @@
package main
import "io"
import "strconv"
func init() {
ctemplates["topics"] = template_topics
}
func template_topics(tmpl_topics_vars Page, w io.Writer) {
w.Write([]byte(`<!doctype html>
<html lang="en">
<head>
<title>` + tmpl_topics_vars.Title + `</title>
<link href="/static/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/static/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
var session = "` + tmpl_topics_vars.CurrentUser.Session + `";
</script>
<script type="text/javascript" src="/static/global.js"></script>
</head>
<body>
<div class="container">
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
`))
if tmpl_topics_vars.CurrentUser.Loggedin {
w.Write([]byte(`
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/` + strconv.Itoa(tmpl_topics_vars.CurrentUser.ID) + `">Profile</a></li>
`))
if tmpl_topics_vars.CurrentUser.Is_Super_Mod {
w.Write([]byte(`<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>`))
}
w.Write([]byte(`
<li class="menu_left menu_logout"><a href="/accounts/logout?session=` + tmpl_topics_vars.CurrentUser.Session + `">Logout</a></li>
`))
} else {
w.Write([]byte(`
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
`))
}
w.Write([]byte(`
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>
`))
if len(tmpl_topics_vars.NoticeList) != 0 {
for _, item := range tmpl_topics_vars.NoticeList {
w.Write([]byte(`<div class="alert">` + item + `</div>`))
}
}
w.Write([]byte(`
<div class="rowblock">
<div class="rowitem"><a>Topic List</a></div>
</div>
<div class="rowblock">
`))
if len(tmpl_topics_vars.ItemList) != 0 {
for _, item := range tmpl_topics_vars.ItemList {
w.Write([]byte(`<div class="rowitem passive" style="`))
if item.(TopicUser).Avatar != "" {
w.Write([]byte(`background-image: url(` + item.(TopicUser).Avatar + `);background-position: left;background-repeat: no-repeat;background-size: 64px;padding-left: 72px;`))
}
if item.(TopicUser).Sticky {
w.Write([]byte(`background-color: #FFFFCC;`))
}
w.Write([]byte(`">
<a href="/topic/` + strconv.Itoa(item.(TopicUser).ID) + `">` + item.(TopicUser).Title + `</a> `))
if item.(TopicUser).Is_Closed {
w.Write([]byte(`<span class="username topic_status_e topic_status_closed" style="float: right;">closed</span>
`))
} else {
w.Write([]byte(`<span class="username topic_status_e topic_status_open" style="float: right;">open</span>`))
}
w.Write([]byte(`
<span class="username" style="border-right: 0;float: right;">Status</span>
</div>`))
}
}
w.Write([]byte(`
</div>
`))
if tmpl_topics_vars.Something.(string) != "" {
w.Write([]byte(`
<div class="rowblock">
<div class="rowitem passive">` + tmpl_topics_vars.Something.(string) + `</div>
</div>
`))
}
w.Write([]byte(`
<!--<link rel="stylesheet" href="https://use.fontawesome.com/8670aa03ca.css">-->
</div>
</body>
</html>`))
}

View File

@ -33,6 +33,9 @@ type CTemplateSet struct
stats map[string]int
pVarList string
pVarPosition int
previousNode parse.NodeType
currentNode parse.NodeType
nextNode parse.NodeType
//tempVars map[string]string
doImports bool
expectsInt interface{}
@ -97,10 +100,17 @@ func (c *CTemplateSet) compile_template(name string, dir string, expects string,
fmt.Println(subtree.Root)
}
for _, node := range subtree.Root.Nodes {
treeLength := len(subtree.Root.Nodes)
for index, node := range subtree.Root.Nodes {
if debug {
fmt.Println("Node: " + node.String())
}
c.previousNode = c.currentNode
c.currentNode = node.Type()
if treeLength != (index + 1) {
c.nextNode = subtree.Root.Nodes[index + 1].Type()
}
out += c.compile_switch(varholder, holdreflect, fname, node)
}
@ -125,6 +135,7 @@ w.Write([]byte(`," + ",-1)
for index, count := range c.stats {
fmt.Println(index + ": " + strconv.Itoa(count))
}
fmt.Println(" ")
if debug {
fmt.Println("Output!")
@ -163,6 +174,9 @@ func (c *CTemplateSet) compile_switch(varholder string, holdreflect reflect.Valu
expr += c.compile_varswitch(varholder, holdreflect, template_name, cmd)
}
c.previousNode = c.currentNode
c.currentNode = parse.NodeList
c.nextNode = -1
if node.ElseList == nil {
if debug {
fmt.Println("Branch 1")
@ -210,6 +224,10 @@ func (c *CTemplateSet) compile_switch(varholder string, holdreflect reflect.Valu
item = outVal.MapIndex(key)
}
out = "if len(" + out + ") != 0 {\nfor _, item := range " + out + " {\n" + c.compile_switch("item", item, template_name, node.List) + "}\n}"
case reflect.Slice:
item := outVal.Index(0)
out = "if len(" + out + ") != 0 {\nfor _, item := range " + out + " {\n" + c.compile_switch("item", item, template_name, node.List) + "}\n}"
case reflect.Invalid:
return ""
@ -227,6 +245,9 @@ func (c *CTemplateSet) compile_switch(varholder string, holdreflect reflect.Valu
}
return c.compile_subtemplate(varholder, holdreflect, node)
case *parse.TextNode:
c.previousNode = c.currentNode
c.currentNode = node.Type()
c.nextNode = 0
return "w.Write([]byte(`" + string(node.Text) + "`))\n"
default:
panic("Unknown Node in main switch")
@ -266,7 +287,7 @@ func (c *CTemplateSet) compile_subswitch(varholder string, holdreflect reflect.V
/*if cur.Kind() == reflect.String && cur.Type().Name() != "string" {
varbit = "string(" + varbit + "." + id + ")"*/
//if cur.Kind() == reflect.String && cur.Type().Name() != "string" {
if cur.Type().PkgPath() != "main" {
if cur.Type().PkgPath() != "main" && cur.Type().PkgPath() != "" {
c.importMap["html/template"] = "html/template"
varbit += "." + id + ".(" + strings.TrimPrefix(cur.Type().PkgPath(),"html/") + "." + cur.Type().Name() + ")"
} else {
@ -364,42 +385,9 @@ func (c *CTemplateSet) compile_varswitch(varholder string, holdreflect reflect.V
if debug {
fmt.Println("Pipe Node!")
fmt.Println(n)
}
/*for _, cmd := range n.Cmds {
if debug {
fmt.Println("Pipe Bit: ")
fmt.Println(cmd)
}
out += c.compile_if_varsub_n(n.String(), varholder, template_name, holdreflect)
}*/
if debug {
fmt.Println("Args: ")
fmt.Println(node.Args)
}
/*argcopy := node.Args[1:]
for _, arg := range argcopy {
if debug {
fmt.Println("Pipe Arg: ")
fmt.Println(arg)
fmt.Println(reflect.ValueOf(arg).Elem().Type().Name())
fmt.Println(reflect.ValueOf(arg).Kind())
}
switch arg.(type) {
case *parse.IdentifierNode:
out += c.compile_identswitch(varholder, holdreflect, template_name, node)
break
case *parse.PipeNode:
break
//out += c.compile_if_varsub_n(a.String(), varholder, template_name, holdreflect)
default:
panic("Unknown Pipe Arg type! Did Mario get stuck in the pipes again?")
}
//out += c.compile_varswitch(arg.String(), holdreflect, template_name, arg)
}*/
out += c.compile_identswitch(varholder, holdreflect, template_name, node)
if debug {
@ -663,10 +651,17 @@ func (c *CTemplateSet) compile_subtemplate(pvarholder string, pholdreflect refle
c.localVars[fname] = make(map[string]VarItemReflect)
c.localVars[fname]["."] = VarItemReflect{".",varholder,holdreflect}
for _, node := range subtree.Root.Nodes {
treeLength := len(subtree.Root.Nodes)
for index, node := range subtree.Root.Nodes {
if debug {
fmt.Println("Node: " + node.String())
}
c.previousNode = c.currentNode
c.currentNode = node.Type()
if treeLength != (index + 1) {
c.nextNode = subtree.Root.Nodes[index + 1].Type()
}
out += c.compile_switch(varholder, holdreflect, fname, node)
}
return out

View File

@ -1,17 +1,22 @@
<div class="nav">
<div class="move_left">
<div class="move_right">
<ul>
<li class="menu_overview"><a href="/">Overview</a></li>
<li class="menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_topics"><a href="/">Topics</a></li>
<li class="menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
<li class="menu_left menu_overview"><a href="/">Overview</a></li>
<li class="menu_left menu_forums"><a href="/forums/">Forums</a></li>
<li class="menu_left menu_topics"><a href="/">Topics</a></li>
<li class="menu_left menu_create_topic"><a href="/topics/create/">Create Topic</a></li>
{{ if .CurrentUser.Loggedin }}
<li class="menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_account"><a href="/user/{{.CurrentUser.ID}}">Profile</a></li>
{{ if .CurrentUser.Is_Super_Mod}}<li class="menu_account"><a href="/panel/forums/">Panel</a></li>{{end}}
<li class="menu_logout"><a href="/accounts/logout?session={{.CurrentUser.Session}}">Logout</a></li>
<li class="menu_left menu_account"><a href="/user/edit/critical/">Account</a></li>
<li class="menu_left menu_account"><a href="/user/{{.CurrentUser.ID}}">Profile</a></li>
{{ if .CurrentUser.Is_Super_Mod}}<li class="menu_left menu_account"><a href="/panel/forums/">Panel</a></li>{{end}}
<li class="menu_left menu_logout"><a href="/accounts/logout?session={{.CurrentUser.Session}}">Logout</a></li>
{{ else }}
<li class="menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_login"><a href="/accounts/login/">Login</a></li>
<li class="menu_left menu_register"><a href="/accounts/create/">Register</a></li>
<li class="menu_left menu_login"><a href="/accounts/login/">Login</a></li>
{{ end }}
</ul>
</div>
</div>
<div style="clear: both;"></div>
</div>

View File

@ -44,7 +44,7 @@
<a class="username" style="color: #505050;float: right;border-right: 0;">{{.URLPrefix}}</a>{{end}}
</div>{{end}}
</div>
{{if not .CurrentUser.Is_Banned}}
{{if not (.CurrentUser.Is_Banned) and (.CurrentUser.Loggedin)}}
<div class="rowblock">
<form action="/reply/create/" method="post">
<input name="tid" value='{{.Something.ID}}' type="hidden" />

View File

@ -47,6 +47,8 @@ func SetPassword(uid int, password string) (error) {
}
func SessionCheck(w http.ResponseWriter, r *http.Request) (user User, noticeList map[int]string, success bool) {
noticeList = make(map[int]string)
// Are there any session cookies..?
// Assign it to user.name to avoid having to create a temporary variable for the type conversion
cookie, err := r.Cookie("uid")
@ -83,7 +85,7 @@ func SessionCheck(w http.ResponseWriter, r *http.Request) (user User, noticeList
}
if user.Is_Banned {
noticeList[0] = "You have been banned. Your ability to post has been revoked."
noticeList[0] = "Your account has been suspended. Some of your permissions may have been revoked."
}
if user.Avatar != "" {