2017-11-11 04:06:16 +00:00
package common
2017-06-16 10:41:30 +00:00
2017-09-22 02:21:17 +00:00
import (
//"fmt"
"bytes"
2017-12-30 05:47:46 +00:00
"html"
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
"net/url"
2017-09-22 02:21:17 +00:00
"regexp"
"strconv"
"strings"
)
2016-12-02 07:38:54 +00:00
2017-11-11 04:06:16 +00:00
var SpaceGap = [ ] byte ( " " )
2017-09-03 04:50:31 +00:00
var httpProtBytes = [ ] byte ( "http://" )
2017-11-11 04:06:16 +00:00
var InvalidURL = [ ] byte ( "<span style='color: red;'>[Invalid URL]</span>" )
var InvalidTopic = [ ] byte ( "<span style='color: red;'>[Invalid Topic]</span>" )
var InvalidProfile = [ ] byte ( "<span style='color: red;'>[Invalid Profile]</span>" )
var InvalidForum = [ ] byte ( "<span style='color: red;'>[Invalid Forum]</span>" )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
var unknownMedia = [ ] byte ( "<span style='color: red;'>[Unknown Media]</span>" )
2017-11-11 04:06:16 +00:00
var UrlOpen = [ ] byte ( "<a href='" )
var UrlOpen2 = [ ] byte ( "'>" )
2017-09-03 04:50:31 +00:00
var bytesSinglequote = [ ] byte ( "'" )
var bytesGreaterthan = [ ] byte ( ">" )
var urlMention = [ ] byte ( " class='mention'" )
2017-11-11 04:06:16 +00:00
var UrlClose = [ ] byte ( "</a>" )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
var imageOpen = [ ] byte ( "<a href=\"" )
var imageOpen2 = [ ] byte ( "\"><img src='" )
var imageClose = [ ] byte ( "' class='postImage' /></a>" )
2017-11-10 03:33:11 +00:00
var urlPattern = ` (?s)([ { 1}])((http|https|ftp|mailto)*)(: { ??)\/\/([\.a-zA-Z\/]+)([ { 1}]) `
2017-09-03 04:50:31 +00:00
var urlReg * regexp . Regexp
2017-01-05 14:41:14 +00:00
func init ( ) {
2017-11-10 03:33:11 +00:00
urlReg = regexp . MustCompile ( urlPattern )
2017-01-05 14:41:14 +00:00
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-09-03 04:50:31 +00:00
func shortcodeToUnicode ( msg string ) string {
2016-12-08 14:11:18 +00:00
//re := regexp.MustCompile(":(.):")
2017-09-03 04:50:31 +00:00
msg = strings . Replace ( msg , ":grinning:" , "😀" , - 1 )
msg = strings . Replace ( msg , ":grin:" , "😁" , - 1 )
msg = strings . Replace ( msg , ":joy:" , "😂" , - 1 )
msg = strings . Replace ( msg , ":rofl:" , "🤣" , - 1 )
msg = strings . Replace ( msg , ":smiley:" , "😃" , - 1 )
msg = strings . Replace ( msg , ":smile:" , "😄" , - 1 )
msg = strings . Replace ( msg , ":sweat_smile:" , "😅" , - 1 )
msg = strings . Replace ( msg , ":laughing:" , "😆" , - 1 )
msg = strings . Replace ( msg , ":satisfied:" , "😆" , - 1 )
msg = strings . Replace ( msg , ":wink:" , "😉" , - 1 )
msg = strings . Replace ( msg , ":blush:" , "😊" , - 1 )
msg = strings . Replace ( msg , ":yum:" , "😋" , - 1 )
msg = strings . Replace ( msg , ":sunglasses:" , "😎" , - 1 )
msg = strings . Replace ( msg , ":heart_eyes:" , "😍" , - 1 )
msg = strings . Replace ( msg , ":kissing_heart:" , "😘" , - 1 )
msg = strings . Replace ( msg , ":kissing:" , "😗" , - 1 )
msg = strings . Replace ( msg , ":kissing_smiling_eyes:" , "😙" , - 1 )
msg = strings . Replace ( msg , ":kissing_closed_eyes:" , "😚" , - 1 )
msg = strings . Replace ( msg , ":relaxed:" , "☺️" , - 1 )
msg = strings . Replace ( msg , ":slight_smile:" , "🙂" , - 1 )
msg = strings . Replace ( msg , ":hugging:" , "🤗" , - 1 )
msg = strings . Replace ( msg , ":thinking:" , "🤔" , - 1 )
msg = strings . Replace ( msg , ":neutral_face:" , "😐" , - 1 )
msg = strings . Replace ( msg , ":expressionless:" , "😑" , - 1 )
msg = strings . Replace ( msg , ":no_mouth:" , "😶" , - 1 )
msg = strings . Replace ( msg , ":rolling_eyes:" , "🙄" , - 1 )
msg = strings . Replace ( msg , ":smirk:" , "😏" , - 1 )
msg = strings . Replace ( msg , ":persevere:" , "😣" , - 1 )
msg = strings . Replace ( msg , ":disappointed_relieved:" , "😥" , - 1 )
msg = strings . Replace ( msg , ":open_mouth:" , "😮" , - 1 )
msg = strings . Replace ( msg , ":zipper_mouth:" , "🤐" , - 1 )
msg = strings . Replace ( msg , ":hushed:" , "😯" , - 1 )
msg = strings . Replace ( msg , ":sleepy:" , "😪" , - 1 )
msg = strings . Replace ( msg , ":tired_face:" , "😫" , - 1 )
msg = strings . Replace ( msg , ":sleeping:" , "😴" , - 1 )
msg = strings . Replace ( msg , ":relieved:" , "😌" , - 1 )
msg = strings . Replace ( msg , ":nerd:" , "🤓" , - 1 )
msg = strings . Replace ( msg , ":stuck_out_tongue:" , "😛" , - 1 )
msg = strings . Replace ( msg , ":worried:" , "😟" , - 1 )
msg = strings . Replace ( msg , ":drooling_face:" , "🤤" , - 1 )
msg = strings . Replace ( msg , ":disappointed:" , "😞" , - 1 )
msg = strings . Replace ( msg , ":astonished:" , "😲" , - 1 )
msg = strings . Replace ( msg , ":slight_frown:" , "🙁" , - 1 )
msg = strings . Replace ( msg , ":skull_crossbones:" , "☠️" , - 1 )
msg = strings . Replace ( msg , ":skull:" , "💀" , - 1 )
msg = strings . Replace ( msg , ":point_up:" , "☝️" , - 1 )
msg = strings . Replace ( msg , ":v:" , "✌️️" , - 1 )
msg = strings . Replace ( msg , ":writing_hand:" , "✍️" , - 1 )
msg = strings . Replace ( msg , ":heart:" , "❤️️" , - 1 )
msg = strings . Replace ( msg , ":heart_exclamation:" , "❣️" , - 1 )
msg = strings . Replace ( msg , ":hotsprings:" , "♨️" , - 1 )
msg = strings . Replace ( msg , ":airplane:" , "✈️️" , - 1 )
msg = strings . Replace ( msg , ":hourglass:" , "⌛" , - 1 )
msg = strings . Replace ( msg , ":watch:" , "⌚" , - 1 )
msg = strings . Replace ( msg , ":comet:" , "☄️" , - 1 )
msg = strings . Replace ( msg , ":snowflake:" , "❄️" , - 1 )
msg = strings . Replace ( msg , ":cloud:" , "☁️" , - 1 )
msg = strings . Replace ( msg , ":sunny:" , "☀️" , - 1 )
msg = strings . Replace ( msg , ":spades:" , "♠️" , - 1 )
msg = strings . Replace ( msg , ":hearts:" , "♥️️" , - 1 )
msg = strings . Replace ( msg , ":diamonds:" , "♦️" , - 1 )
msg = strings . Replace ( msg , ":clubs:" , "♣️" , - 1 )
msg = strings . Replace ( msg , ":phone:" , "☎️" , - 1 )
msg = strings . Replace ( msg , ":telephone:" , "☎️" , - 1 )
msg = strings . Replace ( msg , ":biohazard:" , "☣️" , - 1 )
msg = strings . Replace ( msg , ":radioactive:" , "☢️" , - 1 )
msg = strings . Replace ( msg , ":scissors:" , "✂️" , - 1 )
msg = strings . Replace ( msg , ":arrow_upper_right:" , "↗️" , - 1 )
msg = strings . Replace ( msg , ":arrow_right:" , "➡️" , - 1 )
msg = strings . Replace ( msg , ":arrow_lower_right:" , "↘️" , - 1 )
msg = strings . Replace ( msg , ":arrow_lower_left:" , "↙️" , - 1 )
msg = strings . Replace ( msg , ":arrow_upper_left:" , "↖️" , - 1 )
msg = strings . Replace ( msg , ":arrow_up_down:" , "↕️" , - 1 )
msg = strings . Replace ( msg , ":left_right_arrow:" , "↔️" , - 1 )
msg = strings . Replace ( msg , ":leftwards_arrow_with_hook:" , "↩️" , - 1 )
msg = strings . Replace ( msg , ":arrow_right_hook:" , "↪️" , - 1 )
msg = strings . Replace ( msg , ":arrow_forward:" , "▶️" , - 1 )
msg = strings . Replace ( msg , ":arrow_backward:" , "◀️" , - 1 )
msg = strings . Replace ( msg , ":female:" , "♀️" , - 1 )
msg = strings . Replace ( msg , ":male:" , "♂️" , - 1 )
msg = strings . Replace ( msg , ":ballot_box_with_check:" , "☑️" , - 1 )
msg = strings . Replace ( msg , ":heavy_check_mark:" , "✔️️" , - 1 )
msg = strings . Replace ( msg , ":heavy_multiplication_x:" , "✖️" , - 1 )
msg = strings . Replace ( msg , ":pisces:" , "♓" , - 1 )
msg = strings . Replace ( msg , ":aquarius:" , "♒" , - 1 )
msg = strings . Replace ( msg , ":capricorn:" , "♑" , - 1 )
msg = strings . Replace ( msg , ":sagittarius:" , "♐" , - 1 )
msg = strings . Replace ( msg , ":scorpius:" , "♏" , - 1 )
msg = strings . Replace ( msg , ":libra:" , "♎" , - 1 )
msg = strings . Replace ( msg , ":virgo:" , "♍" , - 1 )
msg = strings . Replace ( msg , ":leo:" , "♌" , - 1 )
msg = strings . Replace ( msg , ":cancer:" , "♋" , - 1 )
msg = strings . Replace ( msg , ":gemini:" , "♊" , - 1 )
msg = strings . Replace ( msg , ":taurus:" , "♉" , - 1 )
msg = strings . Replace ( msg , ":aries:" , "♈" , - 1 )
msg = strings . Replace ( msg , ":peace:" , "☮️" , - 1 )
msg = strings . Replace ( msg , ":eight_spoked_asterisk:" , "✳️" , - 1 )
msg = strings . Replace ( msg , ":eight_pointed_black_star:" , "✴️" , - 1 )
msg = strings . Replace ( msg , ":snowman2:" , "☃️" , - 1 )
msg = strings . Replace ( msg , ":umbrella2:" , "☂️" , - 1 )
msg = strings . Replace ( msg , ":pencil2:" , "✏️" , - 1 )
msg = strings . Replace ( msg , ":black_nib:" , "✒️" , - 1 )
msg = strings . Replace ( msg , ":email:" , "✉️" , - 1 )
msg = strings . Replace ( msg , ":envelope:" , "✉️" , - 1 )
msg = strings . Replace ( msg , ":keyboard:" , "⌨️" , - 1 )
msg = strings . Replace ( msg , ":white_small_square:" , "▫️" , - 1 )
msg = strings . Replace ( msg , ":black_small_square:" , "▪️" , - 1 )
msg = strings . Replace ( msg , ":secret:" , "㊙️" , - 1 )
msg = strings . Replace ( msg , ":congratulations:" , "㊗️" , - 1 )
msg = strings . Replace ( msg , ":m:" , "Ⓜ️" , - 1 )
msg = strings . Replace ( msg , ":tm:" , "™️️" , - 1 )
msg = strings . Replace ( msg , ":registered:" , "®️" , - 1 )
msg = strings . Replace ( msg , ":copyright:" , "©️" , - 1 )
msg = strings . Replace ( msg , ":wavy_dash:" , "〰️" , - 1 )
msg = strings . Replace ( msg , ":bangbang:" , "‼️" , - 1 )
msg = strings . Replace ( msg , ":sparkle:" , "❇️" , - 1 )
msg = strings . Replace ( msg , ":star_of_david:" , "✡️" , - 1 )
msg = strings . Replace ( msg , ":wheel_of_dharma:" , "☸️" , - 1 )
msg = strings . Replace ( msg , ":yin_yang:" , "☯️" , - 1 )
msg = strings . Replace ( msg , ":cross:" , "✝️" , - 1 )
msg = strings . Replace ( msg , ":orthodox_cross:" , "☦️" , - 1 )
msg = strings . Replace ( msg , ":star_and_crescent:" , "☪️" , - 1 )
msg = strings . Replace ( msg , ":frowning2:" , "☹️" , - 1 )
msg = strings . Replace ( msg , ":information_source:" , "ℹ ️ " , - 1 )
msg = strings . Replace ( msg , ":interrobang:" , "⁉️" , - 1 )
2017-06-05 11:57:27 +00:00
2016-12-13 02:14:14 +00:00
return msg
2016-12-08 14:11:18 +00:00
}
2017-12-30 10:07:57 +00:00
// TODO: Write tests for this
2017-12-31 07:01:44 +00:00
// TODO: Preparse Markdown and normalize it into HTML?
2017-11-11 04:06:16 +00:00
func PreparseMessage ( msg string ) string {
2017-12-26 07:17:26 +00:00
msg = strings . Replace ( msg , "<p><br>" , "\n\n" , - 1 )
msg = strings . Replace ( msg , "<p>" , "\n\n" , - 1 )
2017-12-19 05:48:01 +00:00
msg = strings . Replace ( msg , "</p>" , "" , - 1 )
2017-12-26 07:17:26 +00:00
msg = strings . Replace ( msg , "<br>" , "\n\n" , - 1 )
2017-12-31 07:01:44 +00:00
msg = strings . TrimSpace ( msg ) // There are a few useful cases for having spaces, but I'd like to stop the WYSIWYG from inserting random lines here and there
2018-02-19 04:26:01 +00:00
msg = RunSshook ( "preparse_preassign" , msg )
2017-12-30 05:47:46 +00:00
msg = html . EscapeString ( msg )
2018-01-20 06:50:29 +00:00
msg = strings . Replace ( msg , " " , "" , - 1 )
2017-12-31 07:01:44 +00:00
var runes = [ ] rune ( msg )
2017-12-30 06:45:29 +00:00
msg = ""
2017-12-31 07:01:44 +00:00
var inBold = false
var inItalic = false
2018-01-03 07:46:18 +00:00
var inStrike = false
var inUnderline = false
2017-12-31 07:01:44 +00:00
var stepForward = func ( i int , step int , runes [ ] rune ) int {
i += step
if i < len ( runes ) {
return i
}
return i - step
}
2017-12-30 06:45:29 +00:00
for i := 0 ; i < len ( runes ) ; i ++ {
char := runes [ i ]
2017-12-31 07:01:44 +00:00
if char == '&' && peek ( i , 1 , runes ) == 'l' && peek ( i , 2 , runes ) == 't' && peek ( i , 3 , runes ) == ';' {
i = stepForward ( i , 4 , runes )
char := runes [ i ]
if char == '/' {
i = stepForward ( i , 1 , runes )
char := runes [ i ]
if inItalic && char == 'e' && peekMatch ( i , "m>" , runes ) {
i += 5
inItalic = false
msg += "</em>"
} else if inBold && char == 's' && peekMatch ( i , "trong>" , runes ) {
i += 9
inBold = false
msg += "</strong>"
2018-01-03 07:46:18 +00:00
} else if inStrike && char == 'd' && peekMatch ( i , "el>" , runes ) {
i += 6
inStrike = false
msg += "</del>"
} else if inUnderline && char == 'u' && peekMatch ( i , ">" , runes ) {
i += 4
inUnderline = false
msg += "</u>"
2017-12-31 07:01:44 +00:00
}
} else if ! inItalic && char == 'e' && peekMatch ( i , "m>" , runes ) {
i += 5
inItalic = true
msg += "<em>"
} else if ! inBold && char == 's' && peekMatch ( i , "trong>" , runes ) {
i += 9
inBold = true
msg += "<strong>"
2018-01-03 07:46:18 +00:00
} else if ! inStrike && char == 'd' && peekMatch ( i , "el>" , runes ) {
i += 6
inStrike = true
msg += "<del>"
} else if ! inUnderline && char == 'u' && peekMatch ( i , ">" , runes ) {
i += 4
inUnderline = true
msg += "<u>"
2017-12-31 07:01:44 +00:00
}
2017-12-30 06:45:29 +00:00
} else {
msg += string ( char )
}
2017-12-31 07:01:44 +00:00
}
if inItalic {
msg += "</em>"
}
if inBold {
msg += "</strong>"
}
2018-01-03 07:46:18 +00:00
if inStrike {
msg += "</del>"
}
if inUnderline {
msg += "</u>"
}
2017-12-31 07:01:44 +00:00
2017-09-03 04:50:31 +00:00
return shortcodeToUnicode ( msg )
2016-12-03 08:09:40 +00:00
}
2017-12-30 06:45:29 +00:00
// TODO: Test this
// TODO: Use this elsewhere in the parser?
func peek ( cur int , skip int , runes [ ] rune ) rune {
if ( cur + skip ) < len ( runes ) {
return runes [ cur + skip ]
}
return 0 // null byte
}
2017-12-31 07:01:44 +00:00
// TODO: Test this
func peekMatch ( cur int , phrase string , runes [ ] rune ) bool {
if cur + len ( phrase ) > len ( runes ) {
return false
}
for i , char := range phrase {
if runes [ cur + i + 1 ] != char {
return false
}
}
return true
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// TODO: We need a lot more hooks here. E.g. To add custom media types and handlers.
2017-11-11 04:06:16 +00:00
func ParseMessage ( msg string , sectionID int , sectionType string /*, user User*/ ) string {
2017-09-03 04:50:31 +00:00
msg = strings . Replace ( msg , ":)" , "😀" , - 1 )
msg = strings . Replace ( msg , ":(" , "😞" , - 1 )
msg = strings . Replace ( msg , ":D" , "😃" , - 1 )
msg = strings . Replace ( msg , ":P" , "😛" , - 1 )
msg = strings . Replace ( msg , ":O" , "😲" , - 1 )
msg = strings . Replace ( msg , ":p" , "😛" , - 1 )
msg = strings . Replace ( msg , ":o" , "😲" , - 1 )
2017-10-21 00:27:47 +00:00
msg = strings . Replace ( msg , ";)" , "😉" , - 1 )
2017-03-07 07:22:29 +00:00
//msg = url_reg.ReplaceAllString(msg,"<a href=\"$2$3//$4\" rel=\"nofollow\">$2$3//$4</a>")
2017-06-05 11:57:27 +00:00
2017-08-27 09:33:45 +00:00
// Word filter list. E.g. Swear words and other things the admins don't like
2017-11-11 04:06:16 +00:00
wordFilters := WordFilterBox . Load ( ) . ( WordFilterMap )
2017-08-27 09:33:45 +00:00
for _ , filter := range wordFilters {
2017-09-03 04:50:31 +00:00
msg = strings . Replace ( msg , filter . Find , filter . Replacement , - 1 )
2017-08-27 09:33:45 +00:00
}
2017-03-14 10:57:40 +00:00
// Search for URLs, mentions and hashlinks in the messages...
2017-08-13 11:22:34 +00:00
//log.Print("Parser Loop!")
2017-03-07 07:22:29 +00:00
var msgbytes = [ ] byte ( msg )
2017-03-14 10:57:40 +00:00
var outbytes [ ] byte
2017-11-11 04:06:16 +00:00
msgbytes = append ( msgbytes , SpaceGap ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
//log.Printf("string(msgbytes) %+v\n", `"`+string(msgbytes)+`"`)
var lastItem = 0
var i = 0
2017-03-07 07:22:29 +00:00
for ; len ( msgbytes ) > ( i + 1 ) ; i ++ {
2017-10-21 00:27:47 +00:00
//log.Print("Index: ",i)
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
//log.Print("Index Item: ",msgbytes[i])
//log.Print("string(msgbytes[i]): ",string(msgbytes[i]))
2017-08-13 11:22:34 +00:00
//log.Print("End Index")
2017-09-03 04:50:31 +00:00
if ( i == 0 && ( msgbytes [ 0 ] > 32 ) ) || ( ( msgbytes [ i ] < 33 ) && ( msgbytes [ i + 1 ] > 32 ) ) {
2017-10-21 00:27:47 +00:00
//log.Print("IN ",msgbytes[i])
2017-03-14 10:57:40 +00:00
if ( i != 0 ) || msgbytes [ i ] < 33 {
i ++
}
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
if msgbytes [ i ] == '#' {
2017-08-13 11:22:34 +00:00
//log.Print("IN #")
2017-09-03 04:50:31 +00:00
if bytes . Equal ( msgbytes [ i + 1 : i + 5 ] , [ ] byte ( "tid-" ) ) {
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-03-12 07:18:12 +00:00
i += 5
start := i
2017-11-11 04:06:16 +00:00
tid , intLen := CoerceIntBytes ( msgbytes [ start : ] )
2017-09-03 04:50:31 +00:00
i += intLen
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
topic , err := Topics . Get ( tid )
2017-11-23 05:37:08 +00:00
if err != nil || ! Forums . Exists ( topic . ParentID ) {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidTopic ... )
2017-03-12 07:18:12 +00:00
lastItem = i
continue
}
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
var urlBit = [ ] byte ( BuildTopicURL ( "" , tid ) )
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , urlBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen2 ... )
2017-09-03 04:50:31 +00:00
var tidBit = [ ] byte ( "#tid-" + strconv . Itoa ( tid ) )
outbytes = append ( outbytes , tidBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
2017-03-12 07:18:12 +00:00
lastItem = i
2017-06-05 11:57:27 +00:00
2017-10-21 00:27:47 +00:00
//log.Print("string(msgbytes): ",string(msgbytes))
//log.Print("msgbytes: ",msgbytes)
//log.Print("msgbytes[lastItem - 1]: ",msgbytes[lastItem - 1])
//log.Print("lastItem - 1: ",lastItem - 1)
//log.Print("msgbytes[lastItem]: ",msgbytes[lastItem])
//log.Print("lastItem: ",lastItem)
2017-09-03 04:50:31 +00:00
} else if bytes . Equal ( msgbytes [ i + 1 : i + 5 ] , [ ] byte ( "rid-" ) ) {
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-03-14 10:57:40 +00:00
i += 5
start := i
2017-11-11 04:06:16 +00:00
rid , intLen := CoerceIntBytes ( msgbytes [ start : ] )
2017-09-03 04:50:31 +00:00
i += intLen
2017-06-05 11:57:27 +00:00
2018-01-20 06:50:29 +00:00
topic , err := TopicByReplyID ( rid )
2017-11-23 05:37:08 +00:00
if err != nil || ! Forums . Exists ( topic . ParentID ) {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidTopic ... )
2017-03-14 10:57:40 +00:00
lastItem = i
continue
}
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
var urlBit = [ ] byte ( BuildTopicURL ( "" , topic . ID ) )
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , urlBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen2 ... )
2017-09-03 04:50:31 +00:00
var ridBit = [ ] byte ( "#rid-" + strconv . Itoa ( rid ) )
outbytes = append ( outbytes , ridBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
2017-03-14 10:57:40 +00:00
lastItem = i
2017-09-03 04:50:31 +00:00
} else if bytes . Equal ( msgbytes [ i + 1 : i + 5 ] , [ ] byte ( "fid-" ) ) {
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-03-15 08:34:14 +00:00
i += 5
start := i
2017-11-11 04:06:16 +00:00
fid , intLen := CoerceIntBytes ( msgbytes [ start : ] )
2017-09-03 04:50:31 +00:00
i += intLen
2017-06-05 11:57:27 +00:00
2017-11-23 05:37:08 +00:00
if ! Forums . Exists ( fid ) {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidForum ... )
2017-03-15 08:34:14 +00:00
lastItem = i
continue
}
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
var urlBit = [ ] byte ( BuildForumURL ( "" , fid ) )
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , urlBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen2 ... )
2017-09-03 04:50:31 +00:00
var fidBit = [ ] byte ( "#fid-" + strconv . Itoa ( fid ) )
outbytes = append ( outbytes , fidBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
2017-03-15 08:34:14 +00:00
lastItem = i
2017-03-12 07:18:12 +00:00
} else {
2017-09-10 16:57:22 +00:00
// TODO: Forum Shortcode Link
2017-03-12 07:18:12 +00:00
}
2017-09-03 04:50:31 +00:00
} else if msgbytes [ i ] == '@' {
2017-08-13 11:22:34 +00:00
//log.Print("IN @")
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-03-14 10:57:40 +00:00
i ++
start := i
2017-11-11 04:06:16 +00:00
uid , intLen := CoerceIntBytes ( msgbytes [ start : ] )
2017-09-03 04:50:31 +00:00
i += intLen
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
menUser , err := Users . Get ( uid )
2017-03-14 10:57:40 +00:00
if err != nil {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidProfile ... )
2017-03-14 10:57:40 +00:00
lastItem = i
continue
}
2017-06-05 11:57:27 +00:00
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
2017-09-03 04:50:31 +00:00
var urlBit = [ ] byte ( menUser . Link )
outbytes = append ( outbytes , urlBit ... )
outbytes = append ( outbytes , bytesSinglequote ... )
outbytes = append ( outbytes , urlMention ... )
outbytes = append ( outbytes , bytesGreaterthan ... )
var uidBit = [ ] byte ( "@" + menUser . Name )
outbytes = append ( outbytes , uidBit ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
2017-03-14 10:57:40 +00:00
lastItem = i
2017-09-03 04:50:31 +00:00
} else if msgbytes [ i ] == 'h' || msgbytes [ i ] == 'f' || msgbytes [ i ] == 'g' {
2017-08-13 11:22:34 +00:00
//log.Print("IN hfg")
2017-09-03 04:50:31 +00:00
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 ] == '/' {
2017-03-12 07:18:12 +00:00
// Do nothing
2017-09-03 04:50:31 +00:00
} else if msgbytes [ i + 4 ] == ':' && msgbytes [ i + 5 ] == '/' && msgbytes [ i + 6 ] == '/' {
2017-03-12 07:18:12 +00:00
// Do nothing
} else {
continue
}
2017-09-03 04:50:31 +00:00
} else if msgbytes [ i + 1 ] == 't' && msgbytes [ i + 2 ] == 'p' && msgbytes [ i + 3 ] == ':' && msgbytes [ i + 4 ] == '/' && msgbytes [ i + 5 ] == '/' {
2017-03-07 07:22:29 +00:00
// Do nothing
2017-09-03 04:50:31 +00:00
} else if msgbytes [ i + 1 ] == 'i' && msgbytes [ i + 2 ] == 't' && msgbytes [ i + 3 ] == ':' && msgbytes [ i + 4 ] == '/' && msgbytes [ i + 5 ] == '/' {
2017-03-07 07:22:29 +00:00
// Do nothing
} else {
continue
}
2017-06-05 11:57:27 +00:00
2017-10-12 03:24:14 +00:00
//log.Print("Normal URL")
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-11-11 04:06:16 +00:00
urlLen := PartialURLBytesLen ( msgbytes [ i : ] )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if msgbytes [ i + urlLen ] > 32 { // space and invisibles
2017-10-12 03:24:14 +00:00
//log.Print("INVALID URL")
2017-10-21 00:27:47 +00:00
//log.Print("msgbytes[i+urlLen]: ", msgbytes[i+urlLen])
//log.Print("string(msgbytes[i+urlLen]): ", string(msgbytes[i+urlLen]))
//log.Print("msgbytes[i:i+urlLen]: ", msgbytes[i:i+urlLen])
//log.Print("string(msgbytes[i:i+urlLen]): ", string(msgbytes[i:i+urlLen]))
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidURL ... )
2017-10-12 03:24:14 +00:00
i += urlLen
continue
}
media , ok := parseMediaBytes ( msgbytes [ i : i + urlLen ] )
if ! ok {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidURL ... )
2017-09-03 04:50:31 +00:00
i += urlLen
2017-03-12 07:18:12 +00:00
continue
}
2017-10-12 03:24:14 +00:00
if media . Type == "attach" {
outbytes = append ( outbytes , imageOpen ... )
outbytes = append ( outbytes , [ ] byte ( media . URL + "?sectionID=" + strconv . Itoa ( sectionID ) + "§ionType=" + sectionType ) ... )
outbytes = append ( outbytes , imageOpen2 ... )
outbytes = append ( outbytes , [ ] byte ( media . URL + "?sectionID=" + strconv . Itoa ( sectionID ) + "§ionType=" + sectionType ) ... )
outbytes = append ( outbytes , imageClose ... )
i += urlLen
lastItem = i
continue
} else if media . Type == "image" {
outbytes = append ( outbytes , imageOpen ... )
outbytes = append ( outbytes , [ ] byte ( media . URL ) ... )
outbytes = append ( outbytes , imageOpen2 ... )
outbytes = append ( outbytes , [ ] byte ( media . URL ) ... )
outbytes = append ( outbytes , imageClose ... )
i += urlLen
lastItem = i
continue
} else if media . Type == "raw" {
outbytes = append ( outbytes , [ ] byte ( media . Body ) ... )
i += urlLen
lastItem = i
continue
} else if media . Type != "" {
outbytes = append ( outbytes , unknownMedia ... )
i += urlLen
continue
}
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
outbytes = append ( outbytes , msgbytes [ i : i + urlLen ] ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen2 ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
outbytes = append ( outbytes , msgbytes [ i : i + urlLen ] ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
i += urlLen
lastItem = i
} else if msgbytes [ i ] == '/' && msgbytes [ i + 1 ] == '/' {
outbytes = append ( outbytes , msgbytes [ lastItem : i ] ... )
2017-11-11 04:06:16 +00:00
urlLen := PartialURLBytesLen ( msgbytes [ i : ] )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if msgbytes [ i + urlLen ] > 32 { // space and invisibles
//log.Print("INVALID URL")
2017-10-21 00:27:47 +00:00
//log.Print("msgbytes[i+urlLen]: ", msgbytes[i+urlLen])
//log.Print("string(msgbytes[i+urlLen]): ", string(msgbytes[i+urlLen]))
//log.Print("msgbytes[i:i+urlLen]: ", msgbytes[i:i+urlLen])
//log.Print("string(msgbytes[i:i+urlLen]): ", string(msgbytes[i:i+urlLen]))
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidURL ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
i += urlLen
continue
}
//log.Print("VALID URL")
2017-10-21 00:27:47 +00:00
//log.Print("msgbytes[i:i+urlLen]: ", msgbytes[i:i+urlLen])
//log.Print("string(msgbytes[i:i+urlLen]): ", string(msgbytes[i:i+urlLen]))
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
media , ok := parseMediaBytes ( msgbytes [ i : i + urlLen ] )
if ! ok {
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , InvalidURL ... )
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
i += urlLen
continue
}
2017-10-12 03:24:14 +00:00
if media . Type == "attach" {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
outbytes = append ( outbytes , imageOpen ... )
outbytes = append ( outbytes , [ ] byte ( media . URL + "?sectionID=" + strconv . Itoa ( sectionID ) + "§ionType=" + sectionType ) ... )
outbytes = append ( outbytes , imageOpen2 ... )
outbytes = append ( outbytes , [ ] byte ( media . URL + "?sectionID=" + strconv . Itoa ( sectionID ) + "§ionType=" + sectionType ) ... )
outbytes = append ( outbytes , imageClose ... )
i += urlLen
lastItem = i
continue
2017-10-12 03:24:14 +00:00
} else if media . Type == "image" {
outbytes = append ( outbytes , imageOpen ... )
outbytes = append ( outbytes , [ ] byte ( media . URL ) ... )
outbytes = append ( outbytes , imageOpen2 ... )
outbytes = append ( outbytes , [ ] byte ( media . URL ) ... )
outbytes = append ( outbytes , imageClose ... )
i += urlLen
lastItem = i
continue
} else if media . Type == "raw" {
outbytes = append ( outbytes , [ ] byte ( media . Body ) ... )
i += urlLen
lastItem = i
continue
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if media . Type != "" {
outbytes = append ( outbytes , unknownMedia ... )
i += urlLen
continue
}
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen ... )
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , msgbytes [ i : i + urlLen ] ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlOpen2 ... )
2017-09-03 04:50:31 +00:00
outbytes = append ( outbytes , msgbytes [ i : i + urlLen ] ... )
2017-11-11 04:06:16 +00:00
outbytes = append ( outbytes , UrlClose ... )
2017-09-03 04:50:31 +00:00
i += urlLen
2017-03-12 07:18:12 +00:00
lastItem = i
2017-03-07 07:22:29 +00:00
}
}
}
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
if lastItem != i && len ( outbytes ) != 0 {
2017-10-21 00:27:47 +00:00
//log.Print("lastItem: ", msgbytes[lastItem])
//log.Print("lastItem index: ", lastItem)
//log.Print("i: ", i)
//log.Print("lastItem to end: ", msgbytes[lastItem:])
2017-08-13 11:22:34 +00:00
//log.Print("-----")
2017-03-07 07:22:29 +00:00
calclen := len ( msgbytes ) - 10
if calclen <= lastItem {
calclen = lastItem
}
outbytes = append ( outbytes , msgbytes [ lastItem : calclen ] ... )
msg = string ( outbytes )
}
2017-08-13 11:22:34 +00:00
//log.Print(`"`+string(outbytes)+`"`)
//log.Print("msg",`"`+msg+`"`)
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
msg = strings . Replace ( msg , "\n" , "<br>" , - 1 )
2018-02-19 04:26:01 +00:00
msg = RunSshook ( "parse_assign" , msg )
2017-03-07 07:22:29 +00:00
return msg
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// 6, 7, 8, 6, 2, 7
// ftp://, http://, https:// git://, //, mailto: (not a URL, just here for length comparison purposes)
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-09-03 04:50:31 +00:00
func validateURLBytes ( data [ ] byte ) bool {
2017-03-07 07:22:29 +00:00
datalen := len ( data )
i := 0
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
if datalen >= 6 {
2017-09-03 04:50:31 +00:00
if bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "ftp://" ) ) || bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "git://" ) ) {
2017-03-07 07:22:29 +00:00
i = 6
2017-09-03 04:50:31 +00:00
} else if datalen >= 7 && bytes . Equal ( data [ 0 : 7 ] , httpProtBytes ) {
2017-03-07 07:22:29 +00:00
i = 7
2017-09-03 04:50:31 +00:00
} else if datalen >= 8 && bytes . Equal ( data [ 0 : 8 ] , [ ] byte ( "https://" ) ) {
2017-03-07 07:22:29 +00:00
i = 8
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if datalen >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
i = 2
2017-03-07 07:22:29 +00:00
}
2017-06-05 11:57:27 +00:00
2017-10-12 03:24:14 +00:00
// ? - There should only be one : and that's only if the URL is on a non-standard port. Same for ?s.
2017-09-03 04:50:31 +00:00
for ; datalen > i ; i ++ {
2017-10-12 03:24:14 +00:00
if data [ i ] != '\\' && data [ i ] != '_' && data [ i ] != ':' && data [ i ] != '?' && data [ i ] != '&' && data [ i ] != '=' && data [ i ] != ';' && data [ i ] != '@' && ! ( data [ i ] > 44 && data [ i ] < 58 ) && ! ( data [ i ] > 64 && data [ i ] < 91 ) && ! ( data [ i ] > 96 && data [ i ] < 123 ) {
2017-03-07 07:22:29 +00:00
return false
}
}
return true
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-09-03 04:50:31 +00:00
func validatedURLBytes ( data [ ] byte ) ( url [ ] byte ) {
2017-03-07 07:22:29 +00:00
datalen := len ( data )
i := 0
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
if datalen >= 6 {
2017-09-03 04:50:31 +00:00
if bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "ftp://" ) ) || bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "git://" ) ) {
2017-03-07 07:22:29 +00:00
i = 6
2017-09-03 04:50:31 +00:00
} else if datalen >= 7 && bytes . Equal ( data [ 0 : 7 ] , httpProtBytes ) {
2017-03-07 07:22:29 +00:00
i = 7
2017-09-03 04:50:31 +00:00
} else if datalen >= 8 && bytes . Equal ( data [ 0 : 8 ] , [ ] byte ( "https://" ) ) {
2017-03-07 07:22:29 +00:00
i = 8
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if datalen >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
i = 2
2017-03-07 07:22:29 +00:00
}
2017-06-05 11:57:27 +00:00
2017-10-12 03:24:14 +00:00
// ? - There should only be one : and that's only if the URL is on a non-standard port. Same for ?s.
2017-09-03 04:50:31 +00:00
for ; datalen > i ; i ++ {
2017-10-12 03:24:14 +00:00
if data [ i ] != '\\' && data [ i ] != '_' && data [ i ] != ':' && data [ i ] != '?' && data [ i ] != '&' && data [ i ] != '=' && data [ i ] != ';' && data [ i ] != '@' && ! ( data [ i ] > 44 && data [ i ] < 58 ) && ! ( data [ i ] > 64 && data [ i ] < 91 ) && ! ( data [ i ] > 96 && data [ i ] < 123 ) {
2017-11-11 04:06:16 +00:00
return InvalidURL
2017-03-07 07:22:29 +00:00
}
}
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
url = append ( url , data ... )
return url
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-11-11 04:06:16 +00:00
func PartialURLBytes ( data [ ] byte ) ( url [ ] byte ) {
2017-03-07 07:22:29 +00:00
datalen := len ( data )
i := 0
end := datalen - 1
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
if datalen >= 6 {
2017-09-03 04:50:31 +00:00
if bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "ftp://" ) ) || bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "git://" ) ) {
2017-03-07 07:22:29 +00:00
i = 6
2017-09-03 04:50:31 +00:00
} else if datalen >= 7 && bytes . Equal ( data [ 0 : 7 ] , httpProtBytes ) {
2017-03-07 07:22:29 +00:00
i = 7
2017-09-03 04:50:31 +00:00
} else if datalen >= 8 && bytes . Equal ( data [ 0 : 8 ] , [ ] byte ( "https://" ) ) {
2017-03-07 07:22:29 +00:00
i = 8
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if datalen >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
i = 2
2017-03-07 07:22:29 +00:00
}
2017-06-05 11:57:27 +00:00
2017-10-12 03:24:14 +00:00
// ? - There should only be one : and that's only if the URL is on a non-standard port. Same for ?s.
2017-09-03 04:50:31 +00:00
for ; end >= i ; i ++ {
2017-10-12 03:24:14 +00:00
if data [ i ] != '\\' && data [ i ] != '_' && data [ i ] != ':' && data [ i ] != '?' && data [ i ] != '&' && data [ i ] != '=' && data [ i ] != ';' && data [ i ] != '@' && ! ( data [ i ] > 44 && data [ i ] < 58 ) && ! ( data [ i ] > 64 && data [ i ] < 91 ) && ! ( data [ i ] > 96 && data [ i ] < 123 ) {
2017-03-07 07:22:29 +00:00
end = i
}
}
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
url = append ( url , data [ 0 : end ] ... )
return url
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-11-11 04:06:16 +00:00
func PartialURLBytesLen ( data [ ] byte ) int {
2017-03-07 07:22:29 +00:00
datalen := len ( data )
i := 0
2017-06-05 11:57:27 +00:00
2017-03-07 07:22:29 +00:00
if datalen >= 6 {
2017-08-13 11:22:34 +00:00
//log.Print(string(data[0:5]))
2017-09-03 04:50:31 +00:00
if bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "ftp://" ) ) || bytes . Equal ( data [ 0 : 6 ] , [ ] byte ( "git://" ) ) {
2017-03-07 07:22:29 +00:00
i = 6
2017-09-03 04:50:31 +00:00
} else if datalen >= 7 && bytes . Equal ( data [ 0 : 7 ] , httpProtBytes ) {
2017-03-07 07:22:29 +00:00
i = 7
2017-09-03 04:50:31 +00:00
} else if datalen >= 8 && bytes . Equal ( data [ 0 : 8 ] , [ ] byte ( "https://" ) ) {
2017-03-07 07:22:29 +00:00
i = 8
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
} else if datalen >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
i = 2
2017-03-07 07:22:29 +00:00
}
2017-06-05 11:57:27 +00:00
2017-10-12 03:24:14 +00:00
// ? - There should only be one : and that's only if the URL is on a non-standard port. Same for ?s.
2017-09-03 04:50:31 +00:00
for ; datalen > i ; i ++ {
2017-10-12 03:24:14 +00:00
if data [ i ] != '\\' && data [ i ] != '_' && data [ i ] != ':' && data [ i ] != '?' && data [ i ] != '&' && data [ i ] != '=' && data [ i ] != ';' && data [ i ] != '@' && ! ( data [ i ] > 44 && data [ i ] < 58 ) && ! ( data [ i ] > 64 && data [ i ] < 91 ) && ! ( data [ i ] > 96 && data [ i ] < 123 ) {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
//log.Print("Bad Character: ", data[i])
2017-03-07 07:22:29 +00:00
return i
}
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
//log.Print("Data Length: ",datalen)
2017-03-07 07:22:29 +00:00
return datalen
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
type MediaEmbed struct {
Type string //image
URL string
2017-10-12 03:24:14 +00:00
Body string
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
func parseMediaBytes ( data [ ] byte ) ( media MediaEmbed , ok bool ) {
if ! validateURLBytes ( data ) {
return media , false
}
url , err := parseURL ( data )
if err != nil {
return media , false
}
2017-06-05 11:57:27 +00:00
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
//log.Print("url ", url)
hostname := url . Hostname ( )
scheme := url . Scheme
port := url . Port ( )
//log.Print("hostname ", hostname)
//log.Print("scheme ", scheme)
2017-10-12 03:24:14 +00:00
query := url . Query ( )
//log.Printf("query %+v\n", query)
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
2017-11-11 04:06:16 +00:00
var samesite = hostname == "localhost" || hostname == Site . URL
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if samesite {
2017-11-11 04:06:16 +00:00
hostname = strings . Split ( Site . URL , ":" ) [ 0 ]
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// ?- Test this as I'm not sure it'll do what it should. If someone's running SSL on port 80 or non-SSL on port 443 then... Well... They're in far worse trouble than this...
2017-11-11 04:06:16 +00:00
port = Site . Port
if scheme == "" && Site . EnableSsl {
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
scheme = "https"
2017-03-07 07:22:29 +00:00
}
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
if scheme == "" {
scheme = "http"
}
2017-06-05 11:57:27 +00:00
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
path := url . EscapedPath ( )
//log.Print("path", path)
pathFrags := strings . Split ( path , "/" )
//log.Printf("pathFrags %+v\n", pathFrags)
//log.Print("scheme ", scheme)
//log.Print("hostname ", hostname)
if len ( pathFrags ) >= 2 {
if samesite && pathFrags [ 1 ] == "attachs" && ( scheme == "http" || scheme == "https" ) {
//log.Print("Attachment")
2017-10-12 03:24:14 +00:00
media . Type = "attach"
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
var sport string
// ? - Assumes the sysadmin hasn't mixed up the two standard ports
if port != "443" && port != "80" {
sport = ":" + port
}
media . URL = scheme + "://" + hostname + sport + path
2017-10-12 03:24:14 +00:00
return media , true
}
}
// ? - I don't think this hostname will hit every YT domain
// TODO: Make this a more customisable handler rather than hard-coding it in here
if hostname == "www.youtube.com" && path == "/watch" {
video , ok := query [ "v" ]
if ok && len ( video ) >= 1 && video [ 0 ] != "" {
media . Type = "raw"
// TODO: Filter the URL to make sure no nasties end up in there
media . Body = "<iframe class='postIframe' src='https://www.youtube-nocookie.com/embed/" + video [ 0 ] + "' frameborder='0' allowfullscreen></iframe>"
return media , true
2017-03-07 07:22:29 +00:00
}
}
2017-10-12 03:24:14 +00:00
lastFrag := pathFrags [ len ( pathFrags ) - 1 ]
if lastFrag != "" {
// TODO: Write a function for getting the file extension of a string
extarr := strings . Split ( lastFrag , "." )
if len ( extarr ) >= 2 {
ext := extarr [ len ( extarr ) - 1 ]
2017-11-11 04:06:16 +00:00
if ImageFileExts . Contains ( ext ) {
2017-10-12 03:24:14 +00:00
media . Type = "image"
var sport string
if port != "443" && port != "80" {
sport = ":" + port
}
media . URL = scheme + "://" + hostname + sport + path
return media , true
}
}
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
return media , true
}
2017-06-05 11:57:27 +00:00
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
func parseURL ( data [ ] byte ) ( * url . URL , error ) {
return url . Parse ( string ( data ) )
2017-03-07 07:22:29 +00:00
}
2017-03-12 07:18:12 +00:00
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2017-11-11 04:06:16 +00:00
func CoerceIntBytes ( data [ ] byte ) ( res int , length int ) {
2017-03-12 07:18:12 +00:00
if ! ( data [ 0 ] > 47 && data [ 0 ] < 58 ) {
return 0 , 1
}
2017-06-05 11:57:27 +00:00
2017-03-14 10:57:40 +00:00
i := 0
2017-09-03 04:50:31 +00:00
for ; len ( data ) > i ; i ++ {
2017-03-12 07:18:12 +00:00
if ! ( data [ i ] > 47 && data [ i ] < 58 ) {
conv , err := strconv . Atoi ( string ( data [ 0 : i ] ) )
if err != nil {
return 0 , i
}
return conv , i
}
}
2017-06-05 11:57:27 +00:00
2017-03-12 07:18:12 +00:00
conv , err := strconv . Atoi ( string ( data ) )
if err != nil {
return 0 , i
}
return conv , i
}
2017-08-15 13:47:56 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Write tests for this
2017-11-11 04:06:16 +00:00
func Paginate ( count int , perPage int , maxPages int ) [ ] int {
2017-09-03 04:50:31 +00:00
if count < perPage {
2017-08-15 13:47:56 +00:00
return [ ] int { 1 }
}
var page int
var out [ ] int
2017-09-03 04:50:31 +00:00
for current := 0 ; current < count ; current += perPage {
2017-08-15 13:47:56 +00:00
page ++
2017-09-03 04:50:31 +00:00
out = append ( out , page )
2017-08-15 13:47:56 +00:00
if len ( out ) >= maxPages {
break
}
}
return out
}
2017-09-10 16:57:22 +00:00
// TODO: Write tests for this
2017-11-11 04:06:16 +00:00
func PageOffset ( count int , page int , perPage int ) ( int , int , int ) {
2017-08-15 13:47:56 +00:00
var offset int
2017-09-03 04:50:31 +00:00
lastPage := ( count / perPage ) + 1
2017-08-15 13:47:56 +00:00
if page > 1 {
offset = ( perPage * page ) - perPage
} else if page == - 1 {
page = lastPage
offset = ( perPage * page ) - perPage
} else {
page = 1
}
// We don't want the offset to overflow the slices, if everything's in memory
if offset >= ( count - 1 ) {
offset = 0
}
return offset , page , lastPage
}