Exemplo n.º 1
0
        /// <summary>
        /// 编辑主题
        /// </summary>
        /// <returns></returns>
        public string Edit()
        {
            if (Signature != GetParam("sig").ToString())
            {
                ErrorCode = (int)ErrorType.API_EC_SIGNATURE;
                return "";
            }

            ShortUserInfo currentUserInfo = null;

            //如果是桌面程序则需要验证用户身份
            if (this.App.ApplicationType == (int)ApplicationType.DESKTOP)
            {
                if (Uid < 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_SESSIONKEY;
                    return "";
                }

                //判断客户端如果不是管理员就不能修改
                currentUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
                if (currentUserInfo.Adminid != 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PERMISSION_DENIED;
                    return "";
                }

            }

            if (CallId <= LastCallId)
            {
                ErrorCode = (int)ErrorType.API_EC_CALLID;
                return "";
            }

            if (!CheckRequiredParams("topic_info,tid"))
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }
            Topic topic;
            try
            {
                topic = JavaScriptConvert.DeserializeObject<Topic>(GetParam("topic_info").ToString());
            }
            catch
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            if (topic == null)// || AreParamsNullOrZeroOrEmptyString(topic.UId, topic.Fid, topic.Title, topic.Message))//(topic == null || topic.UId == 0 || topic.Fid == 0 || topic.Title == null || topic.Message == null)
            {
                ErrorCode = (int)ErrorType.API_EC_PARAM;
                return "";
            }

            int topicId = GetIntParam("tid");



            //如果设置的主题类型,应该仍可添加topic

            //文档中应说明title长度范围和内容范围
            if (!AreParamsNullOrZeroOrEmptyString(topic.Title) && topic.Title.Length > 60)
            {
                ErrorCode = (int)ErrorType.API_EC_TITLE_INVALID;
                return "";
            }

            //内容长度限制应该在客户程序里实现
            //if (topic.Message.Length < Config.Minpostsize)
            //{
            //    //AddErrLine("您发表的内容过少, 系统设置要求帖子内容不得少于 " + Config.Minpostsize.ToString() + " 字多于 " + Config.Maxpostsize.ToString() + " 字");
            //    ErrorCode = (int)ErrorType.API_EC_PARAM;
            //    return "";

            //}
            //else if (topic.Message.Length > Config.Maxpostsize)
            //{
            //    //AddErrLine("您发表的内容过多, 系统设置要求帖子内容不得少于 " + Config.Minpostsize.ToString() + " 字多于 " + Config.Maxpostsize.ToString() + " 字");
            //    ErrorCode = (int)ErrorType.API_EC_PARAM;
            //    return "";
            //}

            #region Inner
            TopicInfo topicInfo = Discuz.Forum.Topics.GetTopicInfo(topicId);


            ShortUserInfo userInfo = Discuz.Forum.Users.GetShortUserInfo(topicInfo.Posterid);

            //新用户广告强力屏蔽检查
            if (Uid > 0 && (topic.Title != null || topic.Message != null))
            {
                if (currentUserInfo == null)
                {
                    currentUserInfo = Discuz.Forum.Users.GetShortUserInfo(Uid);
                }

                if ((Config.Disablepostad == 1) && userInfo.Adminid < 1)  //如果开启新用户广告强力屏蔽检查或是游客
                {
                    if ((Config.Disablepostadpostcount != 0 && currentUserInfo.Posts <= Config.Disablepostadpostcount) ||
                        (Config.Disablepostadregminute != 0 && DateTime.Now.AddMinutes(-Config.Disablepostadregminute) <= Convert.ToDateTime(currentUserInfo.Joindate)))
                    {
                        foreach (string regular in Config.Disablepostadregular.Replace("\r", "").Split('\n'))
                        {
                            if (Posts.IsAD(regular, (topic.Title ?? string.Empty), (topic.Message ?? string.Empty)))
                            {
                                ErrorCode = (int)ErrorType.API_EC_SPAM;
                                return "";
                            }
                        }
                    }
                }
            }

            UserGroupInfo userGroupInfo = UserGroups.GetUserGroupInfo(userInfo.Groupid);

            int iconid = topic.Iconid ?? 0;
            if (iconid > 15 || iconid < 0)
            {
                iconid = 0;
            }

            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topic.Fid ?? topicInfo.Fid);

            bool enabletag = (Config.Enabletag & forumInfo.Allowtag) == 1;

            if (topic.Fid != null)
                topicInfo.Fid = topic.Fid ?? topicInfo.Fid;
            if (topic.Iconid != null)
                topicInfo.Iconid = iconid;
            if (topic.Title != null)
            {
                topicInfo.Title = Utils.HtmlEncode(ForumUtils.BanWordFilter(topic.Title));
                if (ForumUtils.HasAuditWord(topicInfo.Title))
                {
                    topicInfo.Displayorder = -2;
                }
            }

            string message = null;
            if (topic.Message != null)
            {
                bool htmlon = topic.Message.Length != Utils.RemoveHtml(topic.Message).Length && userGroupInfo.Allowhtml == 1;
                message = ForumUtils.BanWordFilter(topic.Message);
                if (!htmlon)
                {
                    message = Utils.HtmlDecode(message);
                }
                if (ForumUtils.HasBannedWord(topicInfo.Title) || ForumUtils.HasBannedWord(message))
                {
                    ErrorCode = (int)ErrorType.API_EC_SPAM;
                    return "";
                }
                if (ForumUtils.HasAuditWord(message))
                {
                    topicInfo.Displayorder = -2;
                }
            }

            string tags = string.Empty;
            string[] tagArray = null;

            if (!string.IsNullOrEmpty(topic.Tags))
            {
                //标签(Tag)操作                
                tags = topic.Tags.Trim();
                tagArray = Utils.SplitString(tags, ",", true, 2, 10);
                if (enabletag)
                {
                    if (topicInfo.Magic == 0)
                    {
                        topicInfo.Magic = 10000;
                    }
                    topicInfo.Magic = Utils.StrToInt(topicInfo.Magic.ToString() + "1", 0);
                }
            }

            if (forumInfo.Applytopictype == 1)
            {
                if (Discuz.Forum.Forums.IsCurrentForumTopicType(topic.Typeid.ToString(), forumInfo.Topictypes))
                {
                    topicInfo.Typeid = (int)topic.Typeid;
                }
                else if (forumInfo.Postbytopictype == 1)
                {
                    ErrorCode = (int)ErrorType.API_EC_PARAM;
                    return "";
                }
                else
                {
                    topicInfo.Typeid = 0;
                }
            }

            int result = Discuz.Forum.Topics.UpdateTopic(topicInfo);

            if (enabletag && tagArray != null && tagArray.Length > 0)
            {
                if (!ForumUtils.HasBannedWord(tags))
                {
                    ForumTags.CreateTopicTags(tagArray, topicInfo.Tid, userInfo.Uid, topicInfo.Postdatetime);
                }

            }

            PostInfo postInfo = Discuz.Forum.Posts.GetPostInfo(topicInfo.Tid, Discuz.Forum.Posts.GetFirstPostId(topicInfo.Tid));
            if (topic.Fid != null)
                postInfo.Fid = topicInfo.Fid;
            if (topic.Title != null)
            {
                postInfo.Title = topicInfo.Title;
                postInfo.Topictitle = topicInfo.Title;
            }

            if (topic.Message != null)
            {
                postInfo.Message = message;
                if (ForumUtils.HasAuditWord(postInfo.Message))
                {
                    postInfo.Invisible = 1;
                }
            }
            result = Posts.UpdatePost(postInfo);

            TopicEditResponse ter = new TopicEditResponse();
            ter.Successfull = result;

            #endregion

            if (Format == FormatType.JSON)
            {
                return (result == 1).ToString().ToLower();
            }
            return SerializationHelper.Serialize(ter);

        }
Exemplo n.º 2
0
        /*
         * Description:
         * 该接口需要能关联到一个论坛用户,不允许游客操作,如果validate=true或者接口类型为桌面程序,则只获取session_info中的uid,若无则返回API_EC_SESSIONKEY
         */
        public override bool Run(CommandParameter commandParam, ref string result)
        {
            //如果validate为true,则校验数据的合法性,包括广告强力屏蔽,是否含有需审核的,以及非法内容.和当前用户的发帖权限
            bool validate = commandParam.GetIntParam("validate") == 1 || commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP;

            //如果validate是true或者桌面程序则需要验证用户身份
            if (validate && commandParam.LocalUid < 1)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList);
                return false;
            }

            if (!commandParam.CheckRequiredParams("topic_info,tid"))
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

            Topic topic;
            try
            {
                topic = JavaScriptConvert.DeserializeObject<Topic>(commandParam.GetDNTParam("topic_info").ToString());
            }
            catch
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

            if (topic == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                return false;
            }

            //文档中应说明title长度范围和内容范围
            if (!Util.AreParamsNullOrZeroOrEmptyString(topic.Title) && topic.Title.Length > 60)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_TITLE_INVALID, commandParam.ParamList);
                return false;
            }

            //编辑主题必须要能关联到一个用户
            ShortUserInfo userInfo = Users.GetShortUserInfo(validate || topic.UId == null ? commandParam.LocalUid : (int)topic.UId);
            if (userInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_NOUSER, commandParam.ParamList);
                return false;
            }

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

            ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(topic.Fid ?? topicInfo.Fid);
            if (forumInfo == null)
            {
                result = Util.CreateErrorMessage(ErrorType.API_EC_FORUM_NOT_EXIST, commandParam.ParamList);
                return false;
            }

            UserGroupInfo userGroupInfo = UserGroups.GetUserGroupInfo(userInfo.Groupid);
            AdminGroupInfo adminInfo = AdminGroups.GetAdminGroupInfo(userGroupInfo.Groupid);
            //是否受审核、过滤、灌水等限制权限
            int disablePost = adminInfo != null ? adminInfo.Disablepostctrl : userGroupInfo.Disableperiodctrl;
            bool hasAudit = false;
            if (validate)
            {
                string title = topic.Title ?? "";
                string message = topic.Message ?? "";

                ErrorType et = TopicsCommandUtils.GeneralValidate(title, message, userInfo, userGroupInfo, forumInfo, commandParam, disablePost);
                if (et != ErrorType.API_EC_NONE)
                {
                    result = Util.CreateErrorMessage(et, commandParam.ParamList);
                    return false;
                }

                //如果主题作者与当前用户不一样且当前用户不是管理员
                if (topicInfo.Posterid != commandParam.LocalUid && userInfo.Adminid != 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList);
                    return false;
                }

                //如果当前用户是管理组成员,则跳过编辑时间限制校验
                if (!Moderators.IsModer(userInfo.Adminid, commandParam.LocalUid, forumInfo.Fid))
                {
                    if (commandParam.GeneralConfig.Edittimelimit == -1)
                    {
                        result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList);
                        return false;
                    }
                    if (commandParam.GeneralConfig.Edittimelimit > 0 &&
                        Utils.StrDateDiffSeconds(topicInfo.Postdatetime, commandParam.GeneralConfig.Edittimelimit) > 0)
                    {
                        result = Util.CreateErrorMessage(ErrorType.API_EC_EDIT_PERM, commandParam.ParamList);
                        return false;
                    }
                }

                if (!string.IsNullOrEmpty(title + message))
                {
                    if (ForumUtils.HasAuditWord(title) || ForumUtils.HasAuditWord(message))
                        hasAudit = true;

                    if (disablePost != 1)
                    {
                        topic.Title = ForumUtils.BanWordFilter(topic.Title);
                        topic.Message = ForumUtils.BanWordFilter(topic.Message);
                    }
                }
            }

            topic.Iconid = topic.Iconid ?? 0;
            topic.Iconid = topic.Iconid > 15 || topic.Iconid < 0 ? 0 : topic.Iconid;

            topicInfo.Fid = topic.Fid ?? topicInfo.Fid;
            topicInfo.Iconid = (int)topic.Iconid;
            topicInfo.Title = topic.Title != null ? Utils.HtmlEncode(topic.Title) : topicInfo.Title;
            topicInfo.Displayorder = hasAudit ? -2 : topicInfo.Displayorder;

            if (topic.Message != null)
            {
                bool htmlon = topic.Message.Length != Utils.RemoveHtml(topic.Message).Length && userGroupInfo.Allowhtml == 1;
                topic.Message = htmlon ? Utils.HtmlDecode(topic.Message) : topic.Message;
            }

            bool enabletag = (commandParam.GeneralConfig.Enabletag & forumInfo.Allowtag) == 1;
            string tags = string.Empty;
            string[] tagArray = null;

            if (!string.IsNullOrEmpty(topic.Tags))
            {
                //标签(Tag)操作                
                tags = topic.Tags.Trim();
                tagArray = Utils.SplitString(tags, ",", true, 2, 10);
                if (enabletag)
                {
                    if (topicInfo.Magic == 0)
                        topicInfo.Magic = 10000;
                    topicInfo.Magic = Utils.StrToInt(topicInfo.Magic.ToString() + "1", 0);
                }
            }

            if (forumInfo.Applytopictype == 1)
            {
                if (Discuz.Forum.Forums.IsCurrentForumTopicType(topic.Typeid.ToString(), forumInfo.Topictypes))
                {
                    topicInfo.Typeid = (int)topic.Typeid;
                }
                else if (forumInfo.Postbytopictype == 1)
                {
                    result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList);
                    return false;
                }
            }

            int editResult = Discuz.Forum.Topics.UpdateTopic(topicInfo);

            if (enabletag && tagArray != null && tagArray.Length > 0)
            {
                if (disablePost == 1 || !ForumUtils.HasBannedWord(tags))
                    ForumTags.CreateTopicTags(tagArray, topicInfo.Tid, userInfo.Uid, topicInfo.Postdatetime);
            }

            PostInfo postInfo = Discuz.Forum.Posts.GetPostInfo(topicInfo.Tid, Discuz.Forum.Posts.GetFirstPostId(topicInfo.Tid));
            if (topic.Fid != null)
                postInfo.Fid = forumInfo.Fid;
            if (topic.Title != null)
            {
                postInfo.Title = topicInfo.Title;
                postInfo.Topictitle = topicInfo.Title;
            }
            postInfo.Message = topic.Message ?? postInfo.Message;

            editResult = Posts.UpdatePost(postInfo);

            TopicEditResponse ter = new TopicEditResponse();
            ter.Successfull = editResult;

            result = commandParam.Format == FormatType.JSON ? (editResult == 1).ToString().ToLower() : SerializationHelper.Serialize(ter);
            return true;
        }