예제 #1
0
파일: user.go 프로젝트: venliong/ohlala
// 查看粉丝
func user_Fans(ctx *goku.HttpContext) goku.ActionResulter {

	userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	var user *models.User
	if userId > 0 {
		user = models.User_GetById(userId)
	} else {
		if u, ok := ctx.Data["user"]; ok {
			user = u.(*models.User)
			ctx.ViewData["UserMenu"] = "um-fans"
		}
	}

	if user == nil {
		ctx.ViewData["errorMsg"] = "用户不存在"
		return ctx.Render("error", nil)
	}

	page, pagesize := utils.PagerParams(ctx.Request)
	followers, _ := models.UserFollow_Followers(user.Id, page, pagesize)

	ctx.ViewData["Followers"] = models.User_ToVUsers(followers, ctx)
	ctx.ViewData["HasMoreFollowers"] = len(followers) >= pagesize
	return ctx.View(models.User_ToVUser(user, ctx))

}
예제 #2
0
파일: discover.go 프로젝트: hippasus/ohlala
// 发现 首页
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	return ctx.Render("/home/index", nil)
}
예제 #3
0
파일: link.go 프로젝트: polaris1119/ohlala
func admin_links(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	links, total, err := models.Link_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["LinkList"] = links
	ctx.ViewData["TotalLinks"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
예제 #4
0
파일: user.go 프로젝트: polaris1119/ohlala
func admin_users(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	users, total, err := models.User_GetList(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["UserList"] = users
	ctx.ViewData["UserCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
예제 #5
0
func admin_comments(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	comments, total, err := models.Comment_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["CommentList"] = comments
	ctx.ViewData["CommentCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	return ctx.View(nil)
}
예제 #6
0
파일: index.go 프로젝트: yonglehou/ohlala
func admin_index(ctx *goku.HttpContext) goku.ActionResulter {
	var db *goku.MysqlDB = models.GetDB()
	defer db.Close()

	linkCount, err := db.Count("link", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["linkCount"] = linkCount

	userCount, err := db.Count("user", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["userCount"] = userCount

	topicCount, err := db.Count("topic", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["topicCount"] = topicCount

	commentCount, err := db.Count("comment", "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["commentCount"] = commentCount

	return ctx.View(nil)
}
예제 #7
0
파일: topic.go 프로젝트: cloudcache/ohlala
func admin_topics(ctx *goku.HttpContext) goku.ActionResulter {
	page, pagesize := utils.PagerParams(ctx.Request)
	topics, total, err := models.Topic_GetByPage(page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["TopicList"] = topics
	ctx.ViewData["TopicCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	ctx.ViewData["TabName"] = "topics"
	return ctx.View(nil)
}
예제 #8
0
파일: link.go 프로젝트: kicool/ohlala
func link_showWithComments(ctx *goku.HttpContext, slinkId, scommentId string) goku.ActionResulter {

	linkId, err1 := strconv.ParseInt(slinkId, 10, 64)
	commentId, err2 := strconv.ParseInt(scommentId, 10, 64)
	if err1 != nil || err2 != nil {
		ctx.ViewData["errorMsg"] = "参数错误"
		return ctx.Render("error", nil)
	}
	link, err := models.Link_GetById(linkId)
	if err != nil {
		ctx.ViewData["errorMsg"] = "服务器开小差了 >_<!!"
		return ctx.Render("error", nil)
	}

	if link == nil {
		ctx.ViewData["errorMsg"] = "内容不存在,去首页逛逛吧"
		return ctx.Render("error", nil)
	}

	if link.Deleted() {
		ctx.ViewData["errorMsg"] = "内容已被摧毁,去首页逛逛吧"
		return ctx.Render("error", nil)
	}

	if !utils.IsSpider(ctx.Request.UserAgent()) {
		// 更新链接的评论查看计数
		models.Link_IncViewCount(link.Id, 1)
	}

	vlink := models.Link_ToVLink([]models.Link{*link}, ctx)
	sortType := strings.ToLower(ctx.Get("cm_order")) //"hot":热门;"hotc":热议;"time":最新;"vote":得分;"ctvl":"争议"
	if sortType == "" {
		sortType = "hot"
	}
	var comments string
	if commentId > 0 {
		comments = models.GetPermalinkComment(linkId, commentId, sortType)
		ctx.ViewData["SubLinkUrl"] = fmt.Sprintf("permacoment/%d/%d/", linkId, commentId)
	} else {
		comments = models.GetSortComments("", "/", int64(0), linkId, sortType, "", false) //models.Comment_SortForLink(link.Id, "hot")
		ctx.ViewData["SubLinkUrl"] = linkId
	}

	ctx.ViewData["Comments"] = template.HTML(comments)
	ctx.ViewData["SortType"] = sortType
	ctx.ViewData["SortTypeName"] = ORDER_NAMES[sortType]

	return ctx.Render("/link/show", vlink[0])
}
예제 #9
0
파일: link.go 프로젝트: hippasus/ohlala
//link搜索界面
func link_search(ctx *goku.HttpContext) goku.ActionResulter {
	ls := utils.LinkSearch{}
	searchResult, err := ls.SearchLink(ctx.Get("term"), 1, golink.PAGE_SIZE)
	if err == nil && searchResult.TimedOut == false && searchResult.HitResult.HitArray != nil && len(searchResult.HitResult.HitArray) > 0 {
		links, _ := models.Link_GetByIdList(searchResult.HitResult.HitArray)
		ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
		ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE
	} else {
		ctx.ViewData["Links"] = nil
		ctx.ViewData["HasMoreLink"] = false
	}
	ctx.ViewData["Term"] = ctx.Get("term")

	return ctx.Render("/link/search", nil)
}
예제 #10
0
// 发现 首页
func discover_index(ctx *goku.HttpContext) goku.ActionResulter {
	ot := ctx.Get("o")
	if ot == "" {
		ot = "hot"
	}
	dt, _ := strconv.Atoi(ctx.Get("dt"))
	ctx.ViewData["Order"] = ot
	links, _ := models.LinkForHome_GetByPage(ot, dt, 1, golink.PAGE_SIZE)
	ctx.ViewData["Links"] = models.Link_ToVLink(links, ctx)
	ctx.ViewData["TopTab"] = "discover"
	ctx.ViewData["HasMoreLink"] = len(links) >= golink.PAGE_SIZE

	// 最新链接的未读提醒
	var userId, lastReadLinkId int64
	unreadCookieName := "newestUnrLinkId"
	u, ok := ctx.Data["user"]
	if ok && u != nil {
		user := u.(*models.User)
		userId = user.Id
		lastReadLinkId = user.LastReadLinkId
	} else {
		// 从Cook读取最后一次阅读的链接id
		cLastReadLinkId, err := ctx.Request.Cookie(unreadCookieName)
		if err == nil {
			lastReadLinkId, _ = strconv.ParseInt(cLastReadLinkId.Value, 10, 64)
		}
	}
	if ot == "hot" {
		newestUnreadCount, _ := models.NewestLinkUnread_All(userId, lastReadLinkId)
		ctx.ViewData["NewestUnreadCount"] = models.NewestLinkUnread_ToString(userId, newestUnreadCount)
	} else if ot == "time" && links != nil && len(links) > 0 {
		if userId > 0 {
			models.NewestLinkUnread_UpdateForAll(userId, links[0].Id)
		} else {
			c := &http.Cookie{
				Name:     unreadCookieName,
				Value:    fmt.Sprintf("%d", links[0].Id),
				Expires:  time.Now().AddDate(0, 1, 0),
				Path:     "/",
				HttpOnly: true,
			}
			ctx.SetCookie(c)
		}
	}

	return ctx.Render("/home/index", nil)
}
예제 #11
0
// 检查用户的状态(禁言、封号等)
func checkUserStatus(user *models.User, ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	if user != nil && user.IsBaned() {
		if ctx.Request.Method == "POST" {
			if ctx.IsAjax() {
				ar = ctx.Json(map[string]interface{}{
					"success":   false,
					"needLogin": false,
					"errors":    "你已经被禁言。",
				})
			} else {
				ctx.ViewData["errorMsg"] = "你已经被禁言"
				ar = ctx.Render("error", nil)
			}
		}
	}
	return
}
예제 #12
0
파일: comment.go 프로젝트: t7er/ohlala
/**
 * 收到的评论
 */
func comment_Inbox(ctx *goku.HttpContext) goku.ActionResulter {
	user := ctx.Data["user"].(*models.User)
	page, pagesize := utils.PagerParams(ctx.Request)
	comments, total, err := models.CommentForUser_GetByPage(user.Id, page, pagesize, "")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["CommentList"] = comments
	ctx.ViewData["CommentCount"] = total
	ctx.ViewData["Page"] = page
	ctx.ViewData["Pagesize"] = pagesize
	err = models.Remind_Reset(user.Id, models.REMIND_COMMENT)
	if err != nil {
		goku.Logger().Errorln("Reset用户提醒信息数出错:", err.Error())
	}
	return ctx.View(nil)
}
예제 #13
0
func (raf *RequireAdminFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {
	ar, err = raf.RequireLoginFilter.OnActionExecuting(ctx)
	if ar != nil || err != nil {
		return
	}
	user := ctx.Data["user"].(*models.User)
	if !user.IsAdmin() {
		if ctx.IsAjax() {
			ar = ctx.Json(map[string]interface{}{
				"success":   false,
				"needLogin": false,
				"errors":    "没有权限",
			})
		} else {
			ctx.ViewData["errorMsg"] = "没有权限"
			ar = ctx.Render("error", nil)
		}
	}
	return
}
예제 #14
0
파일: home.go 프로젝트: yonglehou/ohlala
// 新用户引导
func home_guideForNew(ctx *goku.HttpContext) goku.ActionResulter {
	pagesize := 30
	users, totalUser, err := models.User_GetList(1, pagesize, "link_count desc")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	topics, totalTopic, err := models.Topic_GetByPage(1, pagesize, "link_count desc")
	if err != nil {
		ctx.ViewData["errorMsg"] = err.Error()
		return ctx.Render("error", nil)
	}
	ctx.ViewData["Users"] = models.User_ToVUsers(users, ctx)
	ctx.ViewData["TotalUser"] = totalUser
	ctx.ViewData["Topics"] = models.Topic_ToVTopics(topics, ctx)
	ctx.ViewData["TotalTopics"] = totalTopic
	return ctx.Render("guide", nil)
}