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 </p> upon finding a </div> produced by plugin_bbcode.
Fixed a problem with plugin_bbcode where the HTML tags weren't getting closed.
This commit is contained in:
Azareal 2017-03-12 07:18:12 +00:00
parent 5a0f4d3a07
commit 3a68e07885
9 changed files with 112 additions and 80 deletions

115
pages.go
View File

@ -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("<span style='color: red;'>[Invalid URL]</span>")
var invalid_topic []byte = []byte("<span style='color: red;'>[Invalid Topic]</span>")
var url_open []byte = []byte("<a href='")
var url_open2 []byte = []byte("'>")
var url_close []byte = []byte("</a>")
@ -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
}

View File

@ -56,7 +56,7 @@ func bbcode_regex_parse(data interface{}) interface{} {
msg = bbcode_strikethrough.ReplaceAllString(msg,"<s>$1</s>")
msg = bbcode_url.ReplaceAllString(msg,"<a href=\"$1$2//$3\" rel=\"nofollow\">$1$2//$3</i>")
msg = bbcode_url_label.ReplaceAllString(msg,"<a href=\"$1$2//$3\" rel=\"nofollow\">$4</i>")
msg = bbcode_quotes.ReplaceAllString(msg,"<div class=\"postQuote\">$1</div>")
msg = bbcode_quotes.ReplaceAllString(msg,"<span class=\"postQuote\">$1</span>")
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,"<a href=\"$1$2//$3\" rel=\"nofollow\">$1$2//$3</i>")
msg = bbcode_url_label.ReplaceAllString(msg,"<a href=\"$1$2//$3\" rel=\"nofollow\">$4</i>")
msg = bbcode_quotes.ReplaceAllString(msg,"<div class=\"postQuote\">$1</div>")
msg = bbcode_quotes.ReplaceAllString(msg,"<span class=\"postQuote\">$1</span>")
}
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,"<a href=\"$1$2//$3\" rel=\"nofollow\">$1$2//$3</i>")
msg = bbcode_url_label.ReplaceAllString(msg,"<a href=\"$1$2//$3\" rel=\"nofollow\">$4</i>")
msg = bbcode_quotes.ReplaceAllString(msg,"<div class=\"postQuote\">$1</div>")
msg = bbcode_quotes.ReplaceAllString(msg,"<span class=\"postQuote\">$1</span>")
// Convert [code] into class="codequotes"
//fmt.Println("guuuaaaa")
} else {

View File

@ -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
}

View File

@ -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

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -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 {