private void SaveWord_Click(object sender, EventArgs e)
 {
     #region 保存过滤字修改
     int  row   = 0;
     bool error = false;
     foreach (object o in DataGrid1.GetKeyIDArray())
     {
         int    id          = int.Parse(o.ToString());
         string find        = DataGrid1.GetControlValue(row, "find").Trim();
         string replacement = DataGrid1.GetControlValue(row, "replacement").Trim();
         if (find == "" || replacement == "")
         {
             error = true;
             continue;
         }
         BanWords.UpdateBanWord(id, find, replacement);
         row++;
     }
     DNTCache.GetCacheService().RemoveObject("/Forum/BanWordList");
     Caches.GetBanWordList();
     if (error)
     {
         base.RegisterStartupScript("PAGE", "alert('某些信息不完整,未能更新!');window.location.href='global_wordgrid.aspx';");
     }
     base.RegisterStartupScript("PAGE", "window.location.href='global_wordgrid.aspx';");
     #endregion
 }
        public void BindData()
        {
            #region 绑定过滤词列表
            DataGrid1.AllowCustomPaging = false;
            DataGrid1.TableHeaderName   = "过滤词列表";
            DataGrid1.BindData(BanWords.GetBanWordList());

            antipamreplacement.Text = config.Antispamreplacement;
            #endregion
        }
Example #3
0
        public BanWord AddBanWord(BanWord word)
        {
            if (BanWords.Select(x => x.Content).Contains(word.Content))
            {
                return(word);
            }
            var ret = BanWords.Add(word);

            SaveChanges();

            return(ret.Entity);
        }
        private void DelRec_Click(object sender, EventArgs e)
        {
            #region  除过滤词

            if (this.CheckCookie())
            {
                if (DNTRequest.GetString("id") != "")
                {
                    BanWords.DeleteBanWords(DNTRequest.GetString("id"));
                    Response.Redirect("global_wordgrid.aspx");
                }
                else
                {
                    base.RegisterStartupScript("", "<script>alert('您未选中任何选项');window.location.href='global_wordgrid.aspx';</script>");
                }
            }

            #endregion
        }
        private void AddNewRec_Click(object sender, EventArgs e)
        {
            #region 添加过滤词

            if (find.Text == "")
            {
                base.RegisterStartupScript("", "<script>alert('要添加的过滤内容不能为空');window.location.href='global_wordgrid.aspx';</script>");
                return;
            }

            if (replacement.Text == "")
            {
                base.RegisterStartupScript("", "<script>alert('要添加的替换内容不能为空');window.location.href='global_wordgrid.aspx';</script>");
                return;
            }

            if (BanWords.IsExistBanWord(find.Text))
            {
                base.RegisterStartupScript("", "<script>alert('数据库中已存在相同的过滤内容');window.location.href='global_wordgrid.aspx';</script>");
                return;
            }


            AdminVistLogs.InsertLog(this.userid, this.username, this.usergroupid, this.grouptitle, this.ip, "加入字符过滤", "字符为:" + find.Text);

            try
            {
                BanWords.CreateBanWord(username, find.Text, replacement.Text);
                BindData();
                base.RegisterStartupScript("PAGE", "window.location.href='global_wordgrid.aspx';");
                return;
            }
            catch
            {
                base.RegisterStartupScript("", "<script>alert('无法更新数据库.');window.location.href='global_wordgrid.aspx';</script>");
                return;
            }

            #endregion
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int    pertask       = DNTRequest.GetInt("pertask", 0);
                int    lastnumber    = DNTRequest.GetInt("lastnumber", 0);
                int    startvalue    = DNTRequest.GetInt("startvalue", 0);
                int    endvalue      = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                case "UpdatePostSP":
                    AdminForumStats.UpdatePostSP(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "UpdateMyPost":
                    AdminForumStats.UpdateMyPost(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost":
                    //AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                    AdminForumStats.ReSetFourmTopicAPost();
                    resultmessage = "-1";
                    break;

                case "ReSetUserDigestPosts":
                    //AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                    //resultmessage = lastnumber.ToString();
                    AdminForumStats.ReSetUserDigestPosts();
                    resultmessage = "-1";
                    break;

                case "ReSetUserPosts":
                    AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetTopicPosts":
                    AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost_StartEnd":
                    AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserDigestPosts_StartEnd":
                    AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserPosts_StartEnd":
                    AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetTopicPosts_StartEnd":
                    AdminForumStats.ResetLastRepliesInfoOfTopics(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ftptest":
                    FTPs   ftps    = new FTPs();
                    string message = "";
                    bool   ok      = ftps.TestConnect(DNTRequest.GetString("serveraddress"), DNTRequest.GetInt("serverport", 0), DNTRequest.GetString("username"),
                                                      DNTRequest.GetString("password"), DNTRequest.GetInt("timeout", 0), DNTRequest.GetString("uploadpath"), ref message);
                    resultmessage = ok ? "ok" : "远程附件设置测试出现错误!\n描述:" + message;
                    break;

                case "setapp":
                    APIConfigInfo aci = APIConfigs.GetConfig();
                    aci.Enable = DNTRequest.GetString("allowpassport") == "1";
                    APIConfigs.SaveConfig(aci);
                    resultmessage = "ok";
                    break;

                case "location":
                    string city = DNTRequest.GetString("city");
                    resultmessage = "ok";
                    DataTable dt = MallPluginProvider.GetInstance().GetLocationsTable();
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["country"].ToString() == DNTRequest.GetString("country") && dr["state"].ToString() == DNTRequest.GetString("state") && dr["city"].ToString() == city)
                        {
                            resultmessage = "<img src='../images/false.gif' title='" + city + "已经存在!'>";
                            break;
                        }
                    }
                    break;

                case "goodsinfo":
                    int       goodsid   = DNTRequest.GetInt("goodsid", 0);
                    Goodsinfo goodsinfo = MallPluginProvider.GetInstance().GetGoodsInfo(goodsid);
                    if (goodsinfo == null)
                    {
                        resultmessage = "商品不存在!";
                        break;
                    }
                    //GoodsattachmentinfoCollection attachmentinfos = GoodsAttachments.GetGoodsAttachmentsByGoodsid(goodsinfo.Goodsid);
                    //string img = "";
                    //if (attachmentinfos != null)
                    //{
                    //    img = attachmentinfos[0].Filename;
                    //}
                    PostpramsInfo param = new PostpramsInfo();
                    param.Allowhtml  = 1;
                    param.Showimages = 1;
                    param.Sdetail    = goodsinfo.Message;
                    resultmessage    = "<table width='100%'><tr><td>" + UBB.UBBToHTML(param) + "</td></tr></table>";
                    break;

                case "downloadword":
                    dt = BanWords.GetBanWordList();
                    string words = "";
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            words += dt.Rows[i][2].ToString() + "=" + dt.Rows[i][3].ToString() + "\r\n";
                        }
                    }

                    string filename = "words.txt";
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Buffer          = false;
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.Write(words);
                    HttpContext.Current.Response.End();
                    break;

                case "gettopicinfo":
                    StringBuilder sb   = new StringBuilder();
                    TopicInfo     info = Topics.GetTopicInfo(DNTRequest.GetInt("tid", 0));
                    sb.Append("[");
                    if (info != null)
                    {
                        sb.Append(string.Format("{{'tid':{0},'title':'{1}'}}", info.Tid, info.Title));
                    }

                    System.Web.HttpContext.Current.Response.Clear();
                    System.Web.HttpContext.Current.Response.ContentType = "application/json";
                    System.Web.HttpContext.Current.Response.Expires     = 0;
                    System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                    System.Web.HttpContext.Current.Response.Write(sb.Append("]").ToString());
                    System.Web.HttpContext.Current.Response.End();
                    break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires         = -1;
                Response.End();
            }
        }
        private void addbadwords_Click(object sender, EventArgs e)
        {
            if (this.badwords.Text == "")
            {
                BindData();
                return;
            }

            String[] badwords = getwords();
            String[] filterwords;

            #region 根据radiobuttonlist选择条件
            if (radfilter.SelectedValue == "0")
            {
                //清空当前词语表,再插入
                string find           = "";
                string replacement    = "";
                string banWordsIdList = "";
                foreach (DataRow dr in BanWords.GetBanWordList().Rows)
                {
                    banWordsIdList += dr["id"].ToString() + ",";
                }
                if (banWordsIdList != "")
                {
                    BanWords.DeleteBanWords(banWordsIdList.TrimEnd(','));
                }

                for (int i = 0; i < badwords.Length; i++)
                {
                    filterwords = badwords[i].Split('=');

                    find = filterwords[0].ToString().Replace("\r", "").Trim();

                    if (!GetReplacement(badwords, filterwords, ref find, ref replacement))
                    {
                        continue;
                    }

                    BanWords.CreateBanWord(username, find, replacement);
                }
            }

            if (radfilter.SelectedValue == "1")
            {
                //使用新的设置覆盖已经存在的词语
                string find        = "";
                string replacement = "";

                for (int i = 0; i < badwords.Length; i++)
                {
                    filterwords = badwords[i].Split('=');

                    find = filterwords[0].ToString().Replace("\r", "").Trim();

                    if (!GetReplacement(badwords, filterwords, ref find, ref replacement))
                    {
                        continue;
                    }
                    BanWords.UpdateBadWords(find, replacement);
                }
            }

            if (radfilter.SelectedValue == "2")
            {
                //不导入已经存在的词语

                string find        = "";
                string replacement = "";

                DataTable dt = BanWords.GetBanWordList();

                for (int i = 0; i < badwords.Length; i++)
                {
                    #region
                    //filterwords = badwords[i].Split('=');

                    //find = filterwords[0].ToString().Replace("\r", "").Trim();

                    //#region

                    //if (find == "")
                    //{
                    //    continue;
                    //}

                    //if (filterwords.Length == 2 && filterwords[1].ToString() != "")
                    //{
                    //        replacement = filterwords[1].ToString();
                    //}
                    //else if (filterwords.Length < 2)
                    //{
                    //    replacement = "**";
                    //}
                    //else//filterwords.Length > 2 的情况
                    //{
                    //    replacement = filterwords[filterwords.Length - 1];

                    //    filterwords.SetValue("", filterwords.Length - 1);

                    //    find = string.Join("=", filterwords);
                    //    find = find.Remove(find.Length - 2);
                    //}


                    //#endregion
                    #endregion

                    filterwords = badwords[i].Split('=');

                    find = filterwords[0].ToString().Replace("\r", "").Trim();

                    if (!GetReplacement(badwords, filterwords, ref find, ref replacement))
                    {
                        continue;
                    }


                    DataRow[] arrRow = dt.Select("find='" + find + "'");

                    if (arrRow.Length == 0)
                    {
                        BanWords.CreateBanWord(username, find, replacement);
                    }
                }
            }
            #endregion

            BindData();

            this.badwords.Text = "";
        }