Example #1
0
        private string ParseForumRow(string Template, Forum fi, int currForumIndex, string ThemePath, int totalForums)
        {
            if (Template.Contains("[SUBFORUMS]") && Template.Contains("[/SUBFORUMS]"))
            {
                Template = GetSubForums(Template, fi.ForumID, ModuleId, TabId, ThemePath);
            }
            else
            {
                Template = Template.Replace("[SUBFORUMS]", GetSubForums(fi.ForumID, ModuleId, TabId));
            }
            string[] css = null;
            string cssmatch = string.Empty;
            if (Template.Contains("[CSS:"))
            {
                string pattern = "(\\[CSS:.+?\\])";
                if (Regex.IsMatch(Template, pattern))
                {
                    cssmatch = Regex.Match(Template, pattern).Value;
                    css = cssmatch.Split(':'); //0=CSS,1=TopRow, 2=mid rows, 3=lastRow
                }
            }
            if (cssmatch != string.Empty)
            {
                if (currForumIndex == 1)
                {
                    Template = Template.Replace(cssmatch, css[1]);
                }
                else if (currForumIndex > 1 & currForumIndex < totalForums)
                {
                    Template = Template.Replace(cssmatch, css[2]);
                }
                else
                {
                    Template = Template.Replace(cssmatch, css[3].Replace("]", string.Empty));
                }
            }

            bool canView = Permissions.HasPerm(fi.Security.View, ForumUser.UserRoles);
            bool canSubscribe = Permissions.HasPerm(fi.Security.Subscribe, ForumUser.UserRoles);
            bool canRead = Permissions.HasPerm(fi.Security.Read, ForumUser.UserRoles);
            string sIcon = TemplateUtils.ShowIcon(canView, fi.ForumID, CurrentUserId, fi.LastPostDateTime, fi.LastRead, fi.LastPostID);
            string sIconImage = "<img alt=\"" + fi.ForumName + "\" src=\"" + ThemePath + "images/" + sIcon + "\" />";

            if (Template.Contains("[FORUMICON]"))
            {
                Template = Template.Replace("[FORUMICON]", sIconImage);
            }
            else if (Template.Contains("[FORUMICONCSS]"))
            {
                string sFolderCSS = "fa-folder fa-blue";
                switch (sIcon.ToLower())
                {
                    case "folder.png":
                        sFolderCSS = "fa-folder fa-blue";
                        break;
                    case "folder_new.png":
                        sFolderCSS = "fa-folder fa-red";
                        break;
                    case "folder_forbidden.png":
                        sFolderCSS = "fa-folder fa-grey";
                        break;
                    case "folder_closed.png":
                        sFolderCSS = "fa-folder-o fa-grey";
                        break;
                }
                Template = Template.Replace("[FORUMICONCSS]", "<div style=\"height:30px;margin-right:10px;\"><i class=\"fa " + sFolderCSS + " fa-2x\"></i></div>");
            }

            var ctlUtils = new ControlUtils();
            ForumURL = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, -1, string.Empty, -1, -1, string.Empty, 1, -1, SocialGroupId);

            //ForumURL = GetForumLink(.ForumID, TabId, canView, MainSettings.UseShortUrls, .PrefixURL)
            Template = Template.Replace("[FORUMNAME]", GetForumLink(fi.ForumName, fi.ForumID, TabId, canView, ForumURL));
            Template = Template.Replace("[FORUMNAMENOLINK]", fi.ForumName);
            Template = Template.Replace("[FORUMID]", fi.ForumID.ToString());
            if (Template.Contains("[RSSLINK]"))
            {
                if (fi.AllowRSS && canRead)
                {
                    string Url;
                    Url = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request)) + "/DesktopModules/ActiveForums/feeds.aspx?portalid=" + PortalId + "&forumid=" + fi.ForumID + "&tabid=" + TabId + "&moduleid=" + ModuleId;
                    Template = Template.Replace("[RSSLINK]", "<a href=\"" + Url + "\" target=\"_blank\"><img src=\"" + ThemePath + "images/rss.png\" border=\"0\" alt=\"[RESX:RSS]\" /></a>");
                }
                else
                {
                    Template = Template.Replace("[RSSLINK]", "<img src=\"" + ThemePath + "images/rss_disabled.png\" border=\"0\" alt=\"[RESX:RSSDisabled]\" />");
                }
            }

            if (Template.Contains("[AF:CONTROL:TOGGLESUBSCRIBE]"))
            {
                if (canSubscribe)
                {
                    bool IsSubscribed = Subscriptions.IsSubscribed(PortalId, ModuleId, fi.ForumID, 0, SubscriptionTypes.Instant, CurrentUserId);
                    string sAlt = "[RESX:ForumSubscribe:" + IsSubscribed.ToString().ToUpper() + "]";
                    string sImg = ThemePath + "images/email_unchecked.png";
                    if (IsSubscribed)
                    {
                        sImg = ThemePath + "images/email_checked.png";
                    }
                    var subControl = new ToggleSubscribe(0, fi.ForumID, -1);
                    subControl.Checked = IsSubscribed;
                    subControl.DisplayMode = 1;
                    subControl.UserId = CurrentUserId;
                    subControl.ImageURL = sImg;
                    subControl.Text = "[RESX:ForumSubscribe:" + IsSubscribed.ToString().ToUpper() + "]";
                    string subOption = subControl.Render();

                    //Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", "<a href=""javascript:af_toggleSubscribe(" & .ForumID & ",'" & PortalId & "|" & ModuleId & "|" & .ForumID & "|" & CurrentUserId & "');""><img id=""toggleSub" & .ForumID & """ src=""" & sImg & """ border=""0"" alt=""" & sAlt & """ /></a>")
                    Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", subOption);
                }
                else
                {
                    Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", "<img src=\"" + ThemePath + "email_disabled.png\" border=\"0\" alt=\"[RESX:ForumSubscribe:Disabled]\" />");
                }
            }

            Template = canRead ? Template.Replace("[AF:CONTROL:ADDFAVORITE]", "<a href=\"javascript:afAddBookmark('" + fi.ForumName + "','" + ForumURL + "');\"><img src=\"" + ThemePath + "images/favorites16_add.png\" border=\"0\" alt=\"[RESX:AddToFavorites]\" /></a>") : Template.Replace("[AF:CONTROL:ADDFAVORITE]", string.Empty);
            if (Template.Contains("[AF:CONTROL:ADDTHIS"))
            {
                Template = TemplateUtils.ParseSpecial(Template, SpecialTokenTypes.AddThis, ForumURL, fi.ForumName, canRead, MainSettings.AddThisAccount);
            }

            if (fi.ForumDesc != "")
            {
                Template = Template.Replace("[FORUMDESCRIPTION]", "<i class=\"fa fa-file-o fa-grey\"></i>&nbsp;" + fi.ForumDesc);
            }
            else
            {
                Template = Template.Replace("[FORUMDESCRIPTION]", "");
            }

            Template = Template.Replace("[TOTALTOPICS]", fi.TotalTopics.ToString());
            Template = Template.Replace("[TOTALREPLIES]", fi.TotalReplies.ToString());
            //Last Post Section
            int intLength = 0;
            if ((Template.IndexOf("[LASTPOSTSUBJECT:", 0) + 1) > 0)
            {
                int inStart = (Template.IndexOf("[LASTPOSTSUBJECT:", 0) + 1) + 17;
                int inEnd = (Template.IndexOf("]", inStart - 1) + 1);
                string sLength = Template.Substring(inStart - 1, inEnd - inStart);
                intLength = Convert.ToInt32(sLength);
            }
            string ReplaceTag = "[LASTPOSTSUBJECT:" + intLength.ToString() + "]";
            if (fi.LastPostID == 0)
            {
                Template = Template.Replace("[RESX:BY]", string.Empty);
                Template = Template.Replace("[DISPLAYNAME]", string.Empty);
                Template = Template.Replace("[LASTPOSTDATE]", string.Empty);
                Template = Template.Replace(ReplaceTag, string.Empty);
                //Template = TemplateUtils.ParseUserDetails(PortalId, -1, Template, String.Empty)
            }
            else
            {
                if (canView)
                {
                    if (fi.LastPostUserID <= 0)
                    {
                        //Template = Template.Replace("[RESX:BY]", String.Empty)
                        Template = Template.Replace("[DISPLAYNAME]", "<i class=\"fa fa-user fa-fw fa-blue\"></i>&nbsp;" + fi.LastPostDisplayName);
                        //Template = TemplateUtils.ParseUserDetails(PortalId, -1, Template, "FG")
                    }
                    else
                    {
                        bool isMod = CurrentUserType == CurrentUserTypes.Admin || CurrentUserType == CurrentUserTypes.ForumMod || CurrentUserType == CurrentUserTypes.SuperUser;
                        bool isAdmin = CurrentUserType == CurrentUserTypes.Admin || CurrentUserType == CurrentUserTypes.SuperUser;
                        Template = Template.Replace("[DISPLAYNAME]", "<i class=\"fa fa-user fa-fw fa-blue\"></i>&nbsp;" + UserProfiles.GetDisplayName(ModuleId, true, isMod, isAdmin, fi.LastPostUserID, fi.LastPostUserName, fi.LastPostFirstName, fi.LastPostLastName, fi.LastPostDisplayName));
                        //Template = TemplateUtils.ParseUserDetails(PortalId, .LastPostUserID, Template, "FG")
                    }
                    DateTime dtLastPostDate = fi.LastPostDateTime;
                    Template = Template.Replace("[LASTPOSTDATE]", Utilities.GetDate(dtLastPostDate, ModuleId, TimeZoneOffset));
                    string Subject = fi.LastPostSubject;
                    if (Subject == "")
                    {
                        Subject = GetSharedResource("[RESX:SubjectPrefix]") + " " + fi.TopicSubject;
                    }
                    if (Subject != string.Empty)
                    {
                        string sDots = "";
                        if (Subject.Length > intLength)
                        {
                            sDots = "...";
                        }

                        Template = Template.Replace(ReplaceTag, GetLastPostSubject(fi.LastPostID, fi.TopicId, fi.ForumID, TabId, Subject, intLength, MainSettings.PageSize, fi));
                    }
                    else
                    {
                        Template = Template.Replace("[RESX:BY]", string.Empty);
                        Template = Template.Replace(ReplaceTag, string.Empty);
                    }
                }
                else
                {
                    Template = Template.Replace("[DISPLAYNAME]", string.Empty);
                    Template = Template.Replace("[LASTPOSTDATE]", string.Empty);
                    Template = Template.Replace("[RESX:BY]", string.Empty);
                    Template = Template.Replace(ReplaceTag, string.Empty);
                }

            }

            return Template;
        }
Example #2
0
        /*
        private void LinkControls(ControlCollection ctrls)
        {
            foreach (Control ctrl in ctrls)
            {
                if ((ctrl) is ForumBase)
                {
                    ((ForumBase)ctrl).ModuleConfiguration = this.ModuleConfiguration;
                    ((ForumBase)ctrl).TopicId = TopicId;
                }
                if (ctrl.Controls.Count > 0)
                {
                    LinkControls(ctrl.Controls);
                }
            }
        }*/
        private string ParseControls(string sOutput)
        {
            // Do a few things before we switch to a string builder

            // Add This
            if (sOutput.Contains("[AF:CONTROL:ADDTHIS"))
            {
                var strHost = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request));
                sOutput = TemplateUtils.ParseSpecial(sOutput, SpecialTokenTypes.AddThis, strHost + Request.RawUrl, _topicSubject, _bRead, MainSettings.AddThisAccount);
            }

            // Banners
            if (sOutput.Contains("[BANNER"))
            {
                sOutput = sOutput.Replace("[BANNER]", "<dnn:BANNER runat=\"server\" GroupName=\"FORUMS\" BannerCount=\"1\" EnableViewState=\"False\" />");

                const string pattern = @"(\[BANNER:(.+?)\])";
                const string sBanner = "<dnn:BANNER runat=\"server\" BannerCount=\"1\" GroupName=\"$1\" EnableViewState=\"False\" />";

                sOutput = Regex.Replace(sOutput, pattern, sBanner);
            }

            // Now use the string builder to do all replacements
            var sbOutput = new StringBuilder(sOutput);

            if (Request.QueryString["dnnprintmode"] != null)
            {
                sbOutput.Replace("[ADDREPLY]", string.Empty);
                sbOutput.Replace("[QUICKREPLY]", string.Empty);
                sbOutput.Replace("[TOPICSUBSCRIBE]", string.Empty);
                sbOutput.Replace("[AF:CONTROL:PRINTER]", string.Empty);
                sbOutput.Replace("[AF:CONTROL:EMAIL]", string.Empty);
                sbOutput.Replace("[PAGER1]", string.Empty);
                sbOutput.Replace("[PAGER2]", string.Empty);
                sbOutput.Replace("[SORTDROPDOWN]", string.Empty);
                sbOutput.Replace("[POSTRATINGBUTTON]", string.Empty);
                sbOutput.Replace("[JUMPTO]", string.Empty);
                sbOutput.Replace("[NEXTTOPIC]", string.Empty);
                sbOutput.Replace("[PREVTOPIC]", string.Empty);
                sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty);
                sbOutput.Replace("[ACTIONS:DELETE]", string.Empty);
                sbOutput.Replace("[ACTIONS:EDIT]", string.Empty);
                sbOutput.Replace("[ACTIONS:QUOTE]", string.Empty);
                sbOutput.Replace("[ACTIONS:REPLY]", string.Empty);
                sbOutput.Replace("[ACTIONS:ANSWER]", string.Empty);
                sbOutput.Replace("[ACTIONS:ALERT]", string.Empty);
                sbOutput.Replace("[RESX:SortPosts]:", string.Empty);
                sbOutput.Append("<img src=\"~/desktopmodules/activeforums/images/spacer.gif\" width=\"800\" height=\"1\" runat=\"server\" alt=\"---\" />");
            }

            sbOutput.Replace("[NOPAGING]", "<script type=\"text/javascript\">afpagesize=" + int.MaxValue + ";</script>");
            sbOutput.Replace("[NOTOOLBAR]", string.Empty);

            // Subscribe Option
            if (_bSubscribe)
            {
                var subControl = new ToggleSubscribe(1, ForumId, TopicId);
                subControl.Checked = _isSubscribedTopic;
                subControl.Text = "[RESX:TopicSubscribe:" + _isSubscribedTopic.ToString().ToUpper() + "]";
                sbOutput.Replace("[TOPICSUBSCRIBE]", subControl.Render());
            }
            else
            {
                sbOutput.Replace("[TOPICSUBSCRIBE]", string.Empty);
            }

            // Topic and post actions
            var tc = new TokensController();
            var topicActions = tc.TokenGet("topic", "[AF:CONTROL:TOPICACTIONS]");
            var postActions = tc.TokenGet("topic", "[AF:CONTROL:POSTACTIONS]");
            if (sOutput.Contains("[AF:CONTROL:TOPICACTIONS]"))
            {
                _useListActions = true;
                sbOutput.Replace("[AF:CONTROL:TOPICACTIONS]", topicActions);
                sbOutput.Replace("[AF:CONTROL:POSTACTIONS]", postActions);
            }

            // Quick Reply
            if (_bLocked)
            {
                sbOutput.Replace("[ADDREPLY]", "<span class=\"afnormal\">[RESX:TopicLocked]</span>");
                sbOutput.Replace("[QUICKREPLY]", string.Empty);
            }
            else
            {
                //TODO: Check for owner
                if (CanReply)
                {
                    var @params = new List<string> { ParamKeys.ViewType + "=post", ParamKeys.TopicId + "=" + TopicId, ParamKeys.ForumId + "=" + ForumId };
                    if (SocialGroupId > 0)
                        @params.Add("GroupId=" + SocialGroupId);

                    sbOutput.Replace("[ADDREPLY]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", @params.ToArray()) + "\" class=\"dnnPrimaryAction\">[RESX:AddReply]</a>");
                    sbOutput.Replace("[QUICKREPLY]", "<asp:placeholder id=\"plhQuickReply\" runat=\"server\" />");
                }
                else
                {
                    sbOutput.Replace("[ADDREPLY]", "<span class=\"afnormal\">[RESX:NotAuthorizedReply]</span>");
                    sbOutput.Replace("[QUICKREPLY]", string.Empty);
                }
            }

            // Parent Forum Link
            if (sOutput.Contains("[PARENTFORUMLINK]"))
            {
                if (ForumInfo.ParentForumId > 0)
                {
                    if (MainSettings.UseShortUrls)
                        sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ForumId + "=" + ForumInfo.ParentForumId }) + "\">" + ForumInfo.ParentForumName + "</a>");
                    else
                        sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=" + Views.Topics, ParamKeys.ForumId + "=" + ForumInfo.ParentForumId }) + "\">" + ForumInfo.ParentForumName + "</a>");
                }
                else if (ForumInfo.ForumGroupId > 0)
                    sbOutput.Replace("[PARENTFORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId) + "\">" + ForumInfo.GroupName + "</a>");
            }

            // Parent Forum Name
            if (string.IsNullOrEmpty(ForumInfo.ParentForumName))
                sbOutput.Replace("[PARENTFORUMNAME]", ForumInfo.ParentForumName);

            // ForumLinks
            sbOutput.Replace("[FORUMMAINLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId) + "\">[RESX:ForumMain]</a>");
            sbOutput.Replace("[FORUMGROUPLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.GroupId + "=" + ForumGroupId) + "\">" + _groupName + "</a>");
            if (MainSettings.UseShortUrls)
                sbOutput.Replace("[FORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId) + "\">" + _forumName + "</a>");
            else
                sbOutput.Replace("[FORUMLINK]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ViewType + "=" + Views.Topics + "&" + ParamKeys.ForumId + "=" + ForumId) + "\">" + _forumName + "</a>");

            // Names and Ids
            sbOutput.Replace("[FORUMID]", ForumId.ToString());
            sbOutput.Replace("[FORUMNAME]", _forumName);
            sbOutput.Replace("[GROUPNAME]", _groupName);

            // Printer Friendly Link
            var sURL = "<a rel=\"nofollow\" href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + TopicId, "mid=" + ModuleId, "dnnprintmode=true") + "?skinsrc=" + HttpUtility.UrlEncode("[G]" + UI.Skins.SkinInfo.RootSkin + "/" + Common.Globals.glbHostSkinFolder + "/" + "No Skin") + "&amp;containersrc=" + HttpUtility.UrlEncode("[G]" + UI.Skins.SkinInfo.RootContainer + "/" + Common.Globals.glbHostSkinFolder + "/" + "No Container") + "\" target=\"_blank\">";
            sURL += "<img src=\"" + _myThemePath + "/images/print16.png\" border=\"0\" alt=\"[RESX:PrinterFriendly]\" /></a>";
            sbOutput.Replace("[AF:CONTROL:PRINTER]", sURL);

            // Email Link
            if (Request.IsAuthenticated)
            {
                sURL = Utilities.NavigateUrl(TabId, "", new [] { ParamKeys.ViewType + "=sendto", ParamKeys.ForumId + "=" + ForumId, ParamKeys.TopicId + "=" + TopicId });
                sbOutput.Replace("[AF:CONTROL:EMAIL]", "<a href=\"" + sURL + "\" rel=\"nofollow\"><img src=\"" + _myThemePath + "/images/email16.png\" border=\"0\" alt=\"[RESX:EmailThis]\" /></a>");
            }
            else
                sbOutput.Replace("[AF:CONTROL:EMAIL]", string.Empty);

            // RSS Link
            if (_bAllowRSS)
            {
                var url = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request)) + "/DesktopModules/ActiveForums/feeds.aspx?portalid=" + PortalId + "&forumid=" + ForumId + "&tabid=" + TabId + "&moduleid=" + ModuleId;
                sbOutput.Replace("[RSSLINK]", "<a href=\"" + url + "\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/rss.png\" runat=server border=\"0\" alt=\"[RESX:RSS]\" /></a>");
            }
            else
                sbOutput.Replace("[RSSLINK]", string.Empty);

            // Subject
            _topicSubject = _topicSubject.Replace("[", "&#91");
            _topicSubject = _topicSubject.Replace("]", "&#93");
            sbOutput.Replace("[SUBJECT]", Utilities.StripHTMLTag(_topicSubject));

            // Reply Count
            sbOutput.Replace("[REPLYCOUNT]", _replyCount.ToString());
            sbOutput.Replace("[AF:LABEL:ReplyCount]", _replyCount.ToString());

            // View Count
            sbOutput.Replace("[VIEWCOUNT]", _viewCount.ToString());

            // Last Post
            sbOutput.Replace("[AF:LABEL:LastPostDate]", _lastPostDate);
            sbOutput.Replace("[AF:LABEL:LastPostAuthor]", UserProfiles.GetDisplayName(ModuleId, true, _bModApprove, ForumUser.IsAdmin || ForumUser.IsSuperUser, _lastPostAuthor.AuthorId, _lastPostAuthor.Username, _lastPostAuthor.FirstName, _lastPostAuthor.LastName, _lastPostAuthor.DisplayName));

            // Topic Info
            sbOutput.Replace("[AF:LABEL:TopicAuthor]", UserProfiles.GetDisplayName(ModuleId, _topicAuthorId, _topicAuthorDisplayName, string.Empty, string.Empty, _topicAuthorDisplayName));
            sbOutput.Replace("[AF:LABEL:TopicDateCreated]", _topicDateCreated);

            // Pagers
            if (_pageSize == int.MaxValue)
            {
                sbOutput.Replace("[PAGER1]", string.Empty);
                sbOutput.Replace("[PAGER2]", string.Empty);
            }
            else
            {
                sbOutput.Replace("[PAGER1]", "<am:pagernav id=\"Pager1\" runat=\"server\" EnableViewState=\"False\" />");
                sbOutput.Replace("[PAGER2]", "<am:pagernav id=\"Pager2\" runat=\"server\" EnableViewState=\"False\" />");
            }

            // Sort
            sbOutput.Replace("[SORTDROPDOWN]", "<asp:placeholder id=\"plhTopicSort\" runat=\"server\" />");
            var rateControl = new Ratings(TopicId, true, _topicRating);
            sbOutput.Replace("[POSTRATINGBUTTON]", rateControl.Render());

            // Jump To
            sbOutput.Replace("[JUMPTO]", "<asp:placeholder id=\"plhQuickJump\" runat=\"server\" />");

            // Next Topic
            if (_nextTopic == 0)
                sbOutput.Replace("[NEXTTOPIC]", string.Empty);
            else
            {
                if (MainSettings.UseShortUrls)
                    sbOutput.Replace("[NEXTTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.TopicId + "=" + _nextTopic) + "\" rel=\"nofollow\"><span>[RESX:NextTopic]</span><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_right_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:NextTopic]\" /></a>");
                else
                    sbOutput.Replace("[NEXTTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId + "&" + ParamKeys.TopicId + "=" + _nextTopic + "&" + ParamKeys.ViewType + "=" + Views.Topic) + "\" rel=\"nofollow\"><span>[RESX:NextTopic]</span><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_right_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:NextTopic]\" /></a>");
            }

            // Previous Topic
            if (_prevTopic == 0)
                sbOutput.Replace("[PREVTOPIC]", string.Empty);
            else
            {
                if (MainSettings.UseShortUrls)
                    sbOutput.Replace("[PREVTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.TopicId + "=" + _prevTopic) + "\" rel=\"nofollow\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_left_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:PrevTopic]\" /><span>[RESX:PrevTopic]</span></a>");
                else
                    sbOutput.Replace("[PREVTOPIC]", "<a href=\"" + Utilities.NavigateUrl(TabId, "", ParamKeys.ForumId + "=" + ForumId + "&" + ParamKeys.TopicId + "=" + _prevTopic + "&" + ParamKeys.ViewType + "=" + Views.Topic) + "\" rel=\"nofollow\"><img src=\"~/DesktopModules/ActiveForums/themes/" + _myTheme + "/images/arrow_left_blue.gif\" runat=server style=\"vertical-align:middle;\" border=\"0\" alt=\"[RESX:PrevTopic]\" /><span>[RESX:PrevTopic]</span></a>");
            }

            // Topic Status
            if (((_bRead && _topicAuthorId == UserId) || _bModEdit) & _statusId >= 0)
            {
                sbOutput.Replace("[AF:CONTROL:STATUS]", "<asp:placeholder id=\"plhStatus\" runat=\"server\" />");
                sbOutput.Replace("[AF:CONTROL:STATUSICON]", "<img alt=\"[RESX:PostStatus" + _statusId.ToString() + "]\" src=\"" + _myThemePath + "/images/status" + _statusId.ToString() + ".png\" />");
            }
            else if (_statusId >= 0)
            {
                sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty);
                sbOutput.Replace("[AF:CONTROL:STATUSICON]", "<img alt=\"[RESX:PostStatus" + _statusId.ToString() + "]\" src=\"" + _myThemePath + "/images/status" + _statusId.ToString() + ".png\" />");
            }
            else
            {
                sbOutput.Replace("[AF:CONTROL:STATUS]", string.Empty);
                sbOutput.Replace("[AF:CONTROL:STATUSICON]", string.Empty);
            }

            // Poll
            if (_topicType == (int)TopicTypes.Poll)
                sbOutput.Replace("[AF:CONTROL:POLL]", "<asp:placeholder id=\"plhPoll\" runat=\"server\" />");
            else
                sbOutput.Replace("[AF:CONTROL:POLL]", string.Empty);

            return sbOutput.ToString();
        }
Example #3
0
        private string ParseForumRow(string Template, Forum fi, int currForumIndex, string ThemePath, int totalForums)
        {
            if (Template.Contains("[SUBFORUMS]") && Template.Contains("[/SUBFORUMS]"))
            {
                Template = GetSubForums(Template, fi.ForumID, ModuleId, TabId, ThemePath);
            }
            else
            {
                Template = Template.Replace("[SUBFORUMS]", GetSubForums(fi.ForumID, ModuleId, TabId));
            }
            string[] css      = null;
            string   cssmatch = string.Empty;

            if (Template.Contains("[CSS:"))
            {
                string pattern = "(\\[CSS:.+?\\])";
                if (Regex.IsMatch(Template, pattern))
                {
                    cssmatch = Regex.Match(Template, pattern).Value;
                    css      = cssmatch.Split(':'); //0=CSS,1=TopRow, 2=mid rows, 3=lastRow
                }
            }
            if (cssmatch != string.Empty)
            {
                if (currForumIndex == 1)
                {
                    Template = Template.Replace(cssmatch, css[1]);
                }
                else if (currForumIndex > 1 & currForumIndex < totalForums)
                {
                    Template = Template.Replace(cssmatch, css[2]);
                }
                else
                {
                    Template = Template.Replace(cssmatch, css[3].Replace("]", string.Empty));
                }
            }

            bool   canView      = Permissions.HasPerm(fi.Security.View, ForumUser.UserRoles);
            bool   canSubscribe = Permissions.HasPerm(fi.Security.Subscribe, ForumUser.UserRoles);
            bool   canRead      = Permissions.HasPerm(fi.Security.Read, ForumUser.UserRoles);
            string sIcon        = TemplateUtils.ShowIcon(canView, fi.ForumID, CurrentUserId, fi.LastPostDateTime, fi.LastRead, fi.LastPostID);
            string sIconImage   = "<img alt=\"" + fi.ForumName + "\" src=\"" + ThemePath + "images/" + sIcon + "\" />";

            if (Template.Contains("[FORUMICON]"))
            {
                Template = Template.Replace("[FORUMICON]", sIconImage);
            }
            else if (Template.Contains("[FORUMICONCSS]"))
            {
                string sFolderCSS = "fa-folder fa-blue";
                switch (sIcon.ToLower())
                {
                case "folder.png":
                    sFolderCSS = "fa-folder fa-blue";
                    break;

                case "folder_new.png":
                    sFolderCSS = "fa-folder fa-red";
                    break;

                case "folder_forbidden.png":
                    sFolderCSS = "fa-folder fa-grey";
                    break;

                case "folder_closed.png":
                    sFolderCSS = "fa-folder-o fa-grey";
                    break;
                }
                Template = Template.Replace("[FORUMICONCSS]", "<div style=\"height:30px;margin-right:10px;\"><i class=\"fa " + sFolderCSS + " fa-2x\"></i></div>");
            }

            var ctlUtils = new ControlUtils();

            ForumURL = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, fi.ForumGroup.PrefixURL, fi.PrefixURL, fi.ForumGroupId, fi.ForumID, -1, string.Empty, -1, -1, string.Empty, 1, -1, SocialGroupId);

            //ForumURL = GetForumLink(.ForumID, TabId, canView, MainSettings.UseShortUrls, .PrefixURL)
            Template = Template.Replace("[FORUMNAME]", GetForumLink(fi.ForumName, fi.ForumID, TabId, canView, ForumURL));
            Template = Template.Replace("[FORUMNAMENOLINK]", fi.ForumName);
            Template = Template.Replace("[FORUMID]", fi.ForumID.ToString());
            if (Template.Contains("[RSSLINK]"))
            {
                if (fi.AllowRSS && canRead)
                {
                    string Url;
                    Url      = Common.Globals.AddHTTP(Common.Globals.GetDomainName(Request)) + "/DesktopModules/ActiveForums/feeds.aspx?portalid=" + PortalId + "&forumid=" + fi.ForumID + "&tabid=" + TabId + "&moduleid=" + ModuleId;
                    Template = Template.Replace("[RSSLINK]", "<a href=\"" + Url + "\" target=\"_blank\"><img src=\"" + ThemePath + "images/rss.png\" border=\"0\" alt=\"[RESX:RSS]\" /></a>");
                }
                else
                {
                    Template = Template.Replace("[RSSLINK]", "<img src=\"" + ThemePath + "images/rss_disabled.png\" border=\"0\" alt=\"[RESX:RSSDisabled]\" />");
                }
            }

            if (Template.Contains("[AF:CONTROL:TOGGLESUBSCRIBE]"))
            {
                if (canSubscribe)
                {
                    bool   IsSubscribed = Subscriptions.IsSubscribed(PortalId, ModuleId, fi.ForumID, 0, SubscriptionTypes.Instant, CurrentUserId);
                    string sAlt         = "[RESX:ForumSubscribe:" + IsSubscribed.ToString().ToUpper() + "]";
                    string sImg         = ThemePath + "images/email_unchecked.png";
                    if (IsSubscribed)
                    {
                        sImg = ThemePath + "images/email_checked.png";
                    }
                    var subControl = new ToggleSubscribe(0, fi.ForumID, -1);
                    subControl.Checked     = IsSubscribed;
                    subControl.DisplayMode = 1;
                    subControl.UserId      = CurrentUserId;
                    subControl.ImageURL    = sImg;
                    subControl.Text        = "[RESX:ForumSubscribe:" + IsSubscribed.ToString().ToUpper() + "]";
                    string subOption = subControl.Render();

                    //Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", "<a href=""javascript:af_toggleSubscribe(" & .ForumID & ",'" & PortalId & "|" & ModuleId & "|" & .ForumID & "|" & CurrentUserId & "');""><img id=""toggleSub" & .ForumID & """ src=""" & sImg & """ border=""0"" alt=""" & sAlt & """ /></a>")
                    Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", subOption);
                }
                else
                {
                    Template = Template.Replace("[AF:CONTROL:TOGGLESUBSCRIBE]", "<img src=\"" + ThemePath + "email_disabled.png\" border=\"0\" alt=\"[RESX:ForumSubscribe:Disabled]\" />");
                }
            }

            Template = canRead ? Template.Replace("[AF:CONTROL:ADDFAVORITE]", "<a href=\"javascript:afAddBookmark('" + fi.ForumName + "','" + ForumURL + "');\"><img src=\"" + ThemePath + "images/favorites16_add.png\" border=\"0\" alt=\"[RESX:AddToFavorites]\" /></a>") : Template.Replace("[AF:CONTROL:ADDFAVORITE]", string.Empty);
            if (Template.Contains("[AF:CONTROL:ADDTHIS"))
            {
                Template = TemplateUtils.ParseSpecial(Template, SpecialTokenTypes.AddThis, ForumURL, fi.ForumName, canRead, MainSettings.AddThisAccount);
            }

            if (fi.ForumDesc != "")
            {
                Template = Template.Replace("[FORUMDESCRIPTION]", "<i class=\"fa fa-file-o fa-grey\"></i>&nbsp;" + fi.ForumDesc);
            }
            else
            {
                Template = Template.Replace("[FORUMDESCRIPTION]", "");
            }

            Template = Template.Replace("[TOTALTOPICS]", fi.TotalTopics.ToString());
            Template = Template.Replace("[TOTALREPLIES]", fi.TotalReplies.ToString());
            //Last Post Section
            int intLength = 0;

            if ((Template.IndexOf("[LASTPOSTSUBJECT:", 0) + 1) > 0)
            {
                int    inStart = (Template.IndexOf("[LASTPOSTSUBJECT:", 0) + 1) + 17;
                int    inEnd   = (Template.IndexOf("]", inStart - 1) + 1);
                string sLength = Template.Substring(inStart - 1, inEnd - inStart);
                intLength = Convert.ToInt32(sLength);
            }
            string ReplaceTag = "[LASTPOSTSUBJECT:" + intLength.ToString() + "]";

            if (fi.LastPostID == 0)
            {
                Template = Template.Replace("[RESX:BY]", string.Empty);
                Template = Template.Replace("[DISPLAYNAME]", string.Empty);
                Template = Template.Replace("[LASTPOSTDATE]", string.Empty);
                Template = Template.Replace(ReplaceTag, string.Empty);
                //Template = TemplateUtils.ParseUserDetails(PortalId, -1, Template, String.Empty)
            }
            else
            {
                if (canView)
                {
                    if (fi.LastPostUserID <= 0)
                    {
                        //Template = Template.Replace("[RESX:BY]", String.Empty)
                        Template = Template.Replace("[DISPLAYNAME]", "<i class=\"fa fa-user fa-fw fa-blue\"></i>&nbsp;" + fi.LastPostDisplayName);
                        //Template = TemplateUtils.ParseUserDetails(PortalId, -1, Template, "FG")
                    }
                    else
                    {
                        bool isMod   = CurrentUserType == CurrentUserTypes.Admin || CurrentUserType == CurrentUserTypes.ForumMod || CurrentUserType == CurrentUserTypes.SuperUser;
                        bool isAdmin = CurrentUserType == CurrentUserTypes.Admin || CurrentUserType == CurrentUserTypes.SuperUser;
                        Template = Template.Replace("[DISPLAYNAME]", "<i class=\"fa fa-user fa-fw fa-blue\"></i>&nbsp;" + UserProfiles.GetDisplayName(ModuleId, true, isMod, isAdmin, fi.LastPostUserID, fi.LastPostUserName, fi.LastPostFirstName, fi.LastPostLastName, fi.LastPostDisplayName));
                        //Template = TemplateUtils.ParseUserDetails(PortalId, .LastPostUserID, Template, "FG")
                    }
                    DateTime dtLastPostDate = fi.LastPostDateTime;
                    Template = Template.Replace("[LASTPOSTDATE]", Utilities.GetDate(dtLastPostDate, ModuleId, TimeZoneOffset));
                    string Subject = fi.LastPostSubject;
                    if (Subject == "")
                    {
                        Subject = GetSharedResource("[RESX:SubjectPrefix]") + " " + fi.TopicSubject;
                    }
                    if (Subject != string.Empty)
                    {
                        string sDots = "";
                        if (Subject.Length > intLength)
                        {
                            sDots = "...";
                        }

                        Template = Template.Replace(ReplaceTag, GetLastPostSubject(fi.LastPostID, fi.TopicId, fi.ForumID, TabId, Subject, intLength, MainSettings.PageSize, fi));
                    }
                    else
                    {
                        Template = Template.Replace("[RESX:BY]", string.Empty);
                        Template = Template.Replace(ReplaceTag, string.Empty);
                    }
                }
                else
                {
                    Template = Template.Replace("[DISPLAYNAME]", string.Empty);
                    Template = Template.Replace("[LASTPOSTDATE]", string.Empty);
                    Template = Template.Replace("[RESX:BY]", string.Empty);
                    Template = Template.Replace(ReplaceTag, string.Empty);
                }
            }

            return(Template);
        }