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 (
"bytes"
2019-05-22 04:45:07 +00:00
//"fmt"
2019-10-13 07:32:05 +00:00
//"log"
2020-06-17 22:03:36 +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
"net/url"
2020-03-27 21:01:44 +00:00
"path/filepath"
2017-09-22 02:21:17 +00:00
"regexp"
"strconv"
"strings"
2018-06-26 04:54:20 +00:00
"unicode/utf8"
2017-09-22 02:21:17 +00:00
)
2016-12-02 07:38:54 +00:00
2020-06-08 11:13:19 +00:00
// TODO: Use the template system?
2019-04-10 07:40:47 +00:00
// TODO: Somehow localise these?
2017-11-11 04:06:16 +00:00
var SpaceGap = [ ] byte ( " " )
2017-09-03 04:50:31 +00:00
var httpProtBytes = [ ] byte ( "http://" )
2019-07-11 10:44:18 +00:00
var DoubleForwardSlash = [ ] byte ( "//" )
2019-04-10 07:40:47 +00:00
var InvalidURL = [ ] byte ( "<red>[Invalid URL]</red>" )
var InvalidTopic = [ ] byte ( "<red>[Invalid Topic]</red>" )
var InvalidProfile = [ ] byte ( "<red>[Invalid Profile]</red>" )
var InvalidForum = [ ] byte ( "<red>[Invalid Forum]</red>" )
var unknownMedia = [ ] byte ( "<red>[Unknown Media]</red>" )
2018-06-17 07:28:18 +00:00
var URLOpen = [ ] byte ( "<a href='" )
2020-03-27 21:01:44 +00:00
var URLOpenUser = [ ] byte ( "<a rel='ugc'href='" )
2018-06-17 07:28:18 +00:00
var URLOpen2 = [ ] byte ( "'>" )
2017-09-03 04:50:31 +00:00
var bytesSinglequote = [ ] byte ( "'" )
2020-04-30 06:28:01 +00:00
var bytesGreaterThan = [ ] byte ( ">" )
2020-03-28 04:48:42 +00:00
var urlMention = [ ] byte ( "'class='mention'" )
2018-06-17 07:28:18 +00:00
var URLClose = [ ] byte ( "</a>" )
2020-04-30 06:28:01 +00:00
var videoOpen = [ ] byte ( "<video controls src=\"" )
var videoOpen2 = [ ] byte ( "\"><a class='attach'href=\"" )
var videoClose = [ ] byte ( "\"download>Attachment</a></video>" )
2020-05-05 08:10:19 +00:00
var audioOpen = [ ] byte ( "<audio controls src=\"" )
var audioOpen2 = [ ] byte ( "\"><a class='attach'href=\"" )
var audioClose = [ ] byte ( "\"download>Attachment</a></audio>" )
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='" )
2020-03-27 21:01:44 +00:00
var imageClose = [ ] byte ( "'class='postImage'></a>" )
2020-04-30 06:28:01 +00:00
var attachOpen = [ ] byte ( "<a class='attach'href=\"" )
var attachClose = [ ] byte ( "\"download>Attachment</a>" )
2019-10-06 00:55:03 +00:00
var sidParam = [ ] byte ( "?sid=" )
var stypeParam = [ ] byte ( "&stype=" )
2020-06-17 22:03:36 +00:00
2020-06-08 11:13:19 +00:00
/ * var textShortOpen = [ ] byte ( "<a class='attach'href=\"" )
var textShortOpen2 = [ ] byte ( "\">View</a> / <a class='attach'href=\"" )
var textShortClose = [ ] byte ( "\"download>Download</a>" ) * /
var textOpen = [ ] byte ( "<div class='attach_box'><div class='attach_info'>" )
var textOpen2 = [ ] byte ( "</div><div class='attach_opts'><a class='attach'href=\"" )
var textOpen3 = [ ] byte ( "\">View</a> / <a class='attach'href=\"" )
var textClose = [ ] byte ( "\"download>Download</a></div></div>" )
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
2020-04-30 06:28:01 +00:00
const imageSizeHint = len ( "<a href=\"" ) + len ( "\"><img src='" ) + len ( "'class='postImage'></a>" )
const videoSizeHint = len ( "<video controls src=\"" ) + len ( "\"><a class='attach'href=\"" ) + len ( "\"download>Attachment</a></video>" ) + len ( "?sid=" ) + len ( "&stype=" ) + 8
2020-05-05 08:10:19 +00:00
const audioSizeHint = len ( "<audio controls src=\"" ) + len ( "\"><a class='attach'href=\"" ) + len ( "\"download>Attachment</a></audio>" ) + len ( "?sid=" ) + len ( "&stype=" ) + 8
2020-04-30 06:28:01 +00:00
const mentionSizeHint = len ( "<a href='" ) + len ( "'class='mention'" ) + len ( ">@" ) + len ( "</a>" )
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
}
2019-07-11 07:13:05 +00:00
var emojis map [ string ] string
type emojiHolder struct {
2020-07-15 07:05:06 +00:00
NoDefault bool ` json:"no_defaults" `
Emojis [ ] map [ string ] string ` json:"emojis" `
2019-07-11 07:13:05 +00:00
}
func InitEmoji ( ) error {
var emoji emojiHolder
2020-06-17 22:03:36 +00:00
err := unmarshalJsonFile ( "./config/emoji_default.json" , & emoji )
2019-07-11 07:13:05 +00:00
if err != nil {
return err
}
emojis = make ( map [ string ] string , len ( emoji . Emojis ) )
2020-07-15 07:05:06 +00:00
if ! emoji . NoDefault {
for _ , item := range emoji . Emojis {
for ikey , ival := range item {
emojis [ ikey ] = ival
}
2019-07-11 07:13:05 +00:00
}
}
emoji = emojiHolder { }
2020-06-17 22:03:36 +00:00
err = unmarshalJsonFileIgnore404 ( "./config/emoji.json" , & emoji )
2019-07-11 07:13:05 +00:00
if err != nil {
return err
}
2020-07-15 07:05:06 +00:00
if emoji . NoDefault {
emojis = make ( map [ string ] string )
}
2019-07-11 07:13:05 +00:00
for _ , item := range emoji . Emojis {
for ikey , ival := range item {
emojis [ ikey ] = ival
}
}
2019-10-13 04:45:15 +00:00
2019-07-11 07:13:05 +00:00
return nil
}
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(":(.):")
2019-07-11 07:13:05 +00:00
for shortcode , emoji := range emojis {
msg = strings . Replace ( msg , shortcode , emoji , - 1 )
}
2016-12-13 02:14:14 +00:00
return msg
2016-12-08 14:11:18 +00:00
}
2018-06-25 14:28:04 +00:00
type TagToAction struct {
Suffix string
Do func ( * TagToAction , bool , int , [ ] rune ) ( int , string ) // func(tagToAction,open,i,runes) (newI, output)
Depth int // For use by Do
PartialMode bool
}
2018-07-18 06:36:16 +00:00
// TODO: Write a test for this
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func tryStepForward ( i , step int , runes [ ] rune ) ( int , bool ) {
2018-06-30 04:34:07 +00:00
i += step
if i < len ( runes ) {
return i , true
}
return i - step , false
}
2018-09-20 06:31:09 +00:00
// TODO: Write a test for this
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func tryStepBackward ( i , step int , runes [ ] rune ) ( int , bool ) {
2018-09-20 06:31:09 +00:00
if i == 0 {
return i , false
}
return i - 1 , true
}
2017-12-31 07:01:44 +00:00
// TODO: Preparse Markdown and normalize it into HTML?
2020-06-08 11:13:19 +00:00
// TODO: Use a string builder
2017-11-11 04:06:16 +00:00
func PreparseMessage ( msg string ) string {
2018-06-26 04:54:20 +00:00
// TODO: Kick this check down a level into SanitiseBody?
if ! utf8 . ValidString ( msg ) {
return ""
}
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 )
2018-06-26 04:54:20 +00:00
// TODO: Make this looser by moving it to the reverse HTML parser?
2017-12-26 07:17:26 +00:00
msg = strings . Replace ( msg , "<br>" , "\n\n" , - 1 )
2018-06-26 04:54:20 +00:00
msg = strings . Replace ( msg , "<br />" , "\n\n" , - 1 ) // XHTML style
msg = strings . Replace ( msg , " " , "" , - 1 )
msg = strings . Replace ( msg , "\r" , "" , - 1 ) // Windows artifact
//msg = strings.Replace(msg, "\n\n\n\n", "\n\n\n", -1)
2018-10-21 13:54:32 +00:00
msg = GetHookTable ( ) . Sshook ( "preparse_preassign" , msg )
2018-05-31 06:51:31 +00:00
// There are a few useful cases for having spaces, but I'd like to stop the WYSIWYG from inserting random lines here and there
msg = SanitiseBody ( msg )
2017-12-31 07:01:44 +00:00
2019-11-06 21:15:43 +00:00
runes := [ ] rune ( msg )
2017-12-30 06:45:29 +00:00
msg = ""
2018-06-25 14:28:04 +00:00
// TODO: We can maybe reduce the size of this by using an offset?
// TODO: Move some of these closures out of this function to make things a little more efficient
2019-11-06 21:15:43 +00:00
allowedTags := [ ] [ ] string {
2021-01-06 06:41:08 +00:00
'e' : { "m" } ,
's' : { "" , "trong" , "poiler" , "pan" } ,
'd' : { "el" } ,
'u' : { "" } ,
'b' : { "" , "lockquote" } ,
'i' : { "" } ,
'h' : { "1" , "2" , "3" } ,
//'p': {""},
'g' : { "" } , // Quick and dirty fix for Grammarly
2018-06-25 14:28:04 +00:00
}
2019-11-06 21:15:43 +00:00
buildLitMatch := func ( tag string ) func ( * TagToAction , bool , int , [ ] rune ) ( int , string ) {
2018-06-25 14:28:04 +00:00
return func ( action * TagToAction , open bool , _ int , _ [ ] rune ) ( int , string ) {
if open {
action . Depth ++
return - 1 , "<" + tag + ">"
}
if action . Depth <= 0 {
return - 1 , ""
}
action . Depth --
return - 1 , "</" + tag + ">"
}
}
2019-11-06 21:15:43 +00:00
tagToAction := [ ] [ ] * TagToAction {
2021-01-06 06:41:08 +00:00
'e' : { { "m" , buildLitMatch ( "em" ) , 0 , false } } ,
's' : {
{ "" , buildLitMatch ( "del" ) , 0 , false } ,
{ "trong" , buildLitMatch ( "strong" ) , 0 , false } ,
{ "poiler" , buildLitMatch ( "spoiler" ) , 0 , false } ,
2018-06-25 14:28:04 +00:00
// Hides the span tags Trumbowyg loves blasting out randomly
2021-01-06 06:41:08 +00:00
{ "pan" , func ( act * TagToAction , open bool , i int , runes [ ] rune ) ( int , string ) {
2018-06-25 14:28:04 +00:00
if open {
act . Depth ++
//fmt.Println("skipping attributes")
for ; i < len ( runes ) ; i ++ {
if runes [ i ] == '&' && peekMatch ( i , "gt;" , runes ) {
//fmt.Println("found tag exit")
return i + 3 , " "
}
}
return - 1 , " "
}
if act . Depth <= 0 {
return - 1 , " "
}
act . Depth --
return - 1 , " "
} , 0 , true } ,
} ,
2021-01-06 06:41:08 +00:00
'd' : { { "el" , buildLitMatch ( "del" ) , 0 , false } } ,
'u' : { { "" , buildLitMatch ( "u" ) , 0 , false } } ,
'b' : {
{ "" , buildLitMatch ( "strong" ) , 0 , false } ,
{ "lockquote" , buildLitMatch ( "blockquote" ) , 0 , false } ,
2019-03-24 07:23:38 +00:00
} ,
2021-01-06 06:41:08 +00:00
'i' : { { "" , buildLitMatch ( "em" ) , 0 , false } } ,
'h' : {
{ "1" , buildLitMatch ( "h2" ) , 0 , false } ,
{ "2" , buildLitMatch ( "h3" ) , 0 , false } ,
{ "3" , buildLitMatch ( "h4" ) , 0 , false } ,
2019-04-09 05:33:39 +00:00
} ,
2021-01-06 06:41:08 +00:00
//'p': {{"", buildLitMatch2("\n\n", ""), 0, false}},
'g' : {
{ "" , func ( act * TagToAction , open bool , i int , runes [ ] rune ) ( int , string ) {
2019-03-03 06:39:08 +00:00
if open {
act . Depth ++
//fmt.Println("skipping attributes")
for ; i < len ( runes ) ; i ++ {
if runes [ i ] == '&' && peekMatch ( i , "gt;" , runes ) {
//fmt.Println("found tag exit")
return i + 3 , " "
}
}
return - 1 , " "
}
if act . Depth <= 0 {
return - 1 , " "
}
act . Depth --
return - 1 , " "
} , 0 , true } ,
} ,
2018-06-25 14:28:04 +00:00
}
// TODO: Implement a less literal parser
2020-07-26 04:36:40 +00:00
// TODO: Use a string builder
// TODO: Implement faster emoji parser
2017-12-30 06:45:29 +00:00
for i := 0 ; i < len ( runes ) ; i ++ {
char := runes [ i ]
2019-03-27 06:36:14 +00:00
// TODO: Make the slashes escapable too in case someone means to use a literaly slash, maybe as an example of how to escape elements?
if char == '\\' {
if peekMatch ( i , "<" , runes ) {
msg += "&"
i ++
}
} else if char == '&' && peekMatch ( i , "lt;" , runes ) {
2018-06-30 04:34:07 +00:00
var ok bool
i , ok = tryStepForward ( i , 4 , runes )
if ! ok {
msg += "<"
break
}
2017-12-31 07:01:44 +00:00
char := runes [ i ]
2018-06-25 14:28:04 +00:00
if int ( char ) >= len ( allowedTags ) {
//fmt.Println("sentinel char out of bounds")
2018-06-26 02:30:29 +00:00
msg += "&"
2018-06-25 14:28:04 +00:00
i -= 4
continue
}
var closeTag bool
2017-12-31 07:01:44 +00:00
if char == '/' {
2018-06-25 14:28:04 +00:00
//fmt.Println("found close tag")
2018-06-30 04:34:07 +00:00
i , ok = tryStepForward ( i , 1 , runes )
if ! ok {
msg += "</"
break
}
2018-06-25 14:28:04 +00:00
char = runes [ i ]
closeTag = true
}
tags := allowedTags [ char ]
if len ( tags ) == 0 {
//fmt.Println("couldn't find char in allowedTags")
2019-06-16 06:30:58 +00:00
msg += "&"
2018-06-25 14:28:04 +00:00
if closeTag {
2018-06-26 02:30:29 +00:00
//msg += "</"
2019-06-16 06:30:58 +00:00
//msg += "&"
2018-06-25 14:28:04 +00:00
i -= 5
} else {
2019-06-16 06:30:58 +00:00
//msg += "&"
2018-06-25 14:28:04 +00:00
i -= 4
}
continue
}
// TODO: Scan through tags and make sure the suffix is present to reduce the number of false positives which hit the loop below
//fmt.Printf("tags: %+v\n", tags)
2019-10-13 04:45:15 +00:00
newI := - 1
2018-06-25 14:28:04 +00:00
var out string
toActionList := tagToAction [ char ]
for _ , toAction := range toActionList {
// TODO: Optimise this, maybe with goto or a function call to avoid scanning the text twice?
if ( toAction . PartialMode && ! closeTag && peekMatch ( i , toAction . Suffix , runes ) ) || peekMatch ( i , toAction . Suffix + ">" , runes ) {
newI , out = toAction . Do ( toAction , ! closeTag , i , runes )
if newI != - 1 {
i = newI
2018-06-26 02:30:29 +00:00
} else if out != "" {
2018-06-25 14:28:04 +00:00
i += len ( toAction . Suffix + ">" )
}
break
}
}
if out == "" {
2018-06-26 02:30:29 +00:00
msg += "&"
2018-06-25 14:28:04 +00:00
if closeTag {
i -= 5
} else {
i -= 4
2017-12-31 07:01:44 +00:00
}
2018-06-25 14:28:04 +00:00
} else if out != " " {
msg += out
2017-12-31 07:01:44 +00:00
}
2018-09-20 06:31:09 +00:00
} else if char == '@' && ( i == 0 || runes [ i - 1 ] < 33 ) {
// TODO: Handle usernames containing spaces, maybe in the front-end with AJAX
// Do not mention-ify ridiculously long things
var ok bool
i , ok = tryStepForward ( i , 1 , runes )
if ! ok {
msg += "@"
continue
}
start := i
for j := 0 ; i < len ( runes ) && j < Config . MaxUsernameLength ; j ++ {
cchar := runes [ i ]
if cchar < 33 {
break
}
i ++
}
username := string ( runes [ start : i ] )
if username == "" {
msg += "@"
i = start - 1
continue
}
user , err := Users . GetByName ( username )
if err != nil {
if err != ErrNoRows {
LogError ( err )
}
msg += "@"
i = start - 1
continue
}
msg += "@" + strconv . Itoa ( user . ID )
i --
2017-12-30 06:45:29 +00:00
} else {
msg += string ( char )
}
2017-12-31 07:01:44 +00:00
}
2018-06-25 14:28:04 +00:00
for _ , actionList := range tagToAction {
for _ , toAction := range actionList {
2018-06-26 02:30:29 +00:00
if toAction . Depth > 0 {
2018-06-25 14:28:04 +00:00
for ; toAction . Depth > 0 ; toAction . Depth -- {
_ , out := toAction . Do ( toAction , false , len ( runes ) , runes )
if out != "" {
msg += out
}
}
}
}
2018-01-03 07:46:18 +00:00
}
2018-06-26 04:54:20 +00:00
return strings . TrimSpace ( 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?
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func peek ( cur , skip int , runes [ ] rune ) rune {
2017-12-30 06:45:29 +00:00
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 {
2018-07-18 06:36:16 +00:00
if cur + i + 1 >= len ( runes ) {
return false
}
2017-12-31 07:01:44 +00:00
if runes [ cur + i + 1 ] != char {
return false
}
}
return true
}
2018-09-20 04:36:50 +00:00
// ! Not concurrency safe
2020-03-31 12:33:40 +00:00
func AddHashLinkType ( prefix string , h func ( * strings . Builder , string , * int ) ) {
2018-09-20 04:36:50 +00:00
// There can only be one hash link type starting with a specific character at the moment
hashType := hashLinkTypes [ prefix [ 0 ] ]
if hashType != "" {
return
}
2020-03-31 12:33:40 +00:00
hashLinkMap [ prefix ] = h
2018-09-20 04:36:50 +00:00
hashLinkTypes [ prefix [ 0 ] ] = prefix
}
2020-01-14 05:07:00 +00:00
func WriteURL ( sb * strings . Builder , url , label string ) {
2018-09-20 04:36:50 +00:00
sb . Write ( URLOpen )
sb . WriteString ( url )
sb . Write ( URLOpen2 )
sb . WriteString ( label )
sb . Write ( URLClose )
}
var hashLinkTypes = [ ] string { 't' : "tid-" , 'r' : "rid-" , 'f' : "fid-" }
var hashLinkMap = map [ string ] func ( * strings . Builder , string , * int ) {
"tid-" : func ( sb * strings . Builder , msg string , i * int ) {
tid , intLen := CoerceIntString ( msg [ * i : ] )
* i += intLen
topic , err := Topics . Get ( tid )
if err != nil || ! Forums . Exists ( topic . ParentID ) {
sb . Write ( InvalidTopic )
return
}
2019-05-22 04:45:07 +00:00
WriteURL ( sb , BuildTopicURL ( "" , tid ) , "#tid-" + strconv . Itoa ( tid ) )
2018-09-20 04:36:50 +00:00
} ,
"rid-" : func ( sb * strings . Builder , msg string , i * int ) {
rid , intLen := CoerceIntString ( msg [ * i : ] )
* i += intLen
topic , err := TopicByReplyID ( rid )
if err != nil || ! Forums . Exists ( topic . ParentID ) {
sb . Write ( InvalidTopic )
return
}
2019-05-22 04:45:07 +00:00
// TODO: Send the user to the right page and post not just the right topic?
WriteURL ( sb , BuildTopicURL ( "" , topic . ID ) , "#rid-" + strconv . Itoa ( rid ) )
2018-09-20 04:36:50 +00:00
} ,
"fid-" : func ( sb * strings . Builder , msg string , i * int ) {
fid , intLen := CoerceIntString ( msg [ * i : ] )
* i += intLen
if ! Forums . Exists ( fid ) {
sb . Write ( InvalidForum )
return
}
2019-05-22 04:45:07 +00:00
WriteURL ( sb , BuildForumURL ( "" , fid ) , "#fid-" + strconv . Itoa ( fid ) )
2018-09-20 04:36:50 +00:00
} ,
// TODO: Forum Shortcode Link
}
2019-12-08 03:40:56 +00:00
// TODO: Pack multiple bit flags into an integer instead of using a struct?
var DefaultParseSettings = & ParseSettings { }
type ParseSettings struct {
NoEmbed bool
}
func ( ps * ParseSettings ) CopyPtr ( ) * ParseSettings {
n := & ParseSettings { }
* n = * ps
return n
}
2020-06-09 02:04:58 +00:00
func ParseMessage ( msg string , sectionID int , sectionType string , settings * ParseSettings , user * User ) string {
2020-06-17 22:03:36 +00:00
msg , _ = ParseMessage2 ( msg , sectionID , sectionType , settings , user )
2020-06-09 02:04:58 +00:00
return msg
}
2021-01-06 06:41:08 +00:00
var litRepPrefix = [ ] byte { ':' , ';' }
//var litRep = [][]byte{':':{')','(','D','O','o','P','p'},';':{')'}}
var litRep = [ ] [ ] string { ':' : { ')' : "😀" , '(' : "😞" , 'D' : "😃" , 'O' : "😲" , 'o' : "😲" , 'P' : "😛" , 'p' : "😛" } , ';' : { ')' : "😉" } }
2020-06-09 02:04:58 +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
// TODO: We need a lot more hooks here. E.g. To add custom media types and handlers.
2018-07-18 06:36:16 +00:00
// TODO: Use templates to reduce the amount of boilerplate?
2020-06-17 22:03:36 +00:00
func ParseMessage2 ( msg string , sectionID int , sectionType string , settings * ParseSettings , user * User ) ( string , bool ) {
2019-12-08 03:40:56 +00:00
if settings == nil {
settings = DefaultParseSettings
}
2020-02-04 11:47:03 +00:00
if user == nil {
user = & GuestUser
}
2018-09-19 06:41:36 +00:00
// TODO: Word boundary detection for these to avoid mangling code
2020-07-26 04:36:40 +00:00
/ * rep := func ( find , replace string ) {
2020-02-04 11:47:03 +00:00
msg = strings . Replace ( msg , find , replace , - 1 )
}
rep ( ":)" , "😀" )
rep ( ":(" , "😞" )
rep ( ":D" , "😃" )
rep ( ":P" , "😛" )
rep ( ":O" , "😲" )
rep ( ":p" , "😛" )
rep ( ":o" , "😲" )
2020-07-26 04:36:40 +00:00
rep ( ";)" , "😉" ) * /
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
2020-07-26 04:36:40 +00:00
filters , err := WordFilters . GetAll ( )
2018-08-04 11:46:36 +00:00
if err != nil {
LogError ( err )
2020-06-09 02:04:58 +00:00
return "" , false
2018-08-04 11:46:36 +00:00
}
2020-07-26 04:36:40 +00:00
for _ , f := range filters {
2020-04-30 06:28:01 +00:00
msg = strings . Replace ( msg , f . Find , f . Replace , - 1 )
}
if len ( msg ) < 2 {
msg = strings . Replace ( msg , "\n" , "<br>" , - 1 )
msg = GetHookTable ( ) . Sshook ( "parse_assign" , msg )
2020-06-09 02:04:58 +00:00
return msg , false
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...
2018-09-20 01:51:18 +00:00
var sb strings . Builder
2019-10-13 04:45:15 +00:00
lastItem := 0
i := 0
2020-06-09 02:04:58 +00:00
var externalHead bool
2019-05-22 04:45:07 +00:00
//var c bool
//fmt.Println("msg:", "'"+msg+"'")
for ; len ( msg ) > i ; i ++ {
//fmt.Printf("msg[%d]: %s\n",i,string(msg[i]))
if ( i == 0 && ( msg [ 0 ] > 32 ) ) || ( len ( msg ) > ( i + 1 ) && ( msg [ i ] < 33 ) && ( msg [ i + 1 ] > 32 ) ) {
//fmt.Println("s1")
2018-09-20 01:51:18 +00:00
if ( i != 0 ) || msg [ i ] < 33 {
2017-03-14 10:57:40 +00:00
i ++
}
2019-10-13 04:45:15 +00:00
if len ( msg ) <= ( i + 1 ) {
2019-05-22 04:45:07 +00:00
break
}
//fmt.Println("s2")
2020-04-30 06:28:01 +00:00
ch := msg [ i ]
2020-07-26 04:36:40 +00:00
// Very short literal matcher
if len ( litRep ) > int ( ch ) {
sl := litRep [ ch ]
if sl != nil {
i ++
ch := msg [ i ]
if len ( sl ) > int ( ch ) {
val := sl [ ch ]
if val != "" {
i --
sb . WriteString ( msg [ lastItem : i ] )
i ++
sb . WriteString ( val )
i ++
lastItem = i
i --
continue
}
}
i --
}
//lastItem = i
//i--
//continue
}
2020-04-30 06:28:01 +00:00
switch ch {
case '#' :
2019-05-22 04:45:07 +00:00
//fmt.Println("msg[i+1]:", msg[i+1])
//fmt.Println("string(msg[i+1]):", string(msg[i+1]))
2018-09-20 02:44:34 +00:00
hashType := hashLinkTypes [ msg [ i + 1 ] ]
if hashType == "" {
2019-05-22 04:45:07 +00:00
//fmt.Println("uh1")
sb . WriteString ( msg [ lastItem : i ] )
i ++
lastItem = i
2018-09-20 02:44:34 +00:00
continue
}
2019-05-22 04:45:07 +00:00
//fmt.Println("hashType:", hashType)
if len ( msg ) <= ( i + len ( hashType ) + 1 ) {
2018-09-20 01:51:18 +00:00
sb . WriteString ( msg [ lastItem : i ] )
2017-03-15 08:34:14 +00:00
lastItem = i
2019-05-22 04:45:07 +00:00
continue
}
if msg [ i + 1 : i + len ( hashType ) + 1 ] != hashType {
continue
2017-03-12 07:18:12 +00:00
}
2019-10-13 04:45:15 +00:00
2019-05-22 04:45:07 +00:00
//fmt.Println("msg[lastItem:i]:", msg[lastItem:i])
sb . WriteString ( msg [ lastItem : i ] )
i += len ( hashType ) + 1
hashLinkMap [ hashType ] ( & sb , msg , & i )
lastItem = i
2018-09-20 06:47:54 +00:00
i --
2020-04-30 06:28:01 +00:00
case '@' :
2018-09-20 01:51:18 +00:00
sb . WriteString ( msg [ lastItem : i ] )
2017-03-14 10:57:40 +00:00
i ++
start := i
2018-09-20 01:51:18 +00:00
uid , intLen := CoerceIntString ( msg [ start : ] )
2017-09-03 04:50:31 +00:00
i += intLen
2017-06-05 11:57:27 +00:00
2020-04-30 06:28:01 +00:00
var menUser * User
if uid != 0 && user . ID == uid {
menUser = user
} else {
menUser = Users . Getn ( uid )
if menUser == nil {
sb . Write ( InvalidProfile )
lastItem = i
i --
continue
}
2017-03-14 10:57:40 +00:00
}
2017-06-05 11:57:27 +00:00
2020-04-30 06:28:01 +00:00
sb . Grow ( mentionSizeHint + len ( menUser . Link ) + len ( menUser . Name ) )
2018-09-20 01:51:18 +00:00
sb . Write ( URLOpen )
sb . WriteString ( menUser . Link )
sb . Write ( urlMention )
2020-04-30 06:28:01 +00:00
sb . Write ( bytesGreaterThan )
2019-07-11 10:44:18 +00:00
sb . WriteByte ( '@' )
sb . WriteString ( menUser . Name )
2018-09-20 01:51:18 +00:00
sb . Write ( URLClose )
2017-03-14 10:57:40 +00:00
lastItem = i
2018-09-20 06:47:54 +00:00
i --
2020-04-30 06:28:01 +00:00
case 'h' , 'f' , 'g' , '/' :
2019-05-22 04:45:07 +00:00
//fmt.Println("s3")
2021-02-18 11:40:42 +00:00
fch := msg [ i + 1 ]
if len ( msg ) > i + 5 && fch == 't' && msg [ i + 2 ] == 't' && msg [ i + 3 ] == 'p' {
2019-05-22 04:45:07 +00:00
if len ( msg ) > i + 6 && msg [ i + 4 ] == 's' && msg [ i + 5 ] == ':' && msg [ i + 6 ] == '/' {
2017-03-12 07:18:12 +00:00
// Do nothing
2019-12-08 03:40:56 +00:00
} else if msg [ i + 4 ] == ':' && msg [ i + 5 ] == '/' {
2017-03-12 07:18:12 +00:00
// Do nothing
} else {
continue
}
2020-04-30 06:28:01 +00:00
} else if len ( msg ) > i + 4 {
if fch == 't' && msg [ i + 2 ] == 'p' && msg [ i + 3 ] == ':' && msg [ i + 4 ] == '/' {
// Do nothing
} else if fch == 'i' && msg [ i + 2 ] == 't' && msg [ i + 3 ] == ':' && msg [ i + 4 ] == '/' {
// Do nothing
} else if fch == '/' {
// Do nothing
} else {
continue
}
2021-02-18 11:40:42 +00:00
} else if fch == '/' {
2017-03-07 07:22:29 +00:00
// Do nothing
} else {
continue
}
2021-02-18 11:40:42 +00:00
if ! user . Perms . AutoLink {
continue
}
2017-06-05 11:57:27 +00:00
2019-05-22 04:45:07 +00:00
//fmt.Println("p1:",i)
2018-09-20 01:51:18 +00:00
sb . WriteString ( msg [ lastItem : i ] )
2019-05-22 04:45:07 +00:00
urlLen , ok := PartialURLStringLen ( msg [ i : ] )
if len ( msg ) < i + urlLen {
//fmt.Println("o1")
2019-07-11 10:44:18 +00:00
if urlLen == 2 {
sb . Write ( DoubleForwardSlash )
} else {
sb . Write ( InvalidURL )
}
2019-05-22 04:45:07 +00:00
i += len ( msg ) - 1
lastItem = i
break
}
2019-07-11 10:44:18 +00:00
if urlLen == 2 {
sb . Write ( DoubleForwardSlash )
i += urlLen
lastItem = i
i --
continue
}
2019-05-22 04:45:07 +00:00
//fmt.Println("msg[i:i+urlLen]:", "'"+msg[i:i+urlLen]+"'")
if ! ok {
//fmt.Printf("o2: i = %d; i+urlLen = %d\n",i,i+urlLen)
2018-09-20 01:51:18 +00:00
sb . Write ( 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
2019-05-22 04:45:07 +00:00
lastItem = i
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
continue
}
2019-12-08 03:40:56 +00:00
media , ok := parseMediaString ( msg [ i : i + urlLen ] , settings )
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 ! ok {
2019-05-22 04:45:07 +00:00
//fmt.Println("o3")
2018-09-20 01:51:18 +00:00
sb . Write ( 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
2019-05-22 04:45:07 +00:00
lastItem = 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
continue
}
2019-05-22 04:45:07 +00:00
//fmt.Println("p2")
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
2019-10-06 00:55:03 +00:00
addImage := func ( url string ) {
2020-04-30 06:28:01 +00:00
sb . Grow ( imageSizeHint + len ( url ) + len ( url ) )
2018-09-20 01:51:18 +00:00
sb . Write ( imageOpen )
sb . WriteString ( url )
sb . Write ( imageOpen2 )
sb . WriteString ( url )
sb . Write ( imageClose )
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
2018-09-19 06:59:07 +00:00
}
// TODO: Reduce the amount of code duplication
2019-10-06 00:55:03 +00:00
// TODO: Avoid allocating a string for media.Type?
2020-04-30 06:28:01 +00:00
switch media . Type {
case AImage :
2019-07-25 07:00:49 +00:00
addImage ( media . URL + "?sid=" + strconv . Itoa ( sectionID ) + "&stype=" + sectionType )
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
continue
2020-04-30 06:28:01 +00:00
case AVideo :
sb . Grow ( videoSizeHint + ( len ( media . URL ) + len ( sectionType ) * 2 ) )
sb . Write ( videoOpen )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( strconv . Itoa ( sectionID ) )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( videoOpen2 )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( strconv . Itoa ( sectionID ) )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( videoClose )
i += urlLen
lastItem = i
continue
2020-05-05 08:10:19 +00:00
case AAudio :
sb . Grow ( audioSizeHint + ( len ( media . URL ) + len ( sectionType ) * 2 ) )
sb . Write ( audioOpen )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( strconv . Itoa ( sectionID ) )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( audioOpen2 )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( strconv . Itoa ( sectionID ) )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( audioClose )
i += urlLen
lastItem = i
continue
2020-04-30 06:28:01 +00:00
case EImage :
2018-09-19 06:59:07 +00:00
addImage ( media . URL )
2017-10-12 03:24:14 +00:00
continue
2020-06-08 07:04:47 +00:00
case AText :
2020-06-08 11:13:19 +00:00
/ * sb . Write ( textOpen )
2020-06-08 07:04:47 +00:00
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sid := strconv . Itoa ( sectionID )
sb . WriteString ( sid )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( textOpen2 )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( sid )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( textClose )
i += urlLen
lastItem = i
2020-06-08 11:13:19 +00:00
continue * /
sb . Write ( textOpen )
sb . WriteString ( media . URL )
sb . Write ( textOpen2 )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sid := strconv . Itoa ( sectionID )
sb . WriteString ( sid )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( textOpen3 )
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( sid )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
sb . Write ( textClose )
i += urlLen
lastItem = i
2020-06-08 07:04:47 +00:00
continue
2020-04-30 06:28:01 +00:00
case AOther :
2019-04-16 11:45:55 +00:00
sb . Write ( attachOpen )
2019-10-06 00:55:03 +00:00
sb . WriteString ( media . URL )
sb . Write ( sidParam )
sb . WriteString ( strconv . Itoa ( sectionID ) )
sb . Write ( stypeParam )
sb . WriteString ( sectionType )
2019-04-16 11:45:55 +00:00
sb . Write ( attachClose )
i += urlLen
lastItem = i
continue
2020-04-30 06:28:01 +00:00
case ERaw :
2018-09-20 01:51:18 +00:00
sb . WriteString ( media . Body )
2017-10-12 03:24:14 +00:00
i += urlLen
lastItem = i
continue
2020-06-09 02:04:58 +00:00
case ERawExternal :
sb . WriteString ( media . Body )
i += urlLen
lastItem = i
externalHead = true
continue
2020-04-30 06:28:01 +00:00
case ENone :
// Do nothing
// TODO: Add support for media plugins
default :
2018-09-20 01:51:18 +00:00
sb . Write ( unknownMedia )
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
}
2019-05-22 04:45:07 +00:00
//fmt.Println("p3")
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
2019-10-06 00:55:03 +00:00
// TODO: Add support for rel="ugc"
2019-10-13 04:45:15 +00:00
sb . Grow ( len ( URLOpen ) + ( len ( msg [ i : i + urlLen ] ) * 2 ) + len ( URLOpen2 ) + len ( URLClose ) )
2019-10-06 00:55:03 +00:00
if media . Trusted {
sb . Write ( URLOpen )
} else {
sb . Write ( URLOpenUser )
}
2019-10-13 07:32:05 +00:00
sb . WriteString ( media . URL )
2018-09-20 01:51:18 +00:00
sb . Write ( URLOpen2 )
2019-10-13 04:45:15 +00:00
sb . WriteString ( media . FURL )
2018-09-20 01:51:18 +00:00
sb . Write ( URLClose )
2017-09-03 04:50:31 +00:00
i += urlLen
2017-03-12 07:18:12 +00:00
lastItem = i
2018-09-20 06:47:54 +00:00
i --
2017-03-07 07:22:29 +00:00
}
}
}
2018-09-20 01:51:18 +00:00
if lastItem != i && sb . Len ( ) != 0 {
2019-05-22 04:45:07 +00:00
/ * calclen := len ( msg )
2017-03-07 07:22:29 +00:00
if calclen <= lastItem {
calclen = lastItem
2019-05-22 04:45:07 +00:00
} * /
//if i == len(msg) {
2019-10-13 04:45:15 +00:00
sb . WriteString ( msg [ lastItem : ] )
2019-05-22 04:45:07 +00:00
/ * } else {
sb . WriteString ( msg [ lastItem : calclen ] )
} * /
}
if sb . Len ( ) != 0 {
2018-09-20 01:51:18 +00:00
msg = sb . String ( )
2019-05-22 04:45:07 +00:00
//fmt.Println("sb.String():", "'"+sb.String()+"'")
2017-03-07 07:22:29 +00:00
}
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
msg = strings . Replace ( msg , "\n" , "<br>" , - 1 )
2018-10-21 13:54:32 +00:00
msg = GetHookTable ( ) . Sshook ( "parse_assign" , msg )
2020-06-09 02:04:58 +00:00
return msg , externalHead
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
// 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
2018-09-20 01:51:18 +00:00
func validateURLString ( data string ) bool {
2017-03-07 07:22:29 +00:00
i := 0
2019-05-22 04:45:07 +00:00
if len ( data ) >= 6 {
2018-09-20 01:51:18 +00:00
if data [ 0 : 6 ] == "ftp://" || data [ 0 : 6 ] == "git://" {
2017-03-07 07:22:29 +00:00
i = 6
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 7 && data [ 0 : 7 ] == "http://" {
2017-03-07 07:22:29 +00:00
i = 7
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 8 && data [ 0 : 8 ] == "https://" {
2017-03-07 07:22:29 +00:00
i = 8
}
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
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 = 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.
2019-05-22 04:45:07 +00:00
for ; len ( data ) > i ; i ++ {
2019-12-08 03:40:56 +00:00
ch := data [ i ]
if ch != '\\' && ch != '_' && ch != '?' && ch != '&' && ch != '=' && ch != '@' && ch != '#' && ch != ']' && ! ( ch > 44 && ch < 60 ) && ! ( ch > 64 && ch < 92 ) && ! ( ch > 96 && ch < 123 ) { // 57 is 9, 58 is :, 59 is ;, 90 is Z, 91 is [
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
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 ++ {
2019-12-08 03:40:56 +00:00
ch := data [ i ]
if ch != '\\' && ch != '_' && ch != '?' && ch != '&' && ch != '=' && ch != '@' && ch != '#' && ch != ']' && ! ( ch > 44 && ch < 60 ) && ! ( ch > 64 && ch < 92 ) && ! ( ch > 96 && ch < 123 ) { // 57 is 9, 58 is :, 59 is ;, 90 is Z, 91 is [
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
2018-09-20 01:51:18 +00:00
func PartialURLString ( data string ) ( url [ ] byte ) {
2017-03-07 07:22:29 +00:00
i := 0
2019-05-22 04:45:07 +00:00
end := len ( data ) - 1
if len ( data ) >= 6 {
2018-09-20 01:51:18 +00:00
if data [ 0 : 6 ] == "ftp://" || data [ 0 : 6 ] == "git://" {
2017-03-07 07:22:29 +00:00
i = 6
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 7 && data [ 0 : 7 ] == "http://" {
2017-03-07 07:22:29 +00:00
i = 7
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 8 && data [ 0 : 8 ] == "https://" {
2017-03-07 07:22:29 +00:00
i = 8
}
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
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 = 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 ++ {
2019-12-08 03:40:56 +00:00
ch := data [ i ]
if ch != '\\' && ch != '_' && ch != '?' && ch != '&' && ch != '=' && ch != '@' && ch != '#' && ch != ']' && ! ( ch > 44 && ch < 60 ) && ! ( ch > 64 && ch < 92 ) && ! ( ch > 96 && ch < 123 ) { // 57 is 9, 58 is :, 59 is ;, 90 is Z, 91 is [
2017-03-07 07:22:29 +00:00
end = i
}
}
2017-06-05 11:57:27 +00:00
2018-09-20 01:51:18 +00:00
url = append ( url , [ ] byte ( data [ 0 : end ] ) ... )
2017-03-07 07:22:29 +00:00
return url
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2019-05-23 23:39:24 +00:00
// TODO: Handle the host bits differently from the paths...
2019-05-22 04:45:07 +00:00
func PartialURLStringLen ( data string ) ( int , bool ) {
2017-03-07 07:22:29 +00:00
i := 0
2019-05-22 04:45:07 +00:00
if len ( data ) >= 6 {
//log.Print(string(data[0:5]))
if data [ 0 : 6 ] == "ftp://" || data [ 0 : 6 ] == "git://" {
i = 6
} else if len ( data ) >= 7 && data [ 0 : 7 ] == "http://" {
i = 7
} else if len ( data ) >= 8 && data [ 0 : 8 ] == "https://" {
i = 8
}
} else if len ( data ) >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
i = 2
}
//fmt.Println("Data Length: ",len(data))
if len ( data ) < i {
//fmt.Println("e1:",i)
2019-10-13 04:45:15 +00:00
return i + 1 , false
2019-05-22 04:45:07 +00:00
}
2017-06-05 11:57:27 +00:00
2019-05-22 04:45:07 +00:00
// ? - There should only be one : and that's only if the URL is on a non-standard port. Same for ?s.
f := i
//fmt.Println("f:",f)
for ; len ( data ) > i ; i ++ {
2019-10-27 23:53:16 +00:00
ch := data [ i ] //char
if ch < 33 { // space and invisibles
2019-05-22 04:45:07 +00:00
//fmt.Println("e2:",i)
return i , i != f
2019-12-08 03:40:56 +00:00
} else if ch != '\\' && ch != '_' && ch != '?' && ch != '&' && ch != '=' && ch != '@' && ch != '#' && ch != ']' && ! ( ch > 44 && ch < 60 ) && ! ( ch > 64 && ch < 92 ) && ! ( ch > 96 && ch < 123 ) { // 57 is 9, 58 is :, 59 is ;, 90 is Z, 91 is [
2019-10-27 23:53:16 +00:00
//log.Print("Bad Character: ", ch)
2019-05-22 04:45:07 +00:00
//fmt.Println("e3")
return i , false
}
}
2019-10-13 04:45:15 +00:00
2019-05-22 04:45:07 +00:00
//fmt.Println("e4:", i)
/ * if data [ i - 1 ] < 33 {
return i - 1 , i != f
} * /
//fmt.Println("e5")
return i , i != f
}
// TODO: Write a test for this
2019-05-23 23:39:24 +00:00
// TODO: Get this to support IPv6 hosts, this isn't currently done as this is used in the bbcode plugin where it thinks the [ is a IPv6 host
2019-05-22 04:45:07 +00:00
func PartialURLStringLen2 ( data string ) int {
i := 0
if len ( data ) >= 6 {
2017-08-13 11:22:34 +00:00
//log.Print(string(data[0:5]))
2018-09-20 01:51:18 +00:00
if data [ 0 : 6 ] == "ftp://" || data [ 0 : 6 ] == "git://" {
2017-03-07 07:22:29 +00:00
i = 6
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 7 && data [ 0 : 7 ] == "http://" {
2017-03-07 07:22:29 +00:00
i = 7
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 8 && data [ 0 : 8 ] == "https://" {
2017-03-07 07:22:29 +00:00
i = 8
}
2019-05-22 04:45:07 +00:00
} else if len ( data ) >= 2 && data [ 0 ] == '/' && data [ 1 ] == '/' {
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 = 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.
2019-05-22 04:45:07 +00:00
for ; len ( data ) > i ; i ++ {
2019-12-08 03:40:56 +00:00
ch := data [ i ]
if ch != '\\' && ch != '_' && ch != '?' && ch != '&' && ch != '=' && ch != '@' && ch != '#' && ch != ']' && ! ( ch > 44 && ch < 60 ) && ! ( ch > 64 && ch < 91 ) && ! ( ch > 96 && ch < 123 ) { // 57 is 9, 58 is :, 59 is ;, 90 is Z, 91 is [
2019-10-27 23:53:16 +00:00
//log.Print("Bad Character: ", ch)
2017-03-07 07:22:29 +00:00
return i
}
}
2019-05-22 04:45:07 +00:00
//log.Print("Data Length: ",len(data))
return len ( data )
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
type MediaEmbed struct {
2020-04-30 06:28:01 +00:00
//Type string //image
Type int
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
URL string
2019-10-13 04:45:15 +00:00
FURL string
2017-10-12 03:24:14 +00:00
Body string
2019-10-06 00:55:03 +00:00
Trusted bool // samesite urls
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
}
2020-04-30 06:28:01 +00:00
const (
ENone = iota
ERaw
2020-06-09 02:04:58 +00:00
ERawExternal
2020-04-30 06:28:01 +00:00
EImage
AImage
AVideo
2020-05-05 08:10:19 +00:00
AAudio
2020-06-08 07:04:47 +00:00
AText
2020-04-30 06:28:01 +00:00
AOther
)
var LastEmbedID = AOther
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
2019-12-08 03:40:56 +00:00
func parseMediaString ( data string , settings * ParseSettings ) ( media MediaEmbed , ok bool ) {
2018-09-20 01:51:18 +00:00
if ! validateURLString ( data ) {
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 , false
}
2019-10-13 07:32:05 +00:00
uurl , err := url . Parse ( data )
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 err != nil {
return media , false
}
2019-10-27 23:53:16 +00:00
host := uurl . Hostname ( )
2019-10-13 07:32:05 +00:00
scheme := uurl . Scheme
port := uurl . Port ( )
query , err := url . ParseQuery ( uurl . RawQuery )
if err != nil {
return media , false
}
2019-10-27 23:53:16 +00:00
//fmt.Println("host:", host)
2019-10-13 07:32:05 +00:00
//log.Print("Site.URL:",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
2019-10-27 23:53:16 +00:00
samesite := host == "localhost" || host == "127.0.0.1" || host == "::1" || host == 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 {
2019-10-27 23:53:16 +00:00
host = 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
2019-11-04 11:55:52 +00:00
if Config . SslSchema {
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
}
}
2019-10-13 07:32:05 +00:00
if scheme != "" {
scheme += ":"
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
}
2019-10-06 00:55:03 +00:00
media . Trusted = samesite
2017-06-05 11:57:27 +00:00
2019-10-13 07:32:05 +00:00
path := uurl . EscapedPath ( )
2020-06-25 07:46:09 +00:00
//fmt.Println("path:", path)
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
pathFrags := strings . Split ( path , "/" )
if len ( pathFrags ) >= 2 {
2019-10-27 23:53:16 +00:00
if samesite && pathFrags [ 1 ] == "attachs" && ( scheme == "http:" || scheme == "https:" ) {
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
2019-10-13 04:45:15 +00:00
if port != "443" && port != "80" && port != "" {
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
sport = ":" + port
}
2019-10-27 23:53:16 +00:00
media . URL = scheme + "//" + host + sport + path
2020-03-27 21:01:44 +00:00
ext := strings . TrimPrefix ( filepath . Ext ( path ) , "." )
if len ( ext ) == 0 {
2019-04-16 11:45:55 +00:00
// TODO: Write a unit test for this
return media , false
}
2020-05-05 08:10:19 +00:00
switch {
case ImageFileExts . Contains ( ext ) :
2020-04-30 06:28:01 +00:00
media . Type = AImage
2020-05-05 08:10:19 +00:00
case WebVideoFileExts . Contains ( ext ) :
2020-04-30 06:28:01 +00:00
media . Type = AVideo
2020-05-05 08:10:19 +00:00
case WebAudioFileExts . Contains ( ext ) :
media . Type = AAudio
2020-06-08 07:04:47 +00:00
case TextFileExts . Contains ( ext ) :
media . Type = AText
2020-05-05 08:10:19 +00:00
default :
2020-04-30 06:28:01 +00:00
media . Type = AOther
2019-04-16 11:45:55 +00:00
}
2017-10-12 03:24:14 +00:00
return media , true
}
}
2020-06-25 07:46:09 +00:00
//fmt.Printf("settings.NoEmbed: %+v\n", settings.NoEmbed)
//settings.NoEmbed = false
2019-12-08 03:40:56 +00:00
if ! settings . NoEmbed {
// ? - 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
2020-06-25 07:46:09 +00:00
ytInvalid := func ( v string ) bool {
for _ , ch := range v {
if ! ( ( ch > 47 && ch < 58 ) || ( ch > 64 && ch < 91 ) || ( ch > 96 && ch < 123 ) || ch == '-' || ch == '_' ) {
var sport string
if port != "443" && port != "80" && port != "" {
sport = ":" + port
}
var q string
if len ( uurl . RawQuery ) > 0 {
q = "?" + uurl . RawQuery
}
var frag string
if len ( uurl . Fragment ) > 0 {
frag = "#" + uurl . Fragment
}
media . FURL = host + sport + path + q + frag
media . URL = scheme + "//" + media . FURL
//fmt.Printf("ytInvalid true: %+v\n",v)
return true
}
}
return false
}
ytInvalid2 := func ( t string ) bool {
for _ , ch := range t {
2020-07-15 07:05:06 +00:00
if ! ( ( ch > 47 && ch < 58 ) || ch == 'h' || ch == 'm' || ch == 's' ) {
2020-06-25 07:46:09 +00:00
//fmt.Printf("ytInvalid2 true: %+v\n",t)
return true
}
}
return false
}
2019-12-08 03:40:56 +00:00
if strings . HasSuffix ( host , ".youtube.com" ) && path == "/watch" {
video , ok := query [ "v" ]
if ok && len ( video ) >= 1 && video [ 0 ] != "" {
2020-06-25 07:46:09 +00:00
v := video [ 0 ]
if ytInvalid ( v ) {
return media , true
}
2020-07-15 07:05:06 +00:00
var t , t2 string
2020-06-25 07:46:09 +00:00
tt , ok := query [ "t" ]
if ok && len ( tt ) >= 1 {
t , t2 = tt [ 0 ] , tt [ 0 ]
}
2020-06-09 02:04:58 +00:00
media . Type = ERawExternal
2020-06-25 07:46:09 +00:00
if t != "" && ! ytInvalid2 ( t ) {
2020-07-15 07:05:06 +00:00
s , m , h := parseDuration ( t2 )
2020-06-25 07:46:09 +00:00
calc := s + ( m * 60 ) + ( h * 60 * 60 )
if calc > 0 {
2020-07-15 07:05:06 +00:00
t = "&t=" + t
t2 = "?start=" + strconv . Itoa ( calc )
2020-06-25 07:46:09 +00:00
} else {
2020-07-15 07:05:06 +00:00
t , t2 = "" , ""
2020-06-25 07:46:09 +00:00
}
}
2020-07-15 07:05:06 +00:00
l := "https://" + host + path + "?v=" + v + t
media . Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v + t2 + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
2020-06-25 07:46:09 +00:00
return media , true
}
} else if host == "youtu.be" {
2020-07-15 07:05:06 +00:00
v := strings . TrimPrefix ( path , "/" )
2020-06-25 07:46:09 +00:00
if ytInvalid ( v ) {
2019-12-08 03:40:56 +00:00
return media , true
}
2020-07-15 07:05:06 +00:00
l := "https://youtu.be/" + v
2020-06-25 07:46:09 +00:00
media . Type = ERawExternal
2020-07-15 07:05:06 +00:00
media . Body = "<iframe class='postIframe'src='https://www.youtube-nocookie.com/embed/" + v + "'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
2020-06-25 07:46:09 +00:00
return media , true
2020-06-08 12:19:32 +00:00
} else if strings . HasPrefix ( host , "www.nicovideo.jp" ) && strings . HasPrefix ( path , "/watch/sm" ) {
vid , err := strconv . ParseInt ( strings . TrimPrefix ( path , "/watch/sm" ) , 10 , 64 )
if err == nil {
2020-06-25 07:46:09 +00:00
var sport string
if port != "443" && port != "80" && port != "" {
sport = ":" + port
}
2020-06-09 02:04:58 +00:00
media . Type = ERawExternal
2020-06-25 07:46:09 +00:00
sm := strconv . FormatInt ( vid , 10 )
2020-07-15 07:05:06 +00:00
l := "https://" + host + sport + path
media . Body = "<iframe class='postIframe'src='https://embed.nicovideo.jp/watch/sm" + sm + "?jsapi=1&playerId=1'frameborder=0 allowfullscreen></iframe><noscript><a href='" + l + "'>" + l + "</a></noscript>"
2020-06-08 12:19:32 +00:00
return media , true
}
2017-03-07 07:22:29 +00:00
}
2017-10-12 03:24:14 +00:00
2019-12-08 03:40:56 +00:00
if lastFrag := pathFrags [ len ( pathFrags ) - 1 ] ; lastFrag != "" {
// TODO: Write a function for getting the file extension of a string
2020-04-30 06:28:01 +00:00
ext := strings . TrimPrefix ( filepath . Ext ( lastFrag ) , "." )
2020-03-28 04:48:42 +00:00
if len ( ext ) != 0 {
2019-12-08 03:40:56 +00:00
if ImageFileExts . Contains ( ext ) {
2020-04-30 06:28:01 +00:00
media . Type = EImage
2019-12-08 03:40:56 +00:00
var sport string
if port != "443" && port != "80" && port != "" {
sport = ":" + port
}
media . URL = scheme + "//" + host + sport + path
return media , true
2017-10-12 03:24:14 +00:00
}
2020-04-30 06:28:01 +00:00
// TODO: Support external videos
2017-10-12 03:24:14 +00:00
}
}
}
2019-10-13 04:45:15 +00:00
var sport string
if port != "443" && port != "80" && port != "" {
sport = ":" + port
}
2019-10-13 07:32:05 +00:00
var q string
if len ( uurl . RawQuery ) > 0 {
q = "?" + uurl . RawQuery
}
var frag string
if len ( uurl . Fragment ) > 0 {
frag = "#" + uurl . Fragment
}
2019-10-27 23:53:16 +00:00
media . FURL = host + sport + path + q + frag
2019-12-08 03:40:56 +00:00
media . URL = scheme + "//" + media . FURL
2019-10-13 04:45:15 +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
return media , true
}
2017-06-05 11:57:27 +00:00
2020-07-15 07:05:06 +00:00
func parseDuration ( dur string ) ( s , m , h int ) {
2020-06-25 07:46:09 +00:00
var ibuf [ ] byte
for _ , ch := range dur {
switch {
case ch > 47 && ch < 58 :
2020-07-15 07:05:06 +00:00
ibuf = append ( ibuf , byte ( ch ) )
2020-06-25 07:46:09 +00:00
case ch == 'h' :
h , _ = strconv . Atoi ( string ( ibuf ) )
ibuf = ibuf [ : 0 ]
case ch == 'm' :
m , _ = strconv . Atoi ( string ( ibuf ) )
ibuf = ibuf [ : 0 ]
case ch == 's' :
s , _ = strconv . Atoi ( string ( ibuf ) )
ibuf = ibuf [ : 0 ]
}
}
// Stop accidental uses of timestamps
if h == 0 && m == 0 && s < 2 {
s = 0
}
2020-07-15 07:05:06 +00:00
return s , m , h
2020-06-25 07:46:09 +00:00
}
2017-09-23 19:57:13 +00:00
// TODO: Write a test for this
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func CoerceIntString ( data string ) ( res , length int ) {
2017-03-12 07:18:12 +00:00
if ! ( data [ 0 ] > 47 && data [ 0 ] < 58 ) {
return 0 , 1
}
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 ) {
2018-09-20 01:51:18 +00:00
conv , err := strconv . Atoi ( data [ 0 : i ] )
2017-03-12 07:18:12 +00:00
if err != nil {
return 0 , i
}
return conv , i
}
}
2017-06-05 11:57:27 +00:00
2018-09-20 01:51:18 +00:00
conv , err := strconv . Atoi ( data )
2017-03-12 07:18:12 +00:00
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
2019-02-10 05:52:26 +00:00
// Make sure we reflect changes to this in the JS port in /public/global.js
2019-12-08 03:40:56 +00:00
func Paginate ( currentPage , lastPage , maxPages int ) ( out [ ] int ) {
2019-06-04 05:48:12 +00:00
diff := lastPage - currentPage
pre := 3
if diff < 3 {
pre = maxPages - diff
2017-08-15 13:47:56 +00:00
}
2019-10-13 04:45:15 +00:00
2019-06-04 05:48:12 +00:00
page := currentPage - pre
if page < 0 {
page = 0
}
for len ( out ) < maxPages && page < lastPage {
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
}
return out
}
2017-09-10 16:57:22 +00:00
// TODO: Write tests for this
2019-02-10 05:52:26 +00:00
// Make sure we reflect changes to this in the JS port in /public/global.js
2019-12-08 03:40:56 +00:00
func PageOffset ( count , page , perPage int ) ( int , int , int ) {
2017-08-15 13:47:56 +00:00
var offset int
2018-12-28 07:12:14 +00:00
lastPage := LastPage ( count , perPage )
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
}
2019-02-24 01:29:06 +00:00
// ? - This has been commented out as it created a bug in the user manager where the first user on a page wouldn't be accessible
2017-08-15 13:47:56 +00:00
// We don't want the offset to overflow the slices, if everything's in memory
2019-02-24 01:29:06 +00:00
/ * if offset >= ( count - 1 ) {
2017-08-15 13:47:56 +00:00
offset = 0
2019-02-24 01:29:06 +00:00
} * /
2017-08-15 13:47:56 +00:00
return offset , page , lastPage
}
2018-12-28 07:12:14 +00:00
// TODO: Write tests for this
2019-02-10 05:52:26 +00:00
// Make sure we reflect changes to this in the JS port in /public/global.js
2019-12-08 03:40:56 +00:00
func LastPage ( count , perPage int ) int {
2018-12-28 07:12:14 +00:00
return ( count / perPage ) + 1
}