private void BindTopics(string TopicsTemplate) { string sOutput = TopicsTemplate; string subTemplate = string.Empty; //Subforum Template if (sOutput.Contains("[SUBFORUMS]")) { if (dtSubForums.Rows.Count > 0) { subTemplate = TemplateUtils.GetTemplateSection(sOutput, "[SUBFORUMS]", "[/SUBFORUMS]"); } sOutput = TemplateUtils.ReplaceSubSection(sOutput, "<asp:placeholder id=\"plhSubForums\" runat=\"server\" />", "[SUBFORUMS]", "[/SUBFORUMS]"); } //Parse Common Controls sOutput = ParseControls(sOutput); //Parse Topics sOutput = ParseTopics(sOutput, dtTopics, "TOPICS"); //Parse Announce string sAnnounce = TemplateUtils.GetTemplateSection(sOutput, "[ANNOUNCEMENTS]", "[/ANNOUNCEMENTS]"); if (dtAnnounce != null) { if (dtAnnounce.Rows.Count > 0) { sAnnounce = ParseTopics(sAnnounce, dtAnnounce, "ANNOUNCEMENT"); } else { sAnnounce = string.Empty; } } else { sAnnounce = string.Empty; } sOutput = TemplateUtils.ReplaceSubSection(sOutput, sAnnounce, "[ANNOUNCEMENTS]", "[/ANNOUNCEMENTS]"); sOutput = Utilities.LocalizeControl(sOutput); this.Controls.Add(this.ParseControl(sOutput)); BuildPager(); PlaceHolder plh = (PlaceHolder)(this.FindControl("plhQuickJump")); if (plh != null) { ctlForumJump = new af_quickjump(); ctlForumJump.MOID = ModuleId; ctlForumJump.dtForums = null; ctlForumJump.ModuleConfiguration = this.ModuleConfiguration; ctlForumJump.ForumId = ForumId; ctlForumJump.ModuleId = ModuleId; if (ForumId > 0) { ctlForumJump.ForumInfo = ForumInfo; } plh.Controls.Add(ctlForumJump); } plh = (PlaceHolder)(this.FindControl("plhSubForums")); if (plh != null) { ctlForumSubs = (ForumView)(LoadControl(typeof(ForumView), null)); ctlForumSubs.ModuleConfiguration = this.ModuleConfiguration; ctlForumSubs.ForumId = ForumId; ctlForumSubs.ForumTable = dtSubForums; ctlForumSubs.ForumTabId = ForumTabId; ctlForumSubs.ForumModuleId = ForumModuleId; ctlForumSubs.SubsOnly = true; ctlForumSubs.DisplayTemplate = subTemplate; if (ForumId > 0) { ctlForumSubs.ForumInfo = ForumInfo; } plh.Controls.Add(ctlForumSubs); } //Me.Controls.Add(cbActions) //this.Controls.Add(ctlModal); // LoadCallBackScripts() }
protected override void OnInit(EventArgs e) { base.OnInit(e); AppRelativeVirtualPath = "~/"; try { if (CurrentUserId == -1) { CurrentUserId = UserId; } string sOutput = string.Empty; try { int defaultTemplateId = MainSettings.ForumTemplateID; if (DefaultForumViewTemplateId >= 0) { defaultTemplateId = DefaultForumViewTemplateId; } sOutput = BuildForumView(defaultTemplateId, CurrentUserId, Page.ResolveUrl("~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme + "/")); } catch (Exception ex) { //sOutput = ex.Message //DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(Me, ex) } if (sOutput != string.Empty) { try { if (sOutput.Contains("[TOOLBAR")) { var lit = new LiteralControl(); object sToolbar = null; //DataCache.CacheRetrieve("aftb" & ModuleId) sToolbar = Utilities.GetFileContent(SettingKeys.TemplatePath + "ToolBar.txt"); DataCache.CacheStore("aftb" + ModuleId, sToolbar); sToolbar = Utilities.ParseToolBar(sToolbar.ToString(), TabId, ModuleId, UserId, CurrentUserType); lit.Text = sToolbar.ToString(); sOutput = sOutput.Replace("[TOOLBAR]", sToolbar.ToString()); } Control tmpCtl = null; try { tmpCtl = ParseControl(sOutput); } catch (Exception ex) { } if (tmpCtl != null) { try { Controls.Add(tmpCtl); LinkControls(Controls); if (!SubsOnly) { var plh = (PlaceHolder)(tmpCtl.FindControl("plhQuickJump")); if (plh != null) { ctlForumJump = new af_quickjump { MOID = ModuleId, dtForums = ForumTable, ModuleId = ModuleId }; plh.Controls.Add(ctlForumJump); } plh = (PlaceHolder)(tmpCtl.FindControl("plhUsersOnline")); if (plh != null) { ForumBase ctlWhosOnline; ctlWhosOnline = (ForumBase)(LoadControl("~/Desktopmodules/ActiveForums/controls/af_usersonline.ascx")); ctlWhosOnline.ModuleConfiguration = ModuleConfiguration; plh.Controls.Add(ctlWhosOnline); } } } catch (Exception ex) { } } } catch (Exception ex) { Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } } } catch (Exception ex) { Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex); } }
private void BindTopic() { string sOutput; var bFullTopic = true; // Load the proper template into out output variable if (!string.IsNullOrWhiteSpace(TopicTemplate)) { // Note: The template may be set in the topic review section of the Post form. bFullTopic = false; sOutput = TopicTemplate; sOutput = Utilities.ParseSpacer(sOutput); } else if (UseTemplatePath && TemplatePath != string.Empty) { sOutput = Utilities.GetFileContent(TemplatePath + "TopicView.htm"); sOutput = Utilities.ParseSpacer(sOutput); } else { sOutput = DataCache.GetCachedTemplate(MainSettings.TemplateCache, ModuleId, "TopicView", _topicTemplateId); } // Handle the postinfo token if present if (sOutput.Contains("[POSTINFO]") && ForumInfo.ProfileTemplateId > 0) sOutput = sOutput.Replace("[POSTINFO]", DataCache.GetCachedTemplate(MainSettings.TemplateCache, ModuleId, "ProfileInfo", ForumInfo.ProfileTemplateId)); // Run some basic rpleacements sOutput = sOutput.Replace("[PORTALID]", PortalId.ToString()); sOutput = sOutput.Replace("[MODULEID]", ForumModuleId.ToString()); sOutput = sOutput.Replace("[TABID]", ForumTabId.ToString()); sOutput = sOutput.Replace("[TOPICID]", TopicId.ToString()); sOutput = sOutput.Replace("[AF:CONTROL:FORUMID]", ForumId.ToString()); sOutput = sOutput.Replace("[AF:CONTROL:FORUMGROUPID]", ForumGroupId.ToString()); sOutput = sOutput.Replace("[AF:CONTROL:PARENTFORUMID]", ParentForumId.ToString()); // Add Topic Scripts var ctlTopicScripts = (af_topicscripts)(LoadControl("~/DesktopModules/ActiveForums/controls/af_topicscripts.ascx")); ctlTopicScripts.ModuleConfiguration = ModuleConfiguration; Controls.Add(ctlTopicScripts); // Pretty sure this is no longer used /* if (sOutput.Contains("<am:TopicsNavigator")) { var ctl = ParseControl(sOutput); if(ctl != null) Controls.Add(ctl); LinkControls(Controls); return; } */ #region Build Topic Properties if (sOutput.Contains("[AF:PROPERTIES")) { var sProps = string.Empty; if(!string.IsNullOrWhiteSpace(_topicData)) { var sPropTemplate = TemplateUtils.GetTemplateSection(sOutput, "[AF:PROPERTIES]", "[/AF:PROPERTIES]"); try { var xDoc = new XmlDocument(); xDoc.LoadXml(_topicData); var xRoot = xDoc.DocumentElement; var xNodeList = (xRoot != null) ? xRoot.SelectNodes("//properties/property") : null; if (xNodeList != null && xNodeList.Count > 0) { for (var i = 0; i < xNodeList.Count; i++) { var pName = Utilities.HTMLDecode(xNodeList[i].ChildNodes[0].InnerText); var pValue = Utilities.HTMLDecode(xNodeList[i].ChildNodes[1].InnerText); // This builds the replacement text for the properties template var tmp = sPropTemplate.Replace("[AF:PROPERTY:LABEL]", "[RESX:" + pName + "]"); tmp = tmp.Replace("[AF:PROPERTY:VALUE]", pValue); sProps += tmp; // This deals with any specific property tokens that may be present outside of the normal properties template sOutput = sOutput.Replace("[AF:PROPERTY:" + pName + ":LABEL]", Utilities.GetSharedResource("[RESX:" + pName + "]")); sOutput = sOutput.Replace("[AF:PROPERTY:" + pName + ":VALUE]", pValue); var pValueKey = string.IsNullOrWhiteSpace(pValue) ? string.Empty : Utilities.CleanName(pValue).ToLowerInvariant(); sOutput = sOutput.Replace("[AF:PROPERTY:" + pName + ":VALUEKEY]", pValueKey); } } } catch (XmlException) { // Property XML is invalid // Nothing to do in this case but ignore the issue. } } sOutput = TemplateUtils.ReplaceSubSection(sOutput, sProps, "[AF:PROPERTIES]", "[/AF:PROPERTIES]"); } #endregion #region Populate Metadata // If the template contains a meta template, grab it then remove the token if (sOutput.Contains("[META]")) { MetaTemplate = TemplateUtils.GetTemplateSection(sOutput, "[META]", "[/META]"); sOutput = TemplateUtils.ReplaceSubSection(sOutput, string.Empty, "[META]", "[/META]"); } //Parse Meta Template if (!string.IsNullOrEmpty(MetaTemplate)) { MetaTemplate = MetaTemplate.Replace("[FORUMNAME]", _forumName); MetaTemplate = MetaTemplate.Replace("[GROUPNAME]", _groupName); var settings = Entities.Portals.PortalController.GetCurrentPortalSettings(); var pageName = (settings.ActiveTab.Title.Length == 0) ? Server.HtmlEncode(settings.ActiveTab.TabName) : Server.HtmlEncode(settings.ActiveTab.Title); MetaTemplate = MetaTemplate.Replace("[PAGENAME]", pageName); MetaTemplate = MetaTemplate.Replace("[PORTALNAME]", settings.PortalName); MetaTemplate = MetaTemplate.Replace("[TAGS]", _tags); // Subject if (MetaTemplate.Contains("[TOPICSUBJECT:")) { const string pattern = "(\\[TOPICSUBJECT:(.+?)\\])"; foreach (Match m in Regex.Matches(MetaTemplate, pattern)) { var maxLength = Utilities.SafeConvertInt(m.Groups[2].Value, 255); if (_topicSubject.Length > maxLength) MetaTemplate = MetaTemplate.Replace(m.Value, _topicSubject.Substring(0, maxLength) + "..."); else MetaTemplate = MetaTemplate.Replace(m.Value, Utilities.StripHTMLTag(_topicSubject)); } } MetaTemplate = MetaTemplate.Replace("[TOPICSUBJECT]", Utilities.StripHTMLTag(_topicSubject)); // Body if (MetaTemplate.Contains("[BODY:")) { const string pattern = "(\\[BODY:(.+?)\\])"; foreach (Match m in Regex.Matches(MetaTemplate, pattern)) { var maxLength = Utilities.SafeConvertInt(m.Groups[2].Value, 512); if (_topicDescription.Length > maxLength) MetaTemplate = MetaTemplate.Replace(m.Value, _topicDescription.Substring(0, maxLength) + "..."); else MetaTemplate = MetaTemplate.Replace(m.Value, _topicDescription); } } MetaTemplate = MetaTemplate.Replace("[BODY]", _topicDescription); MetaTitle = TemplateUtils.GetTemplateSection(MetaTemplate, "[TITLE]", "[/TITLE]").Replace("[TITLE]", string.Empty).Replace("[/TITLE]", string.Empty); MetaTitle = MetaTitle.TruncateAtWord(SEOConstants.MaxMetaTitleLength); MetaDescription = TemplateUtils.GetTemplateSection(MetaTemplate, "[DESCRIPTION]", "[/DESCRIPTION]").Replace("[DESCRIPTION]", string.Empty).Replace("[/DESCRIPTION]", string.Empty); MetaDescription = MetaDescription.TruncateAtWord(SEOConstants.MaxMetaDescriptionLength); MetaKeywords = TemplateUtils.GetTemplateSection(MetaTemplate, "[KEYWORDS]", "[/KEYWORDS]").Replace("[KEYWORDS]", string.Empty).Replace("[/KEYWORDS]", string.Empty); } #endregion #region Setup Breadcrumbs var breadCrumb = TemplateUtils.GetTemplateSection(sOutput, "[BREADCRUMB]", "[/BREADCRUMB]").Replace("[BREADCRUMB]", string.Empty).Replace("[/BREADCRUMB]", string.Empty); if (MainSettings.UseSkinBreadCrumb) { var ctlUtils = new ControlUtils(); var groupUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, ForumInfo.ForumGroup.PrefixURL, string.Empty, ForumInfo.ForumGroupId, -1, -1, -1, string.Empty, 1, SocialGroupId); var forumUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, ForumInfo.ForumGroup.PrefixURL, ForumInfo.PrefixURL, ForumInfo.ForumGroupId, ForumInfo.ForumID, -1, -1, string.Empty, 1, SocialGroupId); var topicUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, ForumInfo.ForumGroup.PrefixURL, ForumInfo.PrefixURL, ForumInfo.ForumGroupId, ForumInfo.ForumID, TopicId, _topicURL, -1, -1, string.Empty, 1, SocialGroupId); var sCrumb = "<a href=\"" + groupUrl + "\">" + _groupName + "</a>|"; sCrumb += "<a href=\"" + forumUrl + "\">" + _forumName + "</a>"; sCrumb += "|<a href=\"" + topicUrl + "\">" + _topicSubject + "</a>"; if (Environment.UpdateBreadCrumb(Page.Controls, sCrumb)) breadCrumb = string.Empty; } sOutput = TemplateUtils.ReplaceSubSection(sOutput, breadCrumb, "[BREADCRUMB]", "[/BREADCRUMB]"); #endregion // Parse Common Controls First sOutput = ParseControls(sOutput); // Note: If the containing element is not found, GetTemplateSection returns the entire template // This is desired behavior in this case as it's possible that the entire template is our topics container. var topic = TemplateUtils.GetTemplateSection(sOutput, "[AF:CONTROL:CALLBACK]", "[/AF:CONTROL:CALLBACK]"); topic = ParseTopic(topic); if (!topic.Contains(Globals.ControlRegisterTag)) topic = Globals.ControlRegisterTag + topic; topic = Utilities.LocalizeControl(topic); // If a template was passed in, we don't need to do this. if (bFullTopic) { sOutput = TemplateUtils.ReplaceSubSection(sOutput, "<asp:placeholder id=\"plhTopic\" runat=\"server\" />", "[AF:CONTROL:CALLBACK]", "[/AF:CONTROL:CALLBACK]"); sOutput = Utilities.LocalizeControl(sOutput); sOutput = Utilities.StripTokens(sOutput); // If we added a banner, make sure we register than banner tag if (sOutput.Contains("<dnn:BANNER") && !sOutput.Contains(Globals.BannerRegisterTag)) sOutput = Globals.BannerRegisterTag + sOutput; var ctl = ParseControl(sOutput); if(ctl != null) Controls.Add(ctl); } // Create a topic placeholder if we don't have one. var plhTopic = FindControl("plhTopic") as PlaceHolder; if (plhTopic == null) { plhTopic = new PlaceHolder { ID = "plhTopic" }; Controls.Add(plhTopic); } // Parse and add out topic control // If we added a banner, make sure we register than banner tag // This has to be done separately from sOutput because they are usually different. if (topic.Contains("<dnn:BANNER") && !topic.Contains(Globals.BannerRegisterTag)) topic = Globals.BannerRegisterTag + topic; var ctlTopic = ParseControl(topic); if(ctlTopic != null) plhTopic.Controls.Add(ctlTopic); //Add helper controls //Quick Jump DropDownList var plh = FindControl("plhQuickJump") as PlaceHolder; if (plh != null) { plh.Controls.Clear(); var ctlForumJump = new af_quickjump { ModuleConfiguration = ModuleConfiguration, MOID = ModuleId, dtForums = null, ForumId = ForumId, EnableViewState = false, ForumInfo = ForumId > 0 ? ForumInfo : null }; if (!(plh.Controls.Contains(ctlForumJump))) { plh.Controls.Add(ctlForumJump); } } //Poll Container plh = FindControl("plhPoll") as PlaceHolder; if (plh != null) { plh.Controls.Clear(); plh.Controls.Add(new af_polls { ModuleConfiguration = ModuleConfiguration, TopicId = TopicId, ForumId = ForumId }); } //Quick Reply if (CanRead && _bLocked == false) { plh = FindControl("plhQuickReply") as PlaceHolder; if (plh != null) { plh.Controls.Clear(); var ctlQuickReply = (af_quickreplyform)(LoadControl("~/DesktopModules/ActiveForums/controls/af_quickreply.ascx")); ctlQuickReply.ModuleConfiguration = ModuleConfiguration; ctlQuickReply.CanTrust = _bTrust; ctlQuickReply.ModApprove = _bModApprove; ctlQuickReply.IsTrusted = _isTrusted; ctlQuickReply.Subject = _topicSubject; ctlQuickReply.AllowSubscribe = _allowSubscribe; ctlQuickReply.AllowHTML = _allowHTML; ctlQuickReply.AllowScripts = _allowScript; ctlQuickReply.ForumId = ForumId; ctlQuickReply.SocialGroupId = SocialGroupId; ctlQuickReply.ForumModuleId = ForumModuleId; ctlQuickReply.ForumTabId = TabId; if (ForumId > 0) ctlQuickReply.ForumInfo = ForumInfo; plh.Controls.Add(ctlQuickReply); } } // Topic Sort plh = FindControl("plhTopicSort") as PlaceHolder; if (plh != null) { plh.Controls.Clear(); var ctlTopicSort = (af_topicsorter)(LoadControl("~/DesktopModules/ActiveForums/controls/af_topicsort.ascx")); ctlTopicSort.ModuleConfiguration = ModuleConfiguration; ctlTopicSort.ForumId = ForumId; ctlTopicSort.DefaultSort = _defaultSort; if (ForumId > 0) ctlTopicSort.ForumInfo = ForumInfo; plh.Controls.Add(ctlTopicSort); } // Topic Status plh = FindControl("plhStatus") as PlaceHolder; if (plh != null) { plh.Controls.Clear(); var ctlTopicStatus = (af_topicstatus)(LoadControl("~/DesktopModules/ActiveForums/controls/af_topicstatus.ascx")); ctlTopicStatus.ModuleConfiguration = ModuleConfiguration; ctlTopicStatus.Status = _statusId; ctlTopicStatus.ForumId = ForumId; if (ForumId > 0) ctlTopicStatus.ForumInfo = ForumInfo; plh.Controls.Add(ctlTopicStatus); } BuildPager(); }