示例#1
0
文件: view.go 项目: eramus/discuss
func profilePage() (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	body.Title = "Profile"
	tpl, _ = profileTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Profile"))
	return
}
示例#2
0
文件: view.go 项目: eramus/discuss
func addForm(r *http.Request, t_id, p_id uint64) (body *shared.Body, tpl *template.Template) {
	t, rerr := shared.RedisClient.Get(fmt.Sprintf("topic:%d:title", t_id))
	if rerr != nil {
		return
	}
	labels, uris := shared.GetTopicBreadcrumbs(t_id)
	if p_id > 0 {
		labels, uris = append(labels, t.String()), append(uris, fmt.Sprintf("/topic/%d#%d", t_id, p_id))
	} else {
		labels, uris = append(labels, t.String()), append(uris, fmt.Sprintf("/topic/%d", t_id))
	}
	labels, uris = append(labels, "Add Post"), append(uris, "")

	body = new(shared.Body)
	f := new(Form)
	f.TId = t_id
	if p_id > 0 {
		f.PId = p_id
	}
	if r.Method == "POST" {
		f.Post = r.FormValue("post")
	}
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}
	body.ContentData = f
	body.Title = "Add Post"
	tpl, _ = addTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Add Post"))
	return
}
示例#3
0
func ViewTopic(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: view topic")
	parts := strings.Split(html.EscapeString(r.URL.Path[1:]), "/")
	if len(parts) < 2 {
		redirect = "/"
		return
	}
	id, err := strconv.ParseUint(parts[1], 10, 64)
	if err != nil {
		redirect = "/"
		return
	}
	if !exists(id) {
		redirect = "/"
		return
	}
	t, err := getById(id)
	body = new(shared.Body)
	labels, uris := shared.GetTopicBreadcrumbs(t.Id)
	labels, uris = append(labels, t.Title), append(uris, "")
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}
	body.ContentData = t
	body.Title = t.Title
	go addView(t.DId, t.Id)
	tpl, _ = viewTpls.Clone()
	tpl.Parse(shared.GetPageTitle(t.Title))
	return
}
示例#4
0
文件: index.go 项目: eramus/discuss
func Index(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: index")
	body = new(shared.Body)
	body.Title = "Discuss"
	tpl, _ = indexTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Discuss"))
	return
}
示例#5
0
文件: view.go 项目: eramus/discuss
func feedPage() (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	body.NoSidebar = true
	body.Title = "Feed"
	tpl, _ = feedTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Feed"))
	return
}
示例#6
0
文件: view.go 项目: eramus/discuss
func loginForm(r *http.Request) (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	if r.Method == "POST" {
		f := new(Form)
		f.Username = r.FormValue("username")
		f.Remember = r.FormValue("remember")

		body.ContentData = f
	}
	body.Breadcrumbs = &shared.Breadcrumbs{
		Labels: []string{"Login"},
		Uris:   []string{""},
	}
	body.Title = "Login"
	tpl, _ = loginTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Login"))
	return
}
示例#7
0
文件: view.go 项目: eramus/discuss
func registerForm(r *http.Request) (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	if r.Method == "POST" {
		f := new(Form)
		f.Username = r.FormValue("username")
		f.Email = r.FormValue("email")

		body.ContentData = f
	}
	body.Breadcrumbs = &shared.Breadcrumbs{
		Labels: []string{"Register"},
		Uris:   []string{""},
	}
	body.Title = "Register"
	tpl, _ = registerTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Register"))
	return
}
示例#8
0
文件: index.go 项目: eramus/discuss
func Search(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: search")
	if r.Method == "POST" {
		query := r.FormValue("search")
		if r.Method != "POST" || query == "" {
			redirect = "/"
			return
		}
		q := fmt.Sprintf(`keywords:"%s" title:"%s" uri:"%s" desc:"%s"`, query, query, query, query)
		dr, err := shared.SolrDiscuss.Query(q)
		if err != nil {
			log.Println("solr error:", err)
			redirect = "/"
			return
		}
		q = fmt.Sprintf(`post:"%s" title:"%s"`, query, query)
		pr, err := shared.SolrPosts.Query(q)
		if err != nil {
			log.Println("solr error:", err)
			redirect = "/"
			return
		}
		res := Results{
			NumFound:    dr.Response.NumFound + pr.Response.NumFound,
			Start:       dr.Response.Start,
			Discussions: parseDiscussions(dr),
			Posts:       parsePosts(pr),
			Query:       query,
		}
		body = new(shared.Body)
		body.Breadcrumbs = &shared.Breadcrumbs{
			Labels: []string{"Results"},
			Uris:   []string{""},
		}
		body.ContentData = res
		body.Title = "Search Results"
		body.Search = query
		tpl, _ = searchTpls.Clone()
		tpl.Parse(shared.GetPageTitle("Search Results"))
	} else {
		redirect = "/"
	}
	return
}
示例#9
0
文件: view.go 项目: eramus/discuss
func addForm(r *http.Request) (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	if r.Method == "POST" {
		f := new(Form)
		f.Uri = r.FormValue("uri")
		f.Title = r.FormValue("title")
		f.Description = r.FormValue("description")
		f.Keywords = r.FormValue("keywords")

		body.ContentData = f
	}
	body.Breadcrumbs = &shared.Breadcrumbs{
		Labels: []string{"Add Discussion"},
		Uris:   []string{""},
	}
	body.Title = "Add Discussion"
	tpl, _ = addTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Add Discussion"))
	return
}
示例#10
0
文件: view.go 项目: eramus/discuss
func addForm(r *http.Request, d_id uint64, parts []string) (body *shared.Body, tpl *template.Template) {
	body = new(shared.Body)
	labels, uris := shared.GetDiscussionBreadcrumbs(d_id, false)
	labels, uris = append(labels, "Add Topic"), append(uris, "")
	body.Breadcrumbs = &shared.Breadcrumbs{labels, uris}

	f := new(Form)
	f.Uri = strings.Join(parts, "/")
	f.DId = d_id

	if r.Method == "POST" {
		f.Title = r.FormValue("title")
		f.Post = r.FormValue("post")

	}
	body.ContentData = f
	body.Title = "Add Topic"
	tpl, _ = addTpls.Clone()
	tpl.Parse(shared.GetPageTitle("Add Topic"))
	return
}
示例#11
0
func ViewDiscussion(r *http.Request, sess *sessions.Session) (body *shared.Body, tpl *template.Template, redirect string) {
	//	log.Println("route: view discussion")
	var u_id uint64
	if _, ok := sess.Values["id"]; ok {
		u_id = sess.Values["id"].(uint64)
	}
	// figure out where we are
	parts := strings.Split(html.EscapeString(r.URL.Path[1:]), "/")
	if len(parts) < 2 {
		redirect = "/"
		return
	}
	parts = parts[1:]
	var uri = strings.Join(parts, "/")
	id, err := getId(uri)
	if err != nil {
		// uhh
		redirect = "/"
	} else if id > 0 {
		// show current topics -- w pagination
		/*		if !shared.CanDo(u_id, id, VIEW) {
				log.Println("no permission")
				redirect = "/"
			} else {*/
		ts, _ := topics(id)
		key := fmt.Sprintf("discussion:%d:title", id)
		te, rerr := shared.RedisClient.Get(key)
		if rerr != nil {
			log.Println("redis err:", rerr)
			redirect = "/"
		} else {
			labels, uris := shared.GetDiscussionBreadcrumbs(id, true)
			key := fmt.Sprintf("user:%d:joined", u_id)
			im, rerr := shared.RedisClient.Sismember(key, id)
			if rerr != nil {
				log.Println("redis err:", rerr)
				redirect = "/"
			}
			if im {
				labels, uris = append(labels, "Unsubscribe"), append(uris, "/leave/"+uri)
			} else {
				labels, uris = append(labels, "Subscribe"), append(uris, "/join/"+uri)
			}
			body = &shared.Body{
				Breadcrumbs: &shared.Breadcrumbs{labels, uris},
				ContentData: &List{
					Id:     id,
					Uri:    uri,
					Topics: ts,
				},
				Title: te.String(),
			}
			tpl, _ = listTpls.Clone()
			tpl.Parse(shared.GetPageTitle(te.String()))
		}
		//		}
	} else {
		// want to add?
		body, tpl = addForm(r)
		if err != nil {
			log.Println("no page:", err)
		}
	}
	return
}