示例#1
0
 public void AddReply(GenericPost reply)
 {
     if (_childs.ContainsKey(reply.ID))
     {
         return;
     }
     else
     {
         reply.OwnerThread = this.Instance;
         this._childs.Add(reply.ID, reply);
     }
 }
示例#2
0
 public void AddReply(GenericPost reply)
 {
     if (_childs.ContainsKey(reply.ID))
     {
         return;
     }
     else
     {
         reply.OwnerThread = this.Instance;
         this._childs.Add(reply.ID, reply);
     }
 }
示例#3
0
        public bool MatchFilters(AniWrap.DataTypes.GenericPost post)
        {
            var filters = this.CurrentModeFilters;

            foreach (var filter in filters)
            {
                try
                {
                    if (filter.Detect(post))
                    {
                        return(true);
                    }
                }
                catch (Exception)
                {
                    // ignore it
                }
            }

            return(false);
        }
示例#4
0
        private GenericPost ParseReply(JsonObject data, string board)
        {
            GenericPost t = new GenericPost();

            t.Board = board;

            //comment
            if (data["com"] != null)
            {
                t.Comment = data["com"].ToString();
            }
            else
            {
                t.Comment = "";
            }

            //mail
            if (data["email"] != null)
            {
                t.Email = HttpUtility.HtmlDecode(data["email"].ToString());
            }
            else
            {
                t.Email = "";
            }

            //poster name
            if (data["name"] != null)
            {
                t.Name = HttpUtility.HtmlDecode(data["name"].ToString());
            }
            else
            {
                t.Name = "";
            }

            //subject
            if (data["sub"] != null)
            {
                t.Subject = HttpUtility.HtmlDecode(data["sub"].ToString());
            }
            else
            {
                t.Subject = "";
            }

            if (data["trip"] != null)
            {
                t.Trip = data["trip"].ToString();
            }
            else
            {
                t.Trip = "";
            }

            if (data["id"] != null)
            {
                t.PosterID = data["id"].ToString();
            }
            else
            {
                t.PosterID = "";
            }

            if (data["country"] != null)
            {
                t.country_flag = data["country"].ToString();
            }
            else
            {
                t.country_flag = "";
            }

            if (data["country_name"] != null)
            {
                t.country_name = data["country_name"].ToString();
            }
            else
            {
                t.country_name = "";
            }

            if (data["capcode"] != null)
            {
                t.Capcode = parse_capcode(Convert.ToString(data["capcode"]));
            }

            t.File = ParseFile(data, board);

            if (t.File != null) { t.File.owner = t; }

            t.ID = Convert.ToInt32(data["no"]); ;

            t.Time = Common.ParseUTC_Stamp(Convert.ToInt32((data["time"])));

            return t;
        }
示例#5
0
        private string get_post_string(GenericPost gp)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();

            if (gp.GetType() == typeof(AniWrap.DataTypes.Thread))
            {
                AniWrap.DataTypes.Thread t = (AniWrap.DataTypes.Thread)gp;
                dic.Add("Closed", t.IsClosed);
                dic.Add("Sticky", t.IsSticky);
            }

            dic.Add("Board", gp.Board);

            dic.Add("ID", gp.ID);

            dic.Add("Name", gp.Name);

            if (gp.Capcode != GenericPost.CapcodeEnum.None)
            {
                dic.Add("Capcode", gp.Capcode);
            }

            if (!string.IsNullOrEmpty(gp.Comment))
            {

                dic.Add("RawComment", Wordfilter.Process(gp.Comment));
                // dic.Add("FormattedComment", gp.CommentText);
            }

            /*// Flag stuffs*/

            if (!string.IsNullOrEmpty(gp.country_flag))
            {
                dic.Add("CountryFlag", gp.country_flag);
            }

            if (!string.IsNullOrEmpty(gp.country_name))
            {
                dic.Add("CountryName", gp.country_name);
            }

            /* Flag stuffs //*/

            if (!string.IsNullOrEmpty(gp.Email))
            {
                dic.Add("Email", gp.Email);
            }

            if (!string.IsNullOrEmpty(gp.Trip))
            {
                dic.Add("Trip", gp.Trip);
            }

            if (!string.IsNullOrEmpty(gp.Subject))
            {
                dic.Add("Subject", gp.Subject);
            }

            if (!string.IsNullOrEmpty(gp.PosterID))
            {
                dic.Add("PosterID", gp.PosterID);
            }

            dic.Add("Time", gp.Time.ToString());

            if (gp.File != null)
            {
                dic.Add("FileHash", Program.base64tostring(gp.File.hash));
                dic.Add("FileName", Wordfilter.Process(gp.File.filename) + "." + gp.File.ext);
                dic.Add("ThumbTime", gp.File.thumbnail_tim);
                dic.Add("FileHeight", gp.File.height);
                dic.Add("FileWidth", gp.File.width);
                dic.Add("FileSize", gp.File.size);
            }

            return JsonConvert.ExportToString(dic);
        }
示例#6
0
        private static GenericPost parse_reply(JsonObject data, FoolFuukaParserData ffp_data)
        {
            GenericPost gp = new GenericPost();

            gp.Board = ffp_data.BOARD;

            gp.ID = Convert.ToInt32(data["num"]);

            if (data["comment_processed"] != null)
            {
                gp.Comment = data["comment_processed"].ToString();
            }

            if (data["email"] != null)
            {
                gp.Email = data["email"].ToString();
            }

            if (data["title"] != null)
            {
                gp.Subject = data["title"].ToString();
            }

            if (data["media"] != null)
            {
                gp.File = parse_file(data, ffp_data, gp);
            }

            if (data["capcode"] != null)
            {
                switch (data["capcode"].ToString())
                {
                    case "N":
                        gp.Capcode = GenericPost.CapcodeEnum.None;
                        break;
                    default:
                        gp.Capcode = GenericPost.CapcodeEnum.None;
                        break;
                }
            }

            if (data["name"] != null)
            {
                gp.Name = data["name"].ToString();
            }

            if (data["trip"] != null)
            {
                gp.Trip = data["trip"].ToString();
            }

            gp.Time = AniWrap.Common.ParseUTC_Stamp(Convert.ToInt32(data["timestamp"]));

            return gp;
        }
示例#7
0
        private static PostFile parse_file(JsonObject data, FoolFuukaParserData ffp_data, GenericPost owner)
        {
            if (data["media"] != null)
            {
                JsonObject media = (JsonObject)data["media"];
                if (media.Count == 0) { return null; }
                if (media["banned"].ToString() != "0") { return null; }
                if (media["media_status"].ToString() == "not-available") { return null; }

                PostFile pf = new PostFile();

                pf.board = ffp_data.BOARD;
                pf.filename = media["media_filename_processed"].ToString();

                pf.ext = pf.filename.Split('.').Last();
                pf.filename = pf.filename.Split('.').First();

                string thumb_link = media["thumb_link"].ToString();

                string media_link = media["media_link"].ToString();

                if (string.IsNullOrEmpty(media_link))
                {
                    return null;
                }

                pf.OverrideFileLinks(thumb_link, media_link);

                pf.hash = media["media_hash"].ToString();

                pf.height = Convert.ToInt32(media["media_h"]);
                pf.width = Convert.ToInt32(media["media_w"]);

                if (media["spoiler"] != null) { pf.IsSpoiler = (media["spoiler"].ToString() != "0"); }

                pf.thumbH = Convert.ToInt32(media["preview_h"]);
                pf.thumbW = Convert.ToInt32(media["preview_w"]);

                pf.size = Convert.ToInt32(media["media_size"]);

                pf.thumbnail_tim = media["media"].ToString().Split('.').First();
                pf.owner = owner;
                return pf;
            }
            else { return null; }
        }
示例#8
0
        /*public static CommentToken[] TokenizeComment(string comment)
        {
            List<CommentToken> tokens = new List<CommentToken>();

            HtmlDocument d = new HtmlDocument();

            d.LoadHtml(comment);

            foreach (HtmlNode node in d.DocumentNode.ChildNodes)
            {
                switch (node.Name)
                {
                    case "#text":
                        tokens.Add(new CommentToken(CommentToken.TokenType.Text, HttpUtility.HtmlDecode(node.InnerText)));
                        break;
                    case "a":
                        if (node.GetAttributeValue("class", "") == "quotelink")
                        {
                            string inner_text = HttpUtility.HtmlDecode(node.InnerText);
                            if (inner_text.StartsWith(">>>"))
                            {
                                //board redirect (sometimes with a post number)
                                int test_i = -1;
                                try
                                {
                                    test_i = Convert.ToInt32(inner_text.Split('/').Last()); // The last should be a number or an empty string. I guess

                                    //if success, it's a board_thread_redirect OR it's a cross-thread link ( I don't know if 4chan handle both the same way )

                                    string board_letter = inner_text.Replace(">", "").Replace("/", "").Replace(test_i.ToString(), "");

                                    tokens.Add(new CommentToken(CommentToken.TokenType.BoardThreadRedirect, board_letter + "-" + test_i.ToString()));

                                }
                                catch (Exception)
                                {
                                    // it is a plain board redirect such as >>>/g/
                                    tokens.Add(new CommentToken(CommentToken.TokenType.BoardRedirect, inner_text.Replace(">", "").Replace("/", ""))); // ex: >>>/g/ -> g
                                }
                            }
                            else if (inner_text.StartsWith(">>"))
                            {
                                int test_i = -1;
                                try
                                {
                                    test_i = Convert.ToInt32(inner_text.Remove(0, 2));
                                    //it's a post quote link
                                    tokens.Add(new CommentToken(CommentToken.TokenType.Quote, inner_text.Remove(0, 2)));
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            //throw new Exception("Unsupported data type");
                        }
                        break;
                    case "br":
                        tokens.Add(new CommentToken(CommentToken.TokenType.Newline, ""));
                        break;
                    case "wbr":
                        //no action
                        break;
                    case "span":
                        if (node.GetAttributeValue("class", "") == "quote")
                        {
                            tokens.Add(new CommentToken(CommentToken.TokenType.GreenText, HttpUtility.HtmlDecode(node.InnerText)));
                        }
                        else if (node.GetAttributeValue("class", "") == "deadlink")
                        {
                            //dead link
                            string inner_text = HttpUtility.HtmlDecode(node.InnerText);
                            int test_i = -1;
                            try
                            {
                                test_i = Convert.ToInt32(inner_text.Remove(0, 2));
                                //it's a post quote link
                                tokens.Add(new CommentToken(CommentToken.TokenType.DeadLink, inner_text.Remove(0, 2)));
                            }
                            catch (Exception)
                            {
                                throw;
                            }

                        }
                        else if (node.GetAttributeValue("class", "") == "fortune")
                        {
                            string data = HttpUtility.HtmlDecode(node.InnerText);
                            string color = node.GetAttributeValue("style", "");
                            tokens.Add(new CommentToken(CommentToken.TokenType.ColoredFText, "#" + color.Split('#')[1] + "$" + data));
                        }
                        else
                        {
                            //throw new Exception("Unsupported data type");
                        }
                        break;
                    case "pre":
                        if (node.GetAttributeValue("class", "") == "prettyprint")
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (HtmlNode prenode in node.ChildNodes)
                            {
                                if (prenode.Name == "br")
                                {
                                    sb.AppendLine();
                                }
                                else
                                {
                                    sb.Append(prenode.InnerText);
                                }
                            }
                            tokens.Add(new CommentToken(CommentToken.TokenType.CodeBlock, sb.ToString()));
                        }
                        break;
                    case "s":
                        tokens.Add(new CommentToken(CommentToken.TokenType.SpoilerText, HttpUtility.HtmlDecode(node.InnerText)));
                        break;
                    case "small":
                        //Oekaki Post
                        break;
                    default:
                        //throw new Exception("Unsupported data type");
                        break;
                }
            }
            return tokens.ToArray();
        }
        */
        public static string Guess_Post_Title(GenericPost t)
        {
            if (String.IsNullOrEmpty(t.Subject))
            {
                if (String.IsNullOrEmpty(t.Comment))
                {
                    return t.ID.ToString();
                }
                else
                {
                    string comment = "";

                    HtmlAgilityPack.HtmlDocument d = new HtmlAgilityPack.HtmlDocument();
                    d.LoadHtml(t.Comment);

                    comment = HttpUtility.HtmlDecode(d.DocumentNode.InnerText);
                    if (comment.Length > 25)
                    {
                        return comment.Remove(24) + "...";
                    }
                    else
                    {
                        return comment;
                    }
                }
            }
            else
            {
                return HttpUtility.HtmlDecode(t.Subject);
            }
        }