Compare commits
2 Commits
bebe6bac81
...
e10dc4e45e
Author | SHA1 | Date | |
---|---|---|---|
e10dc4e45e | |||
13520a0d43 |
10
README.md
10
README.md
@ -19,11 +19,11 @@
|
||||
|
||||
#### 数据显示支持程度
|
||||
|
||||
| 页表 | 支持程度 |
|
||||
|-----|--------------------------------------------|
|
||||
| 列表页 | 首页/搜索/归档/分类/标签/作者 分页列表 |
|
||||
| 详情页 | 显示内容、评论并可以添加评论(转发的php处理,需要配置php版的添加评论的url) |
|
||||
| 侧边栏 | 目前支持旧版小工具的 近期文章、近期评论、规档、分类、其它操作 显示及设置 |
|
||||
| 页表 | 支持程度 |
|
||||
|-----|---------------------------------------------|
|
||||
| 列表页 | 首页/搜索/归档/分类/标签/作者 分页列表 |
|
||||
| 详情页 | 显示内容、评论并可以添加评论(转发的php处理,需要配置php版的添加评论的url) |
|
||||
| 侧边栏 | 支持旧版 近期文章、近期评论、规档、分类、其它操作 显示及设置, 支持新版 分类 |
|
||||
|
||||
#### 后台设置支持程度
|
||||
|
||||
|
@ -8,11 +8,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var blockFn = map[string]func(*wp.Handle, string, block.ParserBlock, map[string]string) (func() string, error){
|
||||
var blockFn = map[string]func(*wp.Handle, string, block.ParserBlock) (func() string, error){
|
||||
"core/categories": block.Category,
|
||||
}
|
||||
|
||||
func Block(id string, args map[string]string) func(*wp.Handle) string {
|
||||
func Block(id string) func(*wp.Handle) string {
|
||||
content := wpconfig.GetPHPArrayVal("widget_block", "", str.ToInteger[int64](id, 0), "content")
|
||||
if content == "" {
|
||||
return nil
|
||||
@ -23,7 +23,7 @@ func Block(id string, args map[string]string) func(*wp.Handle) string {
|
||||
for _, parserBlock := range v.Output {
|
||||
fn, ok := blockFn[parserBlock.Name]
|
||||
if ok {
|
||||
s, err := fn(h, id, parserBlock, args)
|
||||
s, err := fn(h, id, parserBlock)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||
constraints2 "github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/internal/theme/wp"
|
||||
@ -70,7 +71,7 @@ func parseAttr(attr map[any]any) string {
|
||||
return strings.Join(attrs, " ")
|
||||
}
|
||||
|
||||
func Category(h *wp.Handle, id string, blockParser ParserBlock, args map[string]string) (func() string, error) {
|
||||
func Category(h *wp.Handle, id string, blockParser ParserBlock) (func() string, error) {
|
||||
counter := number.Counters[int]()
|
||||
var err error
|
||||
conf := reload.GetAnyValBys("block-category-conf", h, func(h *wp.Handle) map[any]any {
|
||||
@ -115,7 +116,8 @@ func Category(h *wp.Handle, id string, blockParser ParserBlock, args map[string]
|
||||
if maps.GetAnyAnyValWithDefaults(conf, false, "showOnlyTopLevel") {
|
||||
h.C.Set("showOnlyTopLevel", true)
|
||||
}
|
||||
args = reload.GetAnyValBys("block-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := reload.GetAnyValBys("block-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
return maps.FilterZeroMerge(categoryDefaultArgs(), args)
|
||||
})
|
||||
|
||||
|
@ -24,10 +24,6 @@ var archiveTemplate = `{$before_widget}
|
||||
|
||||
func archiveArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="archives-2" class="widget widget_archive">`,
|
||||
"{$after_widget}": "</aside>",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": "</h2>",
|
||||
"{$before_sidebar}": "",
|
||||
"{$after_sidebar}": "",
|
||||
"{$nav}": "",
|
||||
@ -47,24 +43,23 @@ func archivesConfig() map[any]any {
|
||||
}
|
||||
}
|
||||
|
||||
func Archive(h *wp.Handle) string {
|
||||
args := reload.GetAnyValBys("widget-archive-args", h, func(h *wp.Handle) map[string]string {
|
||||
archiveArgs := archiveArgs()
|
||||
args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs)
|
||||
args = maps.FilterZeroMerge(archiveArgs, args)
|
||||
return args
|
||||
})
|
||||
|
||||
func Archive(h *wp.Handle, id string) string {
|
||||
conf := reload.GetAnyValBys("widget-archive-conf", h, func(h *wp.Handle) map[any]any {
|
||||
archivesConfig := archivesConfig()
|
||||
conf := wpconfig.GetPHPArrayVal("widget_archives", archivesConfig, int64(2))
|
||||
return conf
|
||||
})
|
||||
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
args := reload.GetAnyValBys("widget-archive-args", h, func(h *wp.Handle) map[string]string {
|
||||
archiveArgs := archiveArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, CommonArgs())
|
||||
args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs)
|
||||
args = maps.FilterZeroMerge(archiveArgs, CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("archives-", id), str.Join("widget widget_", "archive"))
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
return args
|
||||
})
|
||||
|
||||
s := archiveTemplate
|
||||
if int64(1) == conf["dropdown"].(int64) {
|
||||
s = strings.ReplaceAll(s, "{$html}", archiveDropDown(h, conf, args, cache.Archives(h.C)))
|
||||
|
@ -1,8 +1,8 @@
|
||||
package widget
|
||||
|
||||
func commonArgs() map[string]string {
|
||||
func CommonArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="%s" class="widget widget_%s">`,
|
||||
"{$before_widget}": `<aside id="%s" class="%s">`,
|
||||
"{$after_widget}": "</aside>",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": "</h2>",
|
||||
|
@ -36,10 +36,6 @@ func categoryConfig() map[any]any {
|
||||
|
||||
func categoryArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="categories-2" class="widget widget_categories">`,
|
||||
"{$after_widget}": "</aside>",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": "</h2>",
|
||||
"{$before_sidebar}": "",
|
||||
"{$after_sidebar}": "",
|
||||
"{$class}": "postform",
|
||||
@ -53,28 +49,28 @@ func categoryArgs() map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
func Category(h *wp.Handle) string {
|
||||
args := reload.GetAnyValBys("widget-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
args := wp.GetComponentsArgs(h, widgets.Categories, categoryArgs())
|
||||
args = maps.FilterZeroMerge(categoryArgs(), args)
|
||||
return args
|
||||
})
|
||||
func Category(h *wp.Handle, id string) string {
|
||||
|
||||
conf := reload.GetAnyValBys("widget-category-conf", h, func(a *wp.Handle) map[any]any {
|
||||
conf := wpconfig.GetPHPArrayVal("widget_categories", categoryConfig(), int64(2))
|
||||
conf = maps.FilterZeroMerge(categoryConfig(), conf)
|
||||
return conf
|
||||
})
|
||||
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
args := reload.GetAnyValBys("widget-category-args", h, func(h *wp.Handle) map[string]string {
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.Categories, categoryArgs())
|
||||
args = maps.FilterZeroMerge(categoryArgs(), CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("categories-", id), str.Join("widget widget_", "categories"))
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
return args
|
||||
})
|
||||
|
||||
t := categoryTemplate
|
||||
dropdown := conf["dropdown"].(int64)
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
categories := cache.CategoriesTags(h.C, constraints.Category)
|
||||
if dropdown == 1 {
|
||||
t = strings.ReplaceAll(t, "{$html}", CategoryDropdown(h, args, conf, categories))
|
||||
|
||||
} else {
|
||||
t = strings.ReplaceAll(t, "{$html}", categoryUL(h, args, conf, categories))
|
||||
}
|
||||
|
9
internal/theme/wp/components/widget/fn.go
Normal file
9
internal/theme/wp/components/widget/fn.go
Normal file
@ -0,0 +1,9 @@
|
||||
package widget
|
||||
|
||||
import "github.com/fthvgb1/wp-go/internal/theme/wp"
|
||||
|
||||
func Fn(id string, fn func(*wp.Handle, string) string) func(h *wp.Handle) string {
|
||||
return func(h *wp.Handle) string {
|
||||
return fn(h, id)
|
||||
}
|
||||
}
|
@ -23,37 +23,32 @@ var metaTemplate = `{$before_widget}
|
||||
|
||||
func metaArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="meta-2" class="widget widget_meta">`,
|
||||
"{$after_widget}": `</aside>`,
|
||||
"{$aria_label}": "",
|
||||
"{$title}": "",
|
||||
"": "",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": `</h2>`,
|
||||
"{$aria_label}": "",
|
||||
"{$title}": "",
|
||||
}
|
||||
}
|
||||
|
||||
func Meta(h *wp.Handle) string {
|
||||
func Meta(h *wp.Handle, id string) string {
|
||||
args := reload.GetAnyValBys("widget-meta-args", h, func(h *wp.Handle) map[string]string {
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
metaArgs := metaArgs()
|
||||
args := wp.GetComponentsArgs(h, widgets.Meta, metaArgs)
|
||||
args = maps.FilterZeroMerge(metaArgs, args)
|
||||
args = maps.FilterZeroMerge(metaArgs, CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("meta-", id), str.Join("widget widget_", "meta"))
|
||||
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_meta", "其它操作", int64(2), "title")
|
||||
if args["{$title}"] == "" {
|
||||
args["{$title}"] = "其他操作"
|
||||
}
|
||||
if args["{$title}"] != "" {
|
||||
args["{$h2title}"] = str.Join(args["{$before_title}"], args["{$title}"], args["{$after_title}"])
|
||||
}
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{$title}"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
})
|
||||
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_meta", "其它操作", int64(2), "title")
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
if args["{$title}"] == "" {
|
||||
args["{$title}"] = "其他操作"
|
||||
}
|
||||
if args["{$title}"] != "" {
|
||||
args["{$h2title}"] = str.Join(args["{$before_title}"], args["{$title}"], args["{$after_title}"])
|
||||
}
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, args["{$title}"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
|
||||
ss := str.NewBuilder()
|
||||
if str.ToInteger(wpconfig.GetOption("users_can_register"), 0) > 0 {
|
||||
ss.Sprintf(`<li><a href="/wp-login.php?action=register">注册</li>`)
|
||||
|
@ -16,10 +16,6 @@ import (
|
||||
|
||||
func recentCommentsArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="recent-comments-2" class="widget widget_recent_comments">`,
|
||||
"{$after_widget}": "</aside>",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": "</h2>",
|
||||
"{$before_sidebar}": "",
|
||||
"{$after_sidebar}": "",
|
||||
"{$nav}": "",
|
||||
@ -46,29 +42,27 @@ var recentCommentsTemplate = `{$before_widget}
|
||||
{$after_widget}
|
||||
`
|
||||
|
||||
func RecentComments(h *wp.Handle) string {
|
||||
args := reload.GetAnyValBys("widget-recent-comment-args", h, func(h *wp.Handle) map[string]string {
|
||||
commentsArgs := recentCommentsArgs()
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentComments, commentsArgs)
|
||||
args = maps.FilterZeroMerge(commentsArgs, args)
|
||||
return args
|
||||
})
|
||||
|
||||
func RecentComments(h *wp.Handle, id string) string {
|
||||
conf := reload.GetAnyValBys("widget-recent-comment-conf", h, func(h *wp.Handle) map[any]any {
|
||||
commentConf := recentCommentConf()
|
||||
conf := wpconfig.GetPHPArrayVal("widget_recent-comments", commentConf, int64(2))
|
||||
conf = maps.FilterZeroMerge(commentConf, conf)
|
||||
return conf
|
||||
})
|
||||
args := reload.GetAnyValBys("widget-recent-comment-args", h, func(h *wp.Handle) map[string]string {
|
||||
commentsArgs := recentCommentsArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentComments, commentsArgs)
|
||||
args = maps.FilterZeroMerge(commentsArgs, CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("recent-comments-", id), str.Join("widget widget_", "recent_comments"))
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
})
|
||||
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
comments := slice.Map(cache.RecentComments(h.C, int(conf["number"].(int64))), func(t models.Comments) string {
|
||||
return fmt.Sprintf(` <li>
|
||||
<span class="comment-author-link">%s</span>发表在《
|
||||
|
@ -27,10 +27,6 @@ var recentPostsTemplate = `{$before_widget}
|
||||
|
||||
func recentPostsArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$before_widget}": `<aside id="recent-posts-2" class="widget widget_recent_entries">`,
|
||||
"{$after_widget}": "</aside>",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": "</h2>",
|
||||
"{$before_sidebar}": "",
|
||||
"{$after_sidebar}": "",
|
||||
"{$nav}": "",
|
||||
@ -47,13 +43,7 @@ func recentConf() map[any]any {
|
||||
}
|
||||
}
|
||||
|
||||
func RecentPosts(h *wp.Handle) string {
|
||||
args := reload.GetAnyValBys("widget-recent-posts-args", h, func(h *wp.Handle) map[string]string {
|
||||
recent := recentPostsArgs()
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentPosts, recent)
|
||||
args = maps.FilterZeroMerge(recent, args)
|
||||
return args
|
||||
})
|
||||
func RecentPosts(h *wp.Handle, id string) string {
|
||||
conf := reload.GetAnyValBys("widget-recent-posts-conf", h, func(h *wp.Handle) map[any]any {
|
||||
recent := recentConf()
|
||||
conf := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recent, int64(2))
|
||||
@ -61,14 +51,20 @@ func RecentPosts(h *wp.Handle) string {
|
||||
return conf
|
||||
})
|
||||
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
args := reload.GetAnyValBys("widget-recent-posts-args", h, func(h *wp.Handle) map[string]string {
|
||||
recent := recentPostsArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.RecentPosts, recent)
|
||||
args = maps.FilterZeroMerge(recent, CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("recent-posts-", id), str.Join("widget widget_", "recent_entries"))
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"])
|
||||
if slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
args["{$nav}"] = fmt.Sprintf(`<nav aria-label="%s">`, conf["title"])
|
||||
args["{$navCloser}"] = "</nav>"
|
||||
}
|
||||
return args
|
||||
})
|
||||
|
||||
currentPostId := uint64(0)
|
||||
if h.Scene() == constraints.Detail {
|
||||
currentPostId = str.ToInteger(h.C.Param("id"), uint64(0))
|
||||
|
@ -1,6 +1,7 @@
|
||||
package widget
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/html"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
@ -35,49 +36,44 @@ var xmlSearchForm = `<form role="search" {$aria_label} method="get" id="searchfo
|
||||
|
||||
func searchArgs() map[string]string {
|
||||
return map[string]string{
|
||||
"{$id}": "2",
|
||||
"{$before_widget}": `<aside id="search-2" class="widget widget_search">`,
|
||||
"{$after_widget}": `</aside>`,
|
||||
"{$aria_label}": "",
|
||||
"{$title}": "",
|
||||
"{$before_title}": `<h2 class="widget-title">`,
|
||||
"{$after_title}": `</h2>`,
|
||||
"{$form}": "",
|
||||
"{$button}": "搜索",
|
||||
"{$placeholder}": "搜索…",
|
||||
"{$label}": "搜索:",
|
||||
"{$aria_label}": "",
|
||||
"{$title}": "",
|
||||
"{$form}": "",
|
||||
"{$button}": "搜索",
|
||||
"{$placeholder}": "搜索…",
|
||||
"{$label}": "搜索:",
|
||||
}
|
||||
}
|
||||
|
||||
func Search(h *wp.Handle) string {
|
||||
func Search(h *wp.Handle, id string) string {
|
||||
form := html5SearchForm
|
||||
args := reload.GetAnyValBys("widget-search-args", h, func(h *wp.Handle) map[string]string {
|
||||
search := searchArgs()
|
||||
commonArgs := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
args := wp.GetComponentsArgs(h, widgets.Search, search)
|
||||
args = maps.FilterZeroMerge(search, args)
|
||||
args = maps.FilterZeroMerge(search, CommonArgs(), commonArgs, args)
|
||||
args["{$before_widget}"] = fmt.Sprintf(args["{$before_widget}"], str.Join("search-", id), str.Join("widget widget_", "search"))
|
||||
if args["{$title}"] == "" {
|
||||
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_search", "", int64(2), "title")
|
||||
}
|
||||
|
||||
if args["{$title}"] != "" {
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], args["{$title}"], args["{$after_title}"])
|
||||
}
|
||||
if args["{$form}"] != "" {
|
||||
form = args["{$form}"]
|
||||
delete(args, "{$form}")
|
||||
}
|
||||
if !slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
form = xmlSearchForm
|
||||
}
|
||||
|
||||
return args
|
||||
})
|
||||
if args["{$title}"] == "" {
|
||||
args["{$title}"] = wpconfig.GetPHPArrayVal("widget_search", "", int64(2), "title")
|
||||
}
|
||||
if id, ok := args["{$id}"]; ok && id != "" {
|
||||
args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"])
|
||||
}
|
||||
if args["{$title}"] != "" {
|
||||
args["{$title}"] = str.Join(args["{$before_title}"], args["{$title}"], args["{$after_title}"])
|
||||
}
|
||||
s := strings.ReplaceAll(searchTemplate, "{$form}", form)
|
||||
args["{$value}"] = ""
|
||||
if h.Scene() == constraints.Search {
|
||||
args["{$value}"] = html.SpecialChars(h.Index.Param.Search)
|
||||
}
|
||||
form := html5SearchForm
|
||||
if args["{$form}"] != "" {
|
||||
form = args["{$form}"]
|
||||
delete(args, "{$form}")
|
||||
}
|
||||
|
||||
if !slice.IsContained(h.CommonThemeMods().ThemeSupport.HTML5, "navigation-widgets") {
|
||||
form = xmlSearchForm
|
||||
}
|
||||
s := strings.ReplaceAll(searchTemplate, "{$form}", form)
|
||||
return h.ComponentFilterFnHook(widgets.Search, str.Replace(s, args))
|
||||
}
|
||||
|
@ -1,25 +1,27 @@
|
||||
package components
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets"
|
||||
"github.com/fthvgb1/wp-go/internal/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/internal/theme/wp/components/widget"
|
||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var widgetFn = map[string]wp.Components[string]{
|
||||
"search": {Fn: widget.Search},
|
||||
"recent-posts": {Fn: widget.RecentPosts},
|
||||
"recent-comments": {Fn: widget.RecentComments},
|
||||
"archives": {Fn: widget.Archive},
|
||||
"categories": {Fn: widget.Category},
|
||||
"meta": {Fn: widget.Meta, CacheKey: "widgetMeta"},
|
||||
var widgetFn = map[string]widgetComponent{
|
||||
"search": {fn: widget.Search},
|
||||
"recent-posts": {fn: widget.RecentPosts},
|
||||
"recent-comments": {fn: widget.RecentComments},
|
||||
"archives": {fn: widget.Archive},
|
||||
"categories": {fn: widget.Category},
|
||||
"meta": {fn: widget.Meta, cacheKey: "widgetMeta"},
|
||||
}
|
||||
|
||||
type widgetComponent struct {
|
||||
fn func(h *wp.Handle, id string) string
|
||||
cacheKey string
|
||||
}
|
||||
|
||||
func WidgetArea(h *wp.Handle) {
|
||||
@ -27,49 +29,29 @@ func WidgetArea(h *wp.Handle) {
|
||||
h.PushComponents(constraints.SidebarsWidgets, sidebar...)
|
||||
}
|
||||
|
||||
func sidebars(h *wp.Handle) []wp.Components[string] {
|
||||
args := wp.GetComponentsArgs(h, widgets.Widget, map[string]string{})
|
||||
beforeWidget, ok := args["{$before_widget}"]
|
||||
if !ok {
|
||||
beforeWidget = ""
|
||||
}
|
||||
func sidebars(*wp.Handle) []wp.Components[string] {
|
||||
v := wpconfig.GetPHPArrayVal("sidebars_widgets", []any{}, "sidebar-1")
|
||||
return slice.FilterAndMap(v, func(t any) (wp.Components[string], bool) {
|
||||
vv := t.(string)
|
||||
ss := strings.Split(vv, "-")
|
||||
id := ss[len(ss)-1]
|
||||
name := strings.Join(ss[0:len(ss)-1], "-")
|
||||
components, ok := widgetFn[name]
|
||||
widgetComponents, ok := widgetFn[name]
|
||||
if name != "block" && !ok {
|
||||
return components, false
|
||||
}
|
||||
if id != "2" {
|
||||
wp.SetComponentsArgsForMap(h, name, "{$id}", id)
|
||||
}
|
||||
names := str.Join("widget-", name)
|
||||
|
||||
if beforeWidget != "" && name != "block" {
|
||||
n := strings.ReplaceAll(name, "-", "_")
|
||||
if name == "recent-posts" {
|
||||
n = "recent_entries"
|
||||
}
|
||||
n = str.Join("widget widget_", n)
|
||||
delete(args, "{$before_widget}")
|
||||
wp.SetComponentsArgsForMap(h, names, "{$before_widget}", fmt.Sprintf(beforeWidget, vv, n))
|
||||
} else {
|
||||
args["{$before_widget}"] = beforeWidget
|
||||
}
|
||||
for k, val := range args {
|
||||
wp.SetComponentsArgsForMap(h, names, k, val)
|
||||
return wp.Components[string]{}, false
|
||||
}
|
||||
var component wp.Components[string]
|
||||
if name == "block" {
|
||||
fn := Block(id, args)
|
||||
fn := Block(id)
|
||||
if fn == nil {
|
||||
return wp.Components[string]{}, false
|
||||
return component, false
|
||||
}
|
||||
components = wp.Components[string]{Fn: fn, Order: 10}
|
||||
component.Fn = fn
|
||||
} else {
|
||||
component.Fn = widget.Fn(id, widgetComponents.fn)
|
||||
component.CacheKey = widgetComponents.cacheKey
|
||||
}
|
||||
components.Order = 10
|
||||
return components, true
|
||||
component.Order = 10
|
||||
return component, true
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user