Esempio n. 1
0
func (this *IndexController) Prepare() {
	this.Data["SiteName"] = models.Option.SiteName
	this.Data["SubTitle"] = models.Option.SubTitle
	this.Data["Author"] = models.Option.Author
	this.Data["Email"] = models.Option.Email
	this.Data["StartTime"] = time.Now()

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

	// 获取所有页面
	models.GetAllByQuery(models.DbPost, bson.M{"type": "page"}, &ps)
	// 设置页面
	this.Data["Pages"] = ps
}
Esempio n. 2
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"
}
Esempio n. 3
0
// 内链管理
func (this *AdminController) External() {
	if this.Ctx.Request.Method == "POST" {
		caption := this.GetString("caption")
		link := this.GetString("link")

		redirect := &models.SC_Redirect{
			Caption: caption,
			Link:    link,
		}

		redirect.Save()

		this.Redirect("/admin/redirect", 302)
	}

	var links []models.SC_Redirect

	models.GetAllByQuery(models.DbRedirect, nil, &links)

	this.Data["Lists"] = links

	ids := this.Ctx.Input.Param(":id")
	if ids != "" {
		id := bson.ObjectIdHex(ids)

		var link models.SC_Redirect

		models.GetOneById(models.DbRedirect, id, &link)

		this.Data["Id"] = link.Id
		this.Data["Caption"] = link.Caption
		this.Data["Link"] = link.Link
	}

	this.TplNames = "admin/redirect.html"
}