/// <summary> /// 设置待验证的主题,包括通过,忽略,删除等操作 /// </summary> /// <param name="postTableId">回复表ID</param> /// <param name="ignore">忽略的主题列表</param> /// <param name="validate">验证通过的主题列表</param> /// <param name="delete">删除的主题列表</param> /// <param name="fidlist">版块列表</param> public static void PassAuditNewTopic(string postTableId, string ignore, string validate, string delete, string fidlist) { if (!Utils.IsNumeric(postTableId) || (!string.IsNullOrEmpty(ignore) && !Utils.IsNumericList(ignore)) || (!string.IsNullOrEmpty(validate) && !Utils.IsNumericList(validate)) || (!string.IsNullOrEmpty(delete) && !Utils.IsNumericList(delete)) || (!string.IsNullOrEmpty(fidlist) && !Utils.IsNumericList(fidlist))) { return; } Data.Topics.PassAuditNewTopic(postTableId, ignore, validate, delete, fidlist); //获取验证通过的主题列表信息,为用户增加发主题的扩展积分 if (!string.IsNullOrEmpty(validate)) { foreach (DataRow topicInfo in Topics.GetTopicList(validate).Rows) { ForumInfo forumInfo = Forums.GetForumInfo(TypeConverter.ObjectToInt(topicInfo["fid"]));//获取主题的版块信息 float[] forumPostcredits = Forums.GetValues(forumInfo.Postcredits); if (forumPostcredits != null) //使用版块内积分 { UserCredits.UpdateUserCreditsByPostTopic(TypeConverter.ObjectToInt(topicInfo["posterid"]), forumPostcredits); } else //使用默认积分 { UserCredits.UpdateUserCreditsByPostTopic(TypeConverter.ObjectToInt(topicInfo["posterid"])); } } } }
/// <summary> /// 获得指定版块最新的20个主题的Rss描述 /// </summary> /// <param name="ttl">TTL数值</param> /// <param name="fid">版块id</param> /// <returns>Rss描述</returns> public static string GetForumRssXml(int ttl, int fid) { DNTCache cache = DNTCache.GetCacheService(); string rssContent = cache.RetrieveObject("/Forum/RSS/Forum" + fid) as string; if (rssContent == null) { ForumInfo forum = Forums.GetForumInfo(fid); if (forum == null) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified forum not found</Rss>\r\n"); } //板块d有权限设置,按照用户组权限走,RSS仅检查游客权限 if (!Utils.StrIsNullOrEmpty(forum.Viewperm) && !Utils.InArray("7", forum.Viewperm, ",")) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n"); } else if (UserGroups.GetUserGroupInfo(7).Allowvisit == 0) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n"); } rssContent = Discuz.Data.Feeds.BuildRssOutput(ttl, fid.ToString(), forum.Name); cache.AddObject("/Forum/RSS/Forum" + fid, rssContent, ttl * 60); } return(rssContent); }
public static void DeleteForumTopicTypes(string typeidlist) { string[] array = typeidlist.Split(','); SortedList <int, string> sortedList = new SortedList <int, string>(); sortedList = Caches.GetTopicTypeArray(); DataTable forumListForDataTable = Forums.GetForumListForDataTable(); foreach (DataRow dataRow in forumListForDataTable.Rows) { if (!(dataRow["topictypes"].ToString() == "")) { string text = dataRow["topictypes"].ToString(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text2 = array2[i]; text = text.Replace(text2 + "," + sortedList[int.Parse(text2)].ToString() + ",0|", ""); text = text.Replace(text2 + "," + sortedList[int.Parse(text2)].ToString() + ",1|", ""); Discuz.Data.Topics.ClearTopicType(int.Parse(text2)); } ForumInfo forumInfo = Forums.GetForumInfo(int.Parse(dataRow["fid"].ToString())); forumInfo.Topictypes = text; AdminForums.UpdateForumInfo(forumInfo); } } }
/// <summary> /// 获取需要审核的主题 /// </summary> /// <param name="forumidlist">版块ID</param> /// <param name="tpp">每页主题数</param> /// <param name="pageid">页数</param> /// <returns></returns> public static Discuz.Common.Generic.List <TopicInfo> GetUnauditNewTopic(string forumidlist, int tpp, int pageid, int filter) { Discuz.Common.Generic.List <TopicInfo> list = Data.Topics.GetUnauditNewTopic(forumidlist, tpp, pageid, filter); foreach (TopicInfo info in list) { info.Forumname = Forums.GetForumInfo(info.Fid).Name; } return(list); }
/// <summary> /// 获取我的未通过审核主题 /// </summary> /// <param name="posterid">作者ID</param> /// <param name="filter">-2为未审核</param> /// <param name="tpp">单页显示多少条</param> /// <param name="pageindex">起始页</param> public static Discuz.Common.Generic.List <TopicInfo> GetMyUnauditTopic(int posterId, int tpp, int pageId, int filter) { Discuz.Common.Generic.List <TopicInfo> list = Data.Topics.GetMyUnauditTopic(posterId, tpp, pageId, filter); foreach (TopicInfo info in list) { info.Forumname = Forums.GetForumInfo(info.Fid).Name; } return(list); }
/// <summary> /// 在数据库中删除指定主题 /// </summary> /// <param name="topiclist">主题列表</param> /// <param name="subtractCredits">是否减少用户积分(0不减少,1减少)</param> /// <returns>删除个数</returns> public static int DeleteTopics(string topicList, int subTractCredits, bool reserveAttach) { if (!Utils.IsNumericList(topicList)) { return(-1); } DataTable dt = Topics.GetTopicList(topicList); if (dt == null) { return(-1); } foreach (DataRow dr in dt.Rows) { if (TypeConverter.ObjectToInt(dr["digest"]) > 0) { //UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), -1, CreditsOperationType.Digest, 1, true); CreditsFacade.UnDigest(TypeConverter.ObjectToInt(dr["posterid"])); } } List <PostInfo> list = Posts.GetPostList(topicList); if (list != null && list.Count != 0) { int lastFid = 0; ForumInfo forumInfo = null; foreach (PostInfo postInfo in list) { //如果与上一个帖子是同一版块,将不再重新读取版块信息 if (lastFid != postInfo.Fid) { lastFid = postInfo.Fid; forumInfo = Forums.GetForumInfo(lastFid); } CreditsFacade.DeletePost(postInfo, forumInfo, reserveAttach); } } int reval = 0; foreach (string posttableid in Posts.GetPostTableIdArray(topicList)) { reval = Discuz.Data.TopicAdmins.DeleteTopicByTidList(topicList, posttableid); } if (reval > 0 && !reserveAttach) { Attachments.DeleteAttachmentByTid(topicList); } return(reval); }
/// <summary> /// 通过待验证的主题 /// </summary> /// <param name="postTableId">当前帖子分表Id</param> /// <param name="tid">主题Id</param> public static void PassAuditNewTopic(string tidList) { //string[] tidarray = tidList.Split(','); //float[] values = null; //ForumInfo forum = null; //TopicInfo topic = null; //int fid = -1; foreach (string tid in tidList.Split(',')) { TopicInfo topic = Topics.GetTopicInfo(int.Parse(tid)); //获取主题信息 CreditsFacade.PostTopic(topic.Posterid, Forums.GetForumInfo(topic.Fid)); //if (fid != topic.Fid) //当上一个和当前主题不在一个版块内时,重新读取版块的积分设置 //{ // fid = topic.Fid; // forum = Discuz.Forum.Forums.GetForumInfo(fid); // if (!forum.Postcredits.Equals("")) // { // int index = 0; // float tempval = 0; // values = new float[8]; // foreach (string ext in Utils.SplitString(forum.Postcredits, ",")) // { // if (index == 0) // { // if (!ext.Equals("True")) // { // values = null; // break; // } // index++; // continue; // } // tempval = Utils.StrToFloat(ext, 0); // values[index - 1] = tempval; // index++; // if (index > 8) // { // break; // } // } // } //} //if (values != null) //使用版块内积分 // UserCredits.UpdateUserCreditsByPostTopic(topic.Posterid, values); //else //使用默认积分 // UserCredits.UpdateUserCreditsByPostTopic(topic.Posterid); } Data.Topics.PassAuditNewTopic(PostTables.GetPostTableId(), tidList); }
/// <summary> /// 设置版块列表中层数(layer)和父列表(parentidlist)字段 /// </summary> public static void SetForumslayer() { foreach (ForumInfo singleForumInfo in Forums.GetForumList()) { int layer = 0; string parentidlist = ""; int parentid = singleForumInfo.Parentid; //如果是(分类)顶层则直接更新数据库 if (parentid == 0) { ForumInfo forumInfo = Forums.GetForumInfo(singleForumInfo.Fid); if (forumInfo.Layer != layer) { forumInfo.Layer = layer; forumInfo.Parentidlist = "0"; UpdateForumInfo(forumInfo); } continue; } do { //更新子版块的层数(layer)和父列表(parentidlist)字段 int temp = parentid; parentid = Forums.GetForumInfo(parentid).Parentid; layer++; if (parentid != 0) { parentidlist = temp + "," + parentidlist; } else { parentidlist = (temp + "," + parentidlist).TrimEnd(','); ForumInfo forumInfo = Forums.GetForumInfo(singleForumInfo.Fid); if (forumInfo.Layer != layer || forumInfo.Parentidlist != parentidlist) { forumInfo.Layer = layer; forumInfo.Parentidlist = parentidlist; UpdateForumInfo(forumInfo); } break; } } while (true); } }
/// <summary> /// 删除所选的主题分类 /// </summary> /// <param name="typeidlist"></param> public static void DeleteForumTopicTypes(string typeidlist) { //取得ID的数组 string[] ids = typeidlist.Split(','); //取得主题分类的缓存 Discuz.Common.Generic.SortedList <int, string> topictypearray = new Discuz.Common.Generic.SortedList <int, string>(); topictypearray = Caches.GetTopicTypeArray(); //取得版块的fid,topictypes字段 DataTable dt = Forums.GetForumListForDataTable(); //处理每一个版块 foreach (DataRow dr in dt.Rows) { //如果版块的主题分类字段为空(topictypes==""),则处理下一个 if (dr["topictypes"].ToString() == "") { continue; } string topictypes = dr["topictypes"].ToString(); //处理每一个要删除的ID foreach (string id in ids) { //将删除的ID拼成相应的格式串后,将原来的剔除掉,形成一个新的主题分类的字段 topictypes = topictypes.Replace(id + "," + topictypearray[Int32.Parse(id)].ToString() + ",0|", ""); topictypes = topictypes.Replace(id + "," + topictypearray[Int32.Parse(id)].ToString() + ",1|", ""); //将帖子列表(dnt_topics)中typeid为当前要删除的Id更新为0 Data.Topics.ClearTopicType(int.Parse(id)); } //用剔除了要删除的主题ID的主题列表值更新数据库 ForumInfo forumInfo = Forums.GetForumInfo(int.Parse(dr["fid"].ToString())); forumInfo.Topictypes = topictypes; AdminForums.UpdateForumInfo(forumInfo); } }
/// <summary> /// 加载置顶主题列表附加信息 /// </summary> /// <param name="topicTypePrefix">主题分类前缀</param> /// <param name="newMinutes"></param> /// <param name="hotReplyNumber"></param> /// <param name="list">主题列表</param> private static void LoadTopTopicListExtraInfo(int topicTypePrefix, int newMinutes, int hotReplyNumber, Discuz.Common.Generic.List <TopicInfo> list) { SortedList <int, string> topicTypeList = Caches.GetTopicTypeArray(); StringBuilder closedIds = new StringBuilder(); foreach (TopicInfo topic in list) { ForumInfo forumInfo = Forums.GetForumInfo(topic.Fid); if (topic.Closed == 0 && forumInfo.Autoclose > 0 && Utils.StrDateDiffHours(topic.Postdatetime, forumInfo.Autoclose * 24) > 0) { closedIds.Append(topic.Tid.ToString()); closedIds.Append(","); } LoadTopicFolder(forumInfo.Autoclose, newMinutes, hotReplyNumber, topic); LoadTopicHighlightTitle(topic); LoadTopicType(topicTypePrefix, topicTypeList, topic); } if (closedIds.Length > 0) { TopicAdmins.SetClose(closedIds.ToString().TrimEnd(','), 1); } }
/// <summary> /// 根据参数信息选择相应的模板 /// </summary> /// <param name="strTemplateid">默认的模板ID</param> /// <param name="pagename">请求的页面名称</param> /// <param name="newUrl">请求参数</param> /// <returns>返回相应的模板ID</returns> public string SelectTemplate(string strTemplateid, string pagename, string newUrl) { string pagenamelist = "showforum,showtopic,showdebate,showbonus,posttopic,postreply,showtree,editpost,delpost,topicadmin"; int forumid = 0; //要截取的字段串的开始位置 int startindex = pagename.LastIndexOf("/") + 1; //如果是指定的页面则进行模板查询 int length = pagename.LastIndexOf(".") - startindex; if (length > 0 && Utils.InArray(pagename.Substring(startindex, length), pagenamelist)) { foreach (string urlvalue in newUrl.Split('&')) { if ((urlvalue.IndexOf("forumid=") >= 0) && (urlvalue.Split('=')[1] != "")) { forumid = Utils.StrToInt(urlvalue.Split('=')[1], 0); } else { if ((urlvalue.IndexOf("topicid=") >= 0) && (urlvalue.Split('=')[1] != "")) { Discuz.Entity.TopicInfo topicinfo = Topics.GetTopicInfo(Utils.StrToInt(urlvalue.Split('=')[1], 0)); //主题存在时 if (topicinfo != null) { forumid = topicinfo.Fid; } } else { forumid = DNTRequest.GetInt("forumid", 0); } } if (forumid > 0) { Entity.ForumInfo forumInfo = Forums.GetForumInfo(forumid); int templateid = forumInfo == null ? 0 : forumInfo.Templateid; //当前版块未指定模板时(使用用户选择的模版或系统默认模板) if (templateid <= 0) { //从cookie中获取用户选择的模板 if (Utils.InArray(Utils.GetCookie(Utils.GetTemplateCookieName()), Templates.GetValidTemplateIDList())) { templateid = Utils.StrToInt(Utils.GetCookie(Utils.GetTemplateCookieName()), GeneralConfigs.GetConfig().Templateid); } //使用系统默认模板 if (templateid == 0) { templateid = GeneralConfigs.GetConfig().Templateid; } } strTemplateid = templateid.ToString(); break; } } } return(strTemplateid); }
/// <summary> /// 加载主题所在版块名称 /// </summary> /// <param name="topicInfo"></param> private static void LoadTopicForumName(TopicInfo topicInfo) { ForumInfo forumInfo = Forums.GetForumInfo(topicInfo.Fid); topicInfo.Forumname = forumInfo == null ? "" : forumInfo.Name; }
/// <summary> /// 在数据库中删除指定主题 /// </summary> /// <param name="topiclist">主题列表</param> /// <param name="subtractCredits">是否减少用户积分(0不减少,1减少)</param> /// <returns>删除个数</returns> public static int DeleteTopics(string topicList, int subTractCredits, bool reserveAttach) { if (!Utils.IsNumericList(topicList)) { return(-1); } GeneralConfigInfo configinfo = GeneralConfigs.GetConfig(); DataTable dt = Topics.GetTopicList(topicList); if (dt == null) { return(-1); } foreach (DataRow dr in dt.Rows) { if (TypeConverter.ObjectToInt(dr["digest"]) > 0) { UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), -1, CreditsOperationType.Digest, 1, true); UserCredits.UpdateUserCredits(TypeConverter.ObjectToInt(dr["posterid"])); } } dt = Posts.GetPostList(topicList); if (dt != null) { Hashtable attUidCount = new Hashtable(); foreach (DataRow dr in dt.Rows) { //后台设置的项为多少天外的老帖删除不减积分,而不是多少天内删帖可以不减分 if (configinfo.Losslessdel == 0 || Utils.StrDateDiffHours(dr["postdatetime"].ToString(), configinfo.Losslessdel * 24) < 0) { CreditsOperationType creditsOperationType = TypeConverter.ObjectToInt(dr["layer"]) == 0 ? CreditsOperationType.PostTopic : CreditsOperationType.PostReply; //获取版块积分规则 float[] creditsValue = Forums.GetValues( creditsOperationType == CreditsOperationType.PostTopic ? Forums.GetForumInfo(TypeConverter.ObjectToInt(dr["fid"])).Postcredits : Forums.GetForumInfo(TypeConverter.ObjectToInt(dr["fid"])).Replycredits ); //如果未定义版块积分规则 if (creditsValue == null) { creditsValue = Scoresets.GetUserExtCredits(creditsOperationType); } UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), creditsValue, 1, creditsOperationType, -1, true); int attCount = Attachments.GetAttachmentCountByPid(TypeConverter.ObjectToInt(dr["pid"])); if (attCount > 0) { int posterid = TypeConverter.ObjectToInt(dr["posterid"]); if (attUidCount.ContainsKey(posterid)) { attUidCount[posterid] = (int)attUidCount[posterid] + attCount; } else { attUidCount.Add(TypeConverter.ObjectToInt(dr["posterid"]), attCount); } } } UserCredits.UpdateUserCredits(TypeConverter.ObjectToInt(dr["posterid"])); } int i = 0; int[] tuidlist = new int[attUidCount.Count]; int[] attcountlist = new int[attUidCount.Count]; foreach (DictionaryEntry de in attUidCount) { tuidlist[i] = (int)de.Key; attcountlist[i] = (int)de.Value; i++; } UserCredits.UpdateUserCredits(tuidlist, attcountlist, CreditsOperationType.UploadAttachment, -1); } int reval = 0; foreach (string posttableid in Posts.GetPostTableIdArray(topicList)) { reval = Discuz.Data.TopicAdmins.DeleteTopicByTidList(topicList, posttableid); } if (reval > 0 && !reserveAttach) { Attachments.DeleteAttachmentByTid(topicList); } return(reval); }
/// <summary> /// 获得指定版块最新的20个主题的Rss描述 /// </summary> /// <param name="ttl">TTL数值</param> /// <param name="fid">版块id</param> /// <returns>Rss描述</returns> public static string GetForumRssXml(int ttl, int fid) { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); string str = cache.RetrieveObject("/RSS/Forum" + fid) as string; if (str != null) { return(str); } string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + ("/").ToLower();//GeneralConfigs.GetConfig().Forumurl; //if (!forumurl.EndsWith("/")) //{ // forumurl = forumurl + "/"; //} ForumInfo forum = Forums.GetForumInfo(fid); if (forum == null) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified forum not found</Rss>\r\n"); } if (forum.Viewperm == null || forum.Viewperm == string.Empty) { //板块权限设置为空,按照用户组权限走,RSS仅检查游客权限 UserGroupInfo guestinfo = UserGroups.GetUserGroupInfo(7); if (guestinfo.Allowvisit == 0) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n"); } } else { if (!Utils.InArray("7", forum.Viewperm, ",")) { return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n"); } } StringBuilder sbRss = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"); sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n"); sbRss.Append("<rss version=\"2.0\">\r\n"); sbRss.Append(" <channel>\r\n"); sbRss.Append(" <title>"); sbRss.Append(Utils.HtmlEncode(config.Forumtitle)); sbRss.Append(" - "); sbRss.Append(Utils.HtmlEncode(forum.Name)); sbRss.Append("</title>\r\n"); sbRss.Append(" <link>"); sbRss.Append(forumurl); if (config.Aspxrewrite == 1) { sbRss.Append("showforum-"); sbRss.Append(fid.ToString()); sbRss.Append(config.Extname); } else { sbRss.Append("showforum.aspx?forumid="); sbRss.Append(fid.ToString()); } sbRss.Append("</link>\r\n"); sbRss.Append(" <description>Latest 20 threads</description>\r\n"); sbRss.Append(" <copyright>Copyright (c) "); sbRss.Append(Utils.HtmlEncode(config.Forumtitle)); sbRss.Append("</copyright>\r\n"); sbRss.Append(" <generator>"); sbRss.Append("Discuz!NT"); sbRss.Append("</generator>\r\n"); sbRss.Append(" <pubDate>"); //sbRss.Append(DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'")); sbRss.Append(DateTime.Now.ToString("r")); sbRss.Append("</pubDate>\r\n"); sbRss.AppendFormat(" <ttl>{0}</ttl>\r\n", ttl.ToString()); IDataReader reader = DatabaseProvider.GetInstance().GetForumNewTopics(fid); if (reader != null) { while (reader.Read()) { sbRss.Append(" <item>\r\n"); sbRss.Append(" <title>"); sbRss.Append(Utils.HtmlEncode(reader["title"].ToString().Trim())); sbRss.Append("</title>\r\n"); sbRss.Append(" <description><![CDATA["); if (reader["message"].ToString().IndexOf("[hide]") > -1) { sbRss.Append("***内容隐藏***"); } else { sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(UBB.ClearUBB(reader["message"].ToString()), 200, "......"))); } sbRss.Append("]]></description>\r\n"); sbRss.Append(" <link>"); sbRss.Append(Utils.HtmlEncode(forumurl)); if (config.Aspxrewrite == 1) { sbRss.Append("showtopic-"); sbRss.Append(reader["tid"].ToString()); sbRss.Append(config.Extname); } else { sbRss.Append("showtopic.aspx?topicid="); sbRss.Append(reader["tid"].ToString()); } sbRss.Append("</link>\r\n"); sbRss.Append(" <category>"); sbRss.Append(Utils.HtmlEncode(forum.Name)); sbRss.Append("</category>\r\n"); sbRss.Append(" <author>"); sbRss.Append(Utils.HtmlEncode(reader["poster"].ToString().Trim())); sbRss.Append("</author>\r\n"); sbRss.Append(" <pubDate>"); sbRss.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim())); sbRss.Append("</pubDate>\r\n"); sbRss.Append(" </item>\r\n"); } reader.Close(); } sbRss.Append(" </channel>\r\n"); sbRss.Append("</rss>"); Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy(); ics.TimeOut = ttl; cache.LoadCacheStrategy(ics); cache.AddObject("/RSS/Forum" + fid, sbRss.ToString()); cache.LoadDefaultCacheStrategy(); return(sbRss.ToString()); }