Esempio n. 1
0
func (h *H) Front() (bool, error) {
	uni := h.uni
	tag_map, tag_err := routep.Comp("/tag/{first}/{second}", uni.P)
	// Tag view: list contents in that category.
	if tag_err == nil {
		err, hijack := h.tagView(tag_map)
		if err != nil {
			return true, err
		}
		if hijack {
			return true, nil
		}
	}
	_, tag_search_err := routep.Comp("/tag-search", uni.P)
	if tag_search_err == nil {
		return true, h.tagSearch()
	}
	_, content_search_err := routep.Comp("/content-search", uni.P)
	if content_search_err == nil {
		return true, h.contentSearch()
	}
	content_map, content_err := routep.Comp("/{slug}", uni.P)
	if content_err == nil && len(content_map["slug"]) > 0 {
		err, hijack := h.contentView(content_map)
		if err != nil {
			return true, err
		}
		if hijack {
			return true, nil
		}
	}
	return false, nil
}
Esempio n. 2
0
func (h *H) Front() (bool, error) {
	var hijacked bool
	if _, err := routep.Comp("/skeleton", h.uni.P); err == nil {
		hijacked = true // This stops the main front loop from executing any further modules.
	}
	return hijacked, nil
}
Esempio n. 3
0
func AD(uni *context.Uni) error {
	defer adErr(uni)
	var err error
	if lev, k := jsonp.Get(uni.Dat, "_user.level"); k == false || lev.(int) < 300 {
		if admin_model.SiteHasAdmin(uni.Db) {
			uni.Dat["_points"] = []string{"admin/login"}
		} else {
			uni.Dat["_points"] = []string{"admin/regfirstadmin"}
		}
		return nil
	}
	m, cerr := routep.Comp("/admin/{modname}", uni.P)
	if cerr != nil { // It should be always nil anyway.
		return fmt.Errorf("Control is routed to Admin display, but it does not like the url structure.")
	}
	modname, _ := m["modname"]
	switch modname {
	case "":
		err = Index(uni)
	case "edit-config":
		err = EditConfig(uni)
	case "install":
		err = Install(uni)
	case "uninstall":
		err = Uninstall(uni)
	default:
		_, installed := jsonp.Get(uni.Opt, "Modules."+modname)
		if !installed {
			err = fmt.Errorf("There is no module named ", modname, " installed.")
		}
		var viewname string
		if len(uni.Paths) < 4 {
			viewname = "index"
		} else {
			viewname = uni.Paths[3]
		}
		uni.Caller.Call("views", modname, "AdminInit", nil)
		sanitized_viewname := Viewnameize(viewname)
		if !uni.Caller.Has("views", modname, sanitized_viewname) {
			err = fmt.Errorf("Module %v has no view named %v.", modname, sanitized_viewname)
		}
		ret_rec := func(e error) {
			err = e
		}
		uni.Dat["_points"] = []string{modname + "/" + viewname}
		uni.Caller.Call("views", modname, sanitized_viewname, ret_rec)
	}
	return err
}