Exemplo n.º 1
0
//首页, 只显示前N条
func (this *MainController) Index() {
	var (
		list     []*models.Post
		pagesize int
		err      error
		page     int
	)

	if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
		page = 1
	}

	if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
		pagesize = 10
	}

	query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0)
	count, _ := query.Count()
	if count > 0 {
		query.OrderBy("-istop", "-posttime").Limit(pagesize, (page-1)*pagesize).All(&list)
	}

	this.Data["count"] = count
	this.Data["list"] = list
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "").ToString()
	this.setHeadMetas()
	this.display("index")
}
Exemplo n.º 2
0
/*
心灵鸡汤页面
*/
func (this *AdminController) Shuo() {
	op := this.Input().Get("op")
	uid := this.GetSession("sessionuid")
	if op == "add" {
		this.TplNames = "message/editshuo.html"
		this.Data["op"] = "add"
	} else if op == "edit" {
		shuoid, _ := this.GetInt("shuoid")

		shuo, err := models.Shuofind(shuoid)
		if err != nil {
			return
		}
		this.Data["content"] = shuo.Content
		this.TplNames = "message/editshuo.html"
		this.Data["op"] = "edit"
	} else {

		// this.TplNames = "message/shuo.html"
		// //查询数据,输出
		// uid := this.GetSession("sessionuid")
		// userinfo, err := models.Userinfowithuid(uid)
		// if err != nil {
		// 	return
		// }
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		// this.Data["chicken"] = chicken
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}

		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/admin/shuo", true).ToString()
		this.TplNames = "message/shuo.html"

	}
}
Exemplo n.º 3
0
//管理
func (this *ArticleController) List() {
	var (
		page       int
		pagesize   int = 10
		status     int
		offset     int
		list       []*models.Post
		post       models.Post
		searchtype string
		keyword    string
	)
	searchtype = this.GetString("searchtype")
	keyword = this.GetString("keyword")
	status, _ = this.GetInt("status")
	if page, _ = this.GetInt("page"); page < 1 {
		page = 1
	}
	offset = (page - 1) * pagesize

	query := post.Query().Filter("status", status)

	if keyword != "" {
		switch searchtype {
		case "title":
			query = query.Filter("title__icontains", keyword)
		case "author":
			query = query.Filter("author__icontains", keyword)
		case "tag":
			query = query.Filter("tags__icontains", keyword)
		}
	}
	count, _ := query.Count()
	if count > 0 {
		query.OrderBy("-is_top", "-post_time").Limit(pagesize, offset).All(&list)
	}

	this.Data["searchtype"] = searchtype
	this.Data["keyword"] = keyword
	this.Data["count_1"], _ = post.Query().Filter("status", 1).Count()
	this.Data["count_2"], _ = post.Query().Filter("status", 2).Count()
	this.Data["status"] = status
	this.Data["count"] = count
	this.Data["list"] = list
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, fmt.Sprintf("/admin/article/list?status=%d&searchtype=%s&keyword=%s", status, searchtype, keyword), true).ToString()
	this.display()
}
Exemplo n.º 4
0
//历史归档
func (this *MainController) Archives() {
	var (
		page     int
		pagesize int
		err      error
		count    int64
		result   map[string][]*models.Post
	)

	if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
		page = 1
	}

	if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
		pagesize = 20
	} else {
		pagesize *= 2
	}

	query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0)

	count, _ = query.Count()
	result = make(map[string][]*models.Post)
	if count > 0 {
		var list []*models.Post
		query.OrderBy("-post_time").Limit(pagesize, (page-1)*pagesize).All(&list)
		for _, v := range list {
			year := v.PostTime.Format("2006")
			if _, ok := result[year]; !ok {
				result[year] = make([]*models.Post, 0)
			}
			result[year] = append(result[year], v)
		}
	}

	this.Data["page"] = page
	this.Data["count"] = count
	this.Data["pagesize"] = pagesize
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/archives").ToString()
	this.Data["result"] = result

	this.setHeadMetas("归档")
	this.display("archives")
}
Exemplo n.º 5
0
//用户列表
func (this *UserController) List() {
	var page int
	var pagesize int = 10
	var list []*models.User
	var user models.User

	if page, _ = this.GetInt("page"); page < 1 {
		page = 1
	}
	offset := (page - 1) * pagesize

	count, _ := user.Query().Count()
	if count > 0 {
		user.Query().OrderBy("-id").Limit(pagesize, offset).All(&list)
	}

	this.Data["count"] = count
	this.Data["list"] = list
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/admin/user/list", true).ToString()
	this.display()
}
Exemplo n.º 6
0
//标签列表
func (this *TagController) list() {
	var page int
	var pagesize int = 10
	var list []*models.Tag
	var tag models.Tag

	if page, _ = this.GetInt("page"); page < 1 {
		page = 1
	}
	offset := (page - 1) * pagesize

	count, _ := tag.Query().Count()
	if count > 0 {
		tag.Query().OrderBy("-count").Limit(pagesize, offset).All(&list)
	}

	this.Data["count"] = count
	this.Data["list"] = list
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/admin/tag", true).ToString()
	this.display("tag/list")
}
Exemplo n.º 7
0
//分类查看
func (this *MainController) Category() {
	var (
		page     int
		pagesize int
		name     string
		err      error
		count    int64
		result   map[string][]*models.Post
	)
	name = this.Ctx.Input.Param(":name")
	if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
		page = 1
	}
	if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
		pagesize = 20
	} else {
		pagesize *= 2
	}

	tagpost := new(models.TagPost)
	tag := new(models.Tag)
	tag.Name = name

	if tag.Read("Name") != nil {
		this.Abort("404")
	}

	query := tagpost.Query().Filter("tag_id", tag.Id).Filter("post_status", 0)
	count, _ = query.Count()
	result = make(map[string][]*models.Post)
	if count > 0 {
		var tp []*models.TagPost
		var list []*models.Post
		var pids []int = make([]int, 0)

		query.OrderBy("-post_time").Limit(pagesize, (page-1)*pagesize).All(&tp)
		for _, v := range tp {
			pids = append(pids, v.PostId)
		}

		new(models.Post).Query().Filter("id__in", pids).All(&list)

		for _, v := range list {
			year := v.PostTime.Format("2006")
			if _, ok := result[year]; !ok {
				result[year] = make([]*models.Post, 0)
			}
			result[year] = append(result[year], v)
		}
	}

	this.Data["tag"] = tag
	this.Data["page"] = page
	this.Data["pagesize"] = pagesize
	this.Data["count"] = count
	this.Data["result"] = result
	this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, tag.Link()).ToString()

	this.setHeadMetas(tag.Name, tag.Name, tag.Name)
	this.display("category")
}
Exemplo n.º 8
0
func (this *IndexController) Shuo() {
	//获取uid,判断是否非法访问
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	uid := this.GetSession("sessionuid")
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}
		//读取数据
		// userinfo, _ := models.Userinfowithuid(uid)
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		/*
			定义分页方法
		*/
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}

		//判断count是否为0
		if count == 0 {
			this.Data["noshuo"] = true
		} else {
			this.Data["noshuo"] = false
		}
		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/index/shuo", true).ToString()
		this.TplNames = "blog/shuo.html"

	} else if uid != nil {
		//读取数据
		// userinfo, _ := models.Userinfowithuid(uid)
		// chicken, err := models.Selectshuo(userinfo.Id)
		// if err != nil {
		// 	return
		// }
		// this.Data["chicken"] = chicken
		// this.TplNames = "blog/shuo.html"
		/*
			定义分页方法
		*/
		var page int
		var pagesize int = 10
		var list []*models.Chicken_soup
		var chicken models.Chicken_soup

		if page, _ = this.GetInt("page"); page < 1 {
			page = 1
		}
		offset := (page - 1) * pagesize

		count, _ := chicken.Query(uid).Count()
		if count > 0 {
			chicken.Query(uid).OrderBy("-id").Limit(pagesize, offset).All(&list)
		}
		//判断count是否为0
		if count == 0 {
			this.Data["noshuo"] = true
		} else {
			this.Data["noshuo"] = false
		}
		this.Data["count"] = count
		this.Data["list"] = list
		this.Data["pagebar"] = util.NewPager(page, int(count), pagesize, "/index/shuo", true).ToString()
		this.TplNames = "blog/shuo.html"
	} else {
		this.Redirect("/", 301)
	}
}