From 3a68e07885e9566530fb7bd013608f09c85ca968 Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 12 Mar 2017 07:18:12 +0000 Subject: [PATCH] You can now link to a topic with #tid-{topicid} Shrunk the posts in Tempra Simple. Fixed a problem with the buttons for Tempra Simple on mobile. Tweaked the padding on the quotes. Fixed a browser parser bug where the browsers erroneously terminate a

upon finding a produced by plugin_bbcode. Fixed a problem with plugin_bbcode where the HTML tags weren't getting closed. --- pages.go | 115 +++++++++++++++++--------- plugin_bbcode.go | 30 +++---- routes.go | 4 - template_profile.go | 2 +- themes/cosmo-conflux/public/main.css | 2 +- themes/cosmo/public/main.css | 2 +- themes/tempra-conflux/public/main.css | 4 +- themes/tempra-cursive/public/main.css | 12 +-- themes/tempra-simple/public/main.css | 21 +++-- 9 files changed, 112 insertions(+), 80 deletions(-) diff --git a/pages.go b/pages.go index e6c584dc..6c9ec07c 100644 --- a/pages.go +++ b/pages.go @@ -2,6 +2,7 @@ package main //import "fmt" import "bytes" import "strings" +import "strconv" import "regexp" type Page struct @@ -100,6 +101,7 @@ type AreYouSure struct var space_gap []byte = []byte(" ") var http_prot_b []byte = []byte("http://") var invalid_url []byte = []byte("[Invalid URL]") +var invalid_topic []byte = []byte("[Invalid Topic]") var url_open []byte = []byte("") var url_close []byte = []byte("") @@ -177,42 +179,64 @@ func parse_message(msg string) string { for ; len(msgbytes) > (i + 1); i++ { if i==0 || msgbytes[i] == 10 || (msgbytes[i] == ' ' && msgbytes[i + 1] != ' ') { i++ - if msgbytes[i] != 'h' && msgbytes[i] != 'f' && msgbytes[i] != 'g' && msgbytes[i + 1] != 't' { - continue - } - if msgbytes[i + 2] == 't' && msgbytes[i + 3] == 'p' { - if msgbytes[i + 4] == 's' && msgbytes[i + 5] == ':' && msgbytes[i + 6] == '/' && msgbytes[i + 7] == '/' { + if msgbytes[i]=='#' { + if bytes.Equal(msgbytes[i+1:i+5],[]byte("tid-")) { + outbytes = append(outbytes,msgbytes[lastItem:i]...) + i += 5 + start := i + tid, int_len := coerce_int_bytes(msgbytes[start:]) + i += int_len + + _, err := topics.CascadeGet(tid) + if err != nil { + outbytes = append(outbytes,invalid_topic...) + lastItem = i + continue + } + + outbytes = append(outbytes, url_open...) + var url_bit []byte = []byte(build_topic_url(tid)) + outbytes = append(outbytes, url_bit...) + outbytes = append(outbytes, url_open2...) + var tid_bit []byte = []byte("#tid-" + strconv.Itoa(tid)) + outbytes = append(outbytes, tid_bit...) + outbytes = append(outbytes, url_close...) + lastItem = i + } else { + // TO-DO: Forum Link + } + } else if msgbytes[i]=='h' || msgbytes[i]=='f' || msgbytes[i]=='g' { + if msgbytes[i + 1]=='t' && msgbytes[i + 2]=='t' && msgbytes[i + 3]=='p' { + if msgbytes[i + 4] == 's' && msgbytes[i + 5] == ':' && msgbytes[i + 6] == '/' && msgbytes[i + 7] == '/' { + // Do nothing + } else if msgbytes[i + 4] == ':' && msgbytes[i + 5] == '/' && msgbytes[i + 6] == '/' { + // Do nothing + } else { + continue + } + } else if msgbytes[i + 1] == 't' && msgbytes[i + 2] == 'p' && msgbytes[i + 3] == ':' && msgbytes[i + 4] == '/' && msgbytes[i + 5] == '/' { // Do nothing - } else if msgbytes[i + 4] == ':' && msgbytes[i + 5] == '/' && msgbytes[i + 6] == '/' { + } else if msgbytes[i + 1] == 'i' && msgbytes[i + 2] == 't' && msgbytes[i + 3] == ':' && msgbytes[i + 4] == '/' && msgbytes[i + 5] == '/' { // Do nothing } else { continue } - } else if msgbytes[i + 2] == 'p' && msgbytes[i + 3] == ':' && msgbytes[i + 4] == '/' && msgbytes[i + 5] == '/' { - // Do nothing - } else if msgbytes[i + 1] == 'i' && msgbytes[i + 2] == 't' && msgbytes[i + 3] == ':' && msgbytes[i + 4] == '/' && msgbytes[i + 5] == '/' { - // Do nothing - } else { - continue - } - - outbytes = append(outbytes,msgbytes[lastItem:i]...) - url_len := partial_url_bytes_len(msgbytes[i:]) - if msgbytes[i + url_len] != ' ' && msgbytes[i + url_len] != 10 { - outbytes = append(outbytes,invalid_url...) + + outbytes = append(outbytes,msgbytes[lastItem:i]...) + url_len := partial_url_bytes_len(msgbytes[i:]) + if msgbytes[i + url_len] != ' ' && msgbytes[i + url_len] != 10 { + outbytes = append(outbytes,invalid_url...) + i += url_len + continue + } + outbytes = append(outbytes, url_open...) + outbytes = append(outbytes, msgbytes[i:i + url_len]...) + outbytes = append(outbytes, url_open2...) + outbytes = append(outbytes, msgbytes[i:i + url_len]...) + outbytes = append(outbytes, url_close...) i += url_len - continue + lastItem = i } - //fmt.Println("Parsed URL:") - //fmt.Println("`"+string(msgbytes[i:i + url_len])+"`") - //fmt.Println("-----") - outbytes = append(outbytes, url_open...) - outbytes = append(outbytes, msgbytes[i:i + url_len]...) - outbytes = append(outbytes, url_open2...) - outbytes = append(outbytes, msgbytes[i:i + url_len]...) - outbytes = append(outbytes, url_close...) - i += url_len - lastItem = i } } @@ -335,28 +359,18 @@ func partial_url_bytes_len(data []byte) int { i := 0 if datalen >= 6 { - //fmt.Println(data[0:5]) //fmt.Println(string(data[0:5])) if bytes.Equal(data[0:6],[]byte("ftp://")) || bytes.Equal(data[0:6],[]byte("git://")) { i = 6 } else if datalen >= 7 && bytes.Equal(data[0:7],http_prot_b) { i = 7 - //fmt.Println("http") } else if datalen >= 8 && bytes.Equal(data[0:8],[]byte("https://")) { i = 8 - } else { - //fmt.Println("no protocol") } } for ;datalen > i; i++ { if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) { - //fmt.Println("Trimmed Length") - //fmt.Println(i) - //fmt.Println("Full Length") - //fmt.Println(i) - //fmt.Println("Data Length:") - //fmt.Println(datalen) //fmt.Println("Bad Character:") //fmt.Println(data[i]) return i @@ -396,3 +410,26 @@ func parse_media_bytes(data []byte) (protocol []byte, url []byte) { } return protocol, data[i:] } + +func coerce_int_bytes(data []byte) (res int, length int) { + if !(data[0] > 47 && data[0] < 58) { + return 0, 1 + } + + i := 1 + for ;len(data) > i; i++ { + if !(data[i] > 47 && data[i] < 58) { + conv, err := strconv.Atoi(string(data[0:i])) + if err != nil { + return 0, i + } + return conv, i + } + } + + conv, err := strconv.Atoi(string(data)) + if err != nil { + return 0, i + } + return conv, i +} diff --git a/plugin_bbcode.go b/plugin_bbcode.go index 3a7d8281..9dfe0f8b 100644 --- a/plugin_bbcode.go +++ b/plugin_bbcode.go @@ -56,7 +56,7 @@ func bbcode_regex_parse(data interface{}) interface{} { msg = bbcode_strikethrough.ReplaceAllString(msg,"$1") msg = bbcode_url.ReplaceAllString(msg,"$1$2//$3") msg = bbcode_url_label.ReplaceAllString(msg,"$4") - msg = bbcode_quotes.ReplaceAllString(msg,"
$1
") + msg = bbcode_quotes.ReplaceAllString(msg,"$1") return msg } @@ -70,19 +70,19 @@ func bbcode_simple_parse(data interface{}) interface{} { has_s := false for i := 0; (i + 2) < len(msgbytes); i++ { if msgbytes[i] == '[' && msgbytes[i + 2] == ']' { - if msgbytes[i + 1] == 'b' { + if msgbytes[i + 1] == 'b' && !has_b { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_b = true - } else if msgbytes[i + 1] == 'i' { + } else if msgbytes[i + 1] == 'i' && !has_i { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_i = true - } else if msgbytes[i + 1] == 'u' { + } else if msgbytes[i + 1] == 'u' && !has_u { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_u = true - } else if msgbytes[i + 1] == 's' { + } else if msgbytes[i + 1] == 's' && !has_s { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_s = true @@ -138,19 +138,19 @@ func bbcode_parse_without_code(data interface{}) interface{} { complex_bbc = true } } else { - if msgbytes[i + 1] == 'b' { + if msgbytes[i + 1] == 'b' && !has_b { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_b = true - } else if msgbytes[i + 1] == 'i' { + } else if msgbytes[i + 1] == 'i' && !has_i { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_i = true - } else if msgbytes[i + 1] == 'u' { + } else if msgbytes[i + 1] == 'u' && !has_u { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_u = true - } else if msgbytes[i + 1] == 's' { + } else if msgbytes[i + 1] == 's' && !has_s { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_s = true @@ -170,7 +170,7 @@ func bbcode_parse_without_code(data interface{}) interface{} { if complex_bbc { msg = bbcode_url.ReplaceAllString(msg,"
$1$2//$3") msg = bbcode_url_label.ReplaceAllString(msg,"$4") - msg = bbcode_quotes.ReplaceAllString(msg,"
$1
") + msg = bbcode_quotes.ReplaceAllString(msg,"$1") } return string(msgbytes) } @@ -242,19 +242,19 @@ func bbcode_full_parse(data interface{}) interface{} { complex_bbc = true } } else if !has_c { - if msgbytes[i + 1] == 'b' { + if msgbytes[i + 1] == 'b' && !has_b { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_b = true - } else if msgbytes[i + 1] == 'i' { + } else if msgbytes[i + 1] == 'i' && !has_i { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_i = true - } else if msgbytes[i + 1] == 'u' { + } else if msgbytes[i + 1] == 'u' && !has_u { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_u = true - } else if msgbytes[i + 1] == 's' { + } else if msgbytes[i + 1] == 's' && !has_s { msgbytes[i] = '<' msgbytes[i + 2] = '>' has_s = true @@ -360,7 +360,7 @@ func bbcode_full_parse(data interface{}) interface{} { //msg = bbcode_url.ReplaceAllString(msg,"
$1$2//$3") msg = bbcode_url_label.ReplaceAllString(msg,"$4") - msg = bbcode_quotes.ReplaceAllString(msg,"
$1
") + msg = bbcode_quotes.ReplaceAllString(msg,"$1") // Convert [code] into class="codequotes" //fmt.Println("guuuaaaa") } else { diff --git a/routes.go b/routes.go index 1e778aeb..d8197f15 100644 --- a/routes.go +++ b/routes.go @@ -353,10 +353,6 @@ func route_topic_id(w http.ResponseWriter, r *http.Request){ } else if page == -1 { page = last_page offset = (items_per_page * page) - items_per_page - //fmt.Println(topic.PostCount) - //fmt.Println((topic.PostCount / items_per_page) + 1) - //fmt.Println(page) - //fmt.Println(offset) } else { page = 1 } diff --git a/template_profile.go b/template_profile.go index 71e1c103..1e4dc78d 100644 --- a/template_profile.go +++ b/template_profile.go @@ -1,7 +1,7 @@ /* This file was automatically generated by the software. Please don't edit it as your changes may be overwritten at any moment. */ package main -import "io" import "strconv" +import "io" func init() { template_profile_handle = template_profile diff --git a/themes/cosmo-conflux/public/main.css b/themes/cosmo-conflux/public/main.css index 570b6846..cac9d033 100644 --- a/themes/cosmo-conflux/public/main.css +++ b/themes/cosmo-conflux/public/main.css @@ -454,7 +454,7 @@ button .big { padding: 6px; }*/ padding: 5px; border: 1px solid rgb(200,200,200); display: inline-block; - margin-bottom: 5px; + margin-bottom: 8px; width: 100%; background: rgb(250,250,250); } diff --git a/themes/cosmo/public/main.css b/themes/cosmo/public/main.css index 24555ba9..0e76fc0b 100644 --- a/themes/cosmo/public/main.css +++ b/themes/cosmo/public/main.css @@ -444,7 +444,7 @@ button .big { padding: 6px; }*/ padding: 5px; border: 1px solid rgb(200,200,200); display: inline-block; - margin-bottom: 5px; + margin-bottom: 8px; width: 100%; background: rgb(250,250,250); } diff --git a/themes/tempra-conflux/public/main.css b/themes/tempra-conflux/public/main.css index 4e3faaa9..ff466590 100644 --- a/themes/tempra-conflux/public/main.css +++ b/themes/tempra-conflux/public/main.css @@ -357,11 +357,11 @@ button.username .postQuote { border: rgb(200,200,210); background: rgb(245,245,255); - padding: 3px; + padding: 5px; margin: 0px; display: inline-block; width: 100%; - margin-bottom: 5px; + margin-bottom: 8px; border-style: solid; border-width: 1px; } diff --git a/themes/tempra-cursive/public/main.css b/themes/tempra-cursive/public/main.css index c1724ed1..5be58045 100644 --- a/themes/tempra-cursive/public/main.css +++ b/themes/tempra-cursive/public/main.css @@ -353,12 +353,12 @@ button.username .postQuote { border: 1px solid #ccc; - background: white; - padding: 3px; - margin: 0px; - display: inline-block; - width: 100%; - margin-bottom: 5px; + background: white; + padding: 5px; + margin: 0px; + display: inline-block; + width: 100%; + margin-bottom: 8px; } .level { diff --git a/themes/tempra-simple/public/main.css b/themes/tempra-simple/public/main.css index 826446b3..f5980b73 100644 --- a/themes/tempra-simple/public/main.css +++ b/themes/tempra-simple/public/main.css @@ -318,7 +318,7 @@ button.username .username.real_username:hover { color: black; } .post_item > .username { - margin-top: 44.2px; + margin-top: 20px; display: inline-block; } @@ -349,12 +349,12 @@ button.username .postQuote { border: 1px solid #ccc; - background: white; - padding: 3px; - margin: 0px; - display: inline-block; - width: 100%; - margin-bottom: 5px; + background: white; + padding: 5px; + margin: 0px; + display: inline-block; + width: 100%; + margin-bottom: 8px; } .level { @@ -443,14 +443,14 @@ button.username .menu_right { padding-right: 5px; } .menu_create_topic { display: none;} .menu_alerts { padding-left: 4px; padding-right: 4px; } - .hide_on_mobile { display: none; } + .hide_on_mobile { display: none !important; } .prev_button, .next_button { top: auto; bottom: 5px; } } @media (max-width: 470px) { .menu_overview { display: none; } .menu_profile { display: none; } - .hide_on_micro { display: none; } + .hide_on_micro { display: none !important; } .post_container { overflow: visible !important; } @@ -464,12 +464,11 @@ button.username .post_item > .user_content { margin-left: 75px !important; width: 100% !important; + min-height: 45px; } .post_item > .mod_button { float: right !important; margin-left: 2px !important; - position: relative; - top: -14px; } .post_item > .mod_button > button { opacity: 1; } .post_item > .real_username {