/// <summary> /// 获得关注主题列表 /// </summary> /// <returns></returns> public string GetAttentionList() { if (Signature != GetParam("sig").ToString()) { ErrorCode = (int)ErrorType.API_EC_SIGNATURE; return ""; } //如果是桌面程序则需要验证用户身份 if (this.App.ApplicationType == (int)ApplicationType.DESKTOP) { if (Uid < 1) { ErrorCode = (int)ErrorType.API_EC_SESSIONKEY; return ""; } } if (CallId <= LastCallId) { ErrorCode = (int)ErrorType.API_EC_CALLID; return ""; } if (!CheckRequiredParams("fid,page_size,page_index")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } int fid = GetIntParam("fid", 0); int pageSize = GetIntParam("page_size", 20); int pageIndex = GetIntParam("page_index", 1); //ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); //topiclist = Topics.GetAttentionTopics(forumidlist, 16, pageid, keyword); //counts = Topics.GetAttentionTopicCount(forumidlist, keyword); int count = Discuz.Forum.Topics.GetAttentionTopicCount(fid.ToString(), string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetAttentionTopics(fid.ToString(), pageSize, pageIndex, string.Empty); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = ForumUrl + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; if (Format == FormatType.JSON) { return JavaScriptConvert.SerializeObject(tglr); } return SerializationHelper.Serialize(tglr); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("fid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = commandParam.GetIntParam("fid", 0); int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Tpp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Tpp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; int count = Discuz.Forum.Topics.GetAttentionTopicCount(fid.ToString(), string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetAttentionTopics(fid.ToString(), pageSize, pageIndex, string.Empty); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tglr) : SerializationHelper.Serialize(tglr); return true; }
/// <summary> /// 获得主题列表 /// </summary> /// <returns></returns> public string GetList() { if (Signature != GetParam("sig").ToString()) { ErrorCode = (int)ErrorType.API_EC_SIGNATURE; return ""; } //如果是桌面程序则需要验证用户身份 if (this.App.ApplicationType == (int)ApplicationType.DESKTOP) { if (Uid < 1) { ErrorCode = (int)ErrorType.API_EC_SESSIONKEY; return ""; } } if (CallId <= LastCallId) { ErrorCode = (int)ErrorType.API_EC_CALLID; return ""; } if (!CheckRequiredParams("fid,page_size,page_index")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return ""; } int fid = Utils.StrToInt(GetParam("fid"), 0); int pageSize = GetIntParam("page_size", 20); int pageIndex = GetIntParam("page_index", 1); string topicTypeIdList = GetParam("type_id_list") == null ? "" : GetParam("type_id_list").ToString();//主题分类条件idlist string condition = string.Empty;//查询主题的条件 if (topicTypeIdList != string.Empty && Utils.IsNumericList(topicTypeIdList))//如果条件不为空且是逗号分割的list,则添加condition条件 { condition = " AND [typeid] IN (" + topicTypeIdList + ") "; } ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); int count = Discuz.Forum.Topics.GetTopicCount(fid, true, string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetTopicList(fid, pageSize, pageIndex, 0, 600, Config.Hottopic, forumInfo.Autoclose, forumInfo.Topictypeprefix, condition); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = ForumUrl + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; if (Format == FormatType.JSON) { return JavaScriptConvert.SerializeObject(tglr); } return SerializationHelper.Serialize(tglr); }
public override bool Run(CommandParameter commandParam, ref string result) { //如果是桌面程序则需要验证用户身份 if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP && commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return false; } if (!commandParam.CheckRequiredParams("fid,page_size,page_index")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return false; } int fid = commandParam.GetIntParam("fid"); ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(fid); if (forumInfo == null) { result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList); return false; } int pageSize = commandParam.GetIntParam("page_size", commandParam.GeneralConfig.Tpp); int pageIndex = commandParam.GetIntParam("page_index", 1); pageSize = pageSize < 1 ? commandParam.GeneralConfig.Tpp : pageSize; pageIndex = pageIndex < 1 ? 1 : pageIndex; //主题分类条件idlist string topicTypeIdList = commandParam.GetDNTParam("type_id_list").ToString(); string condition = string.Empty;//查询主题的条件 //如果条件不为空且是逗号分割的list,则添加condition条件 if (!string.IsNullOrEmpty(topicTypeIdList) && Utils.IsNumericList(topicTypeIdList)) condition = " AND [typeid] IN (" + topicTypeIdList + ") "; int count = Discuz.Forum.Topics.GetTopicCount(fid, true, string.Empty); List<TopicInfo> topicList = Discuz.Forum.Topics.GetTopicList(fid, pageSize, pageIndex, 0, 600, commandParam.GeneralConfig.Hottopic, forumInfo.Autoclose, forumInfo.Topictypeprefix, condition); TopicGetListResponse tglr = new TopicGetListResponse(); List<ForumTopic> list = new List<ForumTopic>(); foreach (TopicInfo topicInfo in topicList) { ForumTopic topic = new ForumTopic(); topic.Author = topicInfo.Poster; topic.AuthorId = topicInfo.Posterid; topic.LastPosterId = topicInfo.Lastposterid; topic.LastPostTime = DateTime.Parse(topicInfo.Lastpost).ToString("yyyy-MM-dd HH:mm:ss"); topic.ReplyCount = topicInfo.Replies; topic.ViewCount = topicInfo.Views; topic.Title = topicInfo.Title; topic.TopicId = topicInfo.Tid; topic.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topic.TopicId, 0); list.Add(topic); } tglr.Count = count; tglr.Topics = list.ToArray(); tglr.List = true; result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(tglr) : SerializationHelper.Serialize(tglr); return true; }