diff --git a/README.md b/README.md index 391a4dd5..58504fab 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ 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 template engine which compiles templates down into machine code. Over ten times faster than html/templates. Compatible with templates written for html/templates, you don't need to learn any new templating language. A plugin system. Under development. diff --git a/general_test.go b/general_test.go index b4fa2eb9..e138d4e5 100644 --- a/general_test.go +++ b/general_test.go @@ -2,6 +2,7 @@ package main //import "fmt" import "log" import "bytes" +import "math/rand" import "testing" import "net/http" import "net/http/httptest" @@ -216,17 +217,170 @@ func BenchmarkRoute(b *testing.B) { forums_handler.ServeHTTP(forums_w,forums_req) } }) +} + +func addEmptyRoutesToMux(routes []string, serveMux *http.ServeMux) { + for _, route := range routes { + serveMux.HandleFunc(route, func(_ http.ResponseWriter,_ *http.Request){}) + } +} + +func BenchmarkRouter(b *testing.B) { + w := httptest.NewRecorder() + req := httptest.NewRequest("get","/topics/",bytes.NewReader(nil)) + routes := make([]string, 0) + routes = append(routes,"/test/") serveMux := http.NewServeMux() - serveMux.HandleFunc("/topics/", route_topics) - b.Run("topics_guest_plus_router", func(b *testing.B) { + serveMux.HandleFunc("/test/", func(_ http.ResponseWriter,_ *http.Request){}) + b.Run("one-route", func(b *testing.B) { for i := 0; i < b.N; i++ { - topics_w.Body.Reset() - serveMux.ServeHTTP(topics_w,topics_req) + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + routes = append(routes,"/topic/") + routes = append(routes,"/forums/") + routes = append(routes,"/forum/") + routes = append(routes,"/panel/") + serveMux = http.NewServeMux() + addEmptyRoutesToMux(routes, serveMux) + b.Run("five-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/panel/plugins/") + routes = append(routes,"/panel/groups/") + routes = append(routes,"/panel/settings/") + routes = append(routes,"/panel/users/") + routes = append(routes,"/panel/forums/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("ten-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/panel/forums/create/submit/") + routes = append(routes,"/panel/forums/delete/") + routes = append(routes,"/users/ban/") + routes = append(routes,"/panel/users/edit/") + routes = append(routes,"/panel/forums/create/") + routes = append(routes,"/users/unban/") + routes = append(routes,"/pages/") + routes = append(routes,"/users/activate/") + routes = append(routes,"/panel/forums/edit/submit/") + routes = append(routes,"/panel/plugins/activate/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("twenty-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/panel/plugins/deactivate/") + routes = append(routes,"/panel/plugins/install/") + routes = append(routes,"/panel/plugins/uninstall/") + routes = append(routes,"/panel/templates/") + routes = append(routes,"/panel/templates/edit/") + routes = append(routes,"/panel/templates/create/") + routes = append(routes,"/panel/templates/delete/") + routes = append(routes,"/panel/templates/edit/submit/") + routes = append(routes,"/panel/themes/") + routes = append(routes,"/panel/themes/edit/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("thirty-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/panel/themes/create/") + routes = append(routes,"/panel/themes/delete/") + routes = append(routes,"/panel/themes/delete/submit/") + routes = append(routes,"/panel/templates/create/submit/") + routes = append(routes,"/panel/templates/delete/submit/") + routes = append(routes,"/panel/widgets/") + routes = append(routes,"/panel/widgets/edit/") + routes = append(routes,"/panel/widgets/activate/") + routes = append(routes,"/panel/widgets/deactivate/") + routes = append(routes,"/panel/magical/wombat/path") + addEmptyRoutesToMux(routes, serveMux) + b.Run("forty-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/report/") + routes = append(routes,"/report/submit/") + routes = append(routes,"/topic/create/submit/") + routes = append(routes,"/topics/create/") + routes = append(routes,"/overview/") + routes = append(routes,"/uploads/") + routes = append(routes,"/static/") + routes = append(routes,"/reply/edit/submit/") + routes = append(routes,"/reply/delete/submit/") + routes = append(routes,"/topic/edit/submit/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("fifty-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/topic/delete/submit/") + routes = append(routes,"/topic/stick/submit/") + routes = append(routes,"/topic/unstick/submit/") + routes = append(routes,"/accounts/login/") + routes = append(routes,"/accounts/create/") + routes = append(routes,"/accounts/logout/") + routes = append(routes,"/accounts/login/submit/") + routes = append(routes,"/accounts/create/submit/") + routes = append(routes,"/user/edit/critical/") + routes = append(routes,"/user/edit/critical/submit/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("sixty-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) + } + }) + + serveMux = http.NewServeMux() + routes = append(routes,"/user/edit/avatar/") + routes = append(routes,"/user/edit/avatar/submit/") + routes = append(routes,"/user/edit/username/") + routes = append(routes,"/user/edit/username/submit/") + routes = append(routes,"/profile/reply/create/") + routes = append(routes,"/profile/reply/edit/submit/") + routes = append(routes,"/profile/reply/delete/submit/") + routes = append(routes,"/arcane/tower/") + routes = append(routes,"/magical/kingdom/") + routes = append(routes,"/insert/name/here/") + addEmptyRoutesToMux(routes, serveMux) + b.Run("seventy-routes", func(b *testing.B) { + for i := 0; i < b.N; i++ { + req = httptest.NewRequest("get",routes[rand.Intn(len(routes))],bytes.NewReader(nil)) + serveMux.ServeHTTP(w,req) } }) } -/*func TestRoute(b *testing.T) { - +/*func TestRoute(t *testing.T) { }*/ \ No newline at end of file diff --git a/gosora.exe b/gosora.exe index 21ab5452..2fd6216a 100644 Binary files a/gosora.exe and b/gosora.exe differ diff --git a/images/bench_round2.PNG b/images/bench_round2.PNG new file mode 100644 index 00000000..69e3ecec Binary files /dev/null and b/images/bench_round2.PNG differ diff --git a/images/laptop-1440px.PNG b/images/laptop-1440px.PNG new file mode 100644 index 00000000..d282f228 Binary files /dev/null and b/images/laptop-1440px.PNG differ diff --git a/images/mobile-320px.PNG b/images/mobile-320px.PNG new file mode 100644 index 00000000..e930823e Binary files /dev/null and b/images/mobile-320px.PNG differ diff --git a/images/mobile-375px.PNG b/images/mobile-375px.PNG new file mode 100644 index 00000000..599a6a5f Binary files /dev/null and b/images/mobile-375px.PNG differ diff --git a/images/mobile-425px.PNG b/images/mobile-425px.PNG new file mode 100644 index 00000000..02bdbfbc Binary files /dev/null and b/images/mobile-425px.PNG differ diff --git a/images/tablet-1024px.PNG b/images/tablet-1024px.PNG new file mode 100644 index 00000000..2ce65433 Binary files /dev/null and b/images/tablet-1024px.PNG differ diff --git a/images/tablet-768px.PNG b/images/tablet-768px.PNG new file mode 100644 index 00000000..ca23a1b3 Binary files /dev/null and b/images/tablet-768px.PNG differ diff --git a/images/user-editor-admin-view.PNG b/images/user-editor-admin-view.PNG new file mode 100644 index 00000000..d7b452a4 Binary files /dev/null and b/images/user-editor-admin-view.PNG differ diff --git a/images/user-editor-mod-view.PNG b/images/user-editor-mod-view.PNG new file mode 100644 index 00000000..e780ebc1 Binary files /dev/null and b/images/user-editor-mod-view.PNG differ diff --git a/main.go b/main.go index e4d1e7c7..7f4985de 100644 --- a/main.go +++ b/main.go @@ -194,6 +194,7 @@ func main(){ http.HandleFunc("/users/activate/", route_activate) // Admin + http.HandleFunc("/panel/", route_panel) http.HandleFunc("/panel/forums/", route_panel_forums) http.HandleFunc("/panel/forums/create/", route_panel_forums_create_submit) http.HandleFunc("/panel/forums/delete/", route_panel_forums_delete) diff --git a/mod_routes.go b/mod_routes.go index 09a5bf21..0071c70f 100644 --- a/mod_routes.go +++ b/mod_routes.go @@ -532,12 +532,27 @@ func route_activate(w http.ResponseWriter, r *http.Request) { http.Redirect(w,r,"/users/" + strconv.Itoa(uid),http.StatusSeeOther) } +/* Control Panel*/ +func route_panel(w http.ResponseWriter, r *http.Request){ + user, noticeList, ok := SessionCheck(w,r) + if !ok { + return + } + if !user.Is_Super_Mod { + NoPermissions(w,r,user) + return + } + + pi := Page{"Control Panel Dashboard","panel",user,noticeList,tList,0} + templates.ExecuteTemplate(w,"panel-dashboard.html", pi) +} + func route_panel_forums(w http.ResponseWriter, r *http.Request){ user, noticeList, ok := SessionCheck(w,r) if !ok { return } - if !user.Perms.ManageForums { + if !user.Is_Super_Mod || !user.Perms.ManageForums { NoPermissions(w,r,user) return } @@ -558,7 +573,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.ManageForums { + if !user.Is_Super_Mod || !user.Perms.ManageForums { NoPermissions(w,r,user) return } @@ -595,7 +610,7 @@ func route_panel_forums_delete(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.ManageForums { + if !user.Is_Super_Mod || !user.Perms.ManageForums { NoPermissions(w,r,user) return } @@ -628,7 +643,7 @@ func route_panel_forums_delete_submit(w http.ResponseWriter, r *http.Request) { if !ok { return } - if !user.Perms.ManageForums { + if !user.Is_Super_Mod || !user.Perms.ManageForums { NoPermissions(w,r,user) return } @@ -666,7 +681,7 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { if !ok { return } - if !user.Perms.ManageForums { + if !user.Is_Super_Mod || !user.Perms.ManageForums { NoPermissions(w,r,user) return } @@ -710,7 +725,7 @@ func route_panel_settings(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.EditSettings { + if !user.Is_Super_Mod || !user.Perms.EditSettings { NoPermissions(w,r,user) return } @@ -766,7 +781,7 @@ func route_panel_setting(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.EditSettings { + if !user.Is_Super_Mod || !user.Perms.EditSettings { NoPermissions(w,r,user) return } @@ -816,7 +831,7 @@ func route_panel_setting_edit(w http.ResponseWriter, r *http.Request) { if !ok { return } - if !user.Perms.EditSettings { + if !user.Is_Super_Mod || !user.Perms.EditSettings { NoPermissions(w,r,user) return } @@ -872,7 +887,7 @@ func route_panel_plugins(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.ManagePlugins { + if !user.Is_Super_Mod || !user.Perms.ManagePlugins { NoPermissions(w,r,user) return } @@ -891,7 +906,7 @@ func route_panel_plugins_activate(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.ManagePlugins { + if !user.Is_Super_Mod || !user.Perms.ManagePlugins { NoPermissions(w,r,user) return } @@ -954,7 +969,7 @@ func route_panel_plugins_deactivate(w http.ResponseWriter, r *http.Request){ if !ok { return } - if !user.Perms.ManagePlugins { + if !user.Is_Super_Mod || !user.Perms.ManagePlugins { NoPermissions(w,r,user) return } @@ -1208,4 +1223,4 @@ func route_panel_users_edit_submit(w http.ResponseWriter, r *http.Request){ } http.Redirect(w,r,"/panel/users/edit/" + strconv.Itoa(targetUser.ID),http.StatusSeeOther) -} \ No newline at end of file +} diff --git a/public/main.css b/public/main.css index 0dff9f92..6fbfc80f 100644 --- a/public/main.css +++ b/public/main.css @@ -28,18 +28,8 @@ body } } -/*.move_left -{ - float: left; - position: relative; - left: 50%; -} -.move_right -{ - float: left; - position: relative; - left: -50%; -}*/ +/*.move_left{float: left;position: relative;left: 50%;} +.move_right{float: left;position: relative;left: -50%;}*/ ul { padding-left: 0px; @@ -340,4 +330,82 @@ button.username border: 1px solid #FF004B; margin-bottom: 8px; background-color: #FEB7CC; +} + +@media (max-width: 880px) { + li + { + height: 25px; + font-size: 15px; + padding-left: 7px; + } + ul { height: 26px; margin-top: 8px; } + .menu_left { padding-right: 7px; } + .menu_right { padding-right: 7px; } + body { padding-left: 4px; padding-right: 4px; margin: 0px !important; width: 100% !important; height: 100% !important; overflow-x: hidden; } + .container { width: auto; } +} + +@media (max-width: 810px) { + li + { + font-weight: normal; + text-transform: none; + } + .rowitem + { + text-transform: none; + } +} + +@media (max-width: 620px) { + li + { + padding-left: 5px; + padding-top: 2px; + padding-bottom: 2px; + height: 23px; + } + ul { height: 24px; } + .menu_left { padding-right: 5px; } + .menu_right { padding-right: 5px; } + .menu_create_topic { display: none;} + .hide_on_mobile { display: none; } +} + +@media (max-width: 470px) { + .menu_overview { display: none; } + .menu_profile { display: none; } + .hide_on_micro { display: none; } + .post_container { + overflow: visible !important; + } + .post_item { + background-position: 0px 2px !important; + background-size: 64px 64px !important; + padding-left: 2px !important; + min-height: 96px; + position: relative !important; + } + .post_item > .user_content { + margin-left: 75px !important; + width: 100% !important; + } + .post_item > .mod_button { + float: right !important; + margin-left: 2px !important; + position: relative; + top: -14px; + } + .post_item > .real_username { + position: absolute; + top: 70px; + float: left; + margin-top: 0px; + padding-top: 3px !important; + margin-right: 2px; + width: 60px; + font-size: 15px; + } + .container { width: 100% !important; } } \ No newline at end of file diff --git a/template_forum.go b/template_forum.go index 88775921..b698e62f 100644 --- a/template_forum.go +++ b/template_forum.go @@ -17,6 +17,7 @@ w.Write([]byte(` var session = "` + tmpl_forum_vars.CurrentUser.Session + `"; +
` + string(tmpl_topic_vars.Topic.Content.(template.HTML)) + `