|
@@ -0,0 +1,87 @@
|
|
|
+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.SysSvgIconBug},
|
|
|
+ },
|
|
|
+ }, 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 `<div class="form-group"><div class="row"><div class="col-12"><textarea class="form-control autosize" id="lbl_content" name="content" placeholder="" autocomplete="off">` + html.EscapeString(string(fcont)) + `</textarea></div></div></div>`
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Kind: builder.DFKMessage,
|
|
|
+ CallBack: func(field *builder.DataFormField) string {
|
|
|
+ return `<div class="row"><div class="col-12"><div class="sys-messages"></div></div></div>`
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Kind: builder.DFKSubmit,
|
|
|
+ CallBack: func(field *builder.DataFormField) string {
|
|
|
+ return `<div class="row d-lg-none"><div class="col-12"><button type="submit" class="btn btn-primary" data-target="add-edit-button">Save</button></div></div>`
|
|
|
+ },
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ sidebar += `<button class="btn btn-primary btn-sidebar" id="add-edit-button">Save</button>`
|
|
|
+ }
|
|
|
+ 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);`)
|
|
|
+ })
|
|
|
+}
|