2018-05-27 09:36:35 +00:00
|
|
|
package routes
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
2018-11-12 09:23:36 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2018-12-08 00:45:27 +00:00
|
|
|
"time"
|
2018-10-27 03:21:02 +00:00
|
|
|
|
|
|
|
"github.com/Azareal/Gosora/common"
|
|
|
|
)
|
|
|
|
|
2018-05-27 09:36:35 +00:00
|
|
|
var successJSONBytes = []byte(`{"success":"1"}`)
|
2018-10-27 03:21:02 +00:00
|
|
|
|
2018-11-12 09:23:36 +00:00
|
|
|
func ParseSEOURL(urlBit string) (slug string, id int, err error) {
|
|
|
|
halves := strings.Split(urlBit, ".")
|
|
|
|
if len(halves) < 2 {
|
|
|
|
halves = append(halves, halves[0])
|
|
|
|
}
|
|
|
|
tid, err := strconv.Atoi(halves[1])
|
|
|
|
return halves[0], tid, err
|
|
|
|
}
|
|
|
|
|
2018-10-27 03:21:02 +00:00
|
|
|
func renderTemplate(tmplName string, w http.ResponseWriter, r *http.Request, header *common.Header, pi interface{}) common.RouteError {
|
2018-12-08 00:45:27 +00:00
|
|
|
if header.CurrentUser.IsAdmin {
|
|
|
|
header.Elapsed1 = time.Since(header.StartedAt).String()
|
|
|
|
}
|
2018-10-27 03:21:02 +00:00
|
|
|
if common.RunPreRenderHook("pre_render_"+tmplName, w, r, &header.CurrentUser, pi) {
|
|
|
|
return nil
|
|
|
|
}
|
2018-12-08 00:45:27 +00:00
|
|
|
err := header.Theme.RunTmpl(tmplName, pi, w)
|
2018-10-27 03:21:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return common.InternalError(err, w, r)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|