From 0fd34479e7083dc129d9cd24d06943f766fa92b1 Mon Sep 17 00:00:00 2001 From: John Henley Date: Thu, 31 Oct 2024 16:38:02 +0000 Subject: [PATCH] ENH: Use token replacement for like buttons --- .../LegacyTokenResources.resx | 9 +++ .../Controllers/LikeController.cs | 18 +++--- .../CustomControls/UserControls/TopicView.cs | 32 +--------- Dnn.CommunityForums/Entities/IPostInfo.cs | 4 ++ Dnn.CommunityForums/Entities/ReplyInfo.cs | 40 +++++++++++- Dnn.CommunityForums/Entities/TopicInfo.cs | 39 ++++++++++++ .../Services/Tokens/TokenReplacer.cs | 62 +++++++++++-------- Dnn.CommunityForums/scripts/afcommon.js | 3 + .../templates/TopicView.ascx | 14 ++--- .../templates/TopicView.ascx | 12 ++-- 10 files changed, 152 insertions(+), 81 deletions(-) diff --git a/Dnn.CommunityForums/App_LocalResources/LegacyTokenResources.resx b/Dnn.CommunityForums/App_LocalResources/LegacyTokenResources.resx index f64ca29a..78de01a5 100644 --- a/Dnn.CommunityForums/App_LocalResources/LegacyTokenResources.resx +++ b/Dnn.CommunityForums/App_LocalResources/LegacyTokenResources.resx @@ -408,4 +408,13 @@ <img class='ComposeMessage' data-recipient='{{ "id": "user-{0}", "name": "[FORUMUSER:DISPLAYNAMEFORJSON]" }}' src='[FORUM:THEMELOCATION]images/icon_pm.png' alt="[RESX:SendPM]" title="[RESX:SendPM]" border="0" /> + + <i id="af-topicview-likes-[FORUMPOST:CONTENTID]" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up]" style="cursor: pointer" onclick="{0}"> [FORUMPOST:LIKECOUNT]</i>|<i id="af-topicview-likes" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up] fa-2x"> [FORUMPOST:LIKECOUNT]</i> + + + <i id="af-topicview-likes-[FORUMPOST:CONTENTID]" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up] fa-2x" style="cursor: pointer" onclick="{0}"> [FORUMPOST:LIKECOUNT]</i>|<i id="af-topicview-likes" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up] fa-2x"> [FORUMPOST:LIKECOUNT]</i> + + + <i id="af-topicview-likes-[FORUMPOST:CONTENTID]" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up] fa-3x" style="cursor: pointer" onclick="{0}"> [FORUMPOST:LIKECOUNT]</i>|<i id="af-topicview-likes" class="fa [FORUMPOST:ISLIKED|fa-thumbs-o-up|fa-thumbs-up] fa-2x"> [FORUMPOST:LIKECOUNT]</i> + \ No newline at end of file diff --git a/Dnn.CommunityForums/Controllers/LikeController.cs b/Dnn.CommunityForums/Controllers/LikeController.cs index ef6a95e1..d176e7de 100644 --- a/Dnn.CommunityForums/Controllers/LikeController.cs +++ b/Dnn.CommunityForums/Controllers/LikeController.cs @@ -18,21 +18,16 @@ // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; -using System.Collections.Generic; -using System.Linq; - -using DotNetNuke.Data; - namespace DotNetNuke.Modules.ActiveForums.Controllers { + using System.Collections.Generic; + using System.Linq; + internal partial class LikeController : RepositoryControllerBase { - public LikeController() : base() { } - public bool GetForUser(int userId, int postId) { - return this.Find("WHERE PostId = @0 AND UserId = @1 AND Checked = 1", postId, userId).Any(); + return userId > 0 && this.Find("WHERE PostId = @0 AND UserId = @1 AND Checked = 1", postId, userId).Any(); } public (int count, bool liked) Get(int userId, int postId) @@ -82,6 +77,11 @@ public int Like(int contentId, int userId) namespace DotNetNuke.Modules.ActiveForums { + using System; + using System.Collections.Generic; + + using DotNetNuke.Data; + [Obsolete("Deprecated in Community Forums. Scheduled removal in 09.00.00. Replace with DotNetNuke.Modules.ActiveForums.Controllers.LikeController")] class LikesController : DotNetNuke.Modules.ActiveForums.Controllers.LikeController { diff --git a/Dnn.CommunityForums/CustomControls/UserControls/TopicView.cs b/Dnn.CommunityForums/CustomControls/UserControls/TopicView.cs index 498fa6a1..9e6bc81e 100644 --- a/Dnn.CommunityForums/CustomControls/UserControls/TopicView.cs +++ b/Dnn.CommunityForums/CustomControls/UserControls/TopicView.cs @@ -61,7 +61,6 @@ public class TopicView : ForumBase private int pageSize = 20; private int rowCount; private bool isTrusted; - private bool allowLikes; private bool isSubscribedTopic; private string defaultSort; private string tags = string.Empty; @@ -326,7 +325,6 @@ private void LoadData(int pageId) this.topicTemplateId = Utilities.SafeConvertInt(this.drForum["TopicTemplateId"]); this.tags = this.drForum["Tags"].ToString(); - this.allowLikes = Utilities.SafeConvertBool(this.drForum["AllowLikes"]); this.rowCount = Utilities.SafeConvertInt(this.drForum["ReplyCount"]) + 1; this.isSubscribedTopic = new DotNetNuke.Modules.ActiveForums.Controllers.SubscriptionController().Subscribed(this.PortalId, this.ForumModuleId, this.UserId, this.ForumInfo.ForumID, this.TopicId); @@ -932,6 +930,7 @@ private string ParseTopic(string sOutput) sTopicTemplate = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyUserTokenSynonyms(new StringBuilder(sTopicTemplate), this.PortalSettings, this.MainSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString(); sTopicTemplate = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyAuthorTokenSynonyms(new StringBuilder(sTopicTemplate), this.PortalSettings, this.MainSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString(); sTopicTemplate = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyTopicTokenSynonyms(new StringBuilder(sTopicTemplate), this.PortalSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString(); + sTopicTemplate = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyPostTokenSynonyms(new StringBuilder(sTopicTemplate), this.PortalSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString(); sReplyTemplate = DotNetNuke.Modules.ActiveForums.Services.Tokens.TokenReplacer.MapLegacyPostTokenSynonyms(new StringBuilder(sReplyTemplate), this.PortalSettings, this.ForumUser.UserInfo?.Profile?.PreferredLocale).ToString(); #endregion "Backward compatilbility -- remove in v10.00.00" @@ -1071,35 +1070,6 @@ private string ParseContent(DataRow dr, string template, int rowcount) sbOutput.Replace("[POSTREPLYCSS]", "afpostreply afpostreply2"); } - #region "likes" - - if (this.allowLikes) - { - (int count, bool liked) likes = new DotNetNuke.Modules.ActiveForums.Controllers.LikeController().Get(this.UserId, (reply.ReplyId > 0 ? reply.ContentId : this.topic.ContentId)); - string image = likes.liked ? "fa-thumbs-o-up" : "fa-thumbs-up"; - - if (this.CanReply) - { - sbOutput = sbOutput.Replace("[LIKES]", " 0 ? reply.ContentId : this.topic.ContentId) + "\" class=\"fa " + image + "\" style=\"cursor:pointer\" onclick=\"amaf_likePost(" + this.ModuleId + "," + this.ForumId + "," + (reply.ReplyId > 0 ? reply.ContentId : this.topic.ContentId) + ")\" > " + likes.count.ToString() + ""); - sbOutput = sbOutput.Replace("[LIKESx2]", " 0 ? reply.ContentId : this.topic.ContentId) + "\" class=\"fa " + image + " fa-2x\" style=\"cursor:pointer\" onclick=\"amaf_likePost(" + this.ModuleId + "," + this.ForumId + "," + (reply.ReplyId > 0 ? reply.ContentId : this.topic.ContentId) + ")\" > " + likes.count.ToString() + ""); - sbOutput = sbOutput.Replace("[LIKESx3]", " 0 ? reply.ContentId : this.topic.ContentId) + "\" class=\"fa " + image + " fa-3x\" style=\"cursor:pointer\" onclick=\"amaf_likePost(" + this.ModuleId + "," + this.ForumId + "," + (reply.ReplyId > 0 ? reply.ContentId : this.topic.ContentId) + ")\" > " + likes.count.ToString() + ""); - } - else - { - sbOutput = sbOutput.Replace("[LIKES]", " " + likes.count.ToString() + ""); - sbOutput = sbOutput.Replace("[LIKESx2]", " " + likes.count.ToString() + ""); - sbOutput = sbOutput.Replace("[LIKESx3]", " " + likes.count.ToString() + ""); - } - } - else - { - sbOutput = sbOutput.Replace("[LIKES]", string.Empty); - sbOutput = sbOutput.Replace("[LIKESx2]", string.Empty); - sbOutput = sbOutput.Replace("[LIKESx3]", string.Empty); - } - - #endregion "likes" - // Poll Results if (sOutput.Contains("[POLLRESULTS]")) { diff --git a/Dnn.CommunityForums/Entities/IPostInfo.cs b/Dnn.CommunityForums/Entities/IPostInfo.cs index 27e40ada..c2ee104e 100644 --- a/Dnn.CommunityForums/Entities/IPostInfo.cs +++ b/Dnn.CommunityForums/Entities/IPostInfo.cs @@ -50,6 +50,8 @@ public interface IPostInfo : DotNetNuke.Services.Tokens.IPropertyAccess string RawUrl { get; set; } + int LikeCount { get; } + DotNetNuke.Modules.ActiveForums.Entities.AuthorInfo Author { get; set; } DotNetNuke.Modules.ActiveForums.Entities.ContentInfo Content { get; set; } @@ -58,6 +60,8 @@ public interface IPostInfo : DotNetNuke.Services.Tokens.IPropertyAccess DotNetNuke.Modules.ActiveForums.Entities.TopicInfo Topic { get; } + bool IsLikedByUser(DotNetNuke.Modules.ActiveForums.Entities.ForumUserInfo forumUser); + DotNetNuke.Modules.ActiveForums.Enums.PostStatus GetPostStatusForUser(DotNetNuke.Modules.ActiveForums.Entities.ForumUserInfo forumUser); string GetPostStatusCss(DotNetNuke.Modules.ActiveForums.Entities.ForumUserInfo forumUser); diff --git a/Dnn.CommunityForums/Entities/ReplyInfo.cs b/Dnn.CommunityForums/Entities/ReplyInfo.cs index 86290770..adc4a54a 100644 --- a/Dnn.CommunityForums/Entities/ReplyInfo.cs +++ b/Dnn.CommunityForums/Entities/ReplyInfo.cs @@ -43,8 +43,8 @@ public partial class ReplyInfo : DotNetNuke.Modules.ActiveForums.Entities.IPostI { private DotNetNuke.Modules.ActiveForums.Entities.TopicInfo topicInfo; private DotNetNuke.Modules.ActiveForums.Entities.ContentInfo contentInfo; - private DotNetNuke.Modules.ActiveForums.Entities.ForumInfo forumInfo; private DotNetNuke.Modules.ActiveForums.Entities.AuthorInfo author; + private int? likeCount; [IgnoreColumn] public int ForumId @@ -111,6 +111,26 @@ internal DotNetNuke.Modules.ActiveForums.Entities.TopicInfo GetTopic() [IgnoreColumn] public string Summary => Content.Summary; + [IgnoreColumn] + public int LikeCount + { + get + { + if (this.likeCount == null) + { + this.likeCount = + new DotNetNuke.Modules.ActiveForums.Controllers.LikeController().Count(this.ContentId); + } + + return (int)this.likeCount; + } + } + + public bool IsLikedByUser(ForumUserInfo forumUser) + { + return new DotNetNuke.Modules.ActiveForums.Controllers.LikeController().GetForUser(forumUser.UserId, this.ContentId); + } + [IgnoreColumn] public DotNetNuke.Modules.ActiveForums.Entities.ContentInfo Content { @@ -390,6 +410,24 @@ public string GetProperty(string propertyName, string format, System.Globalizati return PropertyAccess.FormatString(slink, format); } + case "isliked": + return !this.Forum.AllowLikes ? string.Empty : PropertyAccess.FormatString(this.IsLikedByUser(new Controllers.ForumUserController(this.ModuleId).GetByUserId(accessingUser.PortalID, accessingUser.UserID)) ? true.ToString() : string.Empty, format); + case "likecount": + return !this.Forum.AllowLikes ? string.Empty : PropertyAccess.FormatString(this.LikeCount.ToString(), format); + case "likeonclick": + { + var bReply = Controllers.PermissionController.HasPerm(this.Forum.Security.Reply, + accessingUser.PortalID, + this.Forum.ModuleId, accessingUser.UserID); + if (this.Forum.AllowLikes) + { + return PropertyAccess.FormatString(bReply ? + $"amaf_likePost({this.Forum.ModuleId},{this.Forum.ForumID},{this.ContentId})" : string.Empty, + format); + } + } + + return string.Empty; case "authorid": return PropertyAccess.FormatString(this.Content.AuthorId.ToString(), format); case "authorname": diff --git a/Dnn.CommunityForums/Entities/TopicInfo.cs b/Dnn.CommunityForums/Entities/TopicInfo.cs index 2087d76e..9e88aed9 100644 --- a/Dnn.CommunityForums/Entities/TopicInfo.cs +++ b/Dnn.CommunityForums/Entities/TopicInfo.cs @@ -85,6 +85,7 @@ public Category(int id, string name, bool selected) private string tags = string.Empty; private string selectedcategories; private int? subscriberCount; + private int? likeCount; public int TopicId { get; set; } @@ -217,6 +218,26 @@ public int SubscriberCount } } + [IgnoreColumn] + public int LikeCount + { + get + { + if (this.likeCount == null) + { + this.likeCount = + new DotNetNuke.Modules.ActiveForums.Controllers.LikeController().Count(this.ContentId); + } + + return (int)this.likeCount; + } + } + + public bool IsLikedByUser(ForumUserInfo forumUser) + { + return new DotNetNuke.Modules.ActiveForums.Controllers.LikeController().GetForUser(forumUser.UserId, this.ContentId); + } + [IgnoreColumn] public ContentInfo Content { @@ -695,6 +716,24 @@ public string GetProperty(string propertyName, string format, System.Globalizati return PropertyAccess.FormatString(this.ViewCount.ToString(), format); case "subscribercount": return PropertyAccess.FormatString(this.SubscriberCount.ToString(), format); + case "isliked": + return !this.Forum.AllowLikes ? string.Empty : PropertyAccess.FormatString(this.IsLikedByUser(new Controllers.ForumUserController(this.ModuleId).GetByUserId(accessingUser.PortalID, accessingUser.UserID)) ? true.ToString() : string.Empty, format); + case "likecount": + return !this.Forum.AllowLikes ? string.Empty : PropertyAccess.FormatString(this.LikeCount.ToString(), format); + case "likeonclick": + { + var bReply = Controllers.PermissionController.HasPerm(this.Forum.Security.Reply, + accessingUser.PortalID, + this.Forum.ModuleId, accessingUser.UserID); + if (this.Forum.AllowLikes) + { + return PropertyAccess.FormatString(bReply ? + $"amaf_likePost({this.Forum.ModuleId},{this.Forum.ForumID},{this.ContentId})" : string.Empty, + format); + } + } + + return string.Empty; case "status": { var bRead = Controllers.PermissionController.HasPerm(this.Forum.Security.Read, diff --git a/Dnn.CommunityForums/Services/Tokens/TokenReplacer.cs b/Dnn.CommunityForums/Services/Tokens/TokenReplacer.cs index 9beb3569..b5e8e5fe 100644 --- a/Dnn.CommunityForums/Services/Tokens/TokenReplacer.cs +++ b/Dnn.CommunityForums/Services/Tokens/TokenReplacer.cs @@ -18,6 +18,8 @@ // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +using System.Runtime.CompilerServices; + namespace DotNetNuke.Modules.ActiveForums.Services.Tokens { using System; @@ -36,6 +38,7 @@ namespace DotNetNuke.Modules.ActiveForums.Services.Tokens using DotNetNuke.Entities.Portals; using DotNetNuke.Entities.Users; using DotNetNuke.Modules.ActiveForums.Entities; + using DotNetNuke.Modules.ActiveForums.ViewModels; using DotNetNuke.Services.Log.EventLog; using DotNetNuke.Services.Tokens; @@ -92,7 +95,7 @@ public TokenReplacer(PortalSettings portalSettings, ForumUserInfo forumUser, For forumGroupInfo.RequestUri = requestUri; forumUser.RequestUri = requestUri; this.PropertySource[PropertySource_resx] = new ResourceStringTokenReplacer(); - this.PropertySource[PropertySource_dcf] = new ForumsModuleTokenReplacer(portalSettings, forumGroupInfo.TabId, forumGroupInfo.ModuleId, portalSettings.ActiveTab.TabID == -1 || portalSettings.ActiveTab.TabID == portalSettings.HomeTabId? forumGroupInfo.TabId : portalSettings.ActiveTab.TabID, portalSettings.ActiveTab.ModuleID == -1 ? forumGroupInfo.ModuleId : portalSettings.ActiveTab.ModuleID, requestUri, rawUrl); + this.PropertySource[PropertySource_dcf] = new ForumsModuleTokenReplacer(portalSettings, forumGroupInfo.TabId, forumGroupInfo.ModuleId, portalSettings.ActiveTab.TabID == -1 || portalSettings.ActiveTab.TabID == portalSettings.HomeTabId ? forumGroupInfo.TabId : portalSettings.ActiveTab.TabID, portalSettings.ActiveTab.ModuleID == -1 ? forumGroupInfo.ModuleId : portalSettings.ActiveTab.ModuleID, requestUri, rawUrl); this.PropertySource[PropertySource_forumgroup] = forumGroupInfo; this.PropertySource[PropertySource_forumuser] = forumUser; this.PropertySource[PropertySource_user] = forumUser.UserInfo; @@ -294,7 +297,7 @@ internal static StringBuilder ReplaceUserTokens(StringBuilder template, PortalSe internal static StringBuilder ReplaceTopicTokens(StringBuilder template, TopicInfo topic, PortalSettings portalSettings, SettingsInfo mainSettings, INavigationManager navigationManager, ForumUserInfo forumUser, Uri requestUri, string rawUrl) { - topic.Content.Body = ReplaceBody(topic.Content, mainSettings, requestUri).Replace("
", " "); + topic.Content.Body = ReplaceBody(topic.Content.Body, mainSettings, requestUri).Replace("
", " "); topic.Content.Summary = topic.Content.Summary.Replace("
", " "); template = ResourceStringTokenReplacer.ReplaceResourceTokens(template); @@ -305,53 +308,54 @@ internal static StringBuilder ReplaceTopicTokens(StringBuilder template, TopicIn return template; } - private static string ReplaceBody(ContentInfo content, SettingsInfo mainSettings, Uri uri) + private static string ReplaceBody(string body, SettingsInfo mainSettings, Uri uri) { - var sBody = content?.Body; - if (string.IsNullOrEmpty(content?.Body)) - { - sBody = "
"; - } - else + if (!string.IsNullOrEmpty(body)) { - sBody = Utilities.ManageImagePath(HttpUtility.HtmlDecode(content?.Body), uri); - - sBody = sBody.Replace("[", "[").Replace("]", "]"); - if (sBody.ToUpper().Contains("[CODE]")) + body = Utilities.ManageImagePath(HttpUtility.HtmlDecode(body), uri); + body = body.Replace("[", "[").Replace("]", "]"); + if (body.ToUpper().Contains("[CODE]")) { - sBody = Regex.Replace(sBody, "([CODE])", "[CODE]", RegexOptions.IgnoreCase); - sBody = Regex.Replace(sBody, "([\\/CODE])", "[/CODE]", RegexOptions.IgnoreCase); + body = Regex.Replace(body, "([CODE])", "[CODE]", RegexOptions.IgnoreCase); + body = Regex.Replace(body, "([\\/CODE])", "[/CODE]", RegexOptions.IgnoreCase); } // sBody = sBody.Replace("<CODE>", "") - if (Regex.IsMatch(sBody, "\\[CODE([^>]*)\\]", RegexOptions.IgnoreCase)) + if (Regex.IsMatch(body, "\\[CODE([^>]*)\\]", RegexOptions.IgnoreCase)) { - var objCode = new CodeParser(); - sBody = CodeParser.ParseCode(HttpUtility.HtmlDecode(sBody)); + body = CodeParser.ParseCode(HttpUtility.HtmlDecode(body)); } - sBody = Utilities.StripExecCode(sBody); + body = Utilities.StripExecCode(body); if (mainSettings.AutoLinkEnabled) { - sBody = Utilities.AutoLinks(sBody, uri.Host); + body = Utilities.AutoLinks(body, uri.Host); } - if (sBody.Contains("<%@")) + if (body.Contains("<%@")) { - sBody = sBody.Replace("<%@ ", "<%@ "); + body = body.Replace("<%@ ", "<%@ "); } - if (content.Body.ToLowerInvariant().Contains("runat")) + if (body.ToLowerInvariant().Contains("runat")) { - sBody = Regex.Replace(sBody, "runat", "runat", RegexOptions.IgnoreCase); + body = Regex.Replace(body, "runat", "runat", RegexOptions.IgnoreCase); } } - return sBody; + return body; } internal static StringBuilder ReplacePostTokens(StringBuilder template, IPostInfo post, PortalSettings portalSettings, SettingsInfo mainSettings, INavigationManager navigationManager, ForumUserInfo forumUser, Uri requestUri, string rawUrl) { + /* if likes not allowed for forum, remove like-related tokens */ + if (!post.Forum.AllowLikes) + { + template = RemovePrefixedToken(template, "[FORUMPOST:LINKONCLICK"); + template = RemovePrefixedToken(template, "[FORUMPOST:LIKECOUNT"); + template = RemovePrefixedToken(template, "[FORUMPOST:ISLIKED"); + } + // Perform Profile Related replacements var author = new AuthorInfo(post.PortalId, post.Forum.ModuleId, post.Author.AuthorId); if (template.ToString().Contains("[POSTINFO]")) @@ -360,7 +364,7 @@ internal static StringBuilder ReplacePostTokens(StringBuilder template, IPostInf template.Replace("[POSTINFO]", sPostInfo); } - post.Content.Body = ReplaceBody(post.Content, mainSettings, requestUri).Replace("
", " "); + post.Content.Body = ReplaceBody(post.Content.Body, mainSettings, requestUri).Replace("
", " "); template = ResourceStringTokenReplacer.ReplaceResourceTokens(template); var tokenReplacer = new TokenReplacer(portalSettings, forumUser, post, requestUri, rawUrl) { AccessingUser = forumUser.UserInfo, }; @@ -407,7 +411,7 @@ internal static StringBuilder ReplaceDateToken(StringBuilder template, string to return template; } - + internal static StringBuilder RemoveObsoleteTokens(StringBuilder template) { // no longer using this @@ -932,6 +936,10 @@ internal static StringBuilder MapLegacyPostTokenSynonyms(StringBuilder template, template = ReplaceLegacyTokenWithFormatString(template, portalSettings, language, "[LINK]", "[FORUMPOST:LINK", "[LINK]"); template = ReplaceLegacyTokenWithFormatString(template, portalSettings, language, "[HYPERLINK]", "[FORUMPOST:LINK", "[LINK]"); + template = ReplaceLegacyTokenWithFormatString(template, portalSettings, language, "[LIKES]", "[FORUMPOST:LIKEONCLICK", "[LIKESx1]"); + template = ReplaceLegacyTokenWithFormatString(template, portalSettings, language, "[LIKESx2]", "[FORUMPOST:LIKEONCLICK", "[LIKESx2]"); + template = ReplaceLegacyTokenWithFormatString(template, portalSettings, language, "[LIKESx3]", "[FORUMPOST:LIKEONCLICK", "[LIKESx3]"); + return template; } diff --git a/Dnn.CommunityForums/scripts/afcommon.js b/Dnn.CommunityForums/scripts/afcommon.js index ad4d5fee..a01af10f 100644 --- a/Dnn.CommunityForums/scripts/afcommon.js +++ b/Dnn.CommunityForums/scripts/afcommon.js @@ -282,9 +282,12 @@ function amaf_likePost(mid, fid, cid) { url: dnn.getVar("sf_siteRoot", "/") + 'API/ActiveForums/Like/Like', beforeSend: sf.setModuleHeaders }).done(function (data) { + $('#af-topicview-likes-' + cid).toggleClass('fa-thumbs-up').toggleClass('fa-thumbs-o-up').text(" " + data); + /* these are for backward compatibility and can be remove in v10 */ $('#af-topicview-likes1-' + cid).toggleClass('fa-thumbs-up').toggleClass('fa-thumbs-o-up').text(" " + data); $('#af-topicview-likes2-' + cid).toggleClass('fa-thumbs-up').toggleClass('fa-thumbs-o-up').text(" " + data); $('#af-topicview-likes3-' + cid).toggleClass('fa-thumbs-up').toggleClass('fa-thumbs-o-up').text(" " + data); + /* these are for backward compatibility and can be remove in v10 */ }).fail(function (xhr, status) { alert('error liking post'); }); diff --git a/Dnn.CommunityForums/themes/community-bootstrap/templates/TopicView.ascx b/Dnn.CommunityForums/themes/community-bootstrap/templates/TopicView.ascx index e3c72fe4..8d7b945b 100644 --- a/Dnn.CommunityForums/themes/community-bootstrap/templates/TopicView.ascx +++ b/Dnn.CommunityForums/themes/community-bootstrap/templates/TopicView.ascx @@ -95,10 +95,10 @@
[FORUMPOST:MODEDITDATE]
-
- [LIKESx2] -
- +
+ [FORUMPOST:LIKEONCLICK| [FORUMPOST:LIKECOUNT]| [FORUMPOST:LIKECOUNT]] +
+ @@ -145,9 +145,9 @@
[FORUMPOST:MODEDITDATE]
-
- [LIKESx2] -
+
+ [FORUMPOST:LIKEONCLICK| [FORUMPOST:LIKECOUNT]| [FORUMPOST:LIKECOUNT]] +
diff --git a/Dnn.CommunityForums/themes/community-default/templates/TopicView.ascx b/Dnn.CommunityForums/themes/community-default/templates/TopicView.ascx index c9c5d477..fae30fa2 100644 --- a/Dnn.CommunityForums/themes/community-default/templates/TopicView.ascx +++ b/Dnn.CommunityForums/themes/community-default/templates/TopicView.ascx @@ -101,9 +101,9 @@
[FORUMPOST:MODEDITDATE]
-
- [LIKESx2] -
+
+ [FORUMPOST:LIKEONCLICK| [FORUMPOST:LIKECOUNT]| [FORUMPOST:LIKECOUNT]] +
@@ -156,9 +156,9 @@
[FORUMPOST:MODEDITDATE]
-
- [LIKESx2] -
+
+ [FORUMPOST:LIKEONCLICK| [FORUMPOST:LIKECOUNT]| [FORUMPOST:LIKECOUNT]] +