|
|
@ -13,6 +13,7 @@ package writefreely |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"database/sql" |
|
|
|
"database/sql" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"html/template" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
@ -102,13 +103,16 @@ func NewAdminPage(app *App) *AdminPage { |
|
|
|
return ap |
|
|
|
return ap |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c instanceContent) UpdatedFriendly() string { |
|
|
|
func (c instanceContent) UpdatedFriendly() template.HTML { |
|
|
|
/* |
|
|
|
/* |
|
|
|
// TODO: accept a locale in this method and use that for the format
|
|
|
|
// TODO: accept a locale in this method and use that for the format
|
|
|
|
var loc monday.Locale = monday.LocaleEnUS |
|
|
|
var loc monday.Locale = monday.LocaleEnUS |
|
|
|
return monday.Format(u.Created, monday.DateTimeFormatsByLocale[loc], loc) |
|
|
|
return monday.Format(u.Created, monday.DateTimeFormatsByLocale[loc], loc) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
return c.Updated.Format("January 2, 2006, 3:04 PM") |
|
|
|
if c.Updated.IsZero() { |
|
|
|
|
|
|
|
return "<em>Never</em>" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return template.HTML(c.Updated.Format("January 2, 2006, 3:04 PM")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func handleViewAdminDash(app *App, u *User, w http.ResponseWriter, r *http.Request) error { |
|
|
|
func handleViewAdminDash(app *App, u *User, w http.ResponseWriter, r *http.Request) error { |
|
|
@ -426,9 +430,9 @@ func handleViewAdminPages(app *App, u *User, w http.ResponseWriter, r *http.Requ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add in default pages
|
|
|
|
// Add in default pages
|
|
|
|
var hasAbout, hasPrivacy bool |
|
|
|
var hasAbout, hasContact, hasPrivacy bool |
|
|
|
for i, c := range p.Pages { |
|
|
|
for i, c := range p.Pages { |
|
|
|
if hasAbout && hasPrivacy { |
|
|
|
if hasAbout && hasContact && hasPrivacy { |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
if c.ID == "about" { |
|
|
|
if c.ID == "about" { |
|
|
@ -436,6 +440,11 @@ func handleViewAdminPages(app *App, u *User, w http.ResponseWriter, r *http.Requ |
|
|
|
if !c.Title.Valid { |
|
|
|
if !c.Title.Valid { |
|
|
|
p.Pages[i].Title = defaultAboutTitle(app.cfg) |
|
|
|
p.Pages[i].Title = defaultAboutTitle(app.cfg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if c.ID == "contact" { |
|
|
|
|
|
|
|
hasContact = true |
|
|
|
|
|
|
|
if !c.Title.Valid { |
|
|
|
|
|
|
|
p.Pages[i].Title = defaultContactTitle() |
|
|
|
|
|
|
|
} |
|
|
|
} else if c.ID == "privacy" { |
|
|
|
} else if c.ID == "privacy" { |
|
|
|
hasPrivacy = true |
|
|
|
hasPrivacy = true |
|
|
|
if !c.Title.Valid { |
|
|
|
if !c.Title.Valid { |
|
|
@ -451,6 +460,13 @@ func handleViewAdminPages(app *App, u *User, w http.ResponseWriter, r *http.Requ |
|
|
|
Updated: defaultPageUpdatedTime, |
|
|
|
Updated: defaultPageUpdatedTime, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if !hasAbout { |
|
|
|
|
|
|
|
p.Pages = append(p.Pages, &instanceContent{ |
|
|
|
|
|
|
|
ID: "contact", |
|
|
|
|
|
|
|
Title: defaultContactTitle(), |
|
|
|
|
|
|
|
Content: defaultContactPage(app), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
if !hasPrivacy { |
|
|
|
if !hasPrivacy { |
|
|
|
p.Pages = append(p.Pages, &instanceContent{ |
|
|
|
p.Pages = append(p.Pages, &instanceContent{ |
|
|
|
ID: "privacy", |
|
|
|
ID: "privacy", |
|
|
@ -489,6 +505,8 @@ func handleViewAdminPage(app *App, u *User, w http.ResponseWriter, r *http.Reque |
|
|
|
// Get pre-defined pages, or select slug
|
|
|
|
// Get pre-defined pages, or select slug
|
|
|
|
if slug == "about" { |
|
|
|
if slug == "about" { |
|
|
|
p.Content, err = getAboutPage(app) |
|
|
|
p.Content, err = getAboutPage(app) |
|
|
|
|
|
|
|
} else if slug == "contact" { |
|
|
|
|
|
|
|
p.Content, err = getContactPage(app) |
|
|
|
} else if slug == "privacy" { |
|
|
|
} else if slug == "privacy" { |
|
|
|
p.Content, err = getPrivacyPage(app) |
|
|
|
p.Content, err = getPrivacyPage(app) |
|
|
|
} else if slug == "landing" { |
|
|
|
} else if slug == "landing" { |
|
|
@ -523,7 +541,7 @@ func handleAdminUpdateSite(app *App, u *User, w http.ResponseWriter, r *http.Req |
|
|
|
id := vars["page"] |
|
|
|
id := vars["page"] |
|
|
|
|
|
|
|
|
|
|
|
// Validate
|
|
|
|
// Validate
|
|
|
|
if id != "about" && id != "privacy" && id != "landing" && id != "reader" { |
|
|
|
if id != "about" && id != "contact" && id != "privacy" && id != "landing" && id != "reader" { |
|
|
|
return impart.HTTPError{http.StatusNotFound, "No such page."} |
|
|
|
return impart.HTTPError{http.StatusNotFound, "No such page."} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|