2016-12-02 07:38:54 +00:00
|
|
|
package main
|
2017-02-11 14:51:16 +00:00
|
|
|
//import "fmt"
|
2017-02-28 09:27:28 +00:00
|
|
|
import "strconv"
|
2016-12-04 06:16:59 +00:00
|
|
|
import "html/template"
|
2016-12-02 07:38:54 +00:00
|
|
|
|
|
|
|
type Topic struct
|
|
|
|
{
|
|
|
|
ID int
|
2017-06-28 12:05:26 +00:00
|
|
|
Slug string
|
2016-12-02 07:38:54 +00:00
|
|
|
Title string
|
|
|
|
Content string
|
|
|
|
CreatedBy int
|
|
|
|
Is_Closed bool
|
|
|
|
Sticky bool
|
|
|
|
CreatedAt string
|
2017-02-11 14:51:16 +00:00
|
|
|
LastReplyAt string
|
2017-06-05 11:57:27 +00:00
|
|
|
//LastReplyBy int
|
2016-12-02 07:38:54 +00:00
|
|
|
ParentID int
|
2017-01-10 06:51:28 +00:00
|
|
|
Status string // Deprecated. Marked for removal.
|
2017-01-21 18:16:27 +00:00
|
|
|
IpAddress string
|
|
|
|
PostCount int
|
2017-02-11 14:51:16 +00:00
|
|
|
LikeCount int
|
2017-06-05 11:57:27 +00:00
|
|
|
ClassName string // CSS Class Name
|
2017-06-12 09:03:14 +00:00
|
|
|
Data string // Used for report metadata
|
2016-12-02 07:38:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 05:00:21 +00:00
|
|
|
type TopicUser struct
|
|
|
|
{
|
|
|
|
ID int
|
2017-06-28 12:05:26 +00:00
|
|
|
Slug string
|
2016-12-03 05:00:21 +00:00
|
|
|
Title string
|
2017-02-11 14:51:16 +00:00
|
|
|
Content string
|
2016-12-03 05:00:21 +00:00
|
|
|
CreatedBy int
|
|
|
|
Is_Closed bool
|
|
|
|
Sticky bool
|
|
|
|
CreatedAt string
|
2017-02-06 04:52:19 +00:00
|
|
|
LastReplyAt string
|
2017-06-05 11:57:27 +00:00
|
|
|
//LastReplyBy int
|
2016-12-03 05:00:21 +00:00
|
|
|
ParentID int
|
2017-01-10 06:51:28 +00:00
|
|
|
Status string // Deprecated. Marked for removal.
|
2017-01-21 18:16:27 +00:00
|
|
|
IpAddress string
|
|
|
|
PostCount int
|
2017-02-10 13:39:13 +00:00
|
|
|
LikeCount int
|
2017-06-05 11:57:27 +00:00
|
|
|
ClassName string
|
2017-06-12 09:03:14 +00:00
|
|
|
Data string // Used for report metadata
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
UserSlug string
|
2016-12-03 05:00:21 +00:00
|
|
|
CreatedByName string
|
2017-02-11 14:51:16 +00:00
|
|
|
Group int
|
2016-12-03 05:00:21 +00:00
|
|
|
Avatar string
|
2016-12-07 09:34:09 +00:00
|
|
|
ContentLines int
|
|
|
|
Tag string
|
2016-12-09 13:46:29 +00:00
|
|
|
URL string
|
|
|
|
URLPrefix string
|
|
|
|
URLName string
|
2017-01-12 02:55:08 +00:00
|
|
|
Level int
|
2017-02-10 13:39:13 +00:00
|
|
|
Liked bool
|
2016-12-03 05:00:21 +00:00
|
|
|
}
|
2017-02-06 04:52:19 +00:00
|
|
|
|
|
|
|
type TopicsRow struct
|
|
|
|
{
|
|
|
|
ID int
|
2017-06-28 12:05:26 +00:00
|
|
|
Slug string
|
2017-02-06 04:52:19 +00:00
|
|
|
Title string
|
2017-02-11 14:51:16 +00:00
|
|
|
Content string
|
2017-02-06 04:52:19 +00:00
|
|
|
CreatedBy int
|
|
|
|
Is_Closed bool
|
|
|
|
Sticky bool
|
|
|
|
CreatedAt string
|
|
|
|
LastReplyAt string
|
2017-06-05 11:57:27 +00:00
|
|
|
//LastReplyBy int
|
2017-02-06 04:52:19 +00:00
|
|
|
ParentID int
|
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
|
|
|
Status string // Deprecated. Marked for removal. -Is there anything we could use it for?
|
2017-02-06 04:52:19 +00:00
|
|
|
IpAddress string
|
|
|
|
PostCount int
|
2017-02-10 13:39:13 +00:00
|
|
|
LikeCount int
|
2017-06-05 11:57:27 +00:00
|
|
|
ClassName string
|
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
UserSlug string
|
2017-02-06 04:52:19 +00:00
|
|
|
CreatedByName string
|
|
|
|
Avatar string
|
|
|
|
Css template.CSS
|
|
|
|
ContentLines int
|
|
|
|
Tag string
|
|
|
|
URL string
|
|
|
|
URLPrefix string
|
|
|
|
URLName string
|
|
|
|
Level int
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-02-06 04:52:19 +00:00
|
|
|
ForumName string //TopicsRow
|
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
|
|
|
ForumLink string
|
2017-02-06 04:52:19 +00:00
|
|
|
}
|
2017-02-11 14:51:16 +00:00
|
|
|
|
|
|
|
func get_topicuser(tid int) (TopicUser,error) {
|
2017-07-17 10:23:42 +00:00
|
|
|
if config.CacheTopicUser != CACHE_SQL {
|
2017-02-11 14:51:16 +00:00
|
|
|
topic, err := topics.Get(tid)
|
|
|
|
if err == nil {
|
|
|
|
user, err := users.CascadeGet(topic.CreatedBy)
|
|
|
|
if err != nil {
|
|
|
|
return TopicUser{ID:tid}, err
|
|
|
|
}
|
2017-02-15 10:49:30 +00:00
|
|
|
init_user_perms(user)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-02-11 14:51:16 +00:00
|
|
|
// We might be better off just passing seperate topic and user structs to the caller?
|
|
|
|
return copy_topic_to_topicuser(topic, user), nil
|
|
|
|
} else if users.GetLength() < users.GetCapacity() {
|
|
|
|
topic, err = topics.CascadeGet(tid)
|
|
|
|
if err != nil {
|
|
|
|
return TopicUser{ID:tid}, err
|
|
|
|
}
|
|
|
|
user, err := users.CascadeGet(topic.CreatedBy)
|
|
|
|
if err != nil {
|
|
|
|
return TopicUser{ID:tid}, err
|
|
|
|
}
|
2017-02-15 10:49:30 +00:00
|
|
|
init_user_perms(user)
|
2017-02-11 14:51:16 +00:00
|
|
|
tu := copy_topic_to_topicuser(topic, user)
|
|
|
|
return tu, nil
|
|
|
|
}
|
|
|
|
}
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-02-11 14:51:16 +00:00
|
|
|
tu := TopicUser{ID:tid}
|
|
|
|
err := get_topic_user_stmt.QueryRow(tid).Scan(&tu.Title, &tu.Content, &tu.CreatedBy, &tu.CreatedAt, &tu.Is_Closed, &tu.Sticky, &tu.ParentID, &tu.IpAddress, &tu.PostCount, &tu.LikeCount, &tu.CreatedByName, &tu.Avatar, &tu.Group, &tu.URLPrefix, &tu.URLName, &tu.Level)
|
2017-06-28 12:05:26 +00:00
|
|
|
tu.Slug = name_to_slug(tu.Title)
|
|
|
|
tu.UserSlug = name_to_slug(tu.CreatedByName)
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
the_topic := Topic{ID:tu.ID, Slug:tu.Slug, Title:tu.Title, Content:tu.Content, CreatedBy:tu.CreatedBy, Is_Closed:tu.Is_Closed, Sticky:tu.Sticky, CreatedAt:tu.CreatedAt, LastReplyAt:tu.LastReplyAt, ParentID:tu.ParentID, IpAddress:tu.IpAddress, PostCount:tu.PostCount, LikeCount:tu.LikeCount}
|
2017-02-11 14:51:16 +00:00
|
|
|
//fmt.Printf("%+v\n", the_topic)
|
2017-02-15 10:49:30 +00:00
|
|
|
tu.Tag = groups[tu.Group].Tag
|
2017-02-11 14:51:16 +00:00
|
|
|
topics.Add(&the_topic)
|
|
|
|
return tu, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func copy_topic_to_topicuser(topic *Topic, user *User) (tu TopicUser) {
|
2017-06-28 12:05:26 +00:00
|
|
|
tu.UserSlug = user.Slug
|
2017-02-11 14:51:16 +00:00
|
|
|
tu.CreatedByName = user.Name
|
|
|
|
tu.Group = user.Group
|
|
|
|
tu.Avatar = user.Avatar
|
|
|
|
tu.URLPrefix = user.URLPrefix
|
|
|
|
tu.URLName = user.URLName
|
|
|
|
tu.Level = user.Level
|
2017-06-05 11:57:27 +00:00
|
|
|
|
2017-02-11 14:51:16 +00:00
|
|
|
tu.ID = topic.ID
|
2017-06-28 12:05:26 +00:00
|
|
|
tu.Slug = topic.Slug
|
2017-02-11 14:51:16 +00:00
|
|
|
tu.Title = topic.Title
|
|
|
|
tu.Content = topic.Content
|
|
|
|
tu.CreatedBy = topic.CreatedBy
|
|
|
|
tu.Is_Closed = topic.Is_Closed
|
|
|
|
tu.Sticky = topic.Sticky
|
|
|
|
tu.CreatedAt = topic.CreatedAt
|
|
|
|
tu.LastReplyAt = topic.LastReplyAt
|
|
|
|
tu.ParentID = topic.ParentID
|
|
|
|
tu.IpAddress = topic.IpAddress
|
|
|
|
tu.PostCount = topic.PostCount
|
|
|
|
tu.LikeCount = topic.LikeCount
|
2017-06-12 09:03:14 +00:00
|
|
|
tu.Data = topic.Data
|
2017-06-28 12:05:26 +00:00
|
|
|
|
2017-02-11 14:51:16 +00:00
|
|
|
return tu
|
2017-02-28 09:27:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func get_topic_by_reply(rid int) (*Topic, error) {
|
|
|
|
topic := Topic{ID:0}
|
2017-06-12 09:03:14 +00:00
|
|
|
err := get_topic_by_reply_stmt.QueryRow(rid).Scan(&topic.ID, &topic.Title, &topic.Content, &topic.CreatedBy, &topic.CreatedAt, &topic.Is_Closed, &topic.Sticky, &topic.ParentID, &topic.IpAddress, &topic.PostCount, &topic.LikeCount, &topic.Data)
|
2017-06-28 12:05:26 +00:00
|
|
|
topic.Slug = name_to_slug(topic.Title)
|
2017-02-28 09:27:28 +00:00
|
|
|
return &topic, err
|
|
|
|
}
|
|
|
|
|
2017-06-28 12:05:26 +00:00
|
|
|
func build_topic_url(slug string, tid int) string {
|
|
|
|
if slug == "" {
|
|
|
|
return "/topic/" + strconv.Itoa(tid)
|
|
|
|
}
|
|
|
|
return "/topic/" + slug + "." + strconv.Itoa(tid)
|
2017-02-28 09:27:28 +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
|
|
|
|
|
|
|
func get_topic_url_prefix() string {
|
|
|
|
return "/topic/"
|
|
|
|
}
|