Beispiel #1
0
func (this *MainController) Get() {
	page, err := this.GetInt64("p", 1)
	if err != nil {
		beego.Error(err)
	}

	extend := map[string]string{}
	tid := this.GetString("tid", "")
	key := this.GetString("key")
	if tid != "" {
		extend["type_id"] = tid
	}

	beego.Info(extend)
	maps, err := models.GetArtPageList(10, (page-1)*10, extend, key)

	if err != nil {
		beego.Error(err)
	}
	count, err := models.GetCount(extend, key)
	if err != nil {
		beego.Error(err)
	}
	p := pagination.NewPaginator(this.Ctx.Request, 10, count)
	beego.Info(p)
	this.Data["paginator"] = p
	types := models.GetAllType()
	this.Data["articles"] = maps
	this.Data["types"] = types
	this.Data["key"] = key
	beego.AppConfig.String("banner1.name")

	this.TplNames = "index.tpl"
}
Beispiel #2
0
//博客首页
func (this *IndexController) Get() {
	//先处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		beego.Error(err)
	}
	count, err := models.GetArticleCount([]int{1})
	if err != nil {
		beego.Error(err)
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator

	this.Data["Articles"], err = models.GetArticles(paginator.Offset(), pageSize, []int{1})
	if err != nil {
		beego.Error(err)
	}
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
	this.Layout = "index/layout.html"
	this.TplNames = "index/index.html"
	return
}
Beispiel #3
0
//显示列表
func (c *ArticleController) List() {
	//显示列表
	page, _ := c.GetInt("p")
	size, _ := c.GetInt("s")
	if page == 0 {
		page = 1
	}
	if size == 0 {
		size = 10
	}

	//计算开始
	start := (page - 1) * size
	where := "1=1 "
	key := c.GetString("key")
	if key != "" {
		where += " And Title like '%" + key + "%' "
	}
	CheckAdminLogin(&c.Controller, 0)
	list, total := models.GetArticleList(where, "Id desc", size, start)
	//计算页数
	totalpage := total / int64(page)
	if total%int64(page) > 0 {
		totalpage++
	}
	p := pagination.NewPaginator(c.Ctx.Request, size, total)
	c.Data["Title"] = "文章列表"
	c.Data["List"] = list
	c.Data["Key"] = key
	c.Data["Page"] = page
	c.Data["Total"] = total
	c.Data["paginator"] = p
	c.TplNames = "admin/article.tpl"
}
Beispiel #4
0
// 显示文章首页
func (this *ArticleController) Get() {
	//获取类型
	atype := this.Ctx.Input.Param(":type")
	var state []int
	if "trash" != atype {
		state = []int{1}
	} else {
		state = []int{0}
	}

	// 处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		pageSize = 10
	}
	count, err := models.GetArticleCount(state)
	if err != nil {
		beego.Error(err)
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator

	// 查询数据库
	this.Data["Articles"], err = models.GetArticles(paginator.Offset(), pageSize, state)
	if err != nil {
		beego.Error(err)
	}
	this.Data["IsTrash"] = atype == "trash"
	this.Data["Title"] = "管理后台 - 所有文章"
	this.Layout = "manager/layout.html"
	this.TplNames = "manager/article_index.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = "manager/article_index_heade.html"
	return
}
func (c *POIUserMonitorController) QueryUsers() {
	c.Layout = "layout/layout_monitor.tpl"
	c.TplNames = "monitor/user_query.tpl"
	count := models.GetUsersCount()
	if count > 0 {
		p := page.NewPaginator(c.Ctx.Request, 10, count)
		users := models.QueryUsers(p.Offset(), 10)
		c.Data["data"] = users
		c.Data["paginator"] = p
	}
	c.Data["type"] = "user"
}
func (c *POISessionMonitorController) SessionQuery() {
	c.Layout = "layout/layout_monitor.tpl"
	c.TplNames = "monitor/session_query.tpl"
	count := models.GetSessionsCount()
	if count > 0 {
		p := page.NewPaginator(c.Ctx.Request, 10, count)
		sessions := models.QuerySessions(p.Offset(), 10)
		c.Data["data"] = sessions
		c.Data["paginator"] = p
	}
	c.Data["type"] = "session"
}
Beispiel #7
0
func (c *AdminController) Get() {
	var scposts []models.BlogPost

	count := models.Count(models.DbPost, nil)
	page := pagination.NewPaginator(c.Ctx.Request, 10, count)
	c.Data["paginator"] = page

	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", nil, &scposts)
	c.Data["Lists"] = scposts

	c.TplNames = "admin/admin.html"
}
Beispiel #8
0
func (c *UserController) Index() {
	var scposts []models.BlogPost

	count := models.Count(models.DbPost, nil)
	page := pagination.NewPaginator(c.Ctx.Request, 10, count)
	c.Data["paginator"] = page

	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", nil, &scposts)
	c.Data["Lists"] = scposts

	c.Data["SiteName"] = beego.AppConfig.String("sitename")
	c.Data["SubTitle"] = beego.AppConfig.String("subtitle")

	c.TplNames = "user/index.html"
}
Beispiel #9
0
// 标签页面
func (this *IndexController) TagList() {
	tag := this.Ctx.Input.Param(":tag")
	if tag == "" {
		this.Abort("404")
	}

	// 定义一个Tag
	var sctag models.SC_Tag

	// 获取标签信息
	models.GetOneByQuery(models.DbTag, bson.M{"slug": tag}, &sctag)

	if sctag.Id.Hex() == "" {
		this.Data["NotSearch"] = true
		this.TplNames = "home/index.html"
		return
	}

	tag = sctag.Caption

	this.Data["SiteName"] = tag
	this.Data["SubTitle"] = models.Option.SiteName
	this.Data["Keywords"] = models.Option.Keywords
	this.Data["Description"] = models.Option.Description

	// 定义一个Post列表
	var scposts []models.SC_Post

	// 获取文章数量
	count := models.Count(models.DbPost, bson.M{"type": "post", "tags": tag})

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 10, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取文章列表
	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", bson.M{"type": "post", "tags": tag}, &scposts)
	// 设置文章列表
	this.Data["Lists"] = scposts

	if len(scposts) <= 0 {
		this.Data["NotSearch"] = true
	}

	this.TplNames = "home/index.html"
}
Beispiel #10
0
// 默认首页界面
func (this *AdminController) Index() {
	// 定义一个SC_Post列表
	var scposts []models.SC_Post

	// 获取文章数量
	count := models.Count(models.DbPost, nil)

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 10, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取文章列表
	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", nil, &scposts)
	// 设置文章列表
	this.Data["Lists"] = scposts

	this.TplNames = "admin/index.html"
}
Beispiel #11
0
// 搜索
func (this *IndexController) Search() {
	key := this.GetString("q")
	if key == "" {
		this.Redirect("/", 302)
	}

	this.Data["SiteName"] = `搜索 "` + key + `"`
	this.Data["SubTitle"] = models.Option.SiteName
	this.Data["Keywords"] = models.Option.Keywords
	this.Data["Description"] = models.Option.Description
	this.Data["Key"] = key

	// 定义一个Post列表
	var scposts []models.SC_Post

	// 获取文章数量
	count := models.Count(models.DbPost, bson.M{"type": "post", "$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}, bson.M{"tags": bson.M{"$regex": bson.RegEx{key, "i"}}}}})

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 10, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取文章列表
	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", bson.M{"type": "post", "$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}, bson.M{"tags": bson.M{"$regex": bson.RegEx{key, "i"}}}}}, &scposts)
	// 设置文章列表
	this.Data["Lists"] = scposts

	if len(scposts) <= 0 {
		this.Data["NotSearch"] = true

		// 定义一个SC_Tag列表
		var tagslist []models.SC_Tag

		// 获取所有标签
		models.GetAllByQuery(models.DbTag, nil, &tagslist)

		// 设置标签列表
		this.Data["TagsList"] = tagslist
	}

	this.TplNames = "home/search.html"
}
Beispiel #12
0
func (this *UserController) List() {
	page, err := this.GetInt("pageNum", 1)
	numPerPage, err := this.GetInt("numPerPage", 20)
	keyword := this.GetString("keyword", "")

	if err != nil {
		beego.Error(err)
	}
	extend := map[string]string{}
	maps, err := models.GetUserPageList(numPerPage, (page-1)*numPerPage, extend, keyword)
	count, err := models.GetUserCount(extend, "")
	if err != nil {
		beego.Error(err)
	}
	this.Ctx.Request.Form.Add("p", this.GetString("pageNum"))
	p := pagination.NewPaginator(this.Ctx.Request, numPerPage, count)
	this.Data["paginator"] = p
	this.Data["users"] = maps
	this.Data["keyword"] = keyword
	this.TplNames = "user/list.html"
}
Beispiel #13
0
func (this *UserController) TagList() {
	tag := this.Ctx.Input.Param(":tag")
	if tag == "" {
		this.Abort("404")
	}

	var sctag models.BlogTag

	models.GetOneByQuery(models.DbTag, bson.M{"slug": tag}, &sctag)

	if sctag.Id.Hex() == "" {
		this.Data["NotSearch"] = true
		this.TplNames = "home/index.html"
		return
	}

	tag = sctag.Caption

	//      this.Data["SiteName"] = tag
	//      this.Data["SubTitle"] = models.Option.SiteName
	//      this.Data["Keywords"] = models.Option.Keywords
	//      this.Data["Description"] = models.Option.Description

	var scposts []models.BlogPost

	count := models.Count(models.DbPost, bson.M{"type": "post", "tags": tag})

	page := pagination.NewPaginator(this.Ctx.Request, 10, count)

	this.Data["paginator"] = page

	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", bson.M{"type": "post", "tags": tag}, &scposts)
	this.Data["Lists"] = scposts

	if len(scposts) <= 0 {
		this.Data["NotSearch"] = true
	}

	this.TplNames = "user/index.html"
}
Beispiel #14
0
// 默认页面
func (this *IndexController) Index() {
	this.Data["Keywords"] = models.Option.Keywords
	this.Data["Description"] = models.Option.Description

	// 定义一个Post列表
	var scposts []models.SC_Post

	// 获取文章数量
	count := models.Count(models.DbPost, bson.M{"type": "post"})

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 10, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取文章列表
	models.GetDataByQuery(models.DbPost, page.Offset(), 10, "-created", bson.M{"type": "post"}, &scposts)
	// 设置文章列表
	this.Data["Lists"] = scposts

	this.TplNames = "home/index.html"
}
Beispiel #15
0
//显示首页
func (this *CategoryController) Get() {
	//处理分页
	pageSize, err := beego.AppConfig.Int("pagesize")
	if err != nil {
		pageSize = 10
	}
	count, err := models.GetCategoryCount()
	if err != nil {
		this.Abort("404")
	}
	paginator := pagination.NewPaginator(this.Ctx.Request, pageSize, count)
	this.Data["paginator"] = paginator
	//查询数据
	this.Data["Categories"], err = models.GetCategories(paginator.Offset(), pageSize)
	if err != nil {
		this.Abort("404")
	}
	this.Data["Title"] = "管理后台 - 所有分类"
	this.Layout = "manager/layout.html"
	this.TplNames = "manager/category_index.html"
	this.LayoutSections = make(map[string]string)
	this.LayoutSections["HtmlHead"] = "manager/category_index_heade.html"
}
Beispiel #16
0
// 搜索页
func (this *IndexController) Search() {
	// 获取搜索关键字
	key := this.Ctx.Input.Param(":k")
	// 获取排序方式
	sort := this.Ctx.Input.Param(":sort")
	// 设置排序方式
	this.Data["Sort"] = sort
	if sort == "" {
		this.Data["Sort"] = "puttime"
		sort = "-hot"
	}

	sort = "-" + sort

	// 设置搜索词
	this.Data["Key"] = key

	// 定义两个SC_Info列表
	var infos, newlist, hots []models.SC_Info

	// 获取热门种子列表
	models.GetDataByQuery(models.DbInfo, 0, 5, "-hot", nil, &hots)
	// 设置热门列表
	this.Data["HotList"] = hots

	// 获取最新入库
	models.GetDataByQuery(models.DbInfo, 0, 10, "-puttime", nil, &newlist)
	// 设置最新入库
	this.Data["NewList"] = newlist

	// 设置查询条件
	query := bson.M{"$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}, bson.M{"keys": bson.M{"$regex": bson.RegEx{key, "i"}}}}}

	// 获取种子数量
	count := models.Count(models.DbInfo, query)

	// 设置数量
	this.Data["Nums"] = count

	// 获取分页数据
	page := pagination.NewPaginator(this.Ctx.Request, 15, count)
	// 设置分页数据
	this.Data["paginator"] = page

	// 获取种子列表
	models.GetDataByQuery(models.DbInfo, page.Offset(), 15, sort, query, &infos)
	// 设置种子列表
	this.Data["Lists"] = infos

	// 定义三个SC_Search列表
	var randomlist, lastsearch, relevantsearch []models.SC_Search

	// 设置查询条件
	query = bson.M{"$or": []bson.M{bson.M{"caption": bson.M{"$regex": bson.RegEx{key, "i"}}}}}
	// 获取相关搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-searchtime", query, &relevantsearch)
	// 设置相关搜索
	this.Data["RelevantList"] = relevantsearch

	// 获取热门搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-views", nil, &randomlist)
	// 设置热门搜索
	this.Data["RandomList"] = randomlist

	// 获取最近搜索
	models.GetDataByQuery(models.DbSearch, 0, 10, "-searchtime", nil, &lastsearch)
	// 设置最后搜索
	this.Data["LastSearch"] = lastsearch

	// 定义一个SC_Search
	var scsearch models.SC_Search
	// 设置关键字
	scsearch.Caption = key
	// 设置查询次数
	scsearch.Views = 1
	// 设置查询到的数据总量
	scsearch.Count = count
	// 保存数据
	scsearch.Save()

	// 自增查询次数
	models.SaveLog(time.Now().Format("20060102"), "searchnums")

	// 输出模板
	this.TplNames = "list.html"
}
Beispiel #17
0
func (this *BaseController) SetPaginator(per int, nums int64) *pagination.Paginator {
	p := pagination.NewPaginator(this.Ctx.Request, per, nums)
	this.Data["paginator"] = p
	return p
}