package modules import ( "html" "io/ioutil" "net/url" "os" "path/filepath" "strings" "golang-fave/engine/assets" "golang-fave/engine/builder" "golang-fave/engine/consts" "golang-fave/engine/utils" "golang-fave/engine/wrapper" ) func (this *Modules) templates_GetThemeFiles(wrap *wrapper.Wrapper) []string { var result []string files, err := ioutil.ReadDir(wrap.DTemplate) if err == nil { for _, file := range files { if len(file.Name()) > 0 && file.Name()[0] == '.' { continue } if len(file.Name()) > 0 && strings.ToLower(file.Name()) == "robots.txt" { continue } result = append(result, file.Name()) } } return result } func (this *Modules) RegisterModule_Templates() *Module { return this.newModule(MInfo{ Mount: "templates", Name: "Templates", Order: 802, System: true, Icon: assets.SysSvgIconView, Sub: &[]MISub{ {Mount: "default", Name: "Template editor", Show: true, Icon: assets.SysSvgIconEdit}, {Mount: "create", Name: "Add new template", Show: true, Icon: assets.SysSvgIconPlus}, {Mount: "restore", Name: "Restore", Show: true, Icon: assets.SysSvgIconRestore}, }, }, nil, func(wrap *wrapper.Wrapper) (string, string, string) { content := "" sidebar := "" if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Template editor"}, }) files := this.templates_GetThemeFiles(wrap) if len(files) > 0 { selected_file, _ := url.QueryUnescape(wrap.R.URL.Query().Get("file")) if !(selected_file != "" && utils.InArrayString(files, selected_file)) { selected_file = files[0] } list_of_files := `` for _, file := range files { selected := "" if file == selected_file { selected = " selected" } list_of_files += `` } fcont := []byte(``) fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + selected_file) fext := filepath.Ext(selected_file) if len(fext) > 2 { fext = fext[1:] } content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "templates-edit-theme-file", }, { Kind: builder.DFKText, Caption: "Theme file", Name: "file", Value: "0", CallBack: func(field *builder.DataFormField) string { return `
` + `
` + `
` + `
` + `` + `` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } else { content += `
` } } else if wrap.CurrSubModule == "create" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Add new template"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "templates-create-theme-file", }, { Kind: builder.DFKText, Caption: "Theme file", Name: "file", Value: "0", CallBack: func(field *builder.DataFormField) string { return `
` + `
` + `
` + `
` + `` + `
` + `
` + `
` + `
` }, }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } else if wrap.CurrSubModule == "restore" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Restore"}, }) content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
WARNING!
This action will restore current theme files to original, you will lost you theme changes!
Think twice before run this action! If you still want to do this, please press Restore red button!
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } return this.getSidebarModules(wrap), content, sidebar }) }