示例#1
0
        public static string ShowTopic(TopicGetResponse tgr)
        {
            string topicStyle = "Topictitle:{0}<br/>LastPostTime:{1}<br/>Author:{2}<br/>TypeName:{3}<br/>";
            string postStyle  = "User:{0}<br/>DateTime:{1}<br/>Message:{2}<br/>";

            topicStyle = string.Format(topicStyle, tgr.Title, tgr.LastPostTime, tgr.Author, tgr.TypeName);
            string posts = "";

            if (tgr.Posts != null)
            {
                foreach (Post p in tgr.Posts)
                {
                    string post = string.Format(postStyle, p.PosterName, p.PostDateTime, p.Message);
                    if (tgr.Attachments != null)
                    {
                        foreach (AttachmentInfo a in tgr.Attachments)
                        {
                            if (a.Pid == p.Pid)
                            {
                                post += "Attachment:" + a.Filename + "<br/>";
                            }
                        }
                    }
                    post  += "<br/>";
                    posts += post;
                }
            }
            return(topicStyle + "<br/>" + posts);
        }
示例#2
0
        /// <summary>
        /// 获取主题及帖子列表
        /// </summary>
        /// <returns></returns>
        public string Get()
        {
            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("tid,page_size,page_index"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            int tid = Utils.StrToInt(GetParam("tid"), 0);
            TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid);
            if (topicInfo == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }
            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topicInfo.Fid);

            PostpramsInfo postPramsInfo = GetPostParamInfo(topicInfo, forumInfo);
            List<ShowtopicPageAttachmentInfo> attachmentList = new List<ShowtopicPageAttachmentInfo>();

            List<ShowtopicPagePostInfo> postList = Posts.GetPostList(postPramsInfo, out attachmentList, false);

            List<Post> list = new List<Post>();
            foreach (ShowtopicPagePostInfo postInfo in postList)
            {
                Post post = new Post();
                post.AdIndex = postInfo.Adindex;
                post.Invisible = postInfo.Invisible;
                post.Layer = postInfo.Layer;
                post.Message = postInfo.Message;
                post.Pid = postInfo.Pid;
                post.PostDateTime = postInfo.Postdatetime;
                post.PosterAvator = postInfo.Avatar;
                post.PosterAvatorWidth = postInfo.Avatarwidth;
                post.PosterAvatorHeight = postInfo.Avatarheight;
                post.PosterEmail = postInfo.Email;
                post.PosterId = postInfo.Posterid;
                post.PosterLocation = postInfo.Location;
                post.PosterName = postInfo.Poster;
                post.PosterShowEmail = postInfo.Showemail;
                post.PosterSignature = postInfo.Signature;
                post.Rate = postInfo.Rate;
                post.RateTimes = postInfo.Ratetimes;
                post.UseSignature = postInfo.Usesig;

                list.Add(post);

            }
            TopicGetResponse tgr = new TopicGetResponse();
            tgr.Author = topicInfo.Poster;
            tgr.AuthorId = topicInfo.Posterid;
            tgr.Fid = topicInfo.Fid;
            tgr.Iconid = topicInfo.Iconid;
            tgr.LastPosterId = topicInfo.Lastposterid;
            tgr.LastPostTime = topicInfo.Lastpost;
            tgr.List = list.Count > 1;
            tgr.ReplyCount = topicInfo.Replies;
            tgr.Tags = ForumTags.GetTagsByTopicId(topicInfo.Tid);
            tgr.Title = topicInfo.Title;
            tgr.TopicId = topicInfo.Tid;
            tgr.Url = ForumUrl + Discuz.Forum.Urls.ShowTopicAspxRewrite(topicInfo.Tid, 0);
            tgr.ViewCount = topicInfo.Views;
            tgr.TypeId = topicInfo.Typeid;

            SortedList<int, string> topicTypeList = Caches.GetTopicTypeArray();
            topicTypeList.TryGetValue(topicInfo.Typeid, out tgr.TypeName);

            tgr.Posts = list.ToArray();
            tgr.Attachments = ConvertAttachmentArray(attachmentList);

            if (Format == FormatType.JSON)
            {
                return JavaScriptConvert.SerializeObject(tgr);
            }
            return Util.AddTitleCDATA(Util.AddMessageCDATA(SerializationHelper.Serialize(tgr)));
        }
示例#3
0
        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("tid,page_size,page_index"))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

            int tid = commandParam.GetIntParam("tid");
            TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(tid);
            if (topicInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_TOPIC_NOT_EXIST, commandParam.ParamList);
                return false;
            }
            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topicInfo.Fid);

            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;

            PostpramsInfo postPramsInfo = TopicsCommandUtils.GetPostParamInfo(commandParam.LocalUid, topicInfo, forumInfo, pageSize, pageIndex);
            List<ShowtopicPageAttachmentInfo> attachmentList = new List<ShowtopicPageAttachmentInfo>();

            List<ShowtopicPagePostInfo> postList = Posts.GetPostList(postPramsInfo, out attachmentList, false);

            List<Post> list = new List<Post>();
            foreach (ShowtopicPagePostInfo postInfo in postList)
            {
                Post post = new Post();
                post.AdIndex = postInfo.Adindex;
                post.Invisible = postInfo.Invisible;
                post.Layer = postInfo.Layer;
                post.Message = postInfo.Message;
                post.Pid = postInfo.Pid;
                post.PostDateTime = postInfo.Postdatetime;
                post.PosterAvator = postInfo.Avatar;
                post.PosterAvatorWidth = postInfo.Avatarwidth;
                post.PosterAvatorHeight = postInfo.Avatarheight;
                post.PosterEmail = postInfo.Email;
                post.PosterId = postInfo.Posterid;
                post.PosterLocation = postInfo.Location;
                post.PosterName = postInfo.Poster;
                post.PosterShowEmail = postInfo.Showemail;
                post.PosterSignature = postInfo.Signature;
                post.Rate = postInfo.Rate;
                post.RateTimes = postInfo.Ratetimes;
                post.UseSignature = postInfo.Usesig;

                list.Add(post);
            }
            TopicGetResponse tgr = new TopicGetResponse();
            tgr.Author = topicInfo.Poster;
            tgr.AuthorId = topicInfo.Posterid;
            tgr.Fid = topicInfo.Fid;
            tgr.Iconid = topicInfo.Iconid;
            tgr.LastPosterId = topicInfo.Lastposterid;
            tgr.LastPostTime = topicInfo.Lastpost;
            tgr.List = list.Count > 1;
            tgr.ReplyCount = topicInfo.Replies;
            tgr.Tags = ForumTags.GetTagsByTopicId(topicInfo.Tid);
            tgr.Title = topicInfo.Title;
            tgr.TopicId = topicInfo.Tid;
            tgr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Discuz.Forum.Urls.ShowTopicAspxRewrite(topicInfo.Tid, 0);
            tgr.ViewCount = topicInfo.Views;
            tgr.TypeId = topicInfo.Typeid;

            SortedList<int, string> topicTypeList = Caches.GetTopicTypeArray();
            topicTypeList.TryGetValue(topicInfo.Typeid, out tgr.TypeName);

            tgr.Posts = list.ToArray();
            tgr.Attachments = TopicsCommandUtils.ConvertAttachmentArray(attachmentList);

            result = commandParam.Format == FormatType.JSON ?
                JavaScriptConvert.SerializeObject(tgr) : Util.AddTitleCDATA(Util.AddMessageCDATA(SerializationHelper.Serialize(tgr)));

            return true;
        }