Esempio n. 1
0
/*
文章显示,每浏览一次浏览量增加1
*/
func (this *IndexController) New() {
	uid := this.GetSession("sessionuid")

	/*
		输出文章信息
	*/
	article1, _ := models.Articleread(uid, 0)
	this.Data["article1"] = article1

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	articleid1 := this.Input().Get("articleid")
	articleid, _ := strconv.Atoi(articleid1)
	// this.Data["test"] = articleid
	// this.TplNames = "article/testarticle.html"
	// return
	//浏览量加1
	err := models.Articleviewsadd(articleid)
	if err != nil {
		return
	}
	article, _ := models.Articlefindwithaid(articleid1)
	userid := this.GetSession("sessionuid")
	var userinfo *models.User
	userinfo, err = models.Userinfowithuid(userid)
	if err != nil {
		return
	}
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.Data["userinfo"] = userinfo
	this.Data["article"] = article
	this.TplNames = "blog/news.html"
}
Esempio n. 2
0
/*
分类显示
*/
func (this *IndexController) Category() {
	//获取分类
	category := this.GetString("tags")
	//输出文章,显示在左侧
	article1, err := models.Articlecategory(category)
	if err != nil {
		return
	}
	this.Data["article1"] = article1
	this.Data["tags"] = category

	this.Data["status"] = false
	/*
		输出文章信息,用于右侧显示
	*/
	uid := this.GetSession("sessionuid")
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	userinfo, err := models.Userinfowithuid(uid)
	if err != nil {
		return
	}
	this.Data["userinfo"] = userinfo
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.TplNames = "blog/learn.html"

}
Esempio n. 3
0
func (this *IndexController) Riji() {
	uid := this.GetSession("sessionuid")
	/*
		输出文章信息
	*/
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand

	//获取用户信息
	userinfo, _ := models.Userinfowithuid(uid)
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	//获取日记信息
	diary, _, count := models.Dirayfindwithuserid(uid)
	if count == 0 {
		this.Data["nodiary"] = true
	} else {
		this.Data["nodiary"] = false
	}
	this.Data["diary"] = diary
	this.Data["userinfo"] = userinfo
	this.TplNames = "blog/riji.html"
}
Esempio n. 4
0
/*
学无止境
*/
func (this *IndexController) Xuewuzhijing() {
	/*
		输出文章信息
	*/
	uid := this.GetSession("sessionuid")
	article, _ := models.Articleread(uid, 0)
	this.Data["article"] = article

	/*
		文章推荐信息
	*/
	articletuijian, _ := models.Articletuijian()
	this.Data["articletuijian"] = articletuijian

	/*
		随机文章信息
	*/
	articlerand, _ := models.Articlerand()
	this.Data["articlerand"] = articlerand
	this.Data["status"] = true
	userinfo, err := models.Userinfowithuid(uid)
	if err != nil {
		return
	}
	this.Data["userinfo"] = userinfo
	if userinfo.Job != "" {
		this.Data["job"] = userinfo.Job
	} else {
		this.Data["job"] = "暂未填写"
	}
	if userinfo.Brief != "" {
		this.Data["brief"] = userinfo.Brief
	} else {
		this.Data["brief"] = "暂未填写"
	}
	this.TplNames = "blog/learn.html"
}
Esempio n. 5
0
/*
文章列表页面
*/
func (this *AdminController) Articlelist() {
	keyword := this.GetString("keyword")
	searchtype := this.GetString("searchtype")
	uid := this.GetSession("sessionuid")
	//判断点击状态,分别是已发布,草稿箱,回收站
	var status int = 0
	status, _ = this.GetInt("status")
	articlesum1, _ := models.Articletypesum(uid, 0)
	articlesum2, _ := models.Articletypesum(uid, 1)
	articlesum3, _ := models.Articletypesum(uid, 2)
	//用于显示关键字类型
	this.Data["searchtype"] = "false"
	//判断状态
	if status == 0 {
		statusid := 0
		var err error
		var articlelist []*models.Article
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"

			}
		} else {
			articlelist, err = models.Articleread(uid, statusid)
		}
		if err != nil {
			return
		}

		this.TplNames = "article/list.html"
		this.Data["article"] = articlelist
		this.Data["yifabu"] = true
		this.Data["articlesum1"] = articlesum1
		this.Data["articlesum2"] = articlesum2
		this.Data["articlesum3"] = articlesum3
		return
	} else if status == 1 {
		//草稿箱
		statusid := 1
		var err error
		var articlelist []*models.Article
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"
			}
		} else {
			articlelist, err = models.Articleread(uid, statusid)
		}
		if err != nil {
			return
		}
		this.TplNames = "article/list.html"
		this.Data["article"] = articlelist
		this.Data["caogaoxiang"] = true
		this.Data["articlesum1"] = articlesum1
		this.Data["articlesum2"] = articlesum2
		this.Data["articlesum3"] = articlesum3
		return
	} else {
		statusid := 2
		var err error
		var articlelist []*models.Article
		//判断是否关键字搜索,并分类处理
		if len(keyword) > 0 {
			if searchtype == "title" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 0)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
			} else if searchtype == "author" {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 1)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "author"
			} else {
				articlelist, err = models.Articlereadwithkeyword(uid, statusid, keyword, 2)
				this.Data["guanjianzi"] = true
				this.Data["guanjianzivalue"] = keyword
				this.Data["searchtype"] = "tag"
			}
		} else {
			articlelist, err = models.Articleread(uid, statusid)
		}
		if err != nil {
			return
		}
		this.TplNames = "article/list.html"
		this.Data["article"] = articlelist
		this.Data["huishouzhan"] = true
		this.Data["articlesum1"] = articlesum1
		this.Data["articlesum2"] = articlesum2
		this.Data["articlesum3"] = articlesum3
		return
	}

}
Esempio n. 6
0
func (this *IndexController) Get() {
	//获取cookie和session值
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	uid := this.GetSession("sessionuid")
	/*
		如果存在cookie,判断session是否存在,不存在就创建session
	*/
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}
		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		this.TplNames = "blog/index.html"
		return
	} else if uid != nil {

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		this.TplNames = "blog/index.html"
		return
	} else {
		this.Redirect("/", 301)
	}

}
Esempio n. 7
0
func (this *IndexController) About() {
	//获取user表中的introduce字段值
	uid := this.GetSession("sessionuid")
	cookieaccount := this.Ctx.GetCookie("cookieaccount")
	if len(cookieaccount) > 0 {
		if uid == nil {
			//获取用户账号account
			account := DecodeCookie(cookieaccount)
			//获取用户uid
			userinfo, _ := models.Userinfo(account)
			uid = userinfo.Id
			this.SetSession("sessionuid", uid)
		}

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		//读取数据
		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		if userinfo.Introduce != "" {
			this.Data["introduce"] = userinfo.Introduce
			this.TplNames = "blog/about.html"
		} else {
			this.Data["introduce"] = "暂无内容!"
			this.TplNames = "blog/about.html"
		}
	} else if uid != nil {

		/*
			输出文章信息
		*/
		article, _ := models.Articleread(uid, 0)
		this.Data["article"] = article

		/*
			文章推荐信息
		*/
		articletuijian, _ := models.Articletuijian()
		this.Data["articletuijian"] = articletuijian

		/*
			随机文章信息
		*/
		articlerand, _ := models.Articlerand()
		this.Data["articlerand"] = articlerand

		userinfo, err := models.Userinfowithuid(uid)
		if err != nil {
			return
		}
		this.Data["userinfo"] = userinfo
		if userinfo.Job != "" {
			this.Data["job"] = userinfo.Job
		} else {
			this.Data["job"] = "暂未填写"
		}
		if userinfo.Brief != "" {
			this.Data["brief"] = userinfo.Brief
		} else {
			this.Data["brief"] = "暂未填写"
		}
		if userinfo.Introduce != "" {
			this.Data["introduce"] = userinfo.Introduce
			this.TplNames = "blog/about.html"
		} else {
			this.Data["introduce"] = "暂无内容!"
			this.TplNames = "blog/about.html"
		}
	} else {
		this.Redirect("/", 301)
	}

}