plugin

package
v0.5.0-beta.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HookPriorityEarly  = -100
	HookPriorityNormal = 0
	HookPriorityLate   = 100
)
View Source
const (
	HookContentBeforeSave       = "content.before_save"
	HookContentAfterSave        = "content.after_save"
	HookContentBeforeDelete     = "content.before_delete"
	HookContentAfterDelete      = "content.after_delete"
	HookContentBeforeStatus     = "content.before_status_change"
	HookContentAfterStatus      = "content.after_status_change"
	HookContentFilter           = "content.filter"
	HookContentBeforeRender     = "content.before_render"
	HookContentAfterRender      = "content.after_render"
	HookContentTitle            = "content.title"
	HookContentParse            = "content.parse"
	HookExcerpt                 = "content.excerpt"
	HookExcerptAfterRender      = "excerpt.after_render"
	HookContentList             = "content.list"
	HookContentFields           = "content.fields"
	HookContentFieldReadOnly    = "content.field_read_only"
	HookContentPermalink        = "content.permalink"
	HookContentAuthor           = "content.author"
	HookCommentBeforeSave       = "comment.before_save"
	HookCommentAfterSave        = "comment.after_save"
	HookCommentBeforeMark       = "comment.before_mark"
	HookCommentAfterMark        = "comment.after_mark"
	HookCommentBeforeDelete     = "comment.before_delete"
	HookCommentAfterDelete      = "comment.after_delete"
	HookCommentFilter           = "comment.filter"
	HookCommentBeforeRender     = "comment.before_render"
	HookCommentAfterRender      = "comment.after_render"
	HookCommentParse            = "comment.parse"
	HookCommentAvatar           = "comment.avatar"
	HookCommentPermalink        = "comment.permalink"
	HookCommentListRender       = "comment.list_render"
	HookCommentReplyLink        = "comment.reply_link"
	HookCommentPageNav          = "comment.page_nav"
	HookCommentGuard            = "comment.guard_validate"
	HookUploadBeforeSave        = "upload.before_save"
	HookUploadHandle            = "upload.handle"
	HookUploadAfterSave         = "upload.after_save"
	HookAttachmentBeforeEdit    = "attachment.before_edit"
	HookAttachmentAfterEdit     = "attachment.after_edit"
	HookAttachmentBeforeReplace = "attachment.before_replace"
	HookAttachmentReplaceHandle = "attachment.replace_handle"
	HookAttachmentAfterReplace  = "attachment.after_replace"
	HookAttachmentBeforeDelete  = "attachment.before_delete"
	HookAttachmentDeleteHandle  = "attachment.delete_handle"
	HookAttachmentAfterDelete   = "attachment.after_delete"
	HookAttachmentURL           = "attachment.url"
	HookAttachmentData          = "attachment.data"
	HookRequestBefore           = "request.before"
	HookRequestFallback         = "request.fallback"
	HookRequestAfter            = "request.after"
	HookUserLoginBefore         = "user.login_before"
	HookUserLoginAuthenticated  = "user.login_authenticated"
	HookUserLoginAfter          = "user.login_after"
	HookUserLoginFail           = "user.login_fail"
	HookUserLogout              = "user.logout"
	HookUserRegisterBefore      = "user.register_before"
	HookUserRegisterAfter       = "user.register_after"
	HookAdminMenu               = "admin.menu"
	HookFrontendHead            = "frontend.head"
	HookFrontendFooter          = "frontend.footer"
	HookArchiveBeforeQuery      = "archive.before_query"
	HookArchiveAfterQuery       = "archive.after_query"
	HookArchiveBeforeRender     = "archive.before_render"
	HookArchiveAfterRender      = "archive.after_render"
	HookArchiveSearch           = "archive.search"
	HookMetaPermalink           = "meta.permalink"
	HookFeedItem                = "feed.item"
	HookFeedCommentItem         = "feed.comment_item"
	HookXMLRPCTextFilter        = "xmlrpc.text_filter"
	HookXMLRPCUpload            = "xmlrpc.upload"
	HookXMLRPCPingback          = "xmlrpc.pingback"
	HookXMLRPCFinishPingback    = "xmlrpc.finish_pingback"
	HookTrackback               = "trackback.handle"
	HookFinishTrackback         = "trackback.finish"
	HookBackupExport            = "backup.export"
	HookBackupImport            = "backup.import"
	HookUserHashValidate        = "user.hash_validate"
	HookRevisionBeforeSave      = "revision.before_save"
	HookRevisionAfterSave       = "revision.after_save"
	HookWAFCheck                = "waf.check"
	HookImageProcess            = "image.process"
	HookAutosaveBeforeSave      = "autosave.before_save"
	HookAutosaveAfterSave       = "autosave.after_save"
)
View Source
const (
	NoticeInfo    = "info"
	NoticeSuccess = "success"
	NoticeWarning = "warning"
	NoticeError   = "error"

	NoticeAuto     = "auto"
	NoticeSnackbar = "snackbar"
	NoticeCard     = "card"
)
View Source
const GopherInkVersion = "0.5.0"

Variables

View Source
var (
	ErrRuntimeUnavailable = errors.New("plugin runtime unavailable")
	ErrServiceUnavailable = errors.New("plugin service unavailable")
)
View Source
var Default = NewManager()

Functions

func Compatible

func Compatible(required, current string) bool

func ContextWithRuntime

func ContextWithRuntime(ctx context.Context, runtime *Runtime) context.Context

func DatabaseTableName

func DatabaseTableName(owner, name string) string

func JoinMultiValue

func JoinMultiValue(values []string) string

JoinMultiValue encodes selected values for a multi-value field.

func RebindSQL

func RebindSQL(dialect, query string) string

func Register

func Register(p Plugin)

func RegisterTheme

func RegisterTheme(theme Theme)

func SplitMultiValue

func SplitMultiValue(value string) []string

SplitMultiValue decodes a stored multi-value field back into its values. Multi-value fields persist as newline-joined tokens.

Types

type Activator

type Activator interface {
	Activate(context.Context, *Runtime) error
}

type AdminAction

type AdminAction struct {
	Name        string
	Label       string
	Icon        string
	Variant     string
	Description string
}

AdminAction describes a POST action rendered next to a plugin's save button.

type AdminActionProvider

type AdminActionProvider interface {
	AdminActions() []AdminAction
	HandleAdminAction(context.Context, *Runtime, string) (AdminNotice, error)
}

AdminActionProvider handles authenticated, CSRF-protected plugin settings actions.

type AdminMenuItem

type AdminMenuItem struct {
	Label      string
	URL        string
	Icon       string
	OpenNewTab bool
	// Owner is assigned by Manager so the admin renderer can use the
	// registering plugin's optional Translator. Plugins normally leave it blank.
	Owner string
}

type AdminMenuProvider

type AdminMenuProvider interface {
	AdminMenuItems(context.Context) []AdminMenuItem
}

type AdminNotice

type AdminNotice struct {
	Type         string `json:"type"`
	Mode         string `json:"mode,omitempty"`
	Message      string `json:"message"`
	SkipCoreI18n bool   `json:"skipCoreI18n,omitempty"`
}

AdminNotice is a plain-text message displayed by the native admin UI.

type AdminNoticeProvider

type AdminNoticeProvider interface {
	AdminNotices(context.Context, *Runtime, map[string]string) []AdminNotice
}

AdminNoticeProvider supplies messages for a plugin's native configuration page.

type AdminPage

type AdminPage struct {
	Name        string
	Label       string
	Icon        string
	Title       string
	Description string
}

AdminPage describes a native tab on a plugin or theme configuration page.

type AdminPageActionProvider

type AdminPageActionProvider interface {
	HandleAdminPageAction(context.Context, *Runtime, string, map[string][]string) (AdminPageActionResult, error)
}

AdminPageActionProvider handles POST actions from a native plugin page.

type AdminPageActionResult

type AdminPageActionResult struct {
	ConfigPatch map[string]string
	Notice      AdminNotice
}

type AdminPageProvider

type AdminPageProvider interface {
	AdminPages() []AdminPage
	RenderAdminPage(context.Context, *Runtime, string, AdminPageRenderContext) (template.HTML, error)
}

AdminPageProvider renders trusted plugin UI inside the authenticated admin shell.

type AdminPageRenderContext

type AdminPageRenderContext struct {
	CSRF   string
	Config map[string]string
	// Query carries the GET query parameters of the page request (same shape as
	// url.Values), so native pages can support pagination, filtering and other
	// stateful views through their own ?key=value links without a custom route.
	Query map[string][]string
}

type ArchivePayload

type ArchivePayload struct {
	Type    string
	Slug    string
	Query   *PublicContentQuery
	Results []PublicContent
	Total   int64
	Data    map[string]any
	Handled bool
}

type AttachmentDataPayload

type AttachmentDataPayload struct {
	Content any
	Meta    any
	Data    []byte
	Handled bool
}

type AttachmentDeleteHandlePayload

type AttachmentDeleteHandlePayload struct {
	Content any
	Meta    any
	Handled bool
}

type AttachmentEditPayload

type AttachmentEditPayload struct {
	Content     any
	Title       string
	Description string
	Meta        any
}

type AttachmentMetaInfo

type AttachmentMetaInfo struct {
	Name        string
	Description string
	URL         string
	MIME        string
	Size        int64
	IsImage     bool
	Width       int
	Height      int
}

type AttachmentPayload

type AttachmentPayload struct {
	Content any
	Meta    any
}

type AttachmentReplacePayload

type AttachmentReplacePayload struct {
	Content      any
	PreviousMeta any
	Name         string
	ParentID     int64
	Size         int64
	Open         func() (io.ReadCloser, error)
	Meta         any
	Warning      string
	Handled      bool
}

type AttachmentURLPayload

type AttachmentURLPayload struct {
	Content any
	Meta    any
	URL     string
}

type AutosavePayload

type AutosavePayload struct {
	ContentID int64
	Input     any
	Result    any
	Handled   bool
}

type BackupPayload

type BackupPayload struct {
	Data    any
	Handled bool
}

type ColumnDefinition

type ColumnDefinition struct {
	Name     string
	Type     ColumnType
	Length   int
	Nullable bool
	Default  string
	Primary  bool
	AutoInc  bool
}

type ColumnType

type ColumnType string
const (
	ColInt64    ColumnType = "int64"
	ColVarchar  ColumnType = "varchar"
	ColText     ColumnType = "text"
	ColFloat    ColumnType = "float"
	ColDatetime ColumnType = "datetime"
	ColBool     ColumnType = "bool"
)

type CommentActionPayload

type CommentActionPayload struct {
	ID             int64
	Status         string
	PreviousStatus string
	Comment        any
	Content        any
}

type CommentAvatarPayload

type CommentAvatarPayload struct {
	Comment any
	Mail    string
	Size    int
	URL     string
}

type CommentBadge

type CommentBadge struct {
	Label string
	Icon  string
	Tone  string
}

type CommentEnrichment

type CommentEnrichment struct {
	Badges     []CommentBadge
	CSSClasses []string
	Extra      map[string]any
}

type CommentFilterPayload

type CommentFilterPayload struct {
	Comment any
}

type CommentGuardPayload

type CommentGuardPayload struct {
	Request *http.Request
	CID     int64
	Token   string
	Valid   bool
	Reason  string
	Handled bool
}

type CommentLinkPayload

type CommentLinkPayload struct {
	Comment PublicComment
	Content PublicContent
	URL     string
	HTML    template.HTML
}

type CommentListPayload

type CommentListPayload struct {
	Content  PublicContent
	Comments []PublicComment
	Views    any
	Pager    any
	HTML     template.HTML
	Handled  bool
}

type CommentParserPayload

type CommentParserPayload struct {
	Comment any
	Text    string
	Mode    string
	HTML    template.HTML
	Handled bool
}

type CommentPermalinkPayload

type CommentPermalinkPayload struct {
	Comment PublicComment
	Content PublicContent
	URL     string
}

type CommentRenderPayload

type CommentRenderPayload struct {
	Comment any
	Text    string
	HTML    template.HTML
}

type CommentSavePayload

type CommentSavePayload struct {
	ID        int64
	Operation string
	Input     any
	Content   any
	Comment   any
}

type CommentWriteInput

type CommentWriteInput struct {
	ID        int64
	Operation string
	CID       int64
	Author    string
	AuthorID  int64
	OwnerID   int64
	Mail      string
	URL       string
	Text      string
	Type      string
	Status    string
	Parent    int64
	IP        string
	Agent     string
}

type ConfigHandler

type ConfigHandler interface {
	HandleConfig(ctx context.Context, rt *Runtime, values map[string]string, isInit bool) error
}

type ConfigProvider

type ConfigProvider interface {
	ConfigSchema() []FieldSchema
}

type ConfigValidator

type ConfigValidator interface {
	ValidateConfig(values map[string]string) map[string]string
}

type ContentAuthorPayload

type ContentAuthorPayload struct {
	Content PublicContent
	Author  PublicUser
}

type ContentDeletePayload

type ContentDeletePayload struct {
	ID      int64
	Content any
}

type ContentFieldInput

type ContentFieldInput struct {
	Name       string
	Type       string
	StrValue   string
	IntValue   int64
	FloatValue float64
}

type ContentFieldReadOnlyPayload

type ContentFieldReadOnlyPayload struct {
	ContentID int64
	Type      string
	Name      string
	ReadOnly  bool
}

type ContentFieldsPayload

type ContentFieldsPayload struct {
	ContentID int64
	Type      string
	Fields    []FieldSchema
}

type ContentFieldsProvider

type ContentFieldsProvider interface {
	ContentFieldSchema() []FieldSchema
}

type ContentFilterPayload

type ContentFilterPayload struct {
	Content any
}

type ContentListPayload

type ContentListPayload struct {
	Stage   string
	View    string
	Title   string
	Query   any
	Results any
	Total   int64
	Handled bool
}

type ContentParserPayload

type ContentParserPayload struct {
	Content any
	Text    string
	Mode    string
	HTML    template.HTML
	Handled bool
}

type ContentPermalinkPayload

type ContentPermalinkPayload struct {
	Content PublicContent
	URL     string
}

type ContentRenderPayload

type ContentRenderPayload struct {
	Content any
	HTML    template.HTML
	Data    map[string]any
}

type ContentSavePayload

type ContentSavePayload struct {
	ID          int64
	PublishedID int64
	AuthorID    int64
	Operation   string
	Input       any
	Content     any
}

type ContentStatusPayload

type ContentStatusPayload struct {
	ID             int64
	PreviousStatus string
	Status         string
	Content        any
}

type ContentTitlePayload

type ContentTitlePayload struct {
	Content any
	Title   string
}

type ContentWriteInput

type ContentWriteInput struct {
	ID           int64
	PublishedID  int64
	AuthorID     int64
	Operation    string
	Title        string
	Slug         string
	SlugID       int64
	Text         string
	Type         string
	Status       string
	Password     string
	Created      int64
	SortOrder    int64
	Template     string
	Parent       int64
	AllowComment bool
	AllowPing    bool
	AllowFeed    bool
	CategoryIDs  []int64
	Tags         []string
	Fields       []ContentFieldInput
	DraftOf      int64
}

type DatabaseMigrator

type DatabaseMigrator interface {
	Migrate(ctx context.Context, db *sql.DB, dialect string, fromVersion, toVersion int) error
}

type DatabaseProvider

type DatabaseProvider interface {
	DatabaseTables() []TableDefinition
	DatabaseVersion() int
}

type Deactivator

type Deactivator interface {
	Deactivate(context.Context, *Runtime) error
}

type ExcerptAfterPayload

type ExcerptAfterPayload struct {
	Content PublicContent
	Text    string
	Limit   int
	Excerpt string
}

type ExcerptPayload

type ExcerptPayload struct {
	Text   string
	Limit  int
	Output string
}

type FeedItemPayload

type FeedItemPayload struct {
	Kind    string
	Content PublicContent
	Comment PublicComment
	Item    any
	Handled bool
}

type FieldOption

type FieldOption struct {
	Label string
	Value string
}

type FieldSchema

type FieldSchema struct {
	Name          string
	Label         string
	Group         string
	Type          FieldType
	Default       string
	Description   string
	Required      bool
	ShowWhenField string
	ShowWhenValue string
	Min           string
	Max           string
	Step          string
	Options       []FieldOption
	ForTypes      []string
	ReadOnly      bool
	Wide          bool
	// Translate is attached while core collects theme and plugin content
	// fields, keeping extension-owned labels out of the core translation table.
	Translate func(string) string
}

type FieldType

type FieldType string
const (
	FieldText     FieldType = "text"
	FieldPassword FieldType = "password"
	FieldTextarea FieldType = "textarea"
	FieldRadio    FieldType = "radio"
	FieldCheckbox FieldType = "checkbox"
	FieldSelect   FieldType = "select"
	FieldNumber   FieldType = "number"
	FieldColor    FieldType = "color"
	FieldImage    FieldType = "image"
	// FieldSwitch renders an MDUI switch; the stored value is "1"/"0" like a checkbox.
	FieldSwitch FieldType = "switch"
	// FieldSlider renders an MDUI slider bound to Min/Max/Step; the stored value is numeric.
	FieldSlider FieldType = "slider"
	// FieldDate, FieldTime and FieldDatetime render native date/time pickers; the
	// stored value is the raw control value (YYYY-MM-DD, HH:MM, or YYYY-MM-DDTHH:MM).
	FieldDate     FieldType = "date"
	FieldTime     FieldType = "time"
	FieldDatetime FieldType = "datetime"
	// FieldMultiSelect and FieldMultiCheckbox store multiple selected values joined
	// by newlines, mirroring Typecho's Checkbox->multiMode()/multi-select forms.
	FieldMultiSelect   FieldType = "multiselect"
	FieldMultiCheckbox FieldType = "multicheckbox"
)

func (FieldType) IsBoolean

func (t FieldType) IsBoolean() bool

IsBooleanField reports whether a field type stores a "1"/"0" boolean value.

func (FieldType) IsMultiValue

func (t FieldType) IsMultiValue() bool

IsMultiValueField reports whether a field type stores several selected values.

type FrontendHTMLPayload

type FrontendHTMLPayload struct {
	Location string
	HTML     template.HTML
	Data     map[string]any
}

type HookControl

type HookControl struct {
	Payload any
	Stop    bool
}

HookControl lets a hook stop the remaining callbacks while preserving a payload.

func StopHook

func StopHook(payload any) HookControl

type HookDispatch

type HookDispatch struct {
	Payload   any
	Triggered bool
	Stopped   bool
}

HookDispatch reports whether a hook point was handled and whether propagation stopped.

type HookFunc

type HookFunc func(context.Context, any) (any, error)

type ImageProcessPayload

type ImageProcessPayload struct {
	Name    string
	Data    []byte
	MIME    string
	Result  []byte
	Warning string
	Handled bool
}

type IndexDefinition

type IndexDefinition struct {
	Name    string
	Columns []string
	Unique  bool
}

type InfoProvider

type InfoProvider interface {
	Info() PluginInfo
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) ActiveAdminMenuItems

func (m *Manager) ActiveAdminMenuItems(ctx context.Context) []AdminMenuItem

func (*Manager) ActivePublicPaths

func (m *Manager) ActivePublicPaths(ctx context.Context, runtime *Runtime) ([]string, error)

ActivePublicPaths collects configured paths from active plugins. Providers execute outside the manager lock so they can safely use Runtime services.

func (*Manager) ActiveRoutes

func (m *Manager) ActiveRoutes() []Route

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, name string, payload any) (any, error)

func (*Manager) ApplyActive

func (m *Manager) ApplyActive(ctx context.Context, name string, payload any) (any, error)

func (*Manager) CallActiveService

func (m *Manager) CallActiveService(ctx context.Context, runtime *Runtime, name string, args ...any) (any, error)

func (*Manager) Dispatch

func (m *Manager) Dispatch(ctx context.Context, name string, payload any) (HookDispatch, error)

func (*Manager) DispatchActive

func (m *Manager) DispatchActive(ctx context.Context, name string, payload any) (HookDispatch, error)

func (*Manager) HasActiveHook

func (m *Manager) HasActiveHook(name string) bool

func (*Manager) HasActiveService

func (m *Manager) HasActiveService(name string) bool

func (*Manager) IsActive

func (m *Manager) IsActive(name string) bool

func (*Manager) Plugin

func (m *Manager) Plugin(name string) (Plugin, bool)

func (*Manager) PluginInfo

func (m *Manager) PluginInfo(p Plugin) PluginInfo

func (*Manager) Plugins

func (m *Manager) Plugins() []Plugin

func (*Manager) Register

func (m *Manager) Register(p Plugin)

func (*Manager) RegisterAdminMenu

func (m *Manager) RegisterAdminMenu(item AdminMenuItem)

func (*Manager) RegisterHook

func (m *Manager) RegisterHook(name string, fn HookFunc)

func (*Manager) RegisterHookWithPriority

func (m *Manager) RegisterHookWithPriority(name string, priority int, fn HookFunc)

func (*Manager) RegisterPublicPathProvider

func (m *Manager) RegisterPublicPathProvider(provider PublicPathProvider)

RegisterPublicPathProvider registers runtime-configured exact public paths. The handler for those paths can be implemented by a registered route or by HookRequestFallback after the WAF route snapshot has accepted the path.

func (*Manager) RegisterRoute

func (m *Manager) RegisterRoute(method, pattern string, handler RouteHandler)

func (*Manager) RegisterRuntimeHook

func (m *Manager) RegisterRuntimeHook(name string, fn RuntimeHookFunc)

func (*Manager) RegisterRuntimeHookWithPriority

func (m *Manager) RegisterRuntimeHookWithPriority(name string, priority int, fn RuntimeHookFunc)

func (*Manager) RegisterService

func (m *Manager) RegisterService(name string, fn ServiceFunc)

RegisterService publishes a single-owner named service from Plugin.Init. Duplicate names fail during startup so callers never observe an ambiguous provider.

func (*Manager) RegisterTheme

func (m *Manager) RegisterTheme(theme Theme)

func (*Manager) Routes

func (m *Manager) Routes() []Route

func (*Manager) SetActivePlugins

func (m *Manager) SetActivePlugins(names []string)

func (*Manager) Theme

func (m *Manager) Theme(name string) (Theme, bool)

func (*Manager) Themes

func (m *Manager) Themes() []Theme

type MetaPermalinkPayload

type MetaPermalinkPayload struct {
	Meta PublicMeta
	URL  string
}

type PersonalConfigProvider

type PersonalConfigProvider interface {
	PersonalConfigSchema() []FieldSchema
}

type Plugin

type Plugin interface {
	Name() string
	Version() string
	Description() string
	Init(*Manager)
}

type PluginInfo

type PluginInfo struct {
	Name             string
	Version          string
	Author           string
	Description      string
	Homepage         string
	RequireGopherInk string
}

type PublicArchivePeriod

type PublicArchivePeriod struct {
	Year  int
	Month int
	Day   int
	Date  string
	Count int
	URL   string
}

type PublicComment

type PublicComment struct {
	COID     int64
	CID      int64
	Created  int64
	Author   string
	AuthorID int64
	// OwnerID is the author UID of the content this comment belongs to.
	OwnerID int64
	Mail    string
	URL     string
	IP      string
	Agent   string
	Text    string
	Type    string
	Status  string
	Parent  int64
	// Title, Slug and ContentType carry the source metadata that trackback and
	// pingback comments store; for a normal comment Title/Slug are empty and
	// ContentType mirrors the parent content type.
	Title       string
	Slug        string
	ContentType string
}

type PublicCommentQuery

type PublicCommentQuery struct {
	COID     int64
	Status   string
	Type     string
	Keywords string
	CID      int64
	AuthorID int64
	OwnerID  int64
	Mail     string
	IP       string
	Limit    int
	Offset   int
}

type PublicContent

type PublicContent struct {
	CID          int64
	Title        string
	Slug         string
	SlugID       int64
	Created      int64
	Modified     int64
	Text         string
	Type         string
	Status       string
	AuthorID     int64
	Password     string
	CommentsNum  int64
	AllowComment string
	AllowPing    string
	AllowFeed    string
	Template     string
	Parent       int64
	SortOrder    int64
	DraftOf      int64
}

type PublicContentQuery

type PublicContentQuery struct {
	CID           int64
	Slug          string
	SlugID        int64
	Type          string
	Status        string
	Keywords      string
	Category      int64
	Tag           int64
	AuthorID      int64
	Year          int
	Month         int
	Day           int
	Limit         int
	Offset        int
	IncludeDrafts bool
	ExcludeFuture bool
}

type PublicMeta

type PublicMeta struct {
	MID         int64
	Name        string
	Slug        string
	Type        string
	Description string
	Count       int64
	SortOrder   int64
	Parent      int64
}

type PublicMetaQuery

type PublicMetaQuery struct {
	MID    int64
	Type   string
	Slug   string
	Parent int64
	Used   bool
	Limit  int
	Offset int
}

type PublicPathProvider

type PublicPathProvider func(context.Context, *Runtime) ([]string, error)

PublicPathProvider returns exact public paths owned by a plugin whose paths are determined from runtime configuration. The core calls providers only while rebuilding its public route snapshot, never for each unknown request.

type PublicRevision

type PublicRevision struct {
	RID          int64
	CID          int64
	Created      int64
	AuthorID     int64
	Title        string
	Slug         string
	Text         string
	Status       string
	Password     string
	SortOrder    int64
	Template     string
	Parent       int64
	AllowComment string
	AllowPing    string
	AllowFeed    string
}

type PublicUser

type PublicUser struct {
	UID        int64
	Name       string
	Mail       string
	URL        string
	ScreenName string
	Role       string
}

type PublicUserQuery

type PublicUserQuery struct {
	UID      int64
	Name     string
	Mail     string
	Role     string
	Keywords string
	Limit    int
	Offset   int
}

type RequestPayload

type RequestPayload struct {
	Method          string
	Path            string
	RawQuery        string
	RemoteAddr      string
	IP              string
	UserAgent       string
	Referer         string
	Status          int
	Bytes           int64
	Duration        int64
	Admin           bool
	Static          bool
	ContentType     string
	Headers         map[string]string
	ResponseHeaders map[string]string
	Body            string
	Handled         bool
}

type RevisionPayload

type RevisionPayload struct {
	ContentID int64
	Revision  any
	Input     any
	Handled   bool
}

type Route

type Route struct {
	Plugin                string
	Method                string
	Pattern               string
	Handler               RouteHandler
	InvalidatesPublicData bool
}

type RouteHandler

type RouteHandler func(*Runtime, http.ResponseWriter, *http.Request)

type Runtime

type Runtime struct {
	OwnerKind                string
	Owner                    string
	ListContents             func(context.Context, PublicContentQuery) ([]PublicContent, int64, error)
	ListComments             func(context.Context, PublicCommentQuery) ([]PublicComment, int64, error)
	ListUsers                func(context.Context, PublicUserQuery) ([]PublicUser, int64, error)
	ListMetas                func(context.Context, PublicMetaQuery) ([]PublicMeta, int64, error)
	ListRevisions            func(context.Context, int64) ([]PublicRevision, error)
	GetRevision              func(context.Context, int64) (PublicRevision, error)
	RestoreRevision          func(context.Context, int64, int64) error
	DeleteRevision           func(context.Context, int64, int64) error
	ArchiveMonths            func(context.Context, int) ([]PublicArchivePeriod, error)
	AdjacentPosts            func(context.Context, int64) (PublicContent, PublicContent, error)
	RelatedPosts             func(context.Context, int64, int) ([]PublicContent, error)
	GetEditingDraft          func(context.Context, int64) (PublicContent, error)
	PublishDraft             func(context.Context, int64) error
	ListThemeFiles           func(context.Context, ...string) ([]string, error)
	ThemeEditableDir         func(context.Context, ...string) (string, bool)
	ContentURL               func(context.Context, int64) (string, error)
	CommentURL               func(context.Context, int64) (string, error)
	AvatarURL                func(context.Context, string, int) string
	Language                 func(context.Context) string
	SiteURL                  func(context.Context) string
	AdminURL                 func(context.Context) string
	ClientIP                 func(*http.Request) string
	CurrentUser              func(*http.Request) (PublicUser, bool)
	CSRFToken                func(*http.Request, string) string
	ValidateCSRF             func(*http.Request, string) bool
	Option                   func(context.Context, string) (string, error)
	SetOption                func(context.Context, string, string) error
	SaveContent              func(context.Context, ContentWriteInput) (PublicContent, error)
	DeleteContent            func(context.Context, int64) error
	SaveComment              func(context.Context, CommentWriteInput) (PublicComment, error)
	DeleteComment            func(context.Context, int64) error
	Config                   func(context.Context, string) (map[string]string, error)
	PersonalConfig           func(context.Context, string, int64) (map[string]string, error)
	DispatchHook             func(context.Context, string, any) (HookDispatch, error)
	ServiceAvailable         func(string) bool
	CallService              func(context.Context, string, ...any) (any, error)
	NotifyAdmin              func(http.ResponseWriter, *http.Request, ...AdminNotice)
	OpenPluginDB             func(context.Context) (*sql.DB, error)
	PluginDBDialect          func(context.Context) string
	IsIPBanned               func(context.Context, string) bool
	IsURLAllowed             func(context.Context, string) bool
	BanIP                    func(context.Context, string, time.Duration, string) error
	UnbanIP                  func(context.Context, string) error
	WAFStats                 func(context.Context) (WAFStatistics, error)
	GetContentAuthor         func(context.Context, int64) (PublicUser, error)
	ListContentMetas         func(context.Context, int64) ([]PublicMeta, error)
	GetContentFields         func(context.Context, int64) (map[string]any, error)
	SetContentField          func(context.Context, int64, ContentFieldInput) error
	IncrementContentFieldInt func(context.Context, int64, string, int64) (int64, error)
	DeleteContentField       func(context.Context, int64, string) error
	ThumbnailURL             func(context.Context, int64, int, int) (string, error)
	AttachmentMeta           func(context.Context, int64) (AttachmentMetaInfo, error)
	ActiveTheme              func(context.Context) string
	ContentRenderMode        func(context.Context) string
	// PluginActive reports whether a named plugin is currently activated,
	// equivalent to Typecho's Plugin::export()['activated'] lookup.
	PluginActive func(string) bool
	// PluginURL returns the public base URL for a plugin's bundled static
	// assets (served under /plugin/<name>/). When owner is empty the calling
	// plugin's own asset base is returned.
	PluginURL func(ctx context.Context, owner string) string
	// RenderContent returns the rendered HTML of any content by CID, applying
	// the same markdown/autop pipeline and render hooks the frontend uses.
	RenderContent func(context.Context, int64) (template.HTML, error)
	// Excerpt returns a plain-text/HTML excerpt of the given text, honoring the
	// content.excerpt hooks. limit is the maximum rune length.
	Excerpt func(ctx context.Context, text string, limit int) string
	// FeedURL, CommentsFeedURL, XMLRPCURL, LoginURL, RegisterURL, LogoutURL,
	// ProfileURL and ThemeURL expose core-defined route shapes so extensions
	// need not hardcode them. ThemeURL(name, file) resolves a theme asset URL.
	FeedURL         func(context.Context) string
	CommentsFeedURL func(context.Context) string
	XMLRPCURL       func(context.Context) string
	LoginURL        func(context.Context) string
	RegisterURL     func(context.Context) string
	LogoutURL       func(context.Context) string
	ProfileURL      func(context.Context) string
	ThemeURL        func(ctx context.Context, name, file string) string
	// PluginDataDir returns and creates a private on-disk directory for the
	// calling extension under the data directory, for swappable side files such
	// as an IP database that should not be bundled into the binary. It mirrors
	// the theme ThemeEditableDir capability for plugins.
	PluginDataDir func(context.Context) (string, error)
}

func RuntimeFromContext

func RuntimeFromContext(ctx context.Context) (*Runtime, bool)

func (*Runtime) DatabaseTableName

func (r *Runtime) DatabaseTableName(table string) string

func (*Runtime) GetAdminURL

func (r *Runtime) GetAdminURL(ctx context.Context) string

func (*Runtime) GetComment

func (r *Runtime) GetComment(ctx context.Context, coid int64) (PublicComment, error)

func (*Runtime) GetContent

func (r *Runtime) GetContent(ctx context.Context, cid int64) (PublicContent, error)

func (*Runtime) GetMeta

func (r *Runtime) GetMeta(ctx context.Context, mid int64) (PublicMeta, error)

func (*Runtime) GetSiteURL

func (r *Runtime) GetSiteURL(ctx context.Context) string

func (*Runtime) GetUser

func (r *Runtime) GetUser(ctx context.Context, uid int64) (PublicUser, error)

func (*Runtime) OpenPluginDatabase

func (r *Runtime) OpenPluginDatabase(ctx context.Context) (*sql.DB, error)

func (*Runtime) RebindSQL

func (r *Runtime) RebindSQL(ctx context.Context, query string) string

func (*Runtime) WithComponent

func (r *Runtime) WithComponent(kind, owner string) *Runtime

func (*Runtime) WithOwner

func (r *Runtime) WithOwner(owner string) *Runtime

type RuntimeHookFunc

type RuntimeHookFunc func(context.Context, *Runtime, any) (any, error)

type ServiceFunc

type ServiceFunc func(context.Context, *Runtime, ...any) (any, error)

ServiceFunc exposes one named capability to other active plugins and themes. Structured return values remain subject to html/template escaping in themes.

type StaticProvider

type StaticProvider interface {
	PluginStatic() fs.FS
}

StaticProvider lets a plugin ship bundled front-end assets (JS/CSS/images). Core serves the returned filesystem at /plugin/<name>/ and exposes the base URL through Runtime.PluginURL and the pluginURL template function, mirroring the theme Static mechanism and Typecho's pluginUrl option.

type TableDefinition

type TableDefinition struct {
	Name    string
	Columns []ColumnDefinition
	Indexes []IndexDefinition
}

type Theme

type Theme struct {
	Name                  string
	DisplayName           string
	Version               string
	Author                string
	Description           string
	Homepage              string
	Screenshot            string
	TemplateList          []string
	Templates             fs.FS
	Static                fs.FS
	Funcs                 template.FuncMap
	Translate             func(lang, key string) string
	ConfigSchema          []FieldSchema
	ContentFields         []FieldSchema
	ConfigValidator       func(map[string]string) map[string]string
	ConfigHandler         func(context.Context, *Runtime, map[string]string, bool) error
	AdminNotices          func(context.Context, *Runtime, map[string]string) []AdminNotice
	AdminPages            []AdminPage
	RenderAdminPage       func(context.Context, *Runtime, string, AdminPageRenderContext) (template.HTML, error)
	HandleAdminPageAction func(context.Context, *Runtime, string, map[string][]string) (AdminPageActionResult, error)
	EnrichComments        func(context.Context, *Runtime, map[string]string, []PublicComment) map[int64]CommentEnrichment
	Capabilities          ThemeCapabilities
	InitRuntime           func(context.Context, *Runtime) error
	AdjustData            func(context.Context, map[string]any) error
	Routes                []Route
	EditableDir           string
	Embedded              bool
}

type ThemeCapabilities

type ThemeCapabilities struct {
	CommentGuard bool
}

ThemeCapabilities declares optional core protocols implemented by a theme. The core remains responsible for enforcing security-sensitive capabilities.

type TrackbackPayload

type TrackbackPayload struct {
	Content PublicContent
	Input   any
	Comment PublicComment
	Handled bool
}

type Translator

type Translator interface {
	Translate(lang, key string) string
}

Translator lets an extension localize its own labels and messages. Core only provides the current language through Runtime.Language and calls this method when rendering native extension UI.

type UploadHandlePayload

type UploadHandlePayload struct {
	Name     string
	ParentID int64
	Bucket   string
	Size     int64
	MIME     string
	Open     func() (io.ReadCloser, error)
	Meta     any
	Handled  bool
}

type UploadPayload

type UploadPayload struct {
	Name     string
	ParentID int64
	Meta     any
}

type UserHashValidatePayload

type UserHashValidatePayload struct {
	Name     string
	Password string
	Hash     string
	User     PublicUser
	Valid    bool
	Handled  bool
}

type UserLoginPayload

type UserLoginPayload struct {
	Name      string
	User      PublicUser
	IP        string
	UserAgent string
	Next      string
	Success   bool
	Error     string
	Blocked   bool
	Message   string
}

type UserLogoutPayload

type UserLogoutPayload struct {
	User      PublicUser
	IP        string
	UserAgent string
}

type UserRegisterPayload

type UserRegisterPayload struct {
	User      PublicUser
	Input     any
	IP        string
	UserAgent string
	Blocked   bool
	Message   string
}

type WAFPayload

type WAFPayload struct {
	Request *http.Request
	IP      string
	Path    string
	Blocked bool
	Reason  string
	Handled bool
}

type WAFStatistics

type WAFStatistics struct {
	BannedIPs    int
	AllowedPaths int
	RecentBlocks int64
}

type XMLRPCPingbackPayload

type XMLRPCPingbackPayload struct {
	SourceURI string
	TargetURI string
	Content   PublicContent
	Comment   PublicComment
	Message   string
	Handled   bool
}

type XMLRPCTextPayload

type XMLRPCTextPayload struct {
	Method  string
	Content PublicContent
	Text    string
}

type XMLRPCUploadPayload

type XMLRPCUploadPayload struct {
	Name    string
	Data    []byte
	Result  map[string]any
	Handled bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL