public GetForumPermissions ( int forumId ) : Permissions | ||
forumId | int | |
return | Permissions |
private XmlRpcStruct GetTopicStatus(IEnumerable<int> topicIds) { var aftContext = ActiveForumsTapatalkModuleContext.Create(Context); if (aftContext == null || aftContext.Module == null) throw new XmlRpcFaultException(100, "Invalid Context"); Context.Response.AddHeader("Mobiquo_is_login", aftContext.UserId > 0 ? "true" : "false"); var portalId = aftContext.Module.PortalID; var forumModuleId = aftContext.ModuleSettings.ForumModuleId; var userId = aftContext.UserId; // Build a list of forums the user has access to var fc = new AFTForumController(); var forumIds = fc.GetForumsForUser(aftContext.ForumUser.UserRoles, portalId, forumModuleId, "CanRead"); var topicIdsString = topicIds.Aggregate(string.Empty, (current, topicId) => current + (topicId.ToString() + ";")); var unreadTopics = fc.GetTopicStatus(portalId, forumModuleId, userId, forumIds, topicIdsString).ToList(); return new XmlRpcStruct { {"result", true}, {"status", unreadTopics.Select(t => new TopicStatusStructure(){ TopicId = t.TopicId.ToString(), HasNewPosts = (t.LastReplyId < 0 && t.TopicId > t.UserLastTopicRead) || t.LastReplyId > t.UserLastReplyRead, IsLocked = t.IsLocked, IsSubscribed = t.SubscriptionType > 0, CanSubscribe = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fc.GetForumPermissions(t.ForumId).CanSubscribe), // GetforumPermissions uses cache so it shouldn't be a performance issue ReplyCount = t.ReplyCount, ViewCount = t.ViewCount, LastReplyDate = t.LastReplyDate }).ToArray()} }; }
private XmlRpcStruct GetLatestTopics(int startIndex, int endIndex, string searchId, object filters) { var aftContext = ActiveForumsTapatalkModuleContext.Create(Context); if (aftContext == null || aftContext.Module == null) throw new XmlRpcFaultException(100, "Invalid Context"); Context.Response.AddHeader("Mobiquo_is_login", aftContext.UserId > 0 ? "true" : "false"); var portalId = aftContext.Module.PortalID; var forumModuleId = aftContext.ModuleSettings.ForumModuleId; var userId = aftContext.UserId; // Build a list of forums the user has access to var fc = new AFTForumController(); var forumIds = fc.GetForumsForUser(aftContext.ForumUser.UserRoles, portalId, forumModuleId, "CanRead"); var mainSettings = new SettingsInfo { MainSettings = new Entities.Modules.ModuleController().GetModuleSettings(forumModuleId) }; var maxRows = endIndex + 1 - startIndex; var latestTopics = fc.GetLatestTopics(portalId, forumModuleId, userId, forumIds, startIndex, maxRows).ToList(); return new XmlRpcStruct { {"result", true}, {"total_topic_num", latestTopics.Count > 0 ? latestTopics[0].TopicCount : 0}, {"topics", latestTopics.Select(t => new ExtendedTopicStructure{ TopicId = t.TopicId.ToString(), AuthorAvatarUrl = GetAvatarUrl(t.LastReplyAuthorId), AuthorId = t.LastReplyAuthorId.ToString(), AuthorName = GetLastReplyAuthorName(mainSettings, t).ToBytes(), ForumId = t.ForumId.ToString(), ForumName = t.ForumName.ToBytes(), HasNewPosts = (t.LastReplyId < 0 && t.TopicId > t.UserLastTopicRead) || t.LastReplyId > t.UserLastReplyRead, IsLocked = t.IsLocked, IsSubscribed = t.SubscriptionType > 0, CanSubscribe = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fc.GetForumPermissions(t.ForumId).CanSubscribe), // GetforumPermissions uses cache so it shouldn't be a performance issue ReplyCount = t.ReplyCount, Summary = GetSummary(null, t.LastReplyBody).ToBytes(), ViewCount = t.ViewCount, DateCreated = t.LastReplyDate, Title = HttpUtility.HtmlDecode(t.Subject + string.Empty).ToBytes() }).ToArray()} }; }
private XmlRpcStruct GetQuote(string postIds) { var aftContext = ActiveForumsTapatalkModuleContext.Create(Context); if (aftContext == null || aftContext.Module == null) throw new XmlRpcFaultException(100, "Invalid Context"); Context.Response.AddHeader("Mobiquo_is_login", aftContext.UserId > 0 ? "true" : "false"); var portalId = aftContext.Module.PortalID; var forumModuleId = aftContext.ModuleSettings.ForumModuleId; var fc = new AFTForumController(); // Load our forum settings var mainSettings = new SettingsInfo { MainSettings = new Entities.Modules.ModuleController().GetModuleSettings(forumModuleId) }; // Get our quote template info var postedByTemplate = Utilities.GetSharedResource("[RESX:PostedBy]") + " {0} {1} {2}"; var sharedOnText = Utilities.GetSharedResource("On.Text"); var contentIds = postIds.Split('-').Select(int.Parse).ToList(); if (contentIds.Count > 25) // Let's be reasonable throw new XmlRpcFaultException(100, "Bad Request"); var postContent = new StringBuilder(); foreach (var contentId in contentIds) { // Retrieve the forum post var forumPost = fc.GetForumPost(portalId, forumModuleId, contentId); if (forumPost == null) throw new XmlRpcFaultException(100, "Bad Request"); // Verify read permissions - Need to do this for every content id as we can not assume they are all from the same forum (even though they probably should be) var fp = fc.GetForumPermissions(forumPost.ForumId); if (!ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanRead)) continue; // Build our sanitized quote var postedBy = string.Format(postedByTemplate, GetAuthorName(mainSettings, forumPost), sharedOnText, GetServerDateTime(mainSettings, forumPost.DateCreated)); postContent.Append(HtmlToTapatalkQuote(postedBy, forumPost.Body)); postContent.Append("\r\n"); // add the result } return new XmlRpcStruct { {"post_id", postIds}, {"post_title", string.Empty.ToBytes()}, {"post_content", postContent.ToString().ToBytes()} }; }
private TopicListStructure GetTopic(int forumId, int startIndex, int endIndex, string mode = null) { var aftContext = ActiveForumsTapatalkModuleContext.Create(Context); if (aftContext == null || aftContext.Module == null) throw new XmlRpcFaultException(100, "Invalid Context"); Context.Response.AddHeader("Mobiquo_is_login", aftContext.UserId > 0 ? "true" : "false"); var portalId = aftContext.Module.PortalID; var forumModuleId = aftContext.ModuleSettings.ForumModuleId; var fc = new AFTForumController(); var fp = fc.GetForumPermissions(forumId); if (!ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanRead)) throw new XmlRpcFaultException(100, "No Read Permissions"); var maxRows = endIndex + 1 - startIndex; var forumTopicsSummary = fc.GetForumTopicSummary(portalId, forumModuleId, forumId, aftContext.UserId, mode); var forumTopics = fc.GetForumTopics(portalId, forumModuleId, forumId, aftContext.UserId, startIndex, maxRows, mode); var canSubscribe = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanSubscribe); var mainSettings = new SettingsInfo { MainSettings = new Entities.Modules.ModuleController().GetModuleSettings(forumModuleId) }; var profilePath = string.Format("{0}://{1}{2}", Context.Request.Url.Scheme, Context.Request.Url.Host, VirtualPathUtility.ToAbsolute("~/profilepic.ashx")); var forumTopicsStructure = new TopicListStructure { CanPost = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanCreate), ForumId = forumId.ToString(), ForumName = forumTopicsSummary.ForumName.ToBytes(), TopicCount = forumTopicsSummary.TopicCount, Topics = forumTopics.Select(t => new TopicStructure{ TopicId = t.TopicId.ToString(), AuthorAvatarUrl = string.Format("{0}?userId={1}&w=64&h=64", profilePath, t.AuthorId), AuthorName = GetAuthorName(mainSettings, t).ToBytes(), CanSubscribe = canSubscribe, ForumId = forumId.ToString(), HasNewPosts = (t.LastReplyId < 0 && t.TopicId > t.UserLastTopicRead) || t.LastReplyId > t.UserLastReplyRead, IsLocked = t.IsLocked, IsSubscribed = t.SubscriptionType > 0, LastReplyDate = t.LastReplyDate, ReplyCount = t.ReplyCount, Summary = GetSummary(t.Summary, t.Body).ToBytes(), ViewCount = t.ViewCount, Title = HttpUtility.HtmlDecode(t.Subject + string.Empty).ToBytes() }).ToArray() }; return forumTopicsStructure; }
private PostListStructure GetThread(int topicId, int startIndex, int endIndex, bool returnHtml) { var aftContext = ActiveForumsTapatalkModuleContext.Create(Context); if (aftContext == null || aftContext.Module == null) throw new XmlRpcFaultException(100, "Invalid Context"); Context.Response.AddHeader("Mobiquo_is_login", aftContext.UserId > 0 ? "true" : "false"); var portalId = aftContext.Module.PortalID; var forumModuleId = aftContext.ModuleSettings.ForumModuleId; var fc = new AFTForumController(); var forumId = fc.GetTopicForumId(topicId); if (forumId <= 0) throw new XmlRpcFaultException(100, "Invalid Topic"); var fp = fc.GetForumPermissions(forumId); if (!ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanRead)) throw new XmlRpcFaultException(100, "No Read Permissions"); var maxRows = endIndex + 1 - startIndex; var forumPostSummary = fc.GetForumPostSummary(aftContext.Module.PortalID, aftContext.ModuleSettings.ForumModuleId, forumId, topicId, aftContext.UserId); var forumPosts = fc.GetForumPosts(aftContext.Module.PortalID, aftContext.ModuleSettings.ForumModuleId, forumId, topicId, aftContext.UserId, startIndex, maxRows); var breadCrumbs = new List<BreadcrumbStructure> { new BreadcrumbStructure { ForumId = 'G' + forumPostSummary.ForumGroupId.ToString(), IsCategory = true, Name = forumPostSummary.GroupName.ToBytes() }, }; // If we're in a sub forum, add the parent to the breadcrumb if (forumPostSummary.ParentForumId > 0) breadCrumbs.Add(new BreadcrumbStructure { ForumId = forumPostSummary.ParentForumId.ToString(), IsCategory = false, Name = forumPostSummary.ParentForumName.ToBytes() }); breadCrumbs.Add(new BreadcrumbStructure { ForumId = forumId.ToString(), IsCategory = false, Name = forumPostSummary.ForumName.ToBytes() }); var mainSettings = new SettingsInfo { MainSettings = new Entities.Modules.ModuleController().GetModuleSettings(forumModuleId) }; var profilePath = string.Format("{0}://{1}{2}", Context.Request.Url.Scheme, Context.Request.Url.Host, VirtualPathUtility.ToAbsolute("~/profilepic.ashx")); var result = new PostListStructure { PostCount = forumPostSummary.ReplyCount + 1, CanReply = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanReply), CanSubscribe = ActiveForums.Permissions.HasPerm(aftContext.ForumUser.UserRoles, fp.CanSubscribe), ForumId = forumId, ForumName = forumPostSummary.ForumName.ToBytes(), IsLocked = forumPostSummary.IsLocked, IsSubscribed = forumPostSummary.SubscriptionType > 0, Subject = forumPostSummary.Subject.ToBytes(), TopicId = topicId, Posts = forumPosts.Select(p => new PostStructure { PostID = p.ContentId.ToString(), AuthorAvatarUrl = string.Format("{0}?userId={1}&w=64&h=64", profilePath, p.AuthorId), AuthorName = GetAuthorName(mainSettings, p).ToBytes(), AuthorId = p.AuthorId.ToString(), Body = HtmlToTapatalk(p.Body, returnHtml).ToBytes(), CanEdit = false, // TODO: Fix this IsOnline = p.IsUserOnline, PostDate = p.DateCreated, Subject = p.Subject.ToBytes() }).ToArray(), Breadcrumbs = breadCrumbs.ToArray() }; return result; }