package widget import ( "fmt" "github.com/fthvgb1/wp-go/helper/maps" "github.com/fthvgb1/wp-go/helper/slice" str "github.com/fthvgb1/wp-go/helper/strings" "github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets" "github.com/fthvgb1/wp-go/internal/theme/wp" "github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/safety" "strings" ) var metaTemplate = `{$before_widget} {$h2title} {$nav} {$navCloser} {$after_widget}` var metaArgs = func() safety.Var[map[string]string] { v := safety.Var[map[string]string]{} v.Store(map[string]string{ "{$before_widget}": ``, "{$aria_label}": "", "{$title}": "", "": "", "{$before_title}": `

`, "{$after_title}": `

`, }) return v }() func Meta(h *wp.Handle) string { args := wp.GetComponentsArgs(h, widgets.Meta, metaArgs.Load()) args = maps.FilterZeroMerge(metaArgs.Load(), 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(`" } ss := str.NewBuilder() if str.ToInteger(wpconfig.GetOption("users_can_register"), 0) > 0 { ss.Sprintf(`
  • 注册
  • `) } ss.Sprintf(`
  • 登录
  • `, "/wp-login.php") ss.Sprintf(`
  • 条目feed
  • `, "/feed") ss.Sprintf(`
  • 评论feed
  • `, "/comments/feed") s := strings.ReplaceAll(metaTemplate, "{$li}", ss.String()) return h.ComponentFilterFnHook(widgets.Meta, str.Replace(s, args)) }