Esempio n. 1
0
//用户等级划分:正数是普通用户,负数是管理员各种等级划分,为0则尚未注册
func (self *BaseHandler) Prepare() {
	/*
		sess := self.StartSession()
		defer sess.SessionRelease()
		fmt.Println("SID::", sess.SessionID())
	*/
	//从session里读出登录信息
	sess_username, _ = self.GetSession("username").(string)
	sess_uid, _ = self.GetSession("userid").(int64)
	sess_role, _ = self.GetSession("userrole").(int64)
	sess_email, _ = self.GetSession("useremail").(string)
	sess_content, _ = self.GetSession("usercontent").(string)
	//把登录信息写入模板容器

	self.Data["userid"] = sess_uid
	self.Data["username"] = sess_username
	self.Data["userrole"] = sess_role
	self.Data["useremail"] = sess_email
	self.Data["usercontent"] = sess_content

	self.Data["xsrfdata"] = template.HTML(self.XsrfFormHtml())
	//self.Data["xsrfdata"] = template.HTML(`<input type="hidden" name="_xsrf" value="` + self.XsrfToken() + `"/>`)
	//self.Data["xsrftoken"] = self.XsrfToken()

	//for uploadify and &root.RMultipleUploaderHandler{}
	//self.Data["token"] = utils.Encrypt_hash("00d5930debddeb10eb172bba94eed053d12c42c0428f3e09", nil)

	//加载网站常用数据
	if cate, err := model.GetCategorys(0, 0, "id"); err == nil {
		self.Data["categorys"] = cate
	} else {
		fmt.Println("分类数据查询出错", err)
	}
	if nd, err := model.GetNodes(0, 0, "created"); err == nil {
		self.Data["nodes"] = *nd
	} else {
		fmt.Println("节点数据查询出错", err)
	}

	if nd, err := model.GetNodes(0, 4, "views"); err == nil {
		self.Data["nodes_views_4"] = *nd
	} else {
		fmt.Println("热门节点(4_VIEWS)数据查询出错", err)
	}
	if nd, err := model.GetNodes(0, 20, "views"); err == nil {
		self.Data["nodes_views_20"] = *nd
	} else {
		fmt.Println("热门节点(20_VIEWS)数据查询出错", err)
	}
}
Esempio n. 2
0
func (self *SignupHandler) Get() {
	self.TplNames = "signup.html"
	//侧栏九宫格推荐榜单
	//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
	if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
		if len(*nd) > 0 {
			for _, v := range *nd {

				i := 0
				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

					if len(*tps) > 0 {
						for _, v := range *tps {

							i += 1
							if i == 3 {
								output = output + `<li class="similar similar-third">`
								i = 0
							} else {
								output = output + `<li class="similar">`
							}
							output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
						}
					}
				}
				output_end := "</ul>"
				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}

			}
		}
	} else {
		fmt.Println("节点数据查询出错", err)
	}
}
Esempio n. 3
0
func (self *CategoryHandler) Get() {
	//fmt.Println("im CategoryHandler")
	self.TplNames = "category.html"

	ipage, _ := self.GetInt(":page")
	page := int(ipage)
	cid, _ := self.GetInt(":cid")
	tab := self.GetString(":tab")
	catname := self.GetString(":name")
	if cid > 0 {

		if c, e := model.GetCategory(cid); e == nil && c != nil {
			catname = c.Title
		}
	}
	self.Data["category"] = catname
	self.Data["catpage"] = catname

	url := "/category/"
	if tab == "lastest" {
		if catname != "" {
			url = "/category/lastest/" + catname + "/"
		} else {
			url = "/category/lastest/"
		}
		tab = "id"
		self.Data["tab"] = "lastest"
	} else if tab == "hotness" {

		if catname != "" {
			url = "/category/hotness/" + catname + "/"
		} else {
			url = "/category/hotness/"
		}
		tab = "hotness"
		self.Data["tab"] = "hotness"
	} else {
		if catname != "" {
			url = "/category/hotness/" + catname + "/"
		} else {
			url = "/category/hotness/"
		}

		tab = "hotness"
		self.Data["tab"] = "hotness"
	}

	pagesize := 30
	results_count, err := model.GetTopicsByCategoryCount(catname, 0, pagesize, tab)
	if err != nil {
		return
	}
	pages, page, beginnum, endnum, offset := helper.Pages(int(results_count), page, pagesize)

	if tps := model.GetTopicsByCategory(catname, offset, pagesize, 0, tab); len(*tps) > 0 {
		results_count := len(*tps)
		if results_count > 0 {
			i := 1
			output := ""
			for _, v := range *tps {

				i += i
				if i == 3 {
					output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin pin3">`
					i = 0
				} else {

					output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin">`
				}
				output = output + `<div class="pin-coat">
									<a href="/` + strconv.Itoa(int(v.Id)) + `/" class='imageLink image loading' target='_blank'>
										<img src='/static/mzr/img/dot.png' original='` + v.ThumbnailsLarge + `' width='200' height='150' alt='` + v.Title + ` ` + v.Created.String() + ` ` + v.Node + ` ` + v.Category + `' oriheight='300' />
										<span class='bg'>` + v.Title + `</span>
									</a>
									<div class="pin-data clx">
										<span class="timer">
											<em></em>
											<span>` + helper.TimeSince(v.Created) + `</span>
										</span>
										<a href="/` + strconv.Itoa(int(v.Id)) + `/" class="viewsButton" title="阅读` + v.Title + `" target="_blank">
											<em></em>
											<span>` + strconv.Itoa(int(v.Views)) + ` views</span>
										</a>
									</div>
								</div>
							</div>`
			}
			self.Data["topics"] = output
			self.Data["pagesbar"] = helper.Pagesbar(url, "", results_count, pages, page, beginnum, endnum, 0)
		}

	}

	//侧栏九宫格推荐榜单
	//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
	if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
		if len(*nd) > 0 {
			for _, v := range *nd {

				i := 0
				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

					if len(*tps) > 0 {
						for _, v := range *tps {

							i += 1
							if i == 3 {
								output = output + `<li class="similar similar-third">`
								i = 0
							} else {
								output = output + `<li class="similar">`
							}
							output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
						}
					}
				}
				output_end := "</ul>"
				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}

			}
		}
	} else {
		fmt.Println("节点数据查询出错", err)
	}
}
Esempio n. 4
0
func (self *TopicHandler) Get() {
	//fmt.Println("im TopicHandler")
	self.TplNames = "topic.html"

	tid, _ := self.GetInt(":tid")

	if tid > 0 {

		if tp, err := model.GetTopic(tid); tp != nil && err == nil {

			self.Data["article"] = *tp
			self.Data["replys"] = *model.GetReplysByPid(tid, 0, 0, 0, "id")

			//性能瓶颈 亟待优化!!!
			/*
				if tps := model.GetTopicsByCid(tp.Cid, 0, 0, 0, "asc"); *tps != nil && tid != 0 {
					if len(*tps) > 0 {
						self.Data["topics_cat"] = *tps
						//self.Data["topics_cat"] = model.GetTopicsByHotnessCategory(3, 3)

					}

					for i, v := range *tps {

						if v.Id == tid {
							//两侧的翻页按钮参数 初始化 s
							prev := i - 1
							next := i + 1
							//两侧的翻页按钮参数 初始化 e

							//话题内容部位 页码  初始化 s
							ipagesbar := `<div class="link_pages">`
							h := 5
							ipagesbar_start := i - h
							ipagesbar_end := i + h
							j := 0
							//话题内容部位 页码  初始化 e
							for i, v := range *tps {
								//两侧的翻页按钮 s
								if prev == i {
									self.Data["previd"] = v.Id
									self.Data["prev"] = v.Title
								}
								if next == i {
									self.Data["nextid"] = v.Id
									self.Data["next"] = v.Title
								}
								//两侧的翻页按钮 e

								//话题内容部位 页码 s
								if ipagesbar_start == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span><</span></a>`
								}
								if i > ipagesbar_start && i < ipagesbar_end {
									j += 1
									if v.Id == tid { // current

										ipagesbar = ipagesbar + `<span>` + strconv.Itoa(int(v.Id)) + `</span>`

									} else { //loop

										ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>` + strconv.Itoa(int(v.Id)) + `</span></a>`

									}
									if j > (2 * h) {
										break
									}
								}
								if ipagesbar_end == i {
									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>></span></a>`
								}
								//话题内容部位 页码 e
							}
							self.Data["ipagesbar"] = template.HTML(ipagesbar + "</div>")
						}
					}
				}
			*/

			if tps := model.GetTopicsByCidOnBetween(tp.Cid, tid-5, tid+5, 0, 11, 0, "asc"); tps != nil && tid != 0 && len(tps) > 0 {

				for i, v := range tps {

					if v.Id == tid {
						//两侧的翻页按钮参数 初始化 s
						prev := i - 1
						next := i + 1
						//两侧的翻页按钮参数 初始化 e

						//话题内容部位 页码  初始化 s
						ipagesbar := `<div class="link_pages">`
						h := 5
						ipagesbar_start := i - h
						ipagesbar_end := i + h
						j := 0
						//话题内容部位 页码  初始化 e
						for i, v := range tps {
							//两侧的翻页按钮 s
							if prev == i {
								self.Data["previd"] = v.Id
								self.Data["prev"] = v.Title
							}
							if next == i {
								self.Data["nextid"] = v.Id
								self.Data["next"] = v.Title
							}
							//两侧的翻页按钮 e

							//话题内容部位 页码 s
							if ipagesbar_start == i {
								ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span><</span></a>`
							}
							if i > ipagesbar_start && i < ipagesbar_end {
								j += 1
								if v.Id == tid { // current

									ipagesbar = ipagesbar + `<span>` + strconv.Itoa(int(v.Id)) + `</span>`

								} else { //loop

									ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>` + strconv.Itoa(int(v.Id)) + `</span></a>`

								}
								if j > (2 * h) {
									break
								}
							}
							if ipagesbar_end == i {
								ipagesbar = ipagesbar + `<a href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `"><span>></span></a>`
							}
							//话题内容部位 页码 e
						}
						self.Data["ipagesbar"] = template.HTML(ipagesbar + "</div>")
					}
				}
				// (tps []*Topic)

			}
			//侧栏你可能喜欢 推荐同节点下的最热话题
			if tps := model.GetTopicsByNid(tp.Nid, 0, 6, 0, "hotness"); *tps != nil {

				if len(*tps) > 0 {
					i := 0
					output := `<ul class="widgets-similar clx">`
					for _, v := range *tps {

						i += 1
						if i == 3 {
							output = output + `<li class="similar similar-third">`
							i = 0
						} else {
							output = output + `<li class="similar">`
						}
						output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
					}
					output = output + `</ul>`
					self.Data["topic_sidebar_hotness_6_module"] = template.HTML(output)
				}

			}

			//侧栏九宫格推荐榜单
			//先行取出最热门的一个节点 然后根据节点获取该节点下最热门的话题
			if nd, err := model.GetNodes(0, 1, "hotness"); err == nil {
				if len(*nd) == 1 {
					for _, v := range *nd {

						if tps := model.GetTopicsByNid(v.Id, 0, 9, 0, "hotness"); err == nil {

							if len(*tps) > 0 {
								i := 0
								output := `<ul class="widgets-popular widgets-similar clx">`
								for _, v := range *tps {

									i += 1
									if i == 3 {
										output = output + `<li class="similar similar-third">`
										i = 0
									} else {
										output = output + `<li class="similar">`
									}
									output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
								}
								output = output + `</ul>`
								self.Data["topic_hotness_9_module"] = template.HTML(output)
							}
						} else {
							fmt.Println("推荐榜单(9)数据查询出错", err)
						}
					}
				}
			} else {
				fmt.Println("节点数据查询出错", err)
			}

			//底部六格推荐
			//推荐同一作者的最热话题
			if tps := model.GetTopicsByUid(tp.Uid, 0, 6, 0, "hotness"); len(*tps) > 0 {
				i := 0
				output := `<ul class="widgets-similar clx">`
				for _, v := range *tps {

					i += 1
					if i == 3 {
						output = output + `<li class="likesimilar likesimilar-3">`
						i = 0
					} else {
						output = output + `<li class="likesimilar">`
					}
					output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `" alt="` + v.Title + `" class="likeimglink">
												<img src="` + v.ThumbnailsMedium + `" wdith="150" height="150" />
												<span class="bg">` + v.Title + `</span>			
											</a>
										</li>`
				}
				output = output + `</ul>`
				self.Data["topic_hotness_6_module"] = template.HTML(output)
			} else {
				fmt.Println("六格推荐查询出错:", err)
			}

		} else {
			self.Redirect("/", 302)
		}
	} else {
		self.Redirect("/", 302)
	}

}
Esempio n. 5
0
func (self *SearchHandler) Get() {
	self.TplNames = "search.html"
	keyword := self.GetString(":keyword")
	if keyword == "" {
		keyword = self.GetString("keyword")
	}

	ipage, _ := self.GetInt(":page")
	if ipage <= 0 {
		ipage, _ = self.GetInt("page")
	}
	page := int(ipage)

	limit := 9 //每页显示数目

	//如果已经登录登录
	sess_username, _ := self.GetSession("username").(string)
	if sess_username != "" {
		limit = 30
	}

	if keyword != "" {
		if rc, err := model.SearchTopic(keyword, 0, 0, "id"); err == nil {

			rcs := len(*rc)
			pages, pageout, beginnum, endnum, offset := helper.Pages(rcs, page, limit)

			if st, err := model.SearchTopic(keyword, offset, limit, "hotness"); err == nil {
				results_count := len(*st)
				if results_count > 0 {
					i := 1
					output := ""
					for _, v := range *st {

						i += i
						if i == 3 {
							output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin pin3">`
							i = 0
						} else {

							output = output + `<div id="pin-` + strconv.Itoa(int(v.Id)) + `" class="pin">`
						}
						output = output + `<div class="pin-coat">
									<a href="/` + strconv.Itoa(int(v.Id)) + `/" class='imageLink image loading' target='_blank'>
										<img src='/static/mzr/img/dot.png' original='` + v.ThumbnailsLarge + `' width='200' height='150' alt='` + v.Title + ` ` + v.Created.String() + ` ` + v.Node + ` ` + v.Category + `' oriheight='300' />
										<span class='bg'>` + v.Title + `</span>
									</a>
									<div class="pin-data clx">
										<span class="timer">
											<em></em>
											<span>` + helper.TimeSince(v.Created) + `</span>
										</span>
										<a href="/` + strconv.Itoa(int(v.Id)) + `/" class="viewsButton" title="阅读` + v.Title + `" target="_blank">
											<em></em>
											<span>` + strconv.Itoa(int(v.Views)) + ` views</span>
										</a>
									</div>
								</div>
							</div>`
					}
					self.Data["topics"] = output

				}

			}

			if k := self.GetString("keyword"); k != "" {
				self.Data["search_keyword"] = k
			} else {
				self.Data["search_keyword"] = keyword
			}

			self.Data["pagebar"] = helper.Pagesbar("/search/", keyword, rcs, pages, pageout, beginnum, endnum, 0)
		} else {
			fmt.Println("SearchTopic errors:", err)
			return
		}

		//侧栏九宫格推荐榜单
		//根据用户的关键词推荐
		nds, ndserr := model.SearchNode(keyword, 0, 9, "hotness")
		cats, catserr := model.SearchCategory(keyword, 0, 9, "hotness")
		//如果在节点找到关键词
		if (ndserr == catserr) && (ndserr == nil) {

			output_start := `<ul class="widgets-popular widgets-similar clx">`
			output := ""
			i := 0
			if len(*nds) >= len(*cats) && len(*nds) > 0 {
				for _, v := range *nds {

					if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); len(*tps) > 0 {

						for _, v := range *tps {

							i += 1
							if i == 3 {
								output = output + `<li class="similar similar-third">`
								i = 0
							} else {
								output = output + `<li class="similar">`
							}
							output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
						}
					}

				}
			} else if len(*cats) > len(*nds) && len(*cats) > 0 {
				for _, v := range *cats {

					if tps := model.GetTopicsByCid(v.Id, 0, 1, 0, "hotness"); len(*tps) > 0 {

						for _, v := range *tps {

							i += 1
							if i == 3 {
								output = output + `<li class="similar similar-third">`
								i = 0
							} else {
								output = output + `<li class="similar">`
							}
							output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
						}
					}

				}
			}
			output_end := "</ul>"
			if len(output) > 0 {
				output = output_start + output + output_end
				self.Data["topic_hotness_9_module"] = template.HTML(output)
			} else {
				self.Data["topic_hotness_9_module"] = nil
			}
		}
		//侧栏九宫格推荐榜单
		//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
		if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
			if len(*nd) > 0 {
				for _, v := range *nd {

					i := 0
					output_start := `<ul class="widgets-popular widgets-similar clx">`
					output := ""
					if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

						if len(*tps) > 0 {
							for _, v := range *tps {

								i += 1
								if i == 3 {
									output = output + `<li class="similar similar-third">`
									i = 0
								} else {
									output = output + `<li class="similar">`
								}
								output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
							}
						}
					}
					output_end := "</ul>"
					if len(output) > 0 {
						output = output_start + output + output_end
						self.Data["topic_hotness_9_module"] = template.HTML(output)
					} else {
						self.Data["topic_hotness_9_module"] = nil
					}

				}
			}
		} else {
			fmt.Println("节点数据查询出错", err)
		}
	} else {
		self.Redirect("/", 302)
	}

}
Esempio n. 6
0
func (self *SigninHandler) Get() {

	remember, ckerr := self.Ctx.Request.Cookie("remember")
	sess_username, _ := self.GetSession("username").(string)
	//如果未登录
	if sess_username == "" {
		if ckerr == nil {
			if remember.Value == "on" {
				self.Data["remember"] = "on"
			} else {
				self.Data["remember"] = nil
			}
		}
		self.TplNames = "signin.html"

	} else { //如果已登录
		self.Redirect("/", 302)
	}

	//侧栏九宫格推荐榜单
	//先行取出最热门的9个节点 然后根据节点获取该节点下最热门的话题
	if nd, err := model.GetNodes(0, 9, "hotness"); err == nil {
		if len(*nd) > 0 {
			for _, v := range *nd {

				i := 0
				output_start := `<ul class="widgets-popular widgets-similar clx">`
				output := ""
				if tps := model.GetTopicsByNid(v.Id, 0, 1, 0, "hotness"); err == nil {

					if len(*tps) > 0 {
						for _, v := range *tps {

							i += 1
							if i == 3 {
								output = output + `<li class="similar similar-third">`
								i = 0
							} else {
								output = output + `<li class="similar">`
							}
							output = output + `<a target="_blank" href="/` + strconv.Itoa(int(v.Id)) + `/" title="` + v.Title + `">
												<img src="` + v.ThumbnailsSmall + `" wdith="70" height="70" />				
											</a>
										</li>`
						}
					}
				}
				output_end := "</ul>"
				if len(output) > 0 {
					output = output_start + output + output_end
					self.Data["topic_hotness_9_module"] = template.HTML(output)
				} else {
					self.Data["topic_hotness_9_module"] = nil
				}

			}
		}
	} else {
		fmt.Println("节点数据查询出错", err)
	}
}