2017-11-10 03:33:11 +00:00
|
|
|
package common
|
2017-09-28 22:16:34 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
var pluginLangs = make(map[string]PluginLang)
|
|
|
|
|
|
|
|
// For non-native plugins to bind JSON files to. E.g. JS and Lua
|
|
|
|
type PluginMeta struct {
|
|
|
|
UName string
|
|
|
|
Name string
|
|
|
|
Author string
|
|
|
|
URL string
|
|
|
|
Settings string
|
|
|
|
Tag string
|
|
|
|
|
2017-11-02 13:35:19 +00:00
|
|
|
Skip bool // Skip this folder?
|
2017-09-28 22:16:34 +00:00
|
|
|
Main string // The main file
|
|
|
|
Hooks map[string]string // Hooks mapped to functions
|
|
|
|
}
|
|
|
|
|
|
|
|
type PluginLang interface {
|
|
|
|
GetName() string
|
|
|
|
GetExts() []string
|
|
|
|
|
|
|
|
Init() error
|
|
|
|
AddPlugin(meta PluginMeta) (*Plugin, error)
|
|
|
|
//AddHook(name string, handler interface{}) error
|
|
|
|
//RemoveHook(name string, handler interface{})
|
|
|
|
//RunHook(name string, data interface{}) interface{}
|
|
|
|
//RunVHook(name string data ...interface{}) interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
var ext = filepath.Ext(pluginFile.Name())
|
|
|
|
if ext == ".txt" || ext == ".go" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func InitPluginLangs() error {
|
|
|
|
for _, pluginLang := range pluginLangs {
|
|
|
|
pluginLang.Init()
|
|
|
|
}
|
|
|
|
pluginList, err := GetPluginFiles()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, pluginItem := range pluginList {
|
|
|
|
pluginFile, err := ioutil.ReadFile("./extend/" + pluginItem + "/plugin.json")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var plugin PluginMeta
|
|
|
|
err = json.Unmarshal(pluginFile, &plugin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-02 13:35:19 +00:00
|
|
|
if plugin.Skip {
|
|
|
|
continue
|
|
|
|
}
|
2017-09-28 22:16:34 +00:00
|
|
|
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
e := func(field, name string) error {
|
|
|
|
return errors.New("The " + field + " field must not be blank on plugin '" + name + "'")
|
2019-10-27 23:53:16 +00:00
|
|
|
}
|
2017-09-28 22:16:34 +00:00
|
|
|
if plugin.UName == "" {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
return e("UName", pluginItem)
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
if plugin.Name == "" {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
return e("Name", pluginItem)
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
if plugin.Author == "" {
|
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
|
|
|
return e("Author", pluginItem)
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
if plugin.Main == "" {
|
|
|
|
return errors.New("Couldn't find a main file for plugin '" + pluginItem + "'")
|
|
|
|
}
|
|
|
|
|
2019-09-29 04:56:39 +00:00
|
|
|
ext := filepath.Ext(plugin.Main)
|
2017-09-28 22:16:34 +00:00
|
|
|
pluginLang, err := ExtToPluginLang(ext)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pplugin, err := pluginLang.AddPlugin(plugin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-11-11 04:06:16 +00:00
|
|
|
Plugins[plugin.UName] = pplugin
|
2017-09-28 22:16:34 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetPluginFiles() (pluginList []string, err error) {
|
|
|
|
pluginFiles, err := ioutil.ReadDir("./extend")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, pluginFile := range pluginFiles {
|
|
|
|
if !pluginFile.IsDir() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pluginList = append(pluginList, pluginFile.Name())
|
|
|
|
}
|
|
|
|
return pluginList, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ExtToPluginLang(ext string) (PluginLang, error) {
|
|
|
|
for _, pluginLang := range pluginLangs {
|
|
|
|
for _, registeredExt := range pluginLang.GetExts() {
|
|
|
|
if registeredExt == ext {
|
|
|
|
return pluginLang, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, errors.New("No plugin lang handlers are capable of handling extension '" + ext + "'")
|
|
|
|
}
|