private string ParseDataRow(IDataRecord row, string tmp) { try { tmp = tmp.Replace("[AVATAR]", "[AF:AVATAR]"); for (int i = 0; i < row.FieldCount; i++) { string name = row.GetName(i); string k = "[" + name.ToUpperInvariant() + "]"; string value = row[i].ToString(); switch (row[i].GetType().ToString()) { case "System.DateTime": value = Utilities.GetDate(Convert.ToDateTime(row[i].ToString()), ModuleId, TimeZoneOffset); break; } tmp = tmp.Replace(k, value); } ControlUtils cUtils = new ControlUtils(); Author auth = new Author(); string columnPrefix = "Topic"; if (Convert.ToInt32(row["ReplyId"].ToString()) > 0) { columnPrefix = "Reply"; auth.DisplayName = row[columnPrefix + "AuthorDisplayName"].ToString(); } else { auth.DisplayName = row["TopicAuthorName"].ToString(); } auth.AuthorId = int.Parse(row[columnPrefix + "AuthorId"].ToString()); auth.LastName = row[columnPrefix + "AuthorLastName"].ToString(); auth.FirstName = row[columnPrefix + "AuthorFirstName"].ToString(); auth.Username = row[columnPrefix + "AuthorUsername"].ToString(); tmp = tmp.Replace("[TOPICURL]", cUtils.TopicURL(row, TabId, ModuleId)); tmp = tmp.Replace("[FORUMURL]", cUtils.ForumURL(row, TabId, ModuleId)); if (int.Parse(row["LastAuthorId"].ToString()) == -1) { try { tmp = tmp.Replace("[LASTAUTHOR]", UserProfiles.GetDisplayName(ModuleId, true, ForumUser.Profile.IsMod, ForumUser.IsAdmin || ForumUser.IsSuperUser, -1, auth.Username, auth.FirstName, auth.LastName, auth.DisplayName)); } catch (Exception ex) { tmp = tmp.Replace("[LASTAUTHOR]", "anon"); } } else { tmp = tmp.Replace("[LASTAUTHOR]", UserProfiles.GetDisplayName(ModuleId, true, ForumUser.Profile.IsMod, ForumUser.IsAdmin || ForumUser.IsSuperUser, int.Parse(row["LastAuthorId"].ToString()), auth.Username, auth.FirstName, auth.LastName, auth.DisplayName)); } if (_canEdit) { tmp = tmp.Replace("[AF:QUICKEDITLINK]", "<span class=\"af-icon16 af-icon16-gear\" onclick=\"amaf_quickEdit(" + row["TopicId"].ToString() + ");\"></span>"); } else { tmp = tmp.Replace("[AF:QUICKEDITLINK]", string.Empty); } // tmp = tmp.Replace("[TOPICSTATE]", cUtils.TopicState(row)); var sAvatar = UserProfiles.GetAvatar(auth.AuthorId, _mainSettings.AvatarWidth, _mainSettings.AvatarHeight); tmp = tmp.Replace("[AF:AVATAR]", sAvatar); return(tmp); } catch (Exception ex) { return(ex.Message); } }
private string ParseTemplate() { SettingsInfo MainSettings = DataCache.MainSettings(ControlConfig.InstanceId); string sOut = DisplayTemplate; //sOut = ParseForumData(sOut) string sort = SortColumns.ReplyCreated; if (sOut.Contains("[AF:SORT:TOPICCREATED]")) { sort = SortColumns.TopicCreated; sOut = sOut.Replace("[AF:SORT:TOPICCREATED]", string.Empty); } int Replies = 0; int Views = 0; string Subject = string.Empty; string summary = string.Empty; string body = string.Empty; int replyCount = 0; int viewCount = 0; int topicid = 0; string topicIcon = string.Empty; int UserLastTopicRead = 0; int UserLastReplyRead = 0; int topicRating = 0; int LastReplyId = 0; bool isLocked = false; bool isPinned = false; int AuthorId = -1; string AuthorName = string.Empty; string AuthorFirstName = string.Empty; string AuthorLastName = string.Empty; string AuthorUserName = string.Empty; string AuthorDisplayName = string.Empty; string LastPostData = string.Empty; System.DateTime LastPostDate = default(System.DateTime); System.DateTime DateCreated = default(System.DateTime); string sTopicURL = string.Empty; string sBodyTitle = string.Empty; int statusId = -1; bool isAnnounce = false; System.DateTime AnnounceStart = default(System.DateTime); System.DateTime AnnounceEnd = default(System.DateTime); int topicType = 0; Author la = null; string ModApprove = string.Empty; string ModDelete = string.Empty; string ModEdit = string.Empty; string ModPin = string.Empty; string ModLock = string.Empty; string ModMove = string.Empty; string ModSplit = string.Empty; string Reply = string.Empty; string Lock = string.Empty; string Pin = string.Empty; string Delete = string.Empty; string Edit = string.Empty; string groupName = string.Empty; //Dim t As New Data.Topics string topics = TemplateUtils.GetTemplateSection(sOut, "[TOPICS]", "[/TOPICS]"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.Xml.XmlNodeList xTopics = null; xTopics = topicsData.SelectNodes("//topics/topic"); int rowCount = 0; foreach (System.Xml.XmlNode xNode in xTopics) { string ForumName = string.Empty; ForumId = int.Parse(xNode.Attributes["forumid"].Value.ToString()); ForumName = xNode["forumname"].InnerText; groupName = xNode["groupname"].InnerText; topicid = int.Parse(xNode.Attributes["topicid"].Value.ToString()); LastReplyId = int.Parse(xNode.Attributes["lastreplyid"].Value.ToString()); viewCount = int.Parse(xNode.Attributes["viewcount"].Value.ToString()); replyCount = int.Parse(xNode.Attributes["replycount"].Value.ToString()); isLocked = bool.Parse(xNode.Attributes["islocked"].Value.ToString()); isPinned = bool.Parse(xNode.Attributes["ispinned"].Value.ToString()); topicIcon = xNode.Attributes["topicicon"].Value.ToString(); statusId = int.Parse(xNode.Attributes["statusid"].Value.ToString()); isAnnounce = bool.Parse(xNode.Attributes["isannounce"].Value.ToString()); AnnounceStart = Convert.ToDateTime(xNode.Attributes["announcestart"].Value.ToString()); AnnounceEnd = Convert.ToDateTime(xNode.Attributes["announceend"].Value.ToString()); topicType = int.Parse(xNode.Attributes["topictype"].Value.ToString()); AuthorId = int.Parse(xNode.Attributes["authorid"].Value.ToString()); DateCreated = Convert.ToDateTime(xNode.Attributes["datecreated"].Value.ToString()); if (!string.IsNullOrEmpty(xNode.Attributes["lastpostdate"].Value.ToString())) { LastPostDate = Convert.ToDateTime(xNode.Attributes["lastpostdate"].Value.ToString()); } else { LastPostDate = DateCreated; } UserLastReplyRead = int.Parse(xNode.Attributes["userlastreplyread"].Value.ToString()); UserLastTopicRead = int.Parse(xNode.Attributes["userlasttopicread"].Value.ToString()); topicRating = int.Parse(xNode.Attributes["topicrating"].Value.ToString()); Subject = xNode["subject"].InnerText; Subject = Utilities.StripHTMLTag(Subject); Subject = Subject.Replace("[", "["); Subject = Subject.Replace("]", "]"); summary = xNode["summary"].InnerText; body = xNode["body"].InnerText; AuthorName = xNode["authorname"].InnerText; AuthorUserName = xNode["username"].InnerText; AuthorFirstName = xNode["firstname"].InnerText; AuthorLastName = xNode["lastname"].InnerText; AuthorDisplayName = xNode["displayname"].InnerText; XmlNode secNode = xNode["security"]; ModApprove = secNode["modapprove"].InnerText; ModDelete = secNode["moddelete"].InnerText; ModEdit = secNode["modedit"].InnerText; ModPin = secNode["modpin"].InnerText; ModLock = secNode["modlock"].InnerText; ModMove = secNode["modmove"].InnerText; Reply = secNode["reply"].InnerText; Lock = secNode["lock"].InnerText; Pin = secNode["pin"].InnerText; Delete = secNode["delete"].InnerText; Edit = secNode["edit"].InnerText; if ((xNode["lastpost"] != null)) { LastPostData = xNode["lastpost"].OuterXml; } else { LastPostData = string.Empty; } if (!string.IsNullOrEmpty(LastPostData)) { la = new Author(); System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument(); xDoc.LoadXml(LastPostData); System.Xml.XmlNode xLast = xDoc.SelectSingleNode("//lastpost"); if ((xLast != null)) { var _with1 = la; _with1.AuthorId = int.Parse(xLast["authorid"].InnerText.ToString()); _with1.DisplayName = xLast["displayname"].InnerText; _with1.FirstName = xLast["firstname"].InnerText; _with1.LastName = xLast["lastname"].InnerText; _with1.Username = xLast["username"].InnerText; } } int BodyLength = -1; string BodyTrim = ""; sTopicURL = URL.ForTopic(TabId, PortalId, ForumId, topicid, groupName, ForumName, Subject, 1); string tmp = topics; string sLastPost = TemplateUtils.GetTemplateSection(tmp, "[LASTPOST]", "[/LASTPOST]"); if ((la != null)) { sLastPost = sLastPost.Replace("[LASTPOSTDISPLAYNAME]", UserProfiles.GetDisplayName(ModuleId, ProfileVisibility, false, la.AuthorId, UserNameDisplay, DisableUserProfiles, la)); sLastPost = sLastPost.Replace("[AF:PROFILE:AVATAR]", UserProfiles.GetAvatar(la.AuthorId, PortalId, ThemePath, MainSettings.Theme, string.Empty, 0, MainSettings.AvatarWidth, MainSettings.ProfileType, MainSettings.AvatarDefault)); sLastPost = sLastPost.Replace("[LASTPOSTDATE]", Utilities.GetDate(LastPostDate, ModuleId)); if (bRead) { //TODO: Replace with link sLastPost = sLastPost.Replace("[AF:ICONLINK:LASTREPLY]", string.Empty); } else { sLastPost = sLastPost.Replace("[AF:ICONLINK:LASTREPLY]", string.Empty); } tmp = TemplateUtils.ReplaceSubSection(tmp, sLastPost, "[LASTPOST]", "[/LASTPOST]"); } else { tmp = TemplateUtils.ReplaceSubSection(tmp, string.Empty, "[LASTPOST]", "[/LASTPOST]"); } //Dim sLastReplyURL As String = NavigateUrl(TabId, "", New String() {ParamKeys.ForumId & "=" & ForumId, ParamKeys.TopicId & "=" & topicid, ParamKeys.ViewType & "=topic", ParamKeys.ContentJumpId & "=" & LastReplyId}) string sLastReadURL = string.Empty; string sUserJumpUrl = string.Empty; //If UserLastReplyRead > 0 Then //sLastReadURL = NavigateUrl(TabId, "", New String() {ParamKeys.ForumId & "=" & ForumId, ParamKeys.TopicId & "=" & topicid, ParamKeys.ViewType & "=topic", ParamKeys.FirstNewPost & "=" & UserLastReplyRead}) //End If //If UserPrefJumpLastPost And sLastReadURL <> String.Empty Then // ' sTopicURL = sLastReadURL // sUserJumpUrl = sLastReadURL //End If if (tmp.Contains("[BODY:")) { int inStart = Strings.InStr(tmp, "[BODY:") + 5; int inEnd = Strings.InStr(inStart, tmp, "]") - 1; string sLength = tmp.Substring(inStart, inEnd - inStart); BodyLength = Convert.ToInt32(sLength); BodyTrim = "[BODY:" + BodyLength.ToString() + "]"; } if (!(BodyTrim == string.Empty)) { string BodyPlain = body.Replace("<br>", Constants.vbCrLf); BodyPlain = BodyPlain.Replace("<br />", Constants.vbCrLf); BodyPlain = Utilities.StripHTMLTag(BodyPlain); if (BodyLength > 0 & BodyPlain.Length > BodyLength) { BodyPlain = BodyPlain.Substring(0, BodyLength); } BodyPlain = BodyPlain.Replace(Constants.vbCrLf, "<br />"); tmp = tmp.Replace(BodyTrim, BodyPlain); } if (isLocked) { tmp = tmp.Replace("[RESX:LockTopic]", "[RESX:UnLockTopic]"); tmp = tmp.Replace("[RESX:Confirm:Lock]", "[RESX:Confirm:UnLock]"); } if (isPinned) { tmp = tmp.Replace("[RESX:PinTopic]", "[RESX:UnPinTopic]"); tmp = tmp.Replace("[RESX:Confirm:Pin]", "[RESX:Confirm:UnPin]"); } tmp = tmp.Replace("[BODY]", GetBody(body, AuthorId)); tmp = tmp.Replace("[BODYTITLE]", GetTitle(body, AuthorId)); tmp = tmp.Replace("[AUTHORID]", AuthorId.ToString()); tmp = tmp.Replace("[USERID]", UserId.ToString); if (string.IsNullOrEmpty(Subject)) { Subject = "(no subject)"; } string LastSubject = Subject; if (LastReplyId > 0) { LastSubject = "[RESX:RE]" + LastSubject; } tmp = tmp.Replace("[SUBJECT]", Subject); string sSubjectLink = GetTopic(topicid, Subject, sBodyTitle, UserId, AuthorId, replyCount, -1, sUserJumpUrl, groupName, ForumName); string lastSubjectLink = GetTopic(topicid, Subject, string.Empty, UserId, AuthorId, replyCount, -1, sUserJumpUrl, groupName, ForumName); tmp = tmp.Replace("[SUBJECTLINK]", sSubjectLink); tmp = tmp.Replace("[THEMEPATH]", ThemePath); tmp = tmp.Replace("[TOPICID]", topicid.ToString()); tmp = tmp.Replace("[MODEDIT]", string.Empty); tmp = tmp.Replace("[MODDELETE]", string.Empty); tmp = tmp.Replace("[MODMOVE]", string.Empty); tmp = tmp.Replace("[MODLOCK]", string.Empty); tmp = tmp.Replace("[MODPIN]", string.Empty); tmp = tmp.Replace("[REPLIES]", replyCount.ToString()); tmp = tmp.Replace("[VIEWS]", viewCount.ToString()); tmp = tmp.Replace("[POSTICONIMAGE]", GetIcon(UserLastTopicRead, UserLastReplyRead, topicid, LastReplyId, topicIcon, isPinned, isLocked)); tmp = tmp.Replace("[POSTICONCSS]", GetIconCSS(UserLastTopicRead, UserLastReplyRead, topicid, LastReplyId, topicIcon, isPinned, isLocked)); if (tmp.Contains("[STATUSCSS]")) { string sImg = string.Empty; if (statusId == -1) { tmp = tmp.Replace("[STATUSCSS]", string.Empty); } else { sImg = "<span title=\"[RESX:PostStatus" + statusId.ToString() + "]\" class=\"afstatus afstatus" + statusId.ToString() + "\"></span>"; } tmp = tmp.Replace("[STATUSCSS]", sImg); } tmp = tmp.Replace("[STARTEDBY]", UserProfiles.GetDisplayName(ModuleId, ProfileVisibility, false, AuthorId, UserNameDisplay, DisableUserProfiles, AuthorUserName, AuthorFirstName, AuthorLastName, AuthorDisplayName)); tmp = tmp.Replace("[DATECREATED]", Utilities.GetDate(DateCreated, ModuleId)); tmp = tmp.Replace("[TOPICURL]", sTopicURL); //TODO: Still need to process tmp = tmp.Replace("[AF:ICONLINK:LASTREAD]", string.Empty); tmp = tmp.Replace("[AF:URL:LASTREAD]", string.Empty); if (tmp.Contains("[STATUS]")) { string sImg = string.Empty; if (statusId == -1) { tmp = tmp.Replace("[STATUS]", string.Empty); } else { sImg = "<img alt=\"[RESX:PostStatus" + statusId.ToString() + "]\" src=\"" + Utilities.AppPath + "themes/images/status" + statusId.ToString() + ".png\" />"; } tmp = tmp.Replace("[STATUS]", sImg); } //sTopicsTemplate = sTopicsTemplate.Replace("[AF:UI:MINIPAGER]", GetSubPages(TabId, ModuleId, ReplyCount, ForumId, TopicId)) tmp = tmp.Replace("[AF:UI:MINIPAGER]", string.Empty); tmp = tmp.Replace("[POSTRATINGDISPLAY]", string.Empty); tmp = tmp.Replace("[TOPICRATING]", topicRating.ToString()); tmp = tmp.Replace("[ROWCSS]", GetRowCSS(UserLastTopicRead, UserLastReplyRead, topicid, LastReplyId, rowCount)); tmp = tmp.Replace("[AF:TOPIC:FRIENDLYDATE]", Utilities.HumanFriendlyDate(DateCreated, ModuleId)); tmp = tmp.Replace("[AF:REPLY:FRIENDLYDATE]", Utilities.HumanFriendlyDate(LastPostDate, ModuleId)); tmp = tmp.Replace("[AF:TOPIC:FORUMNAME]", ForumName); tmp = tmp.Replace("[AF:TOPIC:LASTSUBJECT:LINK]", lastSubjectLink); tmp = tmp.Replace("[AF:TOPIC:LASTSUBJECT]", LastSubject); tmp = tmp.Replace("[AF:TOPIC:FORUMNAME:LINK]", "<a href=\"" + URL.ForForum(PageId, ForumId, groupName[ForumId], ForumName) + "\" title=\"" + ForumName + "\">" + ForumName + "</a>"); tmp = tmp.Replace("AF:SECURITY:MODROLES]", "AF:SECURITY:MODROLES:" + ModApprove + "]"); tmp = tmp.Replace("AF:SECURITY:MODAPPROVE]", "AF:SECURITY:MODAPPROVE:" + ModApprove + "]"); tmp = tmp.Replace("AF:SECURITY:DELETE]", "AF:SECURITY:DELETE:" + Delete + ModDelete + "]"); tmp = tmp.Replace("AF:SECURITY:EDIT]", "AF:SECURITY:EDIT:" + Edit + ModEdit + "]"); tmp = tmp.Replace("AF:SECURITY:LOCK]", "AF:SECURITY:LOCK:" + Lock + ModLock + "]"); tmp = tmp.Replace("AF:SECURITY:MOVE]", "AF:SECURITY:MOVE:" + ModMove + "]"); tmp = tmp.Replace("AF:SECURITY:PIN]", "AF:SECURITY:PIN:" + Pin + ModPin + "]"); tmp = tmp.Replace("AF:SECURITY:SPLIT]", "AF:SECURITY:SPLIT:" + ModSplit + "]"); tmp = tmp.Replace("AF:SECURITY:REPLY]", "AF:SECURITY:REPLY:" + Reply + "]"); sb.Append(tmp); rowCount += 1; } sOut = TemplateUtils.ReplaceSubSection(sOut, sb.ToString(), "[TOPICS]", "[/TOPICS]"); sOut = sOut.Replace("[TOPICS]", string.Empty); sOut = sOut.Replace("[/TOPICS]", string.Empty); DataCache.CacheStore(ModuleId + "topicsview", sOut); return(sOut); }