Beispiel #1
0
        public static string FormatPostFiles(WPost post)
        {
            if (post.FileCount > 0)
            {

                if (post.FileCount > 1)
                {
                    //Load rotator template, and process files

                    StringBuilder rotator = new StringBuilder(TemplateProvider.FilesRotator);

                    StringBuilder script_items = new StringBuilder();
                    StringBuilder no_script_items = new StringBuilder();

                    bool is_next = false;

                    foreach (WPostFile file in post.Files)
                    {
                        script_items.Append(get_file_html(file, true, is_next));

                        no_script_items.Append(get_file_html_noscript(file));

                        is_next = true;
                    }

                    rotator.Replace("{rotator:filecount}", post.FileCount.ToString());

                    rotator.Replace("{post:id}", post.PostID.ToString());

                    rotator.Replace("{lang:images}", Lang.images);

                    rotator.Replace("{lang:first}", Lang.first);
                    rotator.Replace("{lang:previous}", Lang.previous);
                    rotator.Replace("{lang:next}", Lang.next);
                    rotator.Replace("{lang:last}", Lang.last);
                    rotator.Replace("{WebRoot}", Paths.WebRoot);

                    rotator.Replace("{rotator:items}", script_items.ToString());

                    rotator.Replace("{rotator:noscriptitems}", no_script_items.ToString());

                    return rotator.ToString();
                }
                else
                {
                    return get_file_html(post.Files[0], false, false);
                }
            }
            else { return ""; }
        }
Beispiel #2
0
        public static string ProcessComment(WPost post)
        {
            if (string.IsNullOrEmpty(post.Comment))
            {
                return "";
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (string line in post.Comment.Split('\n'))
                {
                    if (line.StartsWith(">") & !line.StartsWith(">>"))
                    {
                        sb.AppendFormat("<span class=\"quote\">{0}</span>", line);
                    }
                    else
                    {
                        sb.Append(line);
                    }
                    sb.Append("<br/>");
                }

                foreach (Match m in quote_matcher.Matches(post.Comment))
                {
                    sb.Replace(m.Value,
                        string.Format("<a class='backlink' href='{0}{1}.aspx?id={2}#p{3}'>{4}</a>",
                        Settings.Paths.WebRoot,
                        post.IsArchived ? "archive" : "default",
                        post.Parent, m.Value.Replace("&gt;", ""),
                        m.Value));
                }

                for (int i = 0; i < bb_codes.Length; i++)
                {
                    SimpleBBCode bbcode = bb_codes[i];
                    if (post.Comment.Contains("[" + bbcode.TagName + "]"))
                    {
                        MatchCollection cl = bbcode.RegexPattren.Matches(post.Comment);
                        foreach (Match m in cl)
                        {
                            string sb_value = m.Value.Replace("\n", "<br/>");
                            sb.Replace(sb_value, bbcode.Format(m.Value.Replace("[" + bbcode.TagName + "]", "")
                                                            .Replace("[/" + bbcode.TagName + "]", "")));
                        }
                    }
                }

                return sb.ToString();
            }
        }
Beispiel #3
0
        public static ThreadReplies GetThreadReplies(WPost po, DbConnection con)
        {
            int text_replies = 0;
            int image_replies = 0;

            using (DbCommand dc = DatabaseEngine.GenerateDbCommand(con))
            {
                dc.CommandText = "SELECT Count(ID) As T FROM board WHERE (parentT = @id) AND (hasFile = @f) AND (mta = @mta)";

                dc.Parameters.Add(DatabaseEngine.MakeParameter("@mta", po.IsArchived ? 1 : 0, DbType.Int32));
                dc.Parameters.Add(DatabaseEngine.MakeParameter("@id", po.PostID, DbType.Int32));

                dc.Parameters.Add(DatabaseEngine.MakeParameter("@f", false, DbType.Boolean));

                using (DbDataReader reader = dc.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        text_replies = reader.GetInt32(0);
                    }
                }

                dc.Parameters["@f"].Value = true;

                using (DbDataReader reader = dc.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        image_replies = reader.GetInt32(0);
                    }
                }
            }

            return new ThreadReplies() { ImageReplies = image_replies, TextReplies = text_replies };
        }
Beispiel #4
0
        public static WPost GetPostData(int id, DbConnection connection)
        {
            string query = string.Format("SELECT type, time, comment, postername, trip, email, password, parentT, subject, IP, ua, posterID, sticky, locked, mta, hasFile FROM  board  WHERE (id = {0})", id);

            using (DbCommand dc = DatabaseEngine.GenerateDbCommand(query, connection))
            {
                WPost po = null;

                bool has_file = false;

                using (DbDataReader reader = dc.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (Convert.IsDBNull(reader[0]))
                        {
                            return null;
                        }
                        else
                        {
                            po = new WPost()
                            {
                                PostID = id,
                                Type = (PostType)reader.GetInt32(0),
                                Time = Convert.ToDateTime(ReadParam(reader[1])),
                                Comment = Convert.ToString(ReadParam(reader[2])),
                                Name = Convert.ToString(ReadParam(reader[3])),
                                Trip = Convert.ToString(ReadParam(reader[4])),
                                Email = Convert.ToString(ReadParam(reader[5])),
                                Password = Convert.ToString(ReadParam(reader[6])),
                                Parent = Convert.ToInt32(ReadParam(reader[7])),
                                Subject = Convert.ToString(ReadParam(reader[8])),
                                IP = Convert.ToString(ReadParam(reader[9])),
                                UserAgent = Convert.ToString(ReadParam(reader[10])),
                                PosterID = Convert.ToString(ReadParam(reader[11])),
                                IsSticky = Convert.ToBoolean(ReadParam(reader[12])),
                                IsLocked = Convert.ToBoolean(ReadParam(reader[13])),
                                IsArchived = Convert.ToBoolean(ReadParam(reader[14]))
                            };
                            has_file = Convert.ToBoolean(reader[15]);
                        }
                    }
                }

                if (has_file)
                {
                    po.Files = GetPostFiles(id, connection);
                }

                return po;
            }
        }
Beispiel #5
0
        public static WPost[] GetLastReplies(WPost thread, DbConnection con)
        {
            string queryText = "";

            switch (DatabaseSettings.DbType)
            {
                case DatabaseType.MsSQL:
                    queryText = string.Format("SELECT TOP {0} ID FROM board WHERE (parentT = @tid) AND (mta = @mta) ORDER BY ID DESC", ApplicationSettings.TrailPostsCount);
                    break;
                case DatabaseType.MySQL:
                    queryText = string.Format("SELECT ID FROM board WHERE (parentT = @tid) AND (mta = @mta) ORDER BY ID DESC LIMIT 0, {0}", ApplicationSettings.TrailPostsCount - 1);
                    break;
                default:
                    return new WPost[] { };
            }

            using (DbCommand dc = DatabaseEngine.GenerateDbCommand(queryText, con))
            {
                dc.Parameters.Add(DatabaseEngine.MakeParameter("@tid", thread.PostID, System.Data.DbType.Int32));
                dc.Parameters.Add(DatabaseEngine.MakeParameter("@mta", thread.IsArchived ? 1 : 0, System.Data.DbType.Int32));

                List<int> posts_ids = new List<int>();

                List<WPost> posts_list = new List<WPost>();

                using (DbDataReader reader = dc.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        posts_ids.Add(reader.GetInt32(0));
                    }
                }

                foreach (int i in posts_ids)
                {
                    posts_list.Add(GetPostData(i, con));
                }

                posts_list.Reverse();

                return posts_list.ToArray();
            }
        }
Beispiel #6
0
        private string generate_page(WPost post)
        {
            StringBuilder dialog_page = DialogCommon.GetDialogTemplate();

            dialog_page.Replace("{DialogTitle}", Language.Lang.deletefiles);

            StringBuilder deletefile_page = new StringBuilder(TemplateProvider.DeletePostFilePage);

            //Bad password notice
            deletefile_page.Replace("{notice:badpassword}", Request["bp"] == "1" ? string.Format("<span class=\"notice\">{0}</span>", Language.Lang.badpassword) : "");

            //No file selected notice
            deletefile_page.Replace("{notice:nofileselected}", Request["ns"] == "1" ? string.Format("<span class=\"notice\">{0}</span>", Language.Lang.nofileselected) : "");

            //Captcha HTML container and notice

            deletefile_page.Replace("{captcha}", DialogCommon.GetCaptcha_ForDialogs())
                           .Replace("{notice:wrongcaptcha}", Request["wc"] == "1" ? string.Format("<span class=\"notice\">{0}</span>", Language.Lang.wrongcaptcha) : "");

            deletefile_page.Replace("{ID}", post.PostID.ToString())
                .Replace("{lang:password}", Language.Lang.password)
                .Replace("{lang:deletefile}", Language.Lang.deletefiles);

            //Files elements

            StringBuilder files = new StringBuilder();
            foreach (WPostFile file in post.Files)
            {
                files.AppendFormat("<il><input id='{0}' type='checkbox' name='file{0}' value='file' /><label for='{0}'><img class='icon' src='{1}'/><span>{2}</span></label></il><br/>", file.Hash, file.ImageThumbnailWebPath, file.RealName);
            }

            deletefile_page.Replace("{Files}", files.ToString());

            dialog_page.Replace("{DialogBody}", deletefile_page.ToString());
            return dialog_page.ToString();
        }