2017-09-13 15:09:13 +00:00
/ *
*
* Gosora Topic File
* Copyright Azareal 2017 - 2018
*
* /
2017-11-10 03:33:11 +00:00
package common
2017-09-03 04:50:31 +00:00
2017-09-28 22:16:34 +00:00
import (
2017-11-11 04:06:16 +00:00
"database/sql"
2017-12-30 10:07:57 +00:00
"html"
2017-09-28 22:16:34 +00:00
"html/template"
"strconv"
2017-10-14 07:39:22 +00:00
"time"
2017-11-11 04:06:16 +00:00
"../query_gen/lib"
2017-09-28 22:16:34 +00:00
)
2017-11-08 07:28:33 +00:00
// This is also in reply.go
//var ErrAlreadyLiked = errors.New("This item was already liked by this user")
2017-09-28 22:16:34 +00:00
// ? - Add a TopicMeta struct for *Forums?
2016-12-02 07:38:54 +00:00
2017-09-03 04:50:31 +00:00
type Topic struct {
2017-10-16 07:32:58 +00:00
ID int
Link string
Title string
Content string
CreatedBy int
IsClosed bool
Sticky bool
2017-11-02 02:52:21 +00:00
CreatedAt time . Time
RelativeCreatedAt string
2017-10-16 07:32:58 +00:00
LastReplyAt time . Time
RelativeLastReplyAt string
2017-06-05 11:57:27 +00:00
//LastReplyBy int
2017-09-03 04:50:31 +00:00
ParentID int
Status string // Deprecated. Marked for removal.
IPAddress string
2017-01-21 18:16:27 +00:00
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
2018-01-26 05:53:34 +00:00
Poll int
2017-09-03 04:50:31 +00:00
Data string // Used for report metadata
2016-12-02 07:38:54 +00:00
}
2017-09-03 04:50:31 +00:00
type TopicUser struct {
2017-10-16 07:32:58 +00:00
ID int
Link string
Title string
Content string
CreatedBy int
IsClosed bool
Sticky bool
2017-11-02 02:52:21 +00:00
CreatedAt time . Time
RelativeCreatedAt string
2017-10-16 07:32:58 +00:00
LastReplyAt time . Time
RelativeLastReplyAt string
2017-06-05 11:57:27 +00:00
//LastReplyBy int
2017-09-03 04:50:31 +00:00
ParentID int
Status string // Deprecated. Marked for removal.
IPAddress string
2017-01-21 18:16:27 +00:00
PostCount int
2017-02-10 13:39:13 +00:00
LikeCount int
2017-06-05 11:57:27 +00:00
ClassName string
2018-01-26 05:53:34 +00:00
Poll int
2017-09-03 04:50:31 +00:00
Data string // Used for report metadata
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
UserLink string
2016-12-03 05:00:21 +00:00
CreatedByName string
2017-09-03 04:50:31 +00:00
Group int
Avatar string
ContentLines int
2017-09-28 22:16:34 +00:00
ContentHTML string
2017-09-03 04:50:31 +00:00
Tag string
URL string
URLPrefix string
URLName string
Level int
Liked bool
2016-12-03 05:00:21 +00:00
}
2017-02-06 04:52:19 +00:00
2017-09-03 04:50:31 +00:00
type TopicsRow struct {
2017-10-14 07:39:22 +00:00
ID int
Link string
Title string
Content string
CreatedBy int
IsClosed bool
Sticky bool
CreatedAt string
LastReplyAt time . Time
RelativeLastReplyAt string
LastReplyBy int
ParentID int
Status string // Deprecated. Marked for removal. -Is there anything we could use it for?
IPAddress string
PostCount int
LikeCount int
ClassName string
Data string // Used for report metadata
2017-09-03 04:50:31 +00:00
Creator * User
CSS template . CSS
2017-02-06 04:52:19 +00:00
ContentLines int
2017-09-03 04:50:31 +00:00
LastUser * User
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
2017-11-11 04:06:16 +00:00
type TopicStmts struct {
addRepliesToTopic * sql . Stmt
lock * sql . Stmt
unlock * sql . Stmt
2018-01-14 12:03:20 +00:00
moveTo * sql . Stmt
2017-11-11 04:06:16 +00:00
stick * sql . Stmt
unstick * sql . Stmt
hasLikedTopic * sql . Stmt
createLike * sql . Stmt
addLikesToTopic * sql . Stmt
delete * sql . Stmt
edit * sql . Stmt
2018-01-25 04:57:33 +00:00
setPoll * sql . Stmt
2017-11-11 04:06:16 +00:00
createActionReply * sql . Stmt
getTopicUser * sql . Stmt // TODO: Can we get rid of this?
2018-01-20 06:50:29 +00:00
getByReplyID * sql . Stmt
2017-11-11 04:06:16 +00:00
}
var topicStmts TopicStmts
func init ( ) {
2017-11-12 03:29:05 +00:00
DbInits . Add ( func ( acc * qgen . Accumulator ) error {
2017-11-11 04:06:16 +00:00
topicStmts = TopicStmts {
2017-11-11 08:46:30 +00:00
addRepliesToTopic : acc . Update ( "topics" ) . Set ( "postCount = postCount + ?, lastReplyBy = ?, lastReplyAt = UTC_TIMESTAMP()" ) . Where ( "tid = ?" ) . Prepare ( ) ,
lock : acc . Update ( "topics" ) . Set ( "is_closed = 1" ) . Where ( "tid = ?" ) . Prepare ( ) ,
unlock : acc . Update ( "topics" ) . Set ( "is_closed = 0" ) . Where ( "tid = ?" ) . Prepare ( ) ,
2018-01-14 12:03:20 +00:00
moveTo : acc . Update ( "topics" ) . Set ( "parentID = ?" ) . Where ( "tid = ?" ) . Prepare ( ) ,
2017-11-11 08:46:30 +00:00
stick : acc . Update ( "topics" ) . Set ( "sticky = 1" ) . Where ( "tid = ?" ) . Prepare ( ) ,
unstick : acc . Update ( "topics" ) . Set ( "sticky = 0" ) . Where ( "tid = ?" ) . Prepare ( ) ,
hasLikedTopic : acc . Select ( "likes" ) . Columns ( "targetItem" ) . Where ( "sentBy = ? and targetItem = ? and targetType = 'topics'" ) . Prepare ( ) ,
2018-03-31 05:25:27 +00:00
createLike : acc . Insert ( "likes" ) . Columns ( "weight, targetItem, targetType, sentBy, createdAt" ) . Fields ( "?,?,?,?,UTC_TIMESTAMP()" ) . Prepare ( ) ,
2017-11-11 08:46:30 +00:00
addLikesToTopic : acc . Update ( "topics" ) . Set ( "likeCount = likeCount + ?" ) . Where ( "tid = ?" ) . Prepare ( ) ,
delete : acc . Delete ( "topics" ) . Where ( "tid = ?" ) . Prepare ( ) ,
2018-01-25 04:57:33 +00:00
edit : acc . Update ( "topics" ) . Set ( "title = ?, content = ?, parsed_content = ?" ) . Where ( "tid = ?" ) . Prepare ( ) , // TODO: Only run the content update bits on non-polls, does this matter?
setPoll : acc . Update ( "topics" ) . Set ( "content = '', parsed_content = '', poll = ?" ) . Where ( "tid = ? AND poll = 0" ) . Prepare ( ) ,
2017-11-11 08:46:30 +00:00
createActionReply : acc . Insert ( "replies" ) . Columns ( "tid, actionType, ipaddress, createdBy, createdAt, lastUpdated, content, parsed_content" ) . Fields ( "?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''" ) . Prepare ( ) ,
2018-01-26 05:53:34 +00:00
getTopicUser : acc . SimpleLeftJoin ( "topics" , "users" , "topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount, topics.poll, users.name, users.avatar, users.group, users.url_prefix, users.url_name, users.level" , "topics.createdBy = users.uid" , "tid = ?" , "" , "" ) ,
getByReplyID : acc . SimpleLeftJoin ( "replies" , "topics" , "topics.tid, topics.title, topics.content, topics.createdBy, topics.createdAt, topics.is_closed, topics.sticky, topics.parentID, topics.ipaddress, topics.postCount, topics.likeCount, topics.poll, topics.data" , "replies.tid = topics.tid" , "rid = ?" , "" , "" ) ,
2017-11-11 04:06:16 +00:00
}
return acc . FirstError ( )
} )
}
2017-11-08 07:28:33 +00:00
// Flush the topic out of the cache
// ? - We do a CacheRemove() here instead of mutating the pointer to avoid creating a race condition
func ( topic * Topic ) cacheRemove ( ) {
2017-12-19 03:53:13 +00:00
tcache := Topics . GetCache ( )
2017-11-23 05:37:08 +00:00
if tcache != nil {
tcache . Remove ( topic . ID )
2017-09-22 02:21:17 +00:00
}
2017-11-08 07:28:33 +00:00
}
// TODO: Write a test for this
func ( topic * Topic ) AddReply ( uid int ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . addRepliesToTopic . Exec ( 1 , uid , topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
return err
}
func ( topic * Topic ) Lock ( ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . lock . Exec ( topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-22 02:21:17 +00:00
return err
}
func ( topic * Topic ) Unlock ( ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . unlock . Exec ( topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-22 02:21:17 +00:00
return err
}
2018-01-14 12:03:20 +00:00
func ( topic * Topic ) MoveTo ( destForum int ) ( err error ) {
_ , err = topicStmts . moveTo . Exec ( destForum , topic . ID )
topic . cacheRemove ( )
return err
}
2017-09-22 02:21:17 +00:00
// TODO: We might want more consistent terminology rather than using stick in some places and pin in others. If you don't understand the difference, there is none, they are one and the same.
func ( topic * Topic ) Stick ( ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . stick . Exec ( topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-22 02:21:17 +00:00
return err
}
func ( topic * Topic ) Unstick ( ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . unstick . Exec ( topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-22 02:21:17 +00:00
return err
}
2017-11-08 07:28:33 +00:00
// TODO: Test this
// TODO: Use a transaction for this
func ( topic * Topic ) Like ( score int , uid int ) ( err error ) {
2018-03-31 05:25:27 +00:00
var disp int // Unused
err = topicStmts . hasLikedTopic . QueryRow ( uid , topic . ID ) . Scan ( & disp )
2017-11-08 07:28:33 +00:00
if err != nil && err != ErrNoRows {
return err
} else if err != ErrNoRows {
return ErrAlreadyLiked
}
2018-03-31 05:25:27 +00:00
_ , err = topicStmts . createLike . Exec ( score , topic . ID , "topics" , uid )
2017-11-08 07:28:33 +00:00
if err != nil {
return err
}
2018-03-31 05:25:27 +00:00
_ , err = topicStmts . addLikesToTopic . Exec ( 1 , topic . ID )
if err != nil {
return err
}
_ , err = userStmts . incrementLiked . Exec ( 1 , uid )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
return err
2017-09-22 02:21:17 +00:00
}
// TODO: Implement this
2017-11-08 07:28:33 +00:00
func ( topic * Topic ) Unlike ( uid int ) error {
2017-09-22 02:21:17 +00:00
return nil
}
2017-10-30 09:57:08 +00:00
// TODO: Use a transaction here
func ( topic * Topic ) Delete ( ) error {
2017-11-11 04:06:16 +00:00
topicCreator , err := Users . Get ( topic . CreatedBy )
2017-10-30 09:57:08 +00:00
if err == nil {
2017-11-11 04:06:16 +00:00
wcount := WordCount ( topic . Content )
err = topicCreator . DecreasePostStats ( wcount , true )
2017-10-30 09:57:08 +00:00
if err != nil {
return err
}
} else if err != ErrNoRows {
return err
}
2017-11-23 05:37:08 +00:00
err = Forums . RemoveTopic ( topic . ParentID )
2017-10-30 09:57:08 +00:00
if err != nil && err != ErrNoRows {
return err
}
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . delete . Exec ( topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-10-30 09:57:08 +00:00
return err
}
2017-12-30 10:07:57 +00:00
// TODO: Write tests for this
2017-09-28 22:16:34 +00:00
func ( topic * Topic ) Update ( name string , content string ) error {
2018-05-31 06:51:31 +00:00
name = SanitiseSingleLine ( html . UnescapeString ( name ) )
2018-03-17 08:16:43 +00:00
if name == "" {
return ErrNoTitle
}
// ? This number might be a little screwy with Unicode, but it's the only consistent thing we have, as Unicode characters can be any number of bytes in theory?
if len ( name ) > Config . MaxTopicTitleLength {
return ErrLongTitle
}
2017-12-30 10:07:57 +00:00
content = PreparseMessage ( html . UnescapeString ( content ) )
2017-12-30 05:47:46 +00:00
parsedContent := ParseMessage ( content , topic . ParentID , "forums" )
2017-11-11 04:06:16 +00:00
_ , err := topicStmts . edit . Exec ( name , content , parsedContent , topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-28 22:16:34 +00:00
return err
}
2018-01-25 04:57:33 +00:00
func ( topic * Topic ) SetPoll ( pollID int ) error {
_ , err := topicStmts . setPoll . Exec ( pollID , topic . ID ) // TODO: Sniff if this changed anything to see if we hit an existing poll
2018-01-27 07:30:44 +00:00
topic . cacheRemove ( )
2018-01-25 04:57:33 +00:00
return err
}
2017-11-11 04:06:16 +00:00
// TODO: Have this go through the ReplyStore?
2017-09-22 02:21:17 +00:00
func ( topic * Topic ) CreateActionReply ( action string , ipaddress string , user User ) ( err error ) {
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . createActionReply . Exec ( topic . ID , action , ipaddress , user . ID )
2017-09-22 02:21:17 +00:00
if err != nil {
return err
}
2017-11-11 04:06:16 +00:00
_ , err = topicStmts . addRepliesToTopic . Exec ( 1 , user . ID , topic . ID )
2017-11-08 07:28:33 +00:00
topic . cacheRemove ( )
2017-09-22 02:21:17 +00:00
// ? - Update the last topic cache for the parent forum?
return err
}
2018-01-27 07:30:44 +00:00
func ( topic * Topic ) GetID ( ) int {
return topic . ID
}
func ( topic * Topic ) GetTable ( ) string {
return "topics"
}
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
// Copy gives you a non-pointer concurrency safe copy of the topic
2017-09-28 22:16:34 +00:00
func ( topic * Topic ) Copy ( ) Topic {
return * topic
}
2018-01-20 06:50:29 +00:00
func TopicByReplyID ( rid int ) ( * Topic , error ) {
topic := Topic { ID : 0 }
2018-01-26 05:53:34 +00:00
err := topicStmts . getByReplyID . QueryRow ( rid ) . Scan ( & topic . ID , & topic . Title , & topic . Content , & topic . CreatedBy , & topic . CreatedAt , & topic . IsClosed , & topic . Sticky , & topic . ParentID , & topic . IPAddress , & topic . PostCount , & topic . LikeCount , & topic . Poll , & topic . Data )
2018-01-20 06:50:29 +00:00
topic . Link = BuildTopicURL ( NameToSlug ( topic . Title ) , topic . ID )
return & topic , err
}
2017-09-15 22:20:01 +00:00
// TODO: Refactor the caller to take a Topic and a User rather than a combined TopicUser
2017-11-11 04:06:16 +00:00
func GetTopicUser ( tid int ) ( TopicUser , error ) {
2017-11-23 05:37:08 +00:00
tcache := Topics . GetCache ( )
ucache := Users . GetCache ( )
if tcache != nil && ucache != nil {
topic , err := tcache . Get ( tid )
2017-02-11 14:51:16 +00:00
if err == nil {
2017-11-11 04:06:16 +00:00
user , err := Users . Get ( topic . CreatedBy )
2017-02-11 14:51:16 +00:00
if err != nil {
2017-09-03 04:50:31 +00:00
return TopicUser { ID : tid } , err
2017-02-11 14:51:16 +00:00
}
2017-06-05 11:57:27 +00:00
2017-10-30 09:57:08 +00:00
// We might be better off just passing separate topic and user structs to the caller?
2017-09-28 22:16:34 +00:00
return copyTopicToTopicUser ( topic , user ) , nil
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 ucache . Length ( ) < ucache . GetCapacity ( ) {
2017-11-11 04:06:16 +00:00
topic , err = Topics . Get ( tid )
2017-02-11 14:51:16 +00:00
if err != nil {
2017-09-03 04:50:31 +00:00
return TopicUser { ID : tid } , err
2017-02-11 14:51:16 +00:00
}
2017-11-11 04:06:16 +00:00
user , err := Users . Get ( topic . CreatedBy )
2017-02-11 14:51:16 +00:00
if err != nil {
2017-09-03 04:50:31 +00:00
return TopicUser { ID : tid } , err
2017-02-11 14:51:16 +00:00
}
2017-09-28 22:16:34 +00:00
return copyTopicToTopicUser ( topic , user ) , nil
2017-02-11 14:51:16 +00:00
}
}
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
tu := TopicUser { ID : tid }
2018-01-26 05:53:34 +00:00
err := topicStmts . getTopicUser . QueryRow ( tid ) . Scan ( & tu . Title , & tu . Content , & tu . CreatedBy , & tu . CreatedAt , & tu . IsClosed , & tu . Sticky , & tu . ParentID , & tu . IPAddress , & tu . PostCount , & tu . LikeCount , & tu . Poll , & tu . CreatedByName , & tu . Avatar , & tu . Group , & tu . URLPrefix , & tu . URLName , & tu . Level )
2017-11-11 04:06:16 +00:00
tu . Link = BuildTopicURL ( NameToSlug ( tu . Title ) , tu . ID )
tu . UserLink = BuildProfileURL ( NameToSlug ( tu . CreatedByName ) , tu . CreatedBy )
2017-11-23 05:37:08 +00:00
tu . Tag = Groups . DirtyGet ( tu . Group ) . Tag
2017-06-05 11:57:27 +00:00
2017-11-23 05:37:08 +00:00
if tcache != nil {
2018-01-26 05:53:34 +00:00
theTopic := Topic { ID : tu . ID , Link : tu . Link , Title : tu . Title , Content : tu . Content , CreatedBy : tu . CreatedBy , IsClosed : tu . IsClosed , Sticky : tu . Sticky , CreatedAt : tu . CreatedAt , LastReplyAt : tu . LastReplyAt , ParentID : tu . ParentID , IPAddress : tu . IPAddress , PostCount : tu . PostCount , LikeCount : tu . LikeCount , Poll : tu . Poll }
2017-11-11 04:06:16 +00:00
//log.Printf("theTopic: %+v\n", theTopic)
2017-11-23 05:37:08 +00:00
_ = tcache . Add ( & theTopic )
2017-09-15 22:20:01 +00:00
}
2017-02-11 14:51:16 +00:00
return tu , err
}
2017-09-28 22:16:34 +00:00
func copyTopicToTopicUser ( topic * Topic , user * User ) ( tu TopicUser ) {
2017-07-29 14:04:20 +00:00
tu . UserLink = user . Link
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-07-29 14:04:20 +00:00
tu . Link = topic . Link
2017-02-11 14:51:16 +00:00
tu . Title = topic . Title
tu . Content = topic . Content
tu . CreatedBy = topic . CreatedBy
2017-09-03 04:50:31 +00:00
tu . IsClosed = topic . IsClosed
2017-02-11 14:51:16 +00:00
tu . Sticky = topic . Sticky
tu . CreatedAt = topic . CreatedAt
tu . LastReplyAt = topic . LastReplyAt
tu . ParentID = topic . ParentID
2017-09-03 04:50:31 +00:00
tu . IPAddress = topic . IPAddress
2017-02-11 14:51:16 +00:00
tu . PostCount = topic . PostCount
tu . LikeCount = topic . LikeCount
2018-01-26 05:53:34 +00:00
tu . Poll = topic . Poll
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
}
2017-09-28 22:16:34 +00:00
// For use in tests and for generating blank topics for forums which don't have a last poster
2017-11-11 04:06:16 +00:00
func BlankTopic ( ) * Topic {
2018-06-06 06:13:55 +00:00
return new ( Topic )
2017-09-28 22:16:34 +00:00
}
2017-11-11 04:06:16 +00:00
func BuildTopicURL ( slug string , tid int ) string {
2018-04-03 04:34:07 +00:00
if slug == "" || ! Config . BuildSlugs {
2017-06-28 12:05:26 +00:00
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
2017-09-03 04:50:31 +00:00
// I don't care if it isn't used,, it will likely be in the future. Nolint.
// nolint
func getTopicURLPrefix ( ) 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
return "/topic/"
}