package modules import ( "html" "io/ioutil" "os" "golang-fave/assets" "golang-fave/consts" "golang-fave/engine/builder" "golang-fave/engine/wrapper" ) func (this *Modules) RegisterModule_Settings() *Module { return this.newModule(MInfo{ WantDB: false, Mount: "settings", Name: "Settings", Order: 801, System: true, Icon: assets.SysSvgIconGear, Sub: &[]MISub{ {Mount: "default", Name: "Robots.txt", Show: true, Icon: assets.SysSvgIconList}, }, }, nil, func(wrap *wrapper.Wrapper) (string, string, string) { content := "" sidebar := "" if wrap.CurrSubModule == "" || wrap.CurrSubModule == "default" { content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{ {Name: "Robots.txt"}, }) fcont := []byte(``) fcont, _ = ioutil.ReadFile(wrap.DTemplate + string(os.PathSeparator) + "robots.txt") content += builder.DataForm(wrap, []builder.DataFormField{ { Kind: builder.DFKHidden, Name: "action", Value: "settings-robots-txt", }, { Kind: builder.DFKText, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKMessage, CallBack: func(field *builder.DataFormField) string { return `
` }, }, { Kind: builder.DFKSubmit, CallBack: func(field *builder.DataFormField) string { return `
` }, }, }) sidebar += `` } return this.getSidebarModules(wrap), content, sidebar }) } func (this *Modules) RegisterAction_SettingsRobotsTxt() *Action { return this.newAction(AInfo{ WantDB: true, Mount: "settings-robots-txt", WantAdmin: true, }, func(wrap *wrapper.Wrapper) { pf_content := wrap.R.FormValue("content") // Save robots.txt content err := ioutil.WriteFile(wrap.DTemplate+string(os.PathSeparator)+"robots.txt", []byte(pf_content), 0664) if err != nil { wrap.MsgError(err.Error()) return } // Reload current page wrap.Write(`window.location.reload(false);`) }) }