47963e10a9
Renamed the rrow_assign hook to topic_reply_row_assign and gave it access to more data. Fixed a bug where the topic store wouldn't fetch the last reply time for a topic. Refactored the process of adding and removing topics from and to a *Forum. Fixed a bug where editing the opening post of a topic would yield a vast number of <br>s instead of blank lines. Selecting text in Shadow now has it's own CSS instead of falling back onto the browser defaults. Fixed a bug in Shadow where not all the headers filled up the space they should. Fixed a bug in Shadow where the footer is broken on mobile. Added an ARIA Label to the topic list. Refactored the last poster logic to reduce the number of bugs. Renamed ReplyShort to Reply and Reply to ReplyUser. Added a Copy method to Reply, Group, Forum, User, and Topic. Rewrote Hello World into something slightly more useful for new plugin devs to learn off. Added the GetLength() method to ForumCache.
117 lines
2.6 KiB
Go
117 lines
2.6 KiB
Go
package main
|
|
|
|
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
|
|
|
|
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
|
|
}
|
|
|
|
if plugin.UName == "" {
|
|
return errors.New("The UName field must not be blank on plugin '" + pluginItem + "'")
|
|
}
|
|
if plugin.Name == "" {
|
|
return errors.New("The Name field must not be blank on plugin '" + pluginItem + "'")
|
|
}
|
|
if plugin.Author == "" {
|
|
return errors.New("The Author field must not be blank on plugin '" + pluginItem + "'")
|
|
}
|
|
if plugin.Main == "" {
|
|
return errors.New("Couldn't find a main file for plugin '" + pluginItem + "'")
|
|
}
|
|
|
|
var ext = filepath.Ext(plugin.Main)
|
|
pluginLang, err := ExtToPluginLang(ext)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
pplugin, err := pluginLang.AddPlugin(plugin)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
plugins[plugin.UName] = pplugin
|
|
}
|
|
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 + "'")
|
|
}
|