using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; /// /// Summary description for DisplayPost. /// public class DisplayPost : BaseUserControl { protected HyperLink Attach, Edit, Quote; protected LinkButton Delete; protected HyperLink Pm, Home, Yim, Aim, Icq, Email, Msn, Blog; protected HtmlTableCell NameCell, AdminInfo; protected controls.PopMenu PopMenu1; protected HyperLink UserName; private void Page_Load(object sender, System.EventArgs e) { PopMenu1.Visible = ForumPage.IsAdmin; if(PopMenu1.Visible) { PopMenu1.ItemClick += new PopEventHandler(PopMenu1_ItemClick); PopMenu1.AddItem("userprofile","User Profile"); PopMenu1.AddItem("edituser","Edit User (Admin)"); PopMenu1.Attach(UserName); } Page.RegisterClientScriptBlock("yafjs",string.Format("",ResolveUrl("../yaf.js"))); NameCell.ColSpan = int.Parse(GetIndentSpan()); } private void DisplayPost_PreRender(object sender,EventArgs e) { Attach.Visible = CanAttach; Attach.Text = ForumPage.GetThemeContents("BUTTONS","ATTACHMENTS"); Attach.ToolTip = "Attachments"; Attach.NavigateUrl = Forum.GetLink(Pages.attachments,"m={0}",DataRow["MessageID"]); Edit.Visible = CanEditPost; Edit.Text = ForumPage.GetThemeContents("BUTTONS","EDITPOST"); Edit.ToolTip = "Edit this post"; Edit.NavigateUrl = Forum.GetLink(Pages.postmessage,"m={0}",DataRow["MessageID"]); Delete.Visible = CanDeletePost; Delete.Text = ForumPage.GetThemeContents("BUTTONS","DELETEPOST"); Delete.ToolTip = "Delete this post"; Delete.Attributes["onclick"] = string.Format("return confirm('{0}')",ForumPage.GetText("confirm_deletemessage")); Quote.Visible = CanReply; Quote.Text = ForumPage.GetThemeContents("BUTTONS","QUOTEPOST"); Quote.ToolTip = "Reply with quote"; Quote.NavigateUrl = Forum.GetLink(Pages.postmessage,"t={0}&f={1}&q={2}",ForumPage.PageTopicID,ForumPage.PageForumID,DataRow["MessageID"]); // private messages Pm.Visible = ForumPage.User.IsAuthenticated && ForumPage.BoardSettings.AllowPrivateMessages; Pm.Text = ForumPage.GetThemeContents("BUTTONS","PM"); Pm.NavigateUrl = Forum.GetLink(Pages.pmessage,"u={0}",DataRow["UserID"]); // emailing Email.Visible = ForumPage.User.IsAuthenticated && ForumPage.BoardSettings.AllowEmailSending; Email.NavigateUrl = Forum.GetLink(Pages.im_email,"u={0}",DataRow["UserID"]); Email.Text = ForumPage.GetThemeContents("BUTTONS","EMAIL"); Home.Visible = DataRow["HomePage"]!=DBNull.Value; Home.NavigateUrl = DataRow["HomePage"].ToString(); Home.Text = ForumPage.GetThemeContents("BUTTONS","WWW"); Blog.Visible = DataRow["Weblog"]!=DBNull.Value; Blog.NavigateUrl = DataRow["Weblog"].ToString(); Blog.Text = ForumPage.GetThemeContents("BUTTONS","WEBLOG"); Msn.Visible = ForumPage.User.IsAuthenticated && DataRow["MSN"]!=DBNull.Value; Msn.Text = ForumPage.GetThemeContents("BUTTONS","MSN"); Msn.NavigateUrl = Forum.GetLink(Pages.im_email,"u={0}",DataRow["UserID"]); Yim.Visible = ForumPage.User.IsAuthenticated && DataRow["YIM"]!=DBNull.Value; Yim.NavigateUrl = Forum.GetLink(Pages.im_yim,"u={0}",DataRow["UserID"]); Yim.Text = ForumPage.GetThemeContents("BUTTONS","YAHOO"); Aim.Visible = ForumPage.User.IsAuthenticated && DataRow["AIM"]!=DBNull.Value; Aim.Text = ForumPage.GetThemeContents("BUTTONS","AIM"); Aim.NavigateUrl = Forum.GetLink(Pages.im_aim,"u={0}",DataRow["UserID"]); Icq.Visible = ForumPage.User.IsAuthenticated && DataRow["ICQ"]!=DBNull.Value; Icq.Text = ForumPage.GetThemeContents("BUTTONS","ICQ"); Icq.NavigateUrl = Forum.GetLink(Pages.im_icq,"u={0}",DataRow["UserID"]); // display admin only info if (ForumPage.IsAdmin) { AdminInfo.InnerHtml = ""; if (Convert.ToDateTime(DataRow["Edited"]) != Convert.ToDateTime(DataRow["Posted"])) { // message has been edited AdminInfo.InnerHtml += String.Format("Edited: {0}",ForumPage.FormatDateTimeShort(Convert.ToDateTime(DataRow["Edited"]))); } AdminInfo.InnerHtml += String.Format(" IP: {0}",DataRow["IP"].ToString()); AdminInfo.InnerHtml += ""; } } override protected void OnInit(EventArgs e) { this.Load += new System.EventHandler(this.Page_Load); this.PreRender += new EventHandler(DisplayPost_PreRender); Delete.Click += new EventHandler(Delete_Click); base.OnInit(e); } private DataRowView m_row = null; public DataRowView DataRow { get { return m_row; } set { m_row = value; } } protected bool CanEditPost { get { return !PostLocked && ((int)DataRow["ForumFlags"] & (int)ForumFlags.Locked)!=(int)ForumFlags.Locked && ((int)DataRow["TopicFlags"] & (int)TopicFlags.Locked)!=(int)TopicFlags.Locked && ((int)DataRow["UserID"]==ForumPage.PageUserID || ForumPage.ForumModeratorAccess) && ForumPage.ForumEditAccess; } } private bool PostLocked { get { if(!ForumPage.IsAdmin && ForumPage.BoardSettings.LockPosts>0) { DateTime edited = (DateTime)DataRow["Edited"]; if(edited.AddDays(ForumPage.BoardSettings.LockPosts)0) return string.Format("",iIndent*32,Data.ForumRoot); else return ""; } protected string GetIndentSpan() { if(!IsThreaded || (int)DataRow["Indent"]==0) return "2"; else return "1"; } protected string GetPostClass() { if(this.IsAlt) return "post_alt"; else return "post"; } protected string FormatUserBox() { System.Data.DataRowView row = DataRow; string html = ""; // Avatar if(ForumPage.BoardSettings.AvatarUpload && row["HasAvatarImage"]!=null && long.Parse(row["HasAvatarImage"].ToString())>0) { html += String.Format("
",row["UserID"],Data.ForumRoot); } else if(row["Avatar"].ToString().Length>0) // Took out ForumPage.BoardSettings.AvatarRemote { //html += String.Format("
",row["Avatar"]); html += String.Format("
", Server.UrlEncode(row["Avatar"].ToString()), ForumPage.BoardSettings.AvatarWidth, ForumPage.BoardSettings.AvatarHeight, Data.ForumRoot ); } // Rank Image if(row["RankImage"].ToString().Length>0) html += String.Format("
",Data.ForumRoot,row["RankImage"]); // Rank html += String.Format("{0}: {1}
",ForumPage.GetText("rank"),row["RankName"]); // Groups if(ForumPage.BoardSettings.ShowGroups) { using(DataTable dt = DB.usergroup_list(row["UserID"])) { html += String.Format("{0}: ",ForumPage.GetText("groups")); bool bFirst = true; foreach(DataRow grp in dt.Rows) { if(bFirst) { html += grp["Name"].ToString(); bFirst = false; } else { html += String.Format(", {0}",grp["Name"]); } } html += "
"; } } // Extra row html += "
"; // Joined html += String.Format("{0}: {1}
",ForumPage.GetText("joined"),ForumPage.FormatDateShort((DateTime)row["Joined"])); // Posts html += String.Format("{0}: {1:N0}
",ForumPage.GetText("posts"),row["Posts"]); // Location if(row["Location"].ToString().Length>0) html += String.Format("{0}: {1}
",ForumPage.GetText("location"),FormatMsg.RepairHtml(ForumPage,row["Location"].ToString(),false)); return html; } protected string FormatBody() { DataRowView row = DataRow; string html2 = FormatMsg.FormatMessage(ForumPage,row["Message"].ToString(),new MessageFlags(Convert.ToInt32(row["Flags"]))); // define valid image extensions string[] aImageExtensions = {"jpg","gif","png"}; if (long.Parse(row["HasAttachments"].ToString()) > 0) { string stats = ForumPage.GetText("ATTACHMENTINFO"); string strFileIcon = ForumPage.GetThemeContents("ICONS","ATTACHED_FILE"); html2 += "

"; using(DataTable dt = DB.attachment_list(row["MessageID"],null,null)) { // show file then image attachments... int tmpDisplaySort = 0; while (tmpDisplaySort <= 1) { bool bFirstItem = true; foreach(DataRow dr in dt.Rows) { string strFilename = Convert.ToString(dr["FileName"]).ToLower(); bool bShowImage = false; // verify it's not too large to display (might want to make this a board setting) if (Convert.ToInt32(dr["Bytes"]) <= 262144) { // is it an image file? for (int i=0;i"; html2 += String.Format(ForumPage.GetText("IMAGE_ATTACHMENT_TEXT"),Convert.ToString(row["UserName"])); html2 += "
"; bFirstItem = false; } html2 += String.Format("\"{2}\"
",Data.ForumRoot,dr["AttachmentID"],Server.HtmlEncode(Convert.ToString(dr["FileName"]))); } else if (!bShowImage && tmpDisplaySort == 0) { if (bFirstItem) { html2 += String.Format("{0}
",ForumPage.GetText("ATTACHMENTS")); bFirstItem = false; } // regular file attachment int kb = (1023 + (int)dr["Bytes"]) / 1024; html2 += String.Format(" {3} {4}
",strFileIcon,Data.ForumRoot,dr["AttachmentID"],dr["FileName"],String.Format(stats,kb,dr["Downloads"])); } } // now show images tmpDisplaySort++; html2 += "
"; } } } if(row["Signature"] != DBNull.Value && row["Signature"].ToString().ToLower() != "

 

" && ForumPage.BoardSettings.AllowSignatures) { // don't allow any HTML on signatures MessageFlags tFlags = new MessageFlags(); tFlags.IsHTML = false; html2 += "

" + FormatMsg.FormatMessage(ForumPage,row["Signature"].ToString(),tFlags); } return html2; } private void Delete_Click(object sender,EventArgs e) { if(!CanDeletePost) return; // CHANGED BAI 30.01.2004 //Create objects for easy access object tmpMessageID = DataRow["MessageID"]; object tmpForumID = DataRow["ForumID"]; object tmpTopicID = DataRow["TopicID"]; // Delete message. If it is the last message of the topic, the topic is also deleted DB.message_delete(tmpMessageID); // retrieve topic information. DataRow topic = DB.topic_info(tmpTopicID); //If topic has been deleted, redirect to topic list for active forum, else show remaining posts for topic if (topic == null) Forum.Redirect(Pages.topics,"f={0}",tmpForumID); else Forum.Redirect(Pages.posts,"t={0}",tmpTopicID); // END CHANGED BAI 30.01.2004 } private void PopMenu1_ItemClick(object sender, PopEventArgs e) { switch(e.Item) { case "userprofile": Forum.Redirect(Pages.profile,"u={0}",DataRow["UserID"]); break; case "edituser": Forum.Redirect(Pages.admin_edituser,"u={0}",DataRow["UserID"]); break; } } } } <%@ Control Language="c#" AutoEventWireup="false" Codebehind="DisplayPost.ascx.cs" Inherits="yaf.controls.DisplayPost" EnableViewState="false" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> <%@ Register TagPrefix="yaf" Namespace="yaf.controls" Assembly="yaf" %> <%#GetIndentCell()%> "/> <%# Server.HtmlEncode(DataRow["UserName"].ToString()) %>
<%# ForumPage.GetText("POSTED") %>: <%# ForumPage.FormatDateTime((System.DateTime)DataRow["Posted"]) %>
> <%# FormatUserBox() %> <%# FormatBody() %>
<%# ForumPage.GetText("TOP") %>