Exemplo n.º 1
0
func (this *AboutController) Get() {
	this.Data["IsAbout"] = true
	this.Data["Categories"], _ = models.GetAllCategories()
	this.Data["Labels"], _ = models.GetAllLabels()
	this.Data["NewTopics"], _ = models.GetAllNewTopics()
	this.Data["VIewsTopics"], _ = models.GetAllViewsTopics()
	this.TplNames = "about.html"
}
Exemplo n.º 2
0
func (this *ArchiveController) Get() {
	this.Data["Categories"], _ = models.GetAllCategories()
	this.Data["Labels"], _ = models.GetAllLabels()
	this.Data["NewTopics"], _ = models.GetAllNewTopics()
	this.Data["VIewsTopics"], _ = models.GetAllViewsTopics()
	this.Data["IsArchive"] = true
	this.Data["ArchiveTopics"], _ = models.GetAllArchiveTopics()
	this.TplNames = "archive.html"
}
Exemplo n.º 3
0
func (this *CategoryController) Get() {
	this.Layout = "admin/layout.html"
	this.TplNames = "admin/Tpl/T.category.tpl"
	this.Data["isCategory"] = true
	this.Data["Username"] = this.GetSession("username")
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
}
Exemplo n.º 4
0
func (this *TopicController) EditTopicShow() {
	tid := this.Input().Get("tid")
	this.Data["Username"] = this.GetSession("username")
	this.Data["toplicList"] = true
	if tid == "" {
		this.Layout = "admin/layout.html"
		this.TplNames = "admin/Tpl/T.error.tpl"
	} else {
		this.Layout = "admin/layout.html"
		this.TplNames = "admin/Tpl/T.editTopic.tpl"
		topic, err := models.GetTopic(tid)
		if err != nil {
			beego.Error(err)
			this.Redirect("/admin/home", 302)
			return
		}
		this.Data["Topic"] = topic
		Categories, err := models.GetAllCategories()
		if err != nil {
			beego.Error(err)
		}
		for _, v := range Categories {
			cate, _ := strconv.Atoi(topic.Category)
			if v.Id == int64(cate) {
				v.IsSelected = true
			} else {
				v.IsSelected = false
			}
		}
		this.Data["Categories"] = Categories
		AllLabels, err := models.GetAllLabels()
		Lables := strings.Split(topic.Lables, " ")
		if len(Lables) > 0 {
			for _, v := range AllLabels {
				v.IsSelected = false
				for _, s := range Lables {
					lab, _ := strconv.Atoi(s)
					if v.Id == int64(lab) {
						v.IsSelected = true
						break
					}
				}
			}
		}
		this.Data["Labels"] = AllLabels
		if err != nil {
			beego.Error(err)
		}
	}
}
Exemplo n.º 5
0
func (this *TopicController) Get() {
	this.Layout = "admin/layout.html"
	this.TplNames = "admin/Tpl/T.addTopic.tpl"
	this.Data["isAddTopic"] = true
	this.Data["Username"] = this.GetSession("username")
	var err error
	this.Data["Categories"], err = models.GetAllCategories()
	if err != nil {
		beego.Error(err)
	}
	this.Data["Labels"], err = models.GetAllLabels()
	if err != nil {
		beego.Error(err)
	}
}
Exemplo n.º 6
0
func (this *TopicController) Get() {
	topicId := this.Input().Get("topicId")
	if topicId == "" {
		this.TplNames = "error.html"
	} else {
		topic, err := models.GetTopic(topicId)
		if err != nil {
			beego.Error(err)
			this.Redirect("/", 302)
			return
		}
		this.Data["Topic"] = topic
		this.Data["Category"] = models.GetCategory(topic.Category)
		//AllLabels := make([]string, 10)
		Lables := strings.Split(topic.Lables, " ")
		var MyLables []MyLabel

		if len(Lables) > 0 {
			for i, n := 0, len(Lables); i < n; i++ {
				//AllLabels[i] = models.GetLabel(Lables[i])
				LabelOne := MyLabel{
					Name: models.GetLabel(Lables[i]),
					Id:   Lables[i],
				}
				MyLables = append(MyLables, LabelOne)
			}
			//this.Data["LablesId"] = Lables[0:len(Lables)]
		}
		this.Data["Label"] = MyLables
		if err != nil {
			beego.Error(err)
		}
		this.Data["Categories"], _ = models.GetAllCategories()
		this.Data["Labels"], err = models.GetAllLabels()
		this.Data["NewTopics"], err = models.GetAllNewTopics()
		this.Data["VIewsTopics"], err = models.GetAllViewsTopics()
		this.TplNames = "topicView.html"
	}
}
Exemplo n.º 7
0
func (this *MainController) Get() {
	this.Ctx.Request.ParseForm()
	page, _ := strconv.Atoi(this.Ctx.Request.Form.Get("page"))
	offset := 8
	if page == 0 {
		page = 1
	}

	start := (page - 1) * offset
	cate := this.Input().Get("cate")
	label := this.Input().Get("label")
	list, _ := models.GetAllTopics(cate, label, true, start, offset)
	totalCount, _ := models.GetAllTopicsCount(cate, label)
	var pageCount int
	if totalCount%offset == 0 {
		pageCount = totalCount / offset
	} else {
		pageCount = totalCount/offset + 1
	}
	LabelId := make([][]string, 10)
	Label := make([][]string, 10)
	for i, v := range list {
		LabelId[i] = strings.Split(v.Lables, " ")
		LabelLen := len(LabelId[i])
		LabelId[i] = LabelId[i][0 : LabelLen-1]
		LabelOne := make([]string, 10)
		for j, n := 0, len(LabelId[i]); j < n; j++ {
			LabelOne[j] = models.GetLabel(LabelId[i][j])
		}
		Label[i] = LabelOne
	}
	this.Data["Topics"] = list
	this.Data["LabelId"] = LabelId
	this.Data["Label"] = Label
	//分页配置
	var PageUrl string
	if cate != "" {
		PageUrl = "/?cate=" + cate
		this.Data["HomeTitle"] = "分类:" + models.GetCategory(cate)
	} else if label != "" {
		PageUrl = "/?label=" + label
		this.Data["HomeTitle"] = "标签:" + models.GetLabel(label)
	} else {
		PageUrl = "/"
		this.Data["HomeTitle"] = "最新文章"
	}
	conf := utils.Config{
		PageUrl:       PageUrl,
		PageSize:      1,
		RowsNum:       pageCount,
		AnchorClass:   "",
		LinksNum:      1,
		PageNum:       page,
		CurrentClass:  "",
		InfoTagOpen:   "<li>",
		InfoTagClose:  "</li>",
		FirstTagOpen:  "<li>",
		FirstTagClose: "</li>",
		LastTagOpen:   "<li>",
		LastTagClose:  "</li>",
		CurTagOpen:    "<li>",
		CurTagClose:   "</li>",
		NextTagOpen:   "<li>",
		NextTagClose:  "</li>",
		PrevTagOpen:   "<li>",
		PrevTagClose:  "</li>",
		NumTagOpen:    "<li>",
		NumTagClose:   "</li>",
	}

	pageStr, err := utils.CreateLinks(conf)
	if err != nil {
		beego.BeeLogger.Critical("CreateLinks: ", err)
	}

	if pageStr == "404" {
		this.Ctx.Redirect(302, "/")
	}

	this.Data["PageStr"] = "<ul class='pagination'>" + pageStr + "</ul>"
	this.Data["Categories"], _ = models.GetAllCategories()
	this.Data["Labels"], err = models.GetAllLabels()
	this.Data["NewTopics"], err = models.GetAllNewTopics()
	this.Data["VIewsTopics"], err = models.GetAllViewsTopics()
	this.Data["IsHome"] = true
	this.TplNames = "home.html"
}