public ActionResult AddPost(int?id) //patametrenin null geldiğini gösterebilmek için ? koyuyoruz { if (id.HasValue) { ViewBag.Header = "Yazı Güncelle"; var post = PostRepo.Get((int)id); var cat = CatagoryRepo.Get(post.CategoryID); WPost vmpost = new WPost(); vmpost.Title = post.Title; vmpost.Content = post.Concent; vmpost.Category = cat.Name; vmpost.PostID = post.PostID; foreach (var item in post.Tags) { vmpost.Tags += item.Name + ","; } return(View(vmpost)); } else { ViewBag.Header = "Yazı Ekle"; return(View()); } }
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(""); } }
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); } }
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(">", ""), 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()); } }
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()); } }
public ActionResult AddPost(WPost model) { string[] etiketler = model.Tags.Split(',');//Her virgülden sonrasını Obje olarak alıyor. List <Tag> tags = new List <Tag>(); foreach (var item in etiketler) { tags.Add(new Tag { Name = item.Trim() }); //Trim baştaki ve sondaki boşlıkları siler. } int catID; if (CatagoryRepo.Get(model.Category) == null) { CatagoryRepo.Add(new Category { Name = model.Category }); catID = CatagoryRepo.Get(model.Category).CategoryID; } else { catID = CatagoryRepo.Get(model.Category).CategoryID; } Post pst = new Post(); pst.Title = model.Title; pst.PostDate = DateTime.Now; pst.Concent = model.Content; pst.Tags = tags; pst.CategoryID = catID; pst.AdminID = 1; if (model.PostID == 0) { PostRepo.Add(pst); } else { pst.PostID = model.PostID; PostRepo.Uptade(pst); } return(RedirectToAction("List", "Dashboard")); }
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 }); }
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()); }
protected void Page_Load(object sender, EventArgs e) { bool do_action = (!string.IsNullOrEmpty(Request["id"]) & Request["mode"] == "deletefile"); if (do_action) { int id = -1; Int32.TryParse(Request["id"], out id); if (id <= 0) { Response.Write("Invalid post id."); Response.End(); } using (DbConnection dc = Database.DatabaseEngine.GetDBConnection()) { dc.Open(); WPost post = Board.BoardCommon.GetPostData(id, dc); if (post == null) { Response.Write("Post does not exist"); Response.End(); } else { //first check captcha, then check password, and finally delete files if (CaptchaProvider.Verifiy(this.Context)) { if (Request["pwd"] == post.Password) //pwd is the user input password { //We should gather a list of files hashes, and delete them List <string> file_hashes = new List <string>(); foreach (string qs in this.Request.Form) { if (qs.StartsWith("file")) { file_hashes.Add(qs.Remove(0, 4)); } } if (file_hashes.Count > 0) { BoardCommon.DeleteFileFromDatabase(id, file_hashes.ToArray(), dc); if (Settings.ApplicationSettings.AutoDeleteFiles) { foreach (WPostFile file in post.Files) { if (file_hashes.Contains(file.Hash)) { //remove the files physically from the disk System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalFilesStorageFolder, file.ChanbName + "." + file.Extension)); //delete thumbs as well System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalThumbStorageFolder, file.ChanbName + ".jpg")); System.IO.File.Delete(System.IO.Path.Combine(Settings.Paths.PhysicalThumbStorageFolder, file.ChanbName + ".png")); } } } //update thread page and index. IndexView.UpdateThreadIndex(id, dc); ThreadView.UpdateThreadBody(id, dc); Response.Write(file_hashes.Count + " files deleted successfully"); } else { //No file was selected. Redirect to the delete file page, with 'no file selected' notice. Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?ns=1&id=" + id.ToString(), true); //ns == no file seleted } } else { //Bad password. Redirect to the delete file page, with 'bad password' notice. Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?bp=1&id=" + id.ToString(), true); //bp == bad password } } else { //invalid captcha. Redirect to the delete file page, with 'bad captcha' notice Response.Redirect(Settings.Paths.WebRoot + "deletefile.aspx?wc=1&id=" + id.ToString(), true); //wc == wrong captcha } } } } else { int id = -1; Int32.TryParse(Request["id"], out id); if (id <= 0) { Response.Write("Invalid post id."); Response.End(); } using (DbConnection dc = Database.DatabaseEngine.GetDBConnection()) { dc.Open(); WPost post = Board.BoardCommon.GetPostData(id, dc); if (post == null) { Response.Write("Post does not exist"); Response.End(); } else { if (post.FileCount == 0) { Response.Write("Post has no files"); Response.End(); } else if (post.FileCount == 1) { if (string.IsNullOrEmpty(post.Comment) & post.Type == Enums.PostType.Reply) { Response.Write("Cannot delete this post because it has no comment and only a single file. \n Delete the post instead."); Response.End(); } else { //show delete file page Response.Write(generate_page(post)); } } else { Response.Write(generate_page(post)); } } } } }
private static string generate_index_thread_html(int id, DbConnection con) { WPost OP = BoardCommon.GetPostData(id, con); if (OP == null) { return(""); } else { List <WPost> posts = new List <WPost>(); posts.Add(OP); ThreadReplies tr = BoardCommon.GetThreadReplies(OP, con); if (Settings.ApplicationSettings.TrailPostsCount > 0 && tr.TotalReplies > 0) { posts.AddRange(BoardCommon.GetLastReplies(OP, con)); } StringBuilder thread = new StringBuilder(TemplateProvider.Thread); thread.Replace("{id}", posts[0].PostID.ToString()); thread.Replace("{OP}", posts[0].ToString()); StringBuilder replies = new StringBuilder(); int with_image = 0; for (int i = 1; i < posts.Count; i++) { replies.Append(posts[i].ToString()); if (posts[i].FileCount > 0) { with_image++; } } if (tr.TotalReplies > 0) { thread.Replace("{op:replycount}", string.Format("(<b>{0} {1}</b>)", tr.TotalReplies, Lang.replies)); int omitted_text_post_count = tr.TextReplies - (posts.Count - 1 - with_image); int omitted_image_post_count = tr.ImageReplies - with_image; string summary = ""; if (omitted_image_post_count > 0 & omitted_text_post_count <= 0) { //image only. summary = Lang.summaryIonly; } else if (omitted_text_post_count > 0 & omitted_image_post_count <= 0) { //text only summary = Lang.summaryPonly; } else if (omitted_image_post_count > 0 & omitted_text_post_count > 0) { //image and text summary = Lang.summaryPandI; } summary = summary.Replace("{i}", omitted_image_post_count.ToString()).Replace("{p}", omitted_text_post_count.ToString()); thread.Replace("{desktop:summary}", string.Format("<span class=\"summary desktop\">{0}</span>", summary)); thread.Replace("{mobile:summary}", string.Format("<span class=\"info\">{0}</span><br />", summary)); } else { thread.Replace("{op:replycount}", ""); thread.Replace("{desktop:summary}", ""); thread.Replace("{mobile:summary}", ""); } thread.Replace("{postlink}", string.Format("{0}{1}.aspx?id={2}", Settings.Paths.WebRoot, posts[0].IsArchived ? "archive" : "default", posts[0].PostID)); thread.Replace("{Replies}", replies.ToString()); return(thread.ToString()); } }