2016-12-02 07:38:54 +00:00
|
|
|
|
package main
|
2017-06-16 10:41:30 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
//import "fmt"
|
2017-06-16 10:41:30 +00:00
|
|
|
|
import "sync"
|
2017-03-07 07:22:29 +00:00
|
|
|
|
import "bytes"
|
2016-12-02 07:38:54 +00:00
|
|
|
|
import "strings"
|
2017-03-12 07:18:12 +00:00
|
|
|
|
import "strconv"
|
2017-01-05 14:41:14 +00:00
|
|
|
|
import "regexp"
|
2017-04-06 17:37:32 +00:00
|
|
|
|
import "html/template"
|
2016-12-02 07:38:54 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type HeaderVars struct {
|
|
|
|
|
NoticeList []string
|
|
|
|
|
Scripts []string
|
2017-06-16 10:41:30 +00:00
|
|
|
|
Stylesheets []string
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Widgets PageWidgets
|
|
|
|
|
Site *Site
|
|
|
|
|
Settings map[string]interface{}
|
2017-09-10 16:57:22 +00:00
|
|
|
|
Themes map[string]Theme // TODO: Use a slice containing every theme instead of the main map for speed
|
2017-09-03 04:50:31 +00:00
|
|
|
|
ThemeName string
|
|
|
|
|
ExtData ExtData
|
2017-06-19 08:06:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
|
// TODO: Add this to routes which don't use templates. E.g. Json APIs.
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type HeaderLite struct {
|
|
|
|
|
Site *Site
|
2017-08-20 09:39:02 +00:00
|
|
|
|
Settings SettingBox
|
2017-09-03 04:50:31 +00:00
|
|
|
|
ExtData ExtData
|
2017-08-20 09:39:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PageWidgets struct {
|
|
|
|
|
LeftSidebar template.HTML
|
2017-06-25 09:56:39 +00:00
|
|
|
|
RightSidebar template.HTML
|
2017-06-16 10:41:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
|
|
|
|
/*type UnsafeExtData struct
|
|
|
|
|
{
|
|
|
|
|
items map[string]interface{} // Key: pluginname
|
|
|
|
|
}*/
|
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
|
// TODO: Add a ExtDataHolder interface with methods for manipulating the contents?
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type ExtData struct {
|
2017-06-16 10:41:30 +00:00
|
|
|
|
items map[string]interface{} // Key: pluginname
|
|
|
|
|
sync.RWMutex
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type Page struct {
|
|
|
|
|
Title string
|
2016-12-18 12:56:06 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []interface{}
|
|
|
|
|
Something interface{}
|
2016-12-18 12:56:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type TopicPage struct {
|
|
|
|
|
Title string
|
2016-12-02 07:38:54 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []Reply
|
|
|
|
|
Topic TopicUser
|
|
|
|
|
Page int
|
|
|
|
|
LastPage int
|
2016-12-02 07:38:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type TopicsPage struct {
|
|
|
|
|
Title string
|
2017-01-01 15:45:43 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []*TopicsRow
|
2017-01-01 15:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type ForumPage struct {
|
|
|
|
|
Title string
|
2017-01-01 15:45:43 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []*TopicsRow
|
|
|
|
|
Forum Forum
|
|
|
|
|
Page int
|
|
|
|
|
LastPage int
|
2017-01-01 15:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type ForumsPage struct {
|
|
|
|
|
Title string
|
2017-01-01 15:45:43 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []Forum
|
2017-01-01 15:45:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type ProfilePage struct {
|
|
|
|
|
Title string
|
|
|
|
|
CurrentUser User
|
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []Reply
|
2016-12-26 04:44:07 +00:00
|
|
|
|
ProfileOwner User
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type CreateTopicPage struct {
|
|
|
|
|
Title string
|
2017-02-05 14:41:53 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList []Forum
|
|
|
|
|
FID int
|
2017-02-05 14:41:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type IPSearchPage struct {
|
|
|
|
|
Title string
|
|
|
|
|
CurrentUser User
|
|
|
|
|
Header *HeaderVars
|
|
|
|
|
ItemList map[int]*User
|
|
|
|
|
IP string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type PanelStats struct {
|
|
|
|
|
Users int
|
|
|
|
|
Groups int
|
|
|
|
|
Forums int
|
|
|
|
|
Settings int
|
2017-08-27 09:33:45 +00:00
|
|
|
|
WordFilters int
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Themes int
|
|
|
|
|
Reports int
|
2017-08-15 13:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelPage struct {
|
|
|
|
|
Title string
|
2017-08-15 13:47:56 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ItemList []interface{}
|
|
|
|
|
Something interface{}
|
2017-08-15 13:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type GridElement struct {
|
|
|
|
|
ID string
|
|
|
|
|
Body string
|
|
|
|
|
Order int // For future use
|
|
|
|
|
Class string
|
2017-05-07 08:31:41 +00:00
|
|
|
|
Background string
|
|
|
|
|
TextColour string
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Note string
|
2017-05-07 08:31:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelDashboardPage struct {
|
|
|
|
|
Title string
|
2017-05-07 08:31:41 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
GridItems []GridElement
|
2017-05-07 08:31:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelThemesPage struct {
|
|
|
|
|
Title string
|
|
|
|
|
CurrentUser User
|
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
2017-03-07 07:22:29 +00:00
|
|
|
|
PrimaryThemes []Theme
|
|
|
|
|
VariantThemes []Theme
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelUserPage struct {
|
|
|
|
|
Title string
|
2017-08-17 11:13:49 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ItemList []User
|
|
|
|
|
PageList []int
|
|
|
|
|
Page int
|
|
|
|
|
LastPage int
|
2017-08-17 11:13:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelGroupPage struct {
|
|
|
|
|
Title string
|
2017-08-17 11:13:49 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ItemList []GroupAdmin
|
|
|
|
|
PageList []int
|
|
|
|
|
Page int
|
|
|
|
|
LastPage int
|
2017-08-17 11:13:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelEditGroupPage struct {
|
|
|
|
|
Title string
|
2017-03-18 07:23:02 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ID int
|
|
|
|
|
Name string
|
|
|
|
|
Tag string
|
|
|
|
|
Rank string
|
2017-03-18 07:23:02 +00:00
|
|
|
|
DisableRank bool
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type GroupForumPermPreset struct {
|
2017-09-15 22:20:01 +00:00
|
|
|
|
Group *Group
|
2017-06-05 11:57:27 +00:00
|
|
|
|
Preset string
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelEditForumPage struct {
|
|
|
|
|
Title string
|
2017-06-05 11:57:27 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ID int
|
|
|
|
|
Name string
|
|
|
|
|
Desc string
|
|
|
|
|
Active bool
|
|
|
|
|
Preset string
|
|
|
|
|
Groups []GroupForumPermPreset
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-13 15:09:13 +00:00
|
|
|
|
/*type NameLangPair struct {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Name string
|
2017-03-23 12:13:50 +00:00
|
|
|
|
LangStr string
|
2017-09-13 15:09:13 +00:00
|
|
|
|
}*/
|
2017-03-23 12:13:50 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type NameLangToggle struct {
|
|
|
|
|
Name string
|
2017-03-23 12:13:50 +00:00
|
|
|
|
LangStr string
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Toggle bool
|
2017-03-23 12:13:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelEditGroupPermsPage struct {
|
|
|
|
|
Title string
|
2017-03-23 12:13:50 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
ID int
|
|
|
|
|
Name string
|
|
|
|
|
LocalPerms []NameLangToggle
|
2017-03-23 12:13:50 +00:00
|
|
|
|
GlobalPerms []NameLangToggle
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
|
type Log struct {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Action template.HTML
|
2017-04-06 17:37:32 +00:00
|
|
|
|
IPAddress string
|
2017-09-03 04:50:31 +00:00
|
|
|
|
DoneAt string
|
2017-04-06 17:37:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelLogsPage struct {
|
|
|
|
|
Title string
|
2017-04-06 17:37:32 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
Logs []Log
|
|
|
|
|
PageList []int
|
|
|
|
|
Page int
|
|
|
|
|
LastPage int
|
2017-04-06 17:37:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PanelDebugPage struct {
|
|
|
|
|
Title string
|
2017-08-15 13:47:56 +00:00
|
|
|
|
CurrentUser User
|
2017-09-03 04:50:31 +00:00
|
|
|
|
Header *HeaderVars
|
|
|
|
|
Stats PanelStats
|
|
|
|
|
Uptime string
|
|
|
|
|
OpenConns int
|
|
|
|
|
DBAdapter string
|
2017-08-15 13:47:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type PageSimple struct {
|
|
|
|
|
Title string
|
2016-12-05 07:21:17 +00:00
|
|
|
|
Something interface{}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
type AreYouSure struct {
|
|
|
|
|
URL string
|
2016-12-06 10:26:48 +00:00
|
|
|
|
Message string
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
var spaceGap = []byte(" ")
|
|
|
|
|
var httpProtBytes = []byte("http://")
|
|
|
|
|
var invalidURL = []byte("<span style='color: red;'>[Invalid URL]</span>")
|
|
|
|
|
var invalidTopic = []byte("<span style='color: red;'>[Invalid Topic]</span>")
|
|
|
|
|
var invalidProfile = []byte("<span style='color: red;'>[Invalid Profile]</span>")
|
|
|
|
|
var invalidForum = []byte("<span style='color: red;'>[Invalid Forum]</span>")
|
|
|
|
|
var urlOpen = []byte("<a href='")
|
|
|
|
|
var urlOpen2 = []byte("'>")
|
|
|
|
|
var bytesSinglequote = []byte("'")
|
|
|
|
|
var bytesGreaterthan = []byte(">")
|
|
|
|
|
var urlMention = []byte(" class='mention'")
|
|
|
|
|
var urlClose = []byte("</a>")
|
|
|
|
|
var urlpattern = `(?s)([ {1}])((http|https|ftp|mailto)*)(:{??)\/\/([\.a-zA-Z\/]+)([ {1}])`
|
|
|
|
|
var urlReg *regexp.Regexp
|
2017-01-05 14:41:14 +00:00
|
|
|
|
|
|
|
|
|
func init() {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
urlReg = regexp.MustCompile(urlpattern)
|
2017-01-05 14:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func shortcodeToUnicode(msg string) string {
|
2016-12-08 14:11:18 +00:00
|
|
|
|
//re := regexp.MustCompile(":(.):")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = strings.Replace(msg, ":grinning:", "😀", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":grin:", "😁", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":joy:", "😂", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":rofl:", "🤣", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":smiley:", "😃", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":smile:", "😄", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sweat_smile:", "😅", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":laughing:", "😆", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":satisfied:", "😆", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":wink:", "😉", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":blush:", "😊", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":yum:", "😋", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sunglasses:", "😎", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":heart_eyes:", "😍", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":kissing_heart:", "😘", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":kissing:", "😗", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":kissing_smiling_eyes:", "😙", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":kissing_closed_eyes:", "😚", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":relaxed:", "☺️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":slight_smile:", "🙂", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":hugging:", "🤗", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":thinking:", "🤔", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":neutral_face:", "😐", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":expressionless:", "😑", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":no_mouth:", "😶", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":rolling_eyes:", "🙄", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":smirk:", "😏", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":persevere:", "😣", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":disappointed_relieved:", "😥", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":open_mouth:", "😮", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":zipper_mouth:", "🤐", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":hushed:", "😯", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sleepy:", "😪", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":tired_face:", "😫", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sleeping:", "😴", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":relieved:", "😌", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":nerd:", "🤓", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":stuck_out_tongue:", "😛", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":worried:", "😟", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":drooling_face:", "🤤", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":disappointed:", "😞", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":astonished:", "😲", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":slight_frown:", "🙁", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":skull_crossbones:", "☠️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":skull:", "💀", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":point_up:", "☝️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":v:", "✌️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":writing_hand:", "✍️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":heart:", "❤️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":heart_exclamation:", "❣️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":hotsprings:", "♨️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":airplane:", "✈️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":hourglass:", "⌛", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":watch:", "⌚", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":comet:", "☄️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":snowflake:", "❄️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":cloud:", "☁️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sunny:", "☀️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":spades:", "♠️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":hearts:", "♥️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":diamonds:", "♦️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":clubs:", "♣️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":phone:", "☎️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":telephone:", "☎️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":biohazard:", "☣️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":radioactive:", "☢️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":scissors:", "✂️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_upper_right:", "↗️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_right:", "➡️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_lower_right:", "↘️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_lower_left:", "↙️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_upper_left:", "↖️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_up_down:", "↕️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":left_right_arrow:", "↔️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":leftwards_arrow_with_hook:", "↩️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_right_hook:", "↪️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_forward:", "▶️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":arrow_backward:", "◀️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":female:", "♀️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":male:", "♂️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":ballot_box_with_check:", "☑️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":heavy_check_mark:", "✔️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":heavy_multiplication_x:", "✖️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":pisces:", "♓", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":aquarius:", "♒", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":capricorn:", "♑", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sagittarius:", "♐", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":scorpius:", "♏", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":libra:", "♎", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":virgo:", "♍", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":leo:", "♌", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":cancer:", "♋", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":gemini:", "♊", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":taurus:", "♉", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":aries:", "♈", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":peace:", "☮️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":eight_spoked_asterisk:", "✳️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":eight_pointed_black_star:", "✴️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":snowman2:", "☃️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":umbrella2:", "☂️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":pencil2:", "✏️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":black_nib:", "✒️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":email:", "✉️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":envelope:", "✉️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":keyboard:", "⌨️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":white_small_square:", "▫️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":black_small_square:", "▪️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":secret:", "㊙️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":congratulations:", "㊗️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":m:", "Ⓜ️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":tm:", "™️️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":registered:", "®️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":copyright:", "©️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":wavy_dash:", "〰️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":bangbang:", "‼️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":sparkle:", "❇️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":star_of_david:", "✡️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":wheel_of_dharma:", "☸️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":yin_yang:", "☯️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":cross:", "✝️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":orthodox_cross:", "☦️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":star_and_crescent:", "☪️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":frowning2:", "☹️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":information_source:", "ℹ️", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":interrobang:", "⁉️", -1)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2016-12-13 02:14:14 +00:00
|
|
|
|
return msg
|
2016-12-08 14:11:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func preparseMessage(msg string) string {
|
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
|
|
|
|
if sshooks["preparse_preassign"] != nil {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = runSshook("preparse_preassign", msg)
|
2016-12-13 02:14:14 +00:00
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
return shortcodeToUnicode(msg)
|
2016-12-03 08:09:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func parseMessage(msg string /*, user User*/) string {
|
|
|
|
|
msg = strings.Replace(msg, ":)", "😀", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":(", "😞", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":D", "😃", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":P", "😛", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":O", "😲", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":p", "😛", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":o", "😲", -1)
|
2017-03-07 07:22:29 +00:00
|
|
|
|
//msg = url_reg.ReplaceAllString(msg,"<a href=\"$2$3//$4\" rel=\"nofollow\">$2$3//$4</a>")
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-08-27 09:33:45 +00:00
|
|
|
|
// Word filter list. E.g. Swear words and other things the admins don't like
|
|
|
|
|
wordFilters := wordFilterBox.Load().(WordFilterBox)
|
|
|
|
|
for _, filter := range wordFilters {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = strings.Replace(msg, filter.Find, filter.Replacement, -1)
|
2017-08-27 09:33:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-14 10:57:40 +00:00
|
|
|
|
// Search for URLs, mentions and hashlinks in the messages...
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("Parser Loop!")
|
2017-03-07 07:22:29 +00:00
|
|
|
|
var msgbytes = []byte(msg)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
var outbytes []byte
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msgbytes = append(msgbytes, spaceGap...)
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print(`"`+string(msgbytes)+`"`)
|
2017-03-07 07:22:29 +00:00
|
|
|
|
lastItem := 0
|
|
|
|
|
i := 0
|
|
|
|
|
for ; len(msgbytes) > (i + 1); i++ {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("Index:",i)
|
|
|
|
|
//log.Print("Index Item:",msgbytes[i])
|
2017-03-14 10:57:40 +00:00
|
|
|
|
//if msgbytes[i] == 10 {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
// log.Print("NEWLINE")
|
2017-03-14 10:57:40 +00:00
|
|
|
|
//} else if msgbytes[i] == 32 {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
// log.Print("SPACE")
|
2017-03-14 10:57:40 +00:00
|
|
|
|
//} else {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
// log.Print("string(msgbytes[i])",string(msgbytes[i]))
|
2017-03-14 10:57:40 +00:00
|
|
|
|
//}
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("End Index")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if (i == 0 && (msgbytes[0] > 32)) || ((msgbytes[i] < 33) && (msgbytes[i+1] > 32)) {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("IN")
|
|
|
|
|
//log.Print(msgbytes[i])
|
2017-03-14 10:57:40 +00:00
|
|
|
|
if (i != 0) || msgbytes[i] < 33 {
|
|
|
|
|
i++
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if msgbytes[i] == '#' {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("IN #")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(msgbytes[i+1:i+5], []byte("tid-")) {
|
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:i]...)
|
2017-03-12 07:18:12 +00:00
|
|
|
|
i += 5
|
|
|
|
|
start := i
|
2017-09-03 04:50:31 +00:00
|
|
|
|
tid, intLen := coerceIntBytes(msgbytes[start:])
|
|
|
|
|
i += intLen
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-15 22:20:01 +00:00
|
|
|
|
topic, err := topics.Get(tid)
|
2017-06-28 12:05:26 +00:00
|
|
|
|
if err != nil || !fstore.Exists(topic.ParentID) {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, invalidTopic...)
|
2017-03-12 07:18:12 +00:00
|
|
|
|
lastItem = i
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlOpen...)
|
|
|
|
|
var urlBit = []byte(buildTopicURL("", tid))
|
|
|
|
|
outbytes = append(outbytes, urlBit...)
|
|
|
|
|
outbytes = append(outbytes, urlOpen2...)
|
|
|
|
|
var tidBit = []byte("#tid-" + strconv.Itoa(tid))
|
|
|
|
|
outbytes = append(outbytes, tidBit...)
|
|
|
|
|
outbytes = append(outbytes, urlClose...)
|
2017-03-12 07:18:12 +00:00
|
|
|
|
lastItem = i
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("string(msgbytes)",string(msgbytes))
|
|
|
|
|
//log.Print(msgbytes)
|
|
|
|
|
//log.Print(msgbytes[lastItem - 1])
|
|
|
|
|
//log.Print(lastItem - 1)
|
|
|
|
|
//log.Print(msgbytes[lastItem])
|
|
|
|
|
//log.Print(lastItem)
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if bytes.Equal(msgbytes[i+1:i+5], []byte("rid-")) {
|
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:i]...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
i += 5
|
|
|
|
|
start := i
|
2017-09-03 04:50:31 +00:00
|
|
|
|
rid, intLen := coerceIntBytes(msgbytes[start:])
|
|
|
|
|
i += intLen
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
topic, err := getTopicByReply(rid)
|
2017-06-28 12:05:26 +00:00
|
|
|
|
if err != nil || !fstore.Exists(topic.ParentID) {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, invalidTopic...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
lastItem = i
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlOpen...)
|
|
|
|
|
var urlBit = []byte(buildTopicURL("", topic.ID))
|
|
|
|
|
outbytes = append(outbytes, urlBit...)
|
|
|
|
|
outbytes = append(outbytes, urlOpen2...)
|
|
|
|
|
var ridBit = []byte("#rid-" + strconv.Itoa(rid))
|
|
|
|
|
outbytes = append(outbytes, ridBit...)
|
|
|
|
|
outbytes = append(outbytes, urlClose...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
lastItem = i
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if bytes.Equal(msgbytes[i+1:i+5], []byte("fid-")) {
|
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:i]...)
|
2017-03-15 08:34:14 +00:00
|
|
|
|
i += 5
|
|
|
|
|
start := i
|
2017-09-03 04:50:31 +00:00
|
|
|
|
fid, intLen := coerceIntBytes(msgbytes[start:])
|
|
|
|
|
i += intLen
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
|
if !fstore.Exists(fid) {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, invalidForum...)
|
2017-03-15 08:34:14 +00:00
|
|
|
|
lastItem = i
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlOpen...)
|
2017-09-10 16:57:22 +00:00
|
|
|
|
var urlBit = []byte(buildForumURL("", fid))
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlBit...)
|
|
|
|
|
outbytes = append(outbytes, urlOpen2...)
|
|
|
|
|
var fidBit = []byte("#fid-" + strconv.Itoa(fid))
|
|
|
|
|
outbytes = append(outbytes, fidBit...)
|
|
|
|
|
outbytes = append(outbytes, urlClose...)
|
2017-03-15 08:34:14 +00:00
|
|
|
|
lastItem = i
|
2017-03-12 07:18:12 +00:00
|
|
|
|
} else {
|
2017-09-10 16:57:22 +00:00
|
|
|
|
// TODO: Forum Shortcode Link
|
2017-03-12 07:18:12 +00:00
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if msgbytes[i] == '@' {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("IN @")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:i]...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
i++
|
|
|
|
|
start := i
|
2017-09-03 04:50:31 +00:00
|
|
|
|
uid, intLen := coerceIntBytes(msgbytes[start:])
|
|
|
|
|
i += intLen
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-15 22:20:01 +00:00
|
|
|
|
menUser, err := users.Get(uid)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
if err != nil {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, invalidProfile...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
lastItem = i
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlOpen...)
|
|
|
|
|
var urlBit = []byte(menUser.Link)
|
|
|
|
|
outbytes = append(outbytes, urlBit...)
|
|
|
|
|
outbytes = append(outbytes, bytesSinglequote...)
|
|
|
|
|
outbytes = append(outbytes, urlMention...)
|
|
|
|
|
outbytes = append(outbytes, bytesGreaterthan...)
|
|
|
|
|
var uidBit = []byte("@" + menUser.Name)
|
|
|
|
|
outbytes = append(outbytes, uidBit...)
|
|
|
|
|
outbytes = append(outbytes, urlClose...)
|
2017-03-14 10:57:40 +00:00
|
|
|
|
lastItem = i
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print(string(msgbytes))
|
|
|
|
|
//log.Print(msgbytes)
|
|
|
|
|
//log.Print(msgbytes[lastItem - 1])
|
|
|
|
|
//log.Print("lastItem - 1",lastItem - 1)
|
|
|
|
|
//log.Print("msgbytes[lastItem]",msgbytes[lastItem])
|
|
|
|
|
//log.Print("lastItem",lastItem)
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if msgbytes[i] == 'h' || msgbytes[i] == 'f' || msgbytes[i] == 'g' {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("IN hfg")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if msgbytes[i+1] == 't' && msgbytes[i+2] == 't' && msgbytes[i+3] == 'p' {
|
|
|
|
|
if msgbytes[i+4] == 's' && msgbytes[i+5] == ':' && msgbytes[i+6] == '/' && msgbytes[i+7] == '/' {
|
2017-03-12 07:18:12 +00:00
|
|
|
|
// Do nothing
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if msgbytes[i+4] == ':' && msgbytes[i+5] == '/' && msgbytes[i+6] == '/' {
|
2017-03-12 07:18:12 +00:00
|
|
|
|
// Do nothing
|
|
|
|
|
} else {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if msgbytes[i+1] == 't' && msgbytes[i+2] == 'p' && msgbytes[i+3] == ':' && msgbytes[i+4] == '/' && msgbytes[i+5] == '/' {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
// Do nothing
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if msgbytes[i+1] == 'i' && msgbytes[i+2] == 't' && msgbytes[i+3] == ':' && msgbytes[i+4] == '/' && msgbytes[i+5] == '/' {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
// Do nothing
|
|
|
|
|
} else {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:i]...)
|
|
|
|
|
urlLen := partialURLBytesLen(msgbytes[i:])
|
|
|
|
|
if msgbytes[i+urlLen] != ' ' && msgbytes[i+urlLen] != 10 {
|
|
|
|
|
outbytes = append(outbytes, invalidURL...)
|
|
|
|
|
i += urlLen
|
2017-03-12 07:18:12 +00:00
|
|
|
|
continue
|
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
outbytes = append(outbytes, urlOpen...)
|
|
|
|
|
outbytes = append(outbytes, msgbytes[i:i+urlLen]...)
|
|
|
|
|
outbytes = append(outbytes, urlOpen2...)
|
|
|
|
|
outbytes = append(outbytes, msgbytes[i:i+urlLen]...)
|
|
|
|
|
outbytes = append(outbytes, urlClose...)
|
|
|
|
|
i += urlLen
|
2017-03-12 07:18:12 +00:00
|
|
|
|
lastItem = i
|
2017-03-07 07:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if lastItem != i && len(outbytes) != 0 {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("lastItem:",msgbytes[lastItem])
|
|
|
|
|
//log.Print("lastItem index:")
|
|
|
|
|
//log.Print(lastItem)
|
|
|
|
|
//log.Print("i:")
|
|
|
|
|
//log.Print(i)
|
|
|
|
|
//log.Print("lastItem to end:")
|
|
|
|
|
//log.Print(msgbytes[lastItem:])
|
|
|
|
|
//log.Print("-----")
|
2017-03-07 07:22:29 +00:00
|
|
|
|
calclen := len(msgbytes) - 10
|
|
|
|
|
if calclen <= lastItem {
|
|
|
|
|
calclen = lastItem
|
|
|
|
|
}
|
|
|
|
|
outbytes = append(outbytes, msgbytes[lastItem:calclen]...)
|
|
|
|
|
msg = string(outbytes)
|
|
|
|
|
}
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print(`"`+string(outbytes)+`"`)
|
|
|
|
|
//log.Print("msg",`"`+msg+`"`)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = strings.Replace(msg, "\n", "<br>", -1)
|
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
|
|
|
|
if sshooks["parse_assign"] != nil {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = runSshook("parse_assign", msg)
|
2017-03-07 07:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
return msg
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func regexParseMessage(msg string) string {
|
|
|
|
|
msg = strings.Replace(msg, ":)", "😀", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":D", "😃", -1)
|
|
|
|
|
msg = strings.Replace(msg, ":P", "😛", -1)
|
|
|
|
|
msg = urlReg.ReplaceAllString(msg, "<a href=\"$2$3//$4\" rel=\"nofollow\">$2$3//$4</a>")
|
|
|
|
|
msg = strings.Replace(msg, "\n", "<br>", -1)
|
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
|
|
|
|
if sshooks["parse_assign"] != nil {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
msg = runSshook("parse_assign", msg)
|
2016-12-13 02:14:14 +00:00
|
|
|
|
}
|
|
|
|
|
return msg
|
2017-03-07 07:22:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6, 7, 8, 6, 7
|
|
|
|
|
// ftp://, http://, https:// git://, mailto: (not a URL, just here for length comparison purposes)
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func validateURLBytes(data []byte) bool {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
datalen := len(data)
|
|
|
|
|
i := 0
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if datalen >= 6 {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(data[0:6], []byte("ftp://")) || bytes.Equal(data[0:6], []byte("git://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 6
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 7 && bytes.Equal(data[0:7], httpProtBytes) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 7
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 8 && bytes.Equal(data[0:8], []byte("https://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 8
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; datalen > i; i++ {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func validatedURLBytes(data []byte) (url []byte) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
datalen := len(data)
|
|
|
|
|
i := 0
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if datalen >= 6 {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(data[0:6], []byte("ftp://")) || bytes.Equal(data[0:6], []byte("git://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 6
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 7 && bytes.Equal(data[0:7], httpProtBytes) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 7
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 8 && bytes.Equal(data[0:8], []byte("https://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 8
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; datalen > i; i++ {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) {
|
2017-09-03 04:50:31 +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-03 04:50:31 +00:00
|
|
|
|
func partialURLBytes(data []byte) (url []byte) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
datalen := len(data)
|
|
|
|
|
i := 0
|
|
|
|
|
end := datalen - 1
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if datalen >= 6 {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(data[0:6], []byte("ftp://")) || bytes.Equal(data[0:6], []byte("git://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 6
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 7 && bytes.Equal(data[0:7], httpProtBytes) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 7
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 8 && bytes.Equal(data[0:8], []byte("https://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 8
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; end >= i; i++ {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) {
|
|
|
|
|
end = i
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
url = append(url, data[0:end]...)
|
|
|
|
|
return url
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func partialURLBytesLen(data []byte) int {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
datalen := len(data)
|
|
|
|
|
i := 0
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if datalen >= 6 {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print(string(data[0:5]))
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(data[0:6], []byte("ftp://")) || bytes.Equal(data[0:6], []byte("git://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 6
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 7 && bytes.Equal(data[0:7], httpProtBytes) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 7
|
2017-09-03 04:50:31 +00:00
|
|
|
|
} else if datalen >= 8 && bytes.Equal(data[0:8], []byte("https://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 8
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; datalen > i; i++ {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) {
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("Bad Character:",data[i])
|
2017-03-07 07:22:29 +00:00
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-08-13 11:22:34 +00:00
|
|
|
|
//log.Print("Data Length:",datalen)
|
2017-03-07 07:22:29 +00:00
|
|
|
|
return datalen
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func parseMediaBytes(data []byte) (protocol []byte, url []byte) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
datalen := len(data)
|
|
|
|
|
i := 0
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if datalen >= 6 {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
if bytes.Equal(data[0:6], []byte("ftp://")) || bytes.Equal(data[0:6], []byte("git://")) {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
i = 6
|
|
|
|
|
protocol = data[0:2]
|
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
|
|
|
|
|
protocol = []byte("http")
|
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
|
|
|
|
|
protocol = []byte("https")
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; datalen > i; i++ {
|
2017-03-07 07:22:29 +00:00
|
|
|
|
if data[i] != '\\' && data[i] != '_' && !(data[i] > 44 && data[i] < 58) && !(data[i] > 64 && data[i] < 91) && !(data[i] > 96 && data[i] < 123) {
|
2017-09-03 04:50:31 +00:00
|
|
|
|
return []byte(""), 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
|
|
|
|
if len(protocol) == 0 {
|
|
|
|
|
protocol = []byte("http")
|
|
|
|
|
}
|
|
|
|
|
return protocol, data[i:]
|
|
|
|
|
}
|
2017-03-12 07:18:12 +00:00
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func coerceIntBytes(data []byte) (res int, length int) {
|
2017-03-12 07:18:12 +00:00
|
|
|
|
if !(data[0] > 47 && data[0] < 58) {
|
|
|
|
|
return 0, 1
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-14 10:57:40 +00:00
|
|
|
|
i := 0
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for ; len(data) > i; i++ {
|
2017-03-12 07:18:12 +00:00
|
|
|
|
if !(data[i] > 47 && data[i] < 58) {
|
|
|
|
|
conv, err := strconv.Atoi(string(data[0:i]))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, i
|
|
|
|
|
}
|
|
|
|
|
return conv, i
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
|
2017-03-12 07:18:12 +00:00
|
|
|
|
conv, err := strconv.Atoi(string(data))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, i
|
|
|
|
|
}
|
|
|
|
|
return conv, i
|
|
|
|
|
}
|
2017-08-15 13:47:56 +00:00
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
|
// TODO: Write tests for this
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func paginate(count int, perPage int, maxPages int) []int {
|
|
|
|
|
if count < perPage {
|
2017-08-15 13:47:56 +00:00
|
|
|
|
return []int{1}
|
|
|
|
|
}
|
|
|
|
|
var page int
|
|
|
|
|
var out []int
|
2017-09-03 04:50:31 +00:00
|
|
|
|
for current := 0; current < count; current += perPage {
|
2017-08-15 13:47:56 +00:00
|
|
|
|
page++
|
2017-09-03 04:50:31 +00:00
|
|
|
|
out = append(out, page)
|
2017-08-15 13:47:56 +00:00
|
|
|
|
if len(out) >= maxPages {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return out
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-10 16:57:22 +00:00
|
|
|
|
// TODO: Write tests for this
|
2017-09-03 04:50:31 +00:00
|
|
|
|
func pageOffset(count int, page int, perPage int) (int, int, int) {
|
2017-08-15 13:47:56 +00:00
|
|
|
|
var offset int
|
2017-09-03 04:50:31 +00:00
|
|
|
|
lastPage := (count / perPage) + 1
|
2017-08-15 13:47:56 +00:00
|
|
|
|
if page > 1 {
|
|
|
|
|
offset = (perPage * page) - perPage
|
|
|
|
|
} else if page == -1 {
|
|
|
|
|
page = lastPage
|
|
|
|
|
offset = (perPage * page) - perPage
|
|
|
|
|
} else {
|
|
|
|
|
page = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We don't want the offset to overflow the slices, if everything's in memory
|
|
|
|
|
if offset >= (count - 1) {
|
|
|
|
|
offset = 0
|
|
|
|
|
}
|
|
|
|
|
return offset, page, lastPage
|
|
|
|
|
}
|