Exemple #1
0
// The controller function for Values found directly in the controller values of the element
func WrapperValues(w *wrapper.Wrapper) {
	var wrapid string
	if len(w.APIParams) > 0 {
		wrapid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	e, err := elements.LoadWrapperElement(wrapid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Content not found %s : %s", wrapid, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was a problem loading some content on your page.", "Error", w)
		w.Serve()
		return
	}
	var v []elements.Element
	for _, id := range e.Elements {
		e := elements.NewElement()
		err = elements.GetById(id, &e, w)
		if err != nil {
			errmessage := fmt.Sprintf("Content not found %s : %s", id, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
		} else {
			v = append(v, e)
		}
	}
	w.SetDynamicId(e.DynamicId)
	w.SetContent(v)
	w.Serve()
}
Exemple #2
0
// Controller to list all paths
func AdminPaths(w *wrapper.Wrapper) {
	pl, err := paths.PathList(w)
	if err != nil {
		services.AddMessage("There was an error retrieving your site paths", "Error", w)
		errmessage := fmt.Sprintf("Error getting path list: %s", err.Error())
		w.SiteConfig.Logger.Error(errmessage)
	} else {
		w.SetContent(pl)
	}
	w.Serve()
}
Exemple #3
0
// The controller function to retrieve elements ids from the path
func PathValues(w *wrapper.Wrapper) {
	// Request is never url based so we can Never cache this request.
	// TODO: move no caching into a reusable function.
	w.Writer.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
	w.Writer.Header().Add("Pragma", "no-cache")
	w.Writer.Header().Add("Expires", "0")
	p := paths.NewPath()
	u := w.Request.Header.Get("CurrentPath")
	if u == "" {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	qp, err := p.PathMatch(u, "published", w)
	if err != nil {
		if err.Error() == "not found" {
			if "/"+w.SiteConfig.FourOFour != u {
				services.Redirect("/"+w.SiteConfig.FourOFour, w)
				w.Serve()
				return
			} else {
				services.AddMessage("There was a problem with the system.", "Error", w)
				w.Serve()
				return
			}

		}

	}
	var v []elements.Element
	for _, eid := range p.Elements {
		e := elements.NewElement()
		err = elements.GetById(eid, &e, w)
		if err != nil {
			errmessage := fmt.Sprintf("Content not found %s : %s", eid, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
		} else {
			v = append(v, e)
		}
	}
	w.SetPayload("mongolar_slug", qp)
	w.SetContent(v)
	w.SetTemplate(p.Template)
	w.Serve()
	return
}
Exemple #4
0
// The controller function for Values found directly in the controller values of the element
func ContentValues(w *wrapper.Wrapper) {
	var contentid string
	if len(w.APIParams) > 0 {
		contentid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return

	}
	e, err := elements.LoadContentElement(contentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Content not found %s : %s", contentid, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was a problem loading some content on your page.", "Error", w)
		w.Serve()
		return
	}
	w.SetContent(e.ContentValues.Content)
	w.Serve()
	return
}
Exemple #5
0
// Structure of url links that appear on the admin page.
func (a *AdminMenu) AdminMenu(w *wrapper.Wrapper) {
	w.SetContent(a)
	w.Serve()
	return
}