示例#1
0
 /// <summary>
 /// デシリアライズ時に呼ばれるコンストラクタ
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 public BoardInfo(SerializationInfo info, StreamingContext context)
 {
     this.bbs    = (BbsType)info.GetValue("Bbs", typeof(BbsType));
     this.name   = HtmlTextUtility.RemoveTag(info.GetString("Name"));
     this.path   = info.GetString("Path");
     this.server = info.GetString("Server");
 }
示例#2
0
 /// <summary>
 /// BoardInfoクラスのインスタンスを初期化
 /// </summary>
 /// <param name="server">サーバーアドレス</param>
 /// <param name="path">板へのパス</param>
 /// <param name="name">板名</param>
 public BoardInfo(string server, string path, string name)
     : this()
 {
     this.server = server;
     this.path   = path;
     this.name   = HtmlTextUtility.RemoveTag(name);
     this.bbs    = Parse(server);
 }
示例#3
0
        /// <summary>
        /// 指定したResSetを
        /// 設定されているスキンを使用して文字列形式に変換
        /// </summary>
        /// <param name="resSet"></param>
        /// <returns></returns>
        protected virtual string Convert(string skinhtml, ResSet resSet)
        {
            StringBuilder sb = new StringBuilder(2048);
            string        name;
            string        mailname;
            string        dateonly, dateString;
            string        body;

            #region  前の作成
            sb.Append("<b>");
            sb.Append(resSet.Name);
            sb.Append("</b>");
            name = sb.ToString();
            sb.Remove(0, sb.Length);
            #endregion

            #region Email付き名前の作成
            if (resSet.Email != String.Empty)
            {
                sb.Append("<a href=\"mailto:");
                sb.Append(resSet.Email);
                sb.Append("\">");
                sb.Append(name);
                sb.Append("</a>");
                mailname = sb.ToString();
                sb.Remove(0, sb.Length);
            }
            else
            {
                mailname = name;
            }
            #endregion

            #region 日付とIDを作成
            dateString = resSet.DateString;
            dateonly   = resSet.DateString;
            Match m = Regex.Match(resSet.DateString, "( ID:)|(\\[)");

            if (m.Success)
            {
                dateonly = resSet.DateString.Substring(0, m.Index);
            }
            #endregion

            #region Be2chIDのリンクを貼る
            // BE:0123456-# または <BE:0123456:0> 形式の二つあるみたい
            dateString =
                Regex.Replace(dateString, @"BE:(?<id>\d+)\-(?<rank>.+)",
                              "<a href=\"http://be.2ch.net/test/p.php?i=${id}\" target=\"_blank\">?${rank}</a>", RegexOptions.IgnoreCase);

            dateString =            // 面白ネタnews形式
                         Regex.Replace(dateString, @"<BE:(?<id>\d+):(?<rank>.+)>",
                                       "<a href=\"http://be.2ch.net/test/p.php?i=${id}\" target=\"_blank\">Lv.${rank}</a>", RegexOptions.IgnoreCase);
            #endregion

            #region 本分を作成
            body = HtmlTextUtility.RemoveTag(resSet.Body, "a");
            body = HtmlTextUtility.Linking(body);
            #endregion

            #region レス参照を作成
            body = HtmlTextUtility.RefRegex.Replace(body, "<a href=\"" + baseUri + "${num}\" target=\"_blank\">${ref}</a>");
            body = HtmlTextUtility.ExRefRegex.Replace(body, "<a href=\"" + baseUri + "${num}\" target=\"_blank\">${num}</a>");
            #endregion

            sb.Remove(0, sb.Length);
            sb.Append(skinhtml);
            sb.Replace("<PLAINNUMBER/>", resSet.Index.ToString());
            sb.Replace("<NUMBER/>", resSet.Index.ToString());
            sb.Replace("<MAILNAME/>", mailname);
            sb.Replace("<ID/>", resSet.ID);
            sb.Replace("<BE/>", resSet.BeLink);
            sb.Replace("<NAME/>", name);
            sb.Replace("<MAIL/>", resSet.Email);
            sb.Replace("<DATE/>", dateString);
            sb.Replace("<DATEONLY/>", dateonly);
            sb.Replace("<MESSAGE/>", body);
            sb.Replace("<SKINPATH/>", skinPath);

            skinhtml = sb.ToString();

            return(skinhtml);
        }
        protected virtual bool IsMatch(List <__WordSet> wordList, ThreadHeader checkItem, ref int level)
        {
            if (checkItem.IsLimitOverThread)
            {
                return(false);
            }

            float  matchCount = 0;
            string input      = checkItem.Subject;
            string backWord   = String.Empty;

            foreach (__WordSet ws in wordList)
            {
                WordType type = ws.Key;
                string   key  = ws.Value;

                // ひらがな1文字は無視
                if (key.Length == 1 && type == WordType.Hira)
                {
                    continue;
                }

                if (Regex.IsMatch(input, Regex.Escape(key), RegexOptions.IgnoreCase))
                {
                    if (type == WordType.Kanji || type == WordType.Kata || type == WordType.Hankaku || type == WordType.Alpha)
                    {
                        matchCount += key.Length * 2.0f;
                    }
                    else
                    {
                        matchCount += 1;
                    }
                }

                // key を直前の単語 backWord と結合し、ひとつのワードとして検索。
                // "BS11 3691" と "BSフジ 1125" が両方とも "BS" と "11" が一致し、同じ一致レベルとされてしまう問題があったたため
                if (backWord != "" && Regex.IsMatch(input, Regex.Escape(backWord + key), RegexOptions.IgnoreCase))
                {
                    string longKey = backWord + key;
                    matchCount += longKey.Length * 1.5f;
                }

                // スレのカウント+1 の数字が存在したら有力候補…?
                if (type == WordType.Decimal)
                {
                    int dec;
                    if (Int32.TryParse(key, out dec))
                    {
                        dec += 1;
                        if (Regex.IsMatch(input, dec + "|" + HtmlTextUtility.HanToZen(dec.ToString())))
                        {
                            matchCount += 3;
                        }
                    }
                }

                backWord = key;
            }

            // スレの勢いがあればあるほど
            matchCount += new ThreadHeaderInfo(checkItem).ForceValueDay / 10000;

            if (level - matchCount <= 0)
            {
                level = (int)Math.Round(matchCount, MidpointRounding.AwayFromZero);
                Console.WriteLine("{0} level of {1}", level, input);
                return(true);
            }

            return(false);
        }
示例#5
0
        /// <summary>
        /// text内に含まれているレス参照の番号をすべて数値配列に変換
        /// (例: http://.../10-20 → 10,11,12...20)
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static int[] GetArray(string text)
        {
            if (text == null)
            {
                throw new ArgumentNullException("text");
            }

            if (Regex.IsMatch(text, @"/\d{5,}/?$") || Regex.IsMatch(text, "(=|l)\\d+$"))            // "/50l" などは無視する
            {
                return(new int[0]);
            }

            ArrayList list = new ArrayList();

            Match m = RefRegex.Match(
                HtmlTextUtility.ZenToHan(text));

            if (m.Success)
            {
                string[] numbers = m.Groups["num"].Value.Split(",+".ToCharArray());

                foreach (string num in numbers)
                {
                    string[] array = num.Split('-');
                    if (array.Length == 2)
                    {
                        int st = 0, ed = 0;

                        // 数字かどうかをチェック
                        if (Int32.TryParse(array[0], out st))
                        {
                            // "100-" (100番目以降) という数字の場合、array[1] には空文字列が格納される。
                            // この形式の場合は 100番目から最後のレス(1001番目)までを含めるようにする
                            if (array[1] == String.Empty)
                            {
                                ed = 1001;
                            }
                            else
                            {
                                Int32.TryParse(array[1], out ed);
                            }

                            if (st >= 1 && (ed - st) <= 1000)
                            {
                                for (int i = st; i <= ed; i++)
                                {
                                    list.Add(i);
                                }
                            }
                        }
                    }
                    else if (array.Length == 1)
                    {
                        if (HtmlTextUtility.IsDigit(array[0]))
                        {
                            int n;
                            if (Int32.TryParse(array[0], out n))
                            {
                                list.Add(n);
                            }
                        }
                    }
                }
            }
            return((int[])list.ToArray(typeof(int)));
        }
示例#6
0
        /// <summary>
        /// 指定したResSetを
        /// 設定されているスキンを使用して文字列形式に変換
        /// </summary>
        /// <param name="resSet"></param>
        /// <returns></returns>
        public override string Convert(ResSet resSet)
        {
            if (!resSet.Visible)
            {
                return(String.Empty);
            }

            if (resSet.DateString == "透明あぼーん")
            {
                return(String.Empty);
            }

            /*
             * if (resSet.IsABone) {
             *      resSet = ResSet.ABone(resSet, ABoneType.NG, "");
             *      resSet.Email = String.Empty;
             * }*/

            // 使用するスキン
            string skinhtml = resSet.IsNew ? newResSkin : resSkin;
            string dateonly, body;

            // 本分からtagを取り除く
            body = resSet.Body;
            body = Regex.Replace(body, "<a[^>]+>(?<uri>[^<]*)</a>", "${uri}", RegexOptions.IgnoreCase);
            body = Regex.Replace(body, "<(?!br|hr)[^>]+>", "");

            buffer.Append(body);
            buffer.Replace("<br>", "\r\n");
            buffer.Replace("<hr>", "\r\n ————————————————————\r\n");
            buffer.Replace("&gt;", ">");
            buffer.Replace("&lt;", "<");
            body = buffer.ToString();
            buffer.Remove(0, buffer.Length);

            #region 日付とIDを作成
            dateonly = resSet.DateString;
            Match m = Regex.Match(resSet.DateString, "( ID:)|(\\[)");

            if (m.Success)
            {
                dateonly = resSet.DateString.Substring(0, m.Index);
            }
            #endregion

#if REGEX_REPLACE
            skinhtml = PlainNumberRegex.Replace(skinhtml, resSet.Index.ToString());
            skinhtml = IDRegex.Replace(skinhtml, resSet.ID);
            skinhtml = NameRegex.Replace(skinhtml, resSet.Name);
            skinhtml = EmailRegex.Replace(skinhtml, resSet.Email);
            skinhtml = DateRegex.Replace(skinhtml, resSet.DateString);
            skinhtml = DateOnlyRegex.Replace(skinhtml, dateonly);
            skinhtml = BodyRegex.Replace(skinhtml, body);
#else
            buffer.Append(skinhtml);
            buffer.Replace("<PLAINNUMBER/>", resSet.Index.ToString());
            buffer.Replace("<ID/>", resSet.ID);
            buffer.Replace("<NAME/>", HtmlTextUtility.RemoveTag(resSet.Name));
            buffer.Replace("<MAIL/>", resSet.Email);
            buffer.Replace("<DATE/>", resSet.DateString);
            buffer.Replace("<DATEONLY/>", dateonly);
            buffer.Replace("<MESSAGE/>", body);
            skinhtml = buffer.ToString();
            buffer.Remove(0, buffer.Length);
#endif

            return(skinhtml);
        }
        private StringBuilder CreateHtml(string skinhtml, ResSet resSet)
        {
            StringBuilder sb = new StringBuilder(2048);
            string        number;
            string        name;
            string        mailname;
            string        dateonly, dateString;
            string        body;

            #region メニュー付き番号の作成
            int iPos = -1;

            sb.Append("<a href=\"menu:");
            sb.Append(resSet.Index);
            sb.Append("\" name=\"");
            sb.Append(resSet.Index);
            sb.Append("\" target=\"_blank\">");
            iPos = sb.Length;
            sb.Append(resSet.Index);

            if (resSet.IsServerAboned)
            {
                sb.Insert(iPos, "<font color=lime><i>");
                sb.Append("</i></font>");
            }

            sb.Append("</a>");

            number = sb.ToString();
            sb.Remove(0, sb.Length);
            #endregion

            #region  前の作成
            sb.Append("<b>");
            sb.Append(resSet.Name);
            sb.Append("</b>");
            name = sb.ToString();
            sb.Remove(0, sb.Length);
            #endregion

            #region  前欄ポップアップ
            string _resName = String.Empty;
            if (!String.IsNullOrEmpty(resSet.Name))
            {
                if (namePopup && Char.IsDigit(resSet.Name[resSet.Name.Length - 1]))
                {
                    _resName = Regex.Replace(resSet.Name, ">|>|&gt;", String.Empty);
                }
            }

            // 名前欄が数字ならリンクを貼る
            if (namePopup && HtmlTextUtility.IsDigit(_resName))             // 最後の文字が数字のときのみ処理する
            {
                sb.Append("<a href=\"");
                sb.Append(baseUri);
                sb.Append(HtmlTextUtility.ZenToHan(_resName));
                sb.Append("\" target=\"_blank\">");
                sb.Append(name);
                sb.Append("</a>");
                name     = sb.ToString();
                mailname = name;
                sb.Remove(0, sb.Length);
            }
            #endregion

            #region Email付き名前の作成
            else if (resSet.Email != String.Empty)
            {
                sb.Append("<a href=\"mailto:");
                sb.Append(resSet.Email);
                sb.Append("\">");
                sb.Append(name);
                sb.Append("</a>");
                mailname = sb.ToString();
                sb.Remove(0, sb.Length);
            }
            else
            {
                mailname = name;
            }
            #endregion

            #region 日付とIDを作成
            dateString = resSet.DateString;
            dateonly   = resSet.DateString;
            Match m = Regex.Match(resSet.DateString, @"\d{2,4}/\d{2}/\d{2}(\(\w\))?\s\d{2}:\d{2}(:\d{2}.\d{2}|:\d{2})?(\s[0-9a-zA-GJ-Z])?");

            if (m.Success)
            {
                dateonly = m.Value;
            }
            #endregion

            #region Be2chIDのリンクを貼る
            // BE:0123456-# または <BE:0123456:0> 形式の二つあるみたい
            dateString =
                Regex.Replace(dateString, @"BE:(?<id>\d+)\-(?<rank>.+)",
                              "<a href=\"http://be.2ch.net/test/p.php?i=${id}\" target=\"_blank\">?${rank}</a>", RegexOptions.IgnoreCase);

            dateString =            // 面白ネタnews形式
                         Regex.Replace(dateString, @"<BE:(?<id>\d+):(?<rank>.+)>",
                                       "<a href=\"http://be.2ch.net/test/p.php?i=${id}\" target=\"_blank\">Lv.${rank}</a>", RegexOptions.IgnoreCase);
            #endregion

            #region 本分を作成
            body = HtmlTextUtility.RemoveTag(resSet.Body, "a|font");
            body = rexBRSpace.Replace(body, "<BR>");
            body = HtmlTextUtility.Linking(body);
            #endregion

            #region レス参照を作成
            body = HtmlTextUtility.RefRegex.Replace(body, "<a href=\"" + baseUri + "${num}\" target=\"_blank\" name=\"res" + resSet.Index + "_ref${num}\">${ref}</a>");
            // body = HtmlTextUtility.ExRefRegex.Replace(body, "<a href=\"" + baseUri + "${num}\" target=\"_blank\">${num}</a>");  // 2011.12.16 水玉さん
            #endregion

            #region そのほかの置き換え処理
            sb.Remove(0, sb.Length);
            sb.Append(skinhtml);
            sb.Replace("<PLAINNUMBER/>", resSet.Index.ToString());
            sb.Replace("<MAILNAME/>", mailname);
            sb.Replace("<NUMBER/>", number);
            sb.Replace("<ID/>", resSet.ID);
            sb.Replace("<BE/>", resSet.BeLink);
            sb.Replace("<NAME/>", name);
            sb.Replace("<MAIL/>", resSet.Email);
            sb.Replace("<DATE/>", dateString);
            sb.Replace("<DATEONLY/>", dateonly);
            sb.Replace("<MESSAGE/>", body);
            sb.Replace("<SKINPATH/>", skinPath);
            sb.Replace("<HOST/>", resSet.Host);
            #endregion

            return(sb);
        }