/// <summary> /// 创建板块 /// </summary> /// <returns></returns> public string Create() { 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("forum_info")) { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } Forum forum; try { forum = JsonConvert.DeserializeObject <Forum>(GetParam("forum_info").ToString()); } catch { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } if (forum == null || AreParamsNullOrZeroOrEmptyString(forum.Name)) { ErrorCode = (int)ErrorType.API_EC_PARAM; return(""); } if (!Utils.StrIsNullOrEmpty(forum.RewriteName) && Discuz.Forum.Forums.CheckRewriteNameInvalid(forum.RewriteName)) { ErrorCode = (int)ErrorType.API_EC_REWRITENAME; return(""); } int fid; if (forum.ParentId > 0) { #region 添加与当前论坛同级的论坛 //添加与当前论坛同级的论坛 //DataRow dr = AdminForums.GetForum(forum.ParentId); ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(forum.ParentId); //找出当前要插入的记录所用的FID string parentidlist = null; if (forumInfo.Parentidlist == "0") { parentidlist = forumInfo.Fid.ToString(); } else { parentidlist = forumInfo.Parentidlist + "," + forumInfo.Fid; } int maxdisplayorder = 0; DataTable dt = AdminForums.GetMaxDisplayOrder(forum.ParentId); if ((dt.Rows.Count > 0) && (dt.Rows[0][0].ToString() != "")) { maxdisplayorder = Convert.ToInt32(dt.Rows[0][0]); } else { maxdisplayorder = forumInfo.Displayorder; } AdminForums.UpdateForumsDisplayOrder(maxdisplayorder); fid = InsertForum(forum, forumInfo.Layer + 1, parentidlist, 0, maxdisplayorder + 1); AdminForums.SetSubForumCount(forumInfo.Fid); #endregion } else { #region 根论坛插入 int maxdisplayorder = AdminForums.GetMaxDisplayOrder(); fid = InsertForum(forum, 0, "0", 0, maxdisplayorder); #endregion } //string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + BaseConfigs.GetForumPath.ToLower(); ForumCreateResponse fcr = new ForumCreateResponse(); fcr.Fid = fid; fcr.Url = ForumUrl + Urls.ShowForumAspxRewrite(fid, 1, forum.RewriteName); if (Format == FormatType.JSON) { return(JsonConvert.SerializeObject(fcr)); } return(SerializationHelper.Serialize(fcr)); }
public override bool Run(CommandParameter commandParam, ref string result) { if (commandParam.AppInfo.ApplicationType == (int)ApplicationType.DESKTOP) { if (commandParam.LocalUid < 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_SESSIONKEY, commandParam.ParamList); return(false); } ShortUserInfo userInfo = Users.GetShortUserInfo(commandParam.LocalUid); if (userInfo == null || userInfo.Adminid != 1) { result = Util.CreateErrorMessage(ErrorType.API_EC_PERMISSION_DENIED, commandParam.ParamList); return(false); } } if (!commandParam.CheckRequiredParams("forum_info")) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } Forum forum; try { forum = JavaScriptConvert.DeserializeObject <Forum>(commandParam.GetDNTParam("forum_info").ToString()); } catch { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (forum == null || string.IsNullOrEmpty(forum.Name)) { result = Util.CreateErrorMessage(ErrorType.API_EC_PARAM, commandParam.ParamList); return(false); } if (!Utils.StrIsNullOrEmpty(forum.RewriteName) && Discuz.Forum.Forums.CheckRewriteNameInvalid(forum.RewriteName)) { result = Util.CreateErrorMessage(ErrorType.API_EC_REWRITENAME, commandParam.ParamList); return(false); } int fid; if (forum.ParentId > 0) { #region 添加与当前论坛同级的论坛 //添加与当前论坛同级的论坛 ForumInfo forumInfo = Discuz.Forum.Forums.GetForumInfo(forum.ParentId); //找出当前要插入的记录所用的FID string parentidlist = null; parentidlist = forumInfo.Parentidlist == "0" ? forumInfo.Fid.ToString() : forumInfo.Parentidlist + "," + forumInfo.Fid; DataTable dt = AdminForums.GetMaxDisplayOrder(forum.ParentId); int maxdisplayorder = (dt.Rows.Count > 0) && (dt.Rows[0][0].ToString() != "") ? Convert.ToInt32(dt.Rows[0][0]) : forumInfo.Displayorder; AdminForums.UpdateForumsDisplayOrder(maxdisplayorder); fid = ForumsCommandUtils.InsertForum(forum, forumInfo.Layer + 1, parentidlist, 0, maxdisplayorder + 1); AdminForums.SetSubForumCount(forumInfo.Fid); #endregion } else { #region 根论坛插入 int maxdisplayorder = AdminForums.GetMaxDisplayOrder(); fid = ForumsCommandUtils.InsertForum(forum, 0, "0", 0, maxdisplayorder); #endregion } ForumCreateResponse fcr = new ForumCreateResponse(); fcr.Fid = fid; fcr.Url = Utils.GetRootUrl(BaseConfigs.GetForumPath) + Urls.ShowForumAspxRewrite(fid, 1, forum.RewriteName); result = commandParam.Format == FormatType.JSON ? JavaScriptConvert.SerializeObject(fcr) : SerializationHelper.Serialize(fcr); return(true); }