예제 #1
0
        private string MarkAnswer()
        {
            int topicId = -1;
            int forumId = -1;
            int replyId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            if (topicId > 0 & UserId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        t  = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB    db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum           f  = fc.Forums_Get(forumId, this.UserId, true);
                if ((this.UserId == t.Author.AuthorId && !t.IsLocked) || Permissions.HasAccess(f.Security.ModEdit, ForumUser.UserRoles))
                {
                    DataProvider.Instance().Reply_UpdateStatus(PortalId, ModuleId, topicId, replyId, UserId, 1, Permissions.HasAccess(f.Security.ModEdit, ForumUser.UserRoles));
                }
                return(BuildOutput(string.Empty, OutputCodes.Success, true));
            }
            else
            {
                return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
            }
        }
예제 #2
0
        private string MoveTopic()
        {
            int topicId       = -1;
            int forumId       = -1;
            int targetForumId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("forumid") && SimulateIsNumeric.IsNumeric(Params["forumid"]))
            {
                targetForumId = int.Parse(Params["forumid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        t  = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB    db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum           f  = fc.Forums_Get(forumId, this.UserId, true);
                if (f != null)
                {
                    if (Permissions.HasPerm(f.Security.ModMove, ForumUser.UserRoles))
                    {
                        tc.Topics_Move(PortalId, ModuleId, targetForumId, topicId);
                        DataCache.ClearAllCache(ModuleId, TabId);
                        return(BuildOutput(string.Empty, OutputCodes.Success, true));
                    }
                }
            }
            return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
        }
예제 #3
0
        private string DeleteTopic()
        {
            int topicId = -1;
            int forumId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        t  = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB    db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum           f  = fc.Forums_Get(forumId, this.UserId, true);
                if (f != null)
                {
                    if (Permissions.HasPerm(f.Security.ModDelete, ForumUser.UserRoles) || (t.Author.AuthorId == this.UserId && Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles)))
                    {
                        tc.Topics_Delete(PortalId, ModuleId, forumId, topicId, MainSettings.DeleteBehavior);
                        return(BuildOutput(string.Empty, OutputCodes.Success, true));
                    }
                }
            }
            return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
        }
예제 #4
0
        private string DeletePost()
        {
            int replyId = -1;
            int TopicId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                TopicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            int forumId = -1;

            Data.ForumsDB db = new Data.ForumsDB();
            forumId = db.Forum_GetByTopicId(TopicId);
            ForumController fc = new ForumController();
            Forum           f  = fc.Forums_Get(forumId, this.UserId, true);

            if (TopicId > 0 & replyId < 1)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        ti = tc.Topics_Get(PortalId, ModuleId, TopicId);

                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ti.Content.AuthorId == UserId && ti.IsLocked == false))
                {
                    DataProvider.Instance().Topics_Delete(forumId, TopicId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}", forumId.ToString(), TopicId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
                }
            }
            else
            {
                ReplyController rc = new ReplyController();
                ReplyInfo       ri = rc.Reply_Get(PortalId, ModuleId, TopicId, replyId);
                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ri.Content.AuthorId == UserId))
                {
                    DataProvider.Instance().Reply_Delete(forumId, TopicId, replyId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}:{2}", forumId.ToString(), TopicId.ToString(), replyId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
                }
            }
            string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);

            DataCache.CacheClearPrefix(cachekey);
            return(BuildOutput(TopicId + "|" + replyId, OutputCodes.Success, true));
        }
예제 #5
0
        private string SaveTopic()
        {
            int topicId = -1;
            int forumId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo t = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum f = fc.Forums_Get(PortalId, -1, forumId, this.UserId, true, false, -1);
                if (Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles))
                {
                    string subject = Params["subject"].ToString();
                    subject = Utilities.XSSFilter(subject, true);
                    if (! (string.IsNullOrEmpty(f.PrefixURL)))
                    {
                        string cleanSubject = Utilities.CleanName(subject).ToLowerInvariant();
                        if (SimulateIsNumeric.IsNumeric(cleanSubject))
                        {
                            cleanSubject = "Topic-" + cleanSubject;
                        }
                        string topicUrl = cleanSubject;
                        string urlPrefix = "/";
                        if (! (string.IsNullOrEmpty(f.ForumGroup.PrefixURL)))
                        {
                            urlPrefix += f.ForumGroup.PrefixURL + "/";
                        }
                        if (! (string.IsNullOrEmpty(f.PrefixURL)))
                        {
                            urlPrefix += f.PrefixURL + "/";
                        }
                        string urlToCheck = urlPrefix + cleanSubject;
                        Data.Topics topicsDb = new Data.Topics();
                        for (int u = 0; u <= 200; u++)
                        {
                            int tid = topicsDb.TopicIdByUrl(PortalId, f.ModuleId, urlToCheck);
                            if (tid > 0 && tid == topicId)
                            {
                                break;
                            }
                            else if (tid > 0)
                            {
                                topicUrl = (u + 1) + "-" + cleanSubject;
                                urlToCheck = urlPrefix + topicUrl;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (topicUrl.Length > 150)
                        {
                            topicUrl = topicUrl.Substring(0, 149);
                            topicUrl = topicUrl.Substring(0, topicUrl.LastIndexOf("-"));
                        }
                        t.TopicUrl = topicUrl;
                        //.URL = topicUrl
                    }
                    else
                    {
                        //.URL = String.Empty
                        t.TopicUrl = string.Empty;
                    }
                    t.Content.Subject = subject;
                    t.IsPinned = bool.Parse(Params["pinned"].ToString());
                    t.IsLocked = bool.Parse(Params["locked"].ToString());
                    t.Priority = int.Parse(Params["priority"].ToString());
                    t.StatusId = int.Parse(Params["status"].ToString());
                    if (f.Properties != null)
                    {
                        StringBuilder tData = new StringBuilder();
                        tData.Append("<topicdata>");
                        tData.Append("<properties>");
                        foreach (PropertiesInfo p in f.Properties)
                        {
                            string pkey = "prop-" + p.PropertyId.ToString();

                            tData.Append("<property id=\"" + p.PropertyId.ToString() + "\">");
                            tData.Append("<name><![CDATA[");
                            tData.Append(p.Name);
                            tData.Append("]]></name>");
                            if (Params[pkey] != null)
                            {
                                tData.Append("<value><![CDATA[");
                                tData.Append(Utilities.XSSFilter(Params[pkey].ToString()));
                                tData.Append("]]></value>");
                            }
                            else
                            {
                                tData.Append("<value></value>");
                            }
                            tData.Append("</property>");
                        }
                        tData.Append("</properties>");
                        tData.Append("</topicdata>");
                        t.TopicData = tData.ToString();
                    }
                }
                tc.TopicSave(PortalId, t);
                if (Params["tags"] != null)
                {
                    DataProvider.Instance().Tags_DeleteByTopicId(PortalId, f.ModuleId, topicId);
                    string tagForm = string.Empty;
                    if (Params["tags"] != null)
                    {
                        tagForm = Params["tags"].ToString();
                    }
                    if (! (tagForm == string.Empty))
                    {
                        string[] Tags = tagForm.Split(',');
                        foreach (string tag in Tags)
                        {
                            string sTag = Utilities.CleanString(PortalId, tag.Trim(), false, EditorTypes.TEXTBOX, false, false, f.ModuleId, string.Empty, false);
                            DataProvider.Instance().Tags_Save(PortalId, f.ModuleId, -1, sTag, 0, 1, 0, topicId, false, -1, -1);
                        }
                    }
                }

                if (Params["categories"] != null)
                {
                    string[] cats = Params["categories"].ToString().Split(';');
                    DataProvider.Instance().Tags_DeleteTopicToCategory(PortalId, f.ModuleId, -1, topicId);
                    foreach (string c in cats)
                    {
                        int cid = -1;
                        if (! (string.IsNullOrEmpty(c)) && SimulateIsNumeric.IsNumeric(c))
                        {
                            cid = Convert.ToInt32(c);
                            if (cid > 0)
                            {
                                DataProvider.Instance().Tags_AddTopicToCategory(PortalId, f.ModuleId, cid, topicId);
                            }
                        }
                    }
                }
            }

            return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
        }
예제 #6
0
 private string PinTopic()
 {
     int topicId = -1;
     int forumId = -1;
     if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
     {
         topicId = int.Parse(Params["topicid"].ToString());
     }
     if (topicId > 0)
     {
         TopicsController tc = new TopicsController();
         TopicInfo t = tc.Topics_Get(PortalId, ModuleId, topicId);
         Data.ForumsDB db = new Data.ForumsDB();
         forumId = db.Forum_GetByTopicId(topicId);
         ForumController fc = new ForumController();
         Forum f = fc.Forums_Get(forumId, this.UserId, true);
         if (f != null)
         {
             if (Permissions.HasPerm(f.Security.ModPin, ForumUser.UserRoles) || (t.Author.AuthorId == this.UserId && Permissions.HasAccess(f.Security.Pin, ForumUser.UserRoles)))
             {
                 if (t.IsPinned)
                 {
                     t.IsPinned = false;
                 }
                 else
                 {
                     t.IsPinned = true;
                 }
                 tc.TopicSave(PortalId, t);
                 return BuildOutput(string.Empty, OutputCodes.Success, true);
             }
         }
     }
     return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
 }
예제 #7
0
        private string MoveTopic()
        {
            int topicId = -1;
            int forumId = -1;
            int targetForumId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("forumid") && SimulateIsNumeric.IsNumeric(Params["forumid"]))
            {
                targetForumId = int.Parse(Params["forumid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo t = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum f = fc.Forums_Get(forumId, this.UserId, true);
                if (f != null)
                {
                    if (Permissions.HasPerm(f.Security.ModMove, ForumUser.UserRoles))
                    {
                        tc.Topics_Move(PortalId, ModuleId, targetForumId, topicId);
                        DataCache.ClearAllCache(ModuleId, TabId);
                        return BuildOutput(string.Empty, OutputCodes.Success, true);
                    }
                }

            }
            return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
        }
예제 #8
0
        private string MarkAnswer()
        {
            int topicId = -1;
            int forumId = -1;
            int replyId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            if (topicId > 0 & UserId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo t = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum f = fc.Forums_Get(forumId, this.UserId, true);
                if ((this.UserId == t.Author.AuthorId && ! t.IsLocked) || Permissions.HasAccess(f.Security.ModEdit, ForumUser.UserRoles))
                {
                    DataProvider.Instance().Reply_UpdateStatus(PortalId, ModuleId, topicId, replyId, UserId, 1, Permissions.HasAccess(f.Security.ModEdit, ForumUser.UserRoles));

                }
                return BuildOutput(string.Empty, OutputCodes.Success, true);
            }
            else
            {
                return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
            }
        }
예제 #9
0
        private string LoadTopic()
        {
            int topicId = -1;
            int forumId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo t = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum f = fc.Forums_Get(PortalId, -1, forumId, this.UserId, true, false, -1);
                if (f != null)
                {
                    if (Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles))
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("{");
                        sb.Append(Utilities.JSON.Pair("topicid", t.TopicId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("subject", t.Content.Subject));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("authorid", t.Content.AuthorId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("locked", t.IsLocked.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("pinned", t.IsPinned.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("priority", t.Priority.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("status", t.StatusId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("forumid", forumId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("forumname", f.ForumName));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("tags", t.Tags));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("categories", t.Categories));
                        sb.Append(",");
                        sb.Append("\"properties\":[");
                        string sCats = string.Empty;
                        if (f.Properties != null)
                        {
                            int i = 0;
                            foreach (PropertiesInfo p in f.Properties)
                            {
                                sb.Append("{");
                                sb.Append(Utilities.JSON.Pair("propertyid", p.PropertyId.ToString()));
                                sb.Append(",");
                                sb.Append(Utilities.JSON.Pair("datatype", p.DataType));
                                sb.Append(",");
                                sb.Append(Utilities.JSON.Pair("propertyname", p.Name));
                                sb.Append(",");
                                string pvalue = p.DefaultValue;
                                foreach (PropertiesInfo tp in t.TopicProperties)
                                {
                                    if (tp.PropertyId == p.PropertyId)
                                    {
                                        pvalue = tp.DefaultValue;
                                    }
                                }

                                sb.Append(Utilities.JSON.Pair("propertyvalue", pvalue));
                                if (p.DataType.Contains("list"))
                                {
                                    sb.Append(",\"listdata\":[");
                                    if (p.DataType.Contains("list|categories"))
                                    {
                                        using (IDataReader dr = DataProvider.Instance().Tags_List(PortalId, f.ModuleId, true, 0, 200, "ASC", "TagName", forumId, f.ForumGroupId))
                                        {
                                            dr.NextResult();
                                            while (dr.Read())
                                            {
                                                sCats += "{";
                                                sCats += Utilities.JSON.Pair("id", dr["TagId"].ToString());
                                                sCats += ",";
                                                sCats += Utilities.JSON.Pair("name", dr["TagName"].ToString());
                                                sCats += ",";
                                                sCats += Utilities.JSON.Pair("selected", IsSelected(dr["TagName"].ToString(), t.Categories).ToString());
                                                sCats += "},";
                                            }
                                            dr.Close();
                                        }
                                        if (! (string.IsNullOrEmpty(sCats)))
                                        {
                                            sCats = sCats.Substring(0, sCats.Length - 1);
                                        }
                                        sb.Append(sCats);
                                    }
                                    else
                                    {
                                        DotNetNuke.Common.Lists.ListController lists = new DotNetNuke.Common.Lists.ListController();
                                        string lName = p.DataType.Substring(p.DataType.IndexOf("|") + 1);
                                        DotNetNuke.Common.Lists.ListEntryInfoCollection lc = lists.GetListEntryInfoCollection(lName, string.Empty);
                                        int il = 0;
                                        foreach (DotNetNuke.Common.Lists.ListEntryInfo l in lc)
                                        {
                                            sb.Append("{");
                                            sb.Append(Utilities.JSON.Pair("itemId", l.Value));
                                            sb.Append(",");
                                            sb.Append(Utilities.JSON.Pair("itemName", l.Text));
                                            sb.Append("}");
                                            il += 1;
                                            if (il < lc.Count)
                                            {
                                                sb.Append(",");
                                            }
                                        }
                                    }
                                    sb.Append("]");
                                }
                                sb.Append("}");
                                i += 1;
                                if (i < f.Properties.Count)
                                {
                                    sb.Append(",");
                                }

                            }
                        }

                        sb.Append("],\"categories\":[");
                        sCats = string.Empty;
                        using (IDataReader dr = DataProvider.Instance().Tags_List(PortalId, f.ModuleId, true, 0, 200, "ASC", "TagName", forumId, f.ForumGroupId))
                        {
                            dr.NextResult();
                            while (dr.Read())
                            {
                                sCats += "{";
                                sCats += Utilities.JSON.Pair("id", dr["TagId"].ToString());
                                sCats += ",";
                                sCats += Utilities.JSON.Pair("name", dr["TagName"].ToString());
                                sCats += ",";
                                sCats += Utilities.JSON.Pair("selected", IsSelected(dr["TagName"].ToString(), t.Categories).ToString());
                                sCats += "},";
                            }
                            dr.Close();
                        }
                        if (! (string.IsNullOrEmpty(sCats)))
                        {
                            sCats = sCats.Substring(0, sCats.Length - 1);
                        }
                        sb.Append(sCats);
                        sb.Append("]");
                        sb.Append("}");
                        return BuildOutput(sb.ToString(), OutputCodes.Success, true, true);
                    }
                }

            }
            return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
        }
예제 #10
0
        private string DeletePost()
        {
            int replyId = -1;
            int TopicId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                TopicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            int forumId = -1;
            Data.ForumsDB db = new Data.ForumsDB();
            forumId = db.Forum_GetByTopicId(TopicId);
            ForumController fc = new ForumController();
            Forum f = fc.Forums_Get(forumId, this.UserId, true);

            // Need to get the list of attachments BEFORE we remove the post recods
            var attachmentController = new Data.AttachController();
            var attachmentList = (MainSettings.DeleteBehavior == 0)
                                     ? attachmentController.ListForPost(TopicId, replyId)
                                     : null;

            if (TopicId > 0 & replyId < 1)
            {
                TopicsController tc = new TopicsController();
                TopicInfo ti = tc.Topics_Get(PortalId, ModuleId, TopicId);

                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ti.Content.AuthorId == UserId && ti.IsLocked == false))
                {
                    DataProvider.Instance().Topics_Delete(forumId, TopicId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}", forumId.ToString(), TopicId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
                }
            }
            else
            {
                ReplyController rc = new ReplyController();
                ReplyInfo ri = rc.Reply_Get(PortalId, ModuleId, TopicId, replyId);
                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ri.Content.AuthorId == UserId))
                {
                    DataProvider.Instance().Reply_Delete(forumId, TopicId, replyId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}:{2}", forumId.ToString(), TopicId.ToString(), replyId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);

                }
                else
                {
                    return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
                }

            }

            // If it's a hard delete, delete associated attachments
            // attachmentList will only be populated if the DeleteBehavior is 0
            if (attachmentList != null)
            {
                var fileManager = FileManager.Instance;
                var folderManager = FolderManager.Instance;
                var attachmentFolder = folderManager.GetFolder(PortalId, "activeforums_Attach");

                foreach (var attachment in attachmentList)
                {
                    attachmentController.Delete(attachment.AttachmentId);

                    var file = attachment.FileId.HasValue
                                   ? fileManager.GetFile(attachment.FileId.Value)
                                   : fileManager.GetFile(attachmentFolder, attachment.FileName);

                    // Only delete the file if it exists in the attachment folder
                    if (file != null && file.FolderId == attachmentFolder.FolderID)
                        fileManager.DeleteFile(file);
                }
            }

            // Return the result
            string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
            DataCache.CacheClearPrefix(cachekey);
            return BuildOutput(TopicId + "|" + replyId, OutputCodes.Success, true);
        }
예제 #11
0
        private string SaveTopic()
        {
            int topicId = -1;
            int forumId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        t  = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB    db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum           f  = fc.Forums_Get(PortalId, -1, forumId, this.UserId, true, false, -1);
                if (Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles))
                {
                    string subject = Params["subject"].ToString();
                    subject = Utilities.XSSFilter(subject, true);
                    if (!(string.IsNullOrEmpty(f.PrefixURL)))
                    {
                        string cleanSubject = Utilities.CleanName(subject).ToLowerInvariant();
                        if (SimulateIsNumeric.IsNumeric(cleanSubject))
                        {
                            cleanSubject = "Topic-" + cleanSubject;
                        }
                        string topicUrl  = cleanSubject;
                        string urlPrefix = "/";
                        if (!(string.IsNullOrEmpty(f.ForumGroup.PrefixURL)))
                        {
                            urlPrefix += f.ForumGroup.PrefixURL + "/";
                        }
                        if (!(string.IsNullOrEmpty(f.PrefixURL)))
                        {
                            urlPrefix += f.PrefixURL + "/";
                        }
                        string      urlToCheck = urlPrefix + cleanSubject;
                        Data.Topics topicsDb   = new Data.Topics();
                        for (int u = 0; u <= 200; u++)
                        {
                            int tid = topicsDb.TopicIdByUrl(PortalId, f.ModuleId, urlToCheck);
                            if (tid > 0 && tid == topicId)
                            {
                                break;
                            }
                            else if (tid > 0)
                            {
                                topicUrl   = (u + 1) + "-" + cleanSubject;
                                urlToCheck = urlPrefix + topicUrl;
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (topicUrl.Length > 150)
                        {
                            topicUrl = topicUrl.Substring(0, 149);
                            topicUrl = topicUrl.Substring(0, topicUrl.LastIndexOf("-"));
                        }
                        t.TopicUrl = topicUrl;
                        //.URL = topicUrl
                    }
                    else
                    {
                        //.URL = String.Empty
                        t.TopicUrl = string.Empty;
                    }
                    t.Content.Subject = subject;
                    t.IsPinned        = bool.Parse(Params["pinned"].ToString());
                    t.IsLocked        = bool.Parse(Params["locked"].ToString());
                    t.Priority        = int.Parse(Params["priority"].ToString());
                    t.StatusId        = int.Parse(Params["status"].ToString());
                    if (f.Properties != null)
                    {
                        StringBuilder tData = new StringBuilder();
                        tData.Append("<topicdata>");
                        tData.Append("<properties>");
                        foreach (PropertiesInfo p in f.Properties)
                        {
                            string pkey = "prop-" + p.PropertyId.ToString();

                            tData.Append("<property id=\"" + p.PropertyId.ToString() + "\">");
                            tData.Append("<name><![CDATA[");
                            tData.Append(p.Name);
                            tData.Append("]]></name>");
                            if (Params[pkey] != null)
                            {
                                tData.Append("<value><![CDATA[");
                                tData.Append(Utilities.XSSFilter(Params[pkey].ToString()));
                                tData.Append("]]></value>");
                            }
                            else
                            {
                                tData.Append("<value></value>");
                            }
                            tData.Append("</property>");
                        }
                        tData.Append("</properties>");
                        tData.Append("</topicdata>");
                        t.TopicData = tData.ToString();
                    }
                }
                tc.TopicSave(PortalId, t);
                if (Params["tags"] != null)
                {
                    DataProvider.Instance().Tags_DeleteByTopicId(PortalId, f.ModuleId, topicId);
                    string tagForm = string.Empty;
                    if (Params["tags"] != null)
                    {
                        tagForm = Params["tags"].ToString();
                    }
                    if (!(tagForm == string.Empty))
                    {
                        string[] Tags = tagForm.Split(',');
                        foreach (string tag in Tags)
                        {
                            string sTag = Utilities.CleanString(PortalId, tag.Trim(), false, EditorTypes.TEXTBOX, false, false, f.ModuleId, string.Empty, false);
                            DataProvider.Instance().Tags_Save(PortalId, f.ModuleId, -1, sTag, 0, 1, 0, topicId, false, -1, -1);
                        }
                    }
                }

                if (Params["categories"] != null)
                {
                    string[] cats = Params["categories"].ToString().Split(';');
                    DataProvider.Instance().Tags_DeleteTopicToCategory(PortalId, f.ModuleId, -1, topicId);
                    foreach (string c in cats)
                    {
                        int cid = -1;
                        if (!(string.IsNullOrEmpty(c)) && SimulateIsNumeric.IsNumeric(c))
                        {
                            cid = Convert.ToInt32(c);
                            if (cid > 0)
                            {
                                DataProvider.Instance().Tags_AddTopicToCategory(PortalId, f.ModuleId, cid, topicId);
                            }
                        }
                    }
                }
            }


            return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
        }
예제 #12
0
        private string LoadTopic()
        {
            int topicId = -1;
            int forumId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                topicId = int.Parse(Params["topicid"].ToString());
            }
            if (topicId > 0)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        t  = tc.Topics_Get(PortalId, ModuleId, topicId);
                Data.ForumsDB    db = new Data.ForumsDB();
                forumId = db.Forum_GetByTopicId(topicId);
                ForumController fc = new ForumController();
                Forum           f  = fc.Forums_Get(PortalId, -1, forumId, this.UserId, true, false, -1);
                if (f != null)
                {
                    if (Permissions.HasPerm(f.Security.ModEdit, ForumUser.UserRoles))
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("{");
                        sb.Append(Utilities.JSON.Pair("topicid", t.TopicId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("subject", t.Content.Subject));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("authorid", t.Content.AuthorId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("locked", t.IsLocked.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("pinned", t.IsPinned.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("priority", t.Priority.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("status", t.StatusId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("forumid", forumId.ToString()));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("forumname", f.ForumName));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("tags", t.Tags));
                        sb.Append(",");
                        sb.Append(Utilities.JSON.Pair("categories", t.Categories));
                        sb.Append(",");
                        sb.Append("\"properties\":[");
                        string sCats = string.Empty;
                        if (f.Properties != null)
                        {
                            int i = 0;
                            foreach (PropertiesInfo p in f.Properties)
                            {
                                sb.Append("{");
                                sb.Append(Utilities.JSON.Pair("propertyid", p.PropertyId.ToString()));
                                sb.Append(",");
                                sb.Append(Utilities.JSON.Pair("datatype", p.DataType));
                                sb.Append(",");
                                sb.Append(Utilities.JSON.Pair("propertyname", p.Name));
                                sb.Append(",");
                                string pvalue = p.DefaultValue;
                                foreach (PropertiesInfo tp in t.TopicProperties)
                                {
                                    if (tp.PropertyId == p.PropertyId)
                                    {
                                        pvalue = tp.DefaultValue;
                                    }
                                }

                                sb.Append(Utilities.JSON.Pair("propertyvalue", pvalue));
                                if (p.DataType.Contains("list"))
                                {
                                    sb.Append(",\"listdata\":[");
                                    if (p.DataType.Contains("list|categories"))
                                    {
                                        using (IDataReader dr = DataProvider.Instance().Tags_List(PortalId, f.ModuleId, true, 0, 200, "ASC", "TagName", forumId, f.ForumGroupId))
                                        {
                                            dr.NextResult();
                                            while (dr.Read())
                                            {
                                                sCats += "{";
                                                sCats += Utilities.JSON.Pair("id", dr["TagId"].ToString());
                                                sCats += ",";
                                                sCats += Utilities.JSON.Pair("name", dr["TagName"].ToString());
                                                sCats += ",";
                                                sCats += Utilities.JSON.Pair("selected", IsSelected(dr["TagName"].ToString(), t.Categories).ToString());
                                                sCats += "},";
                                            }
                                            dr.Close();
                                        }
                                        if (!(string.IsNullOrEmpty(sCats)))
                                        {
                                            sCats = sCats.Substring(0, sCats.Length - 1);
                                        }
                                        sb.Append(sCats);
                                    }
                                    else
                                    {
                                        DotNetNuke.Common.Lists.ListController lists = new DotNetNuke.Common.Lists.ListController();
                                        string lName = p.DataType.Substring(p.DataType.IndexOf("|") + 1);
                                        DotNetNuke.Common.Lists.ListEntryInfoCollection lc = lists.GetListEntryInfoCollection(lName, string.Empty);
                                        int il = 0;
                                        foreach (DotNetNuke.Common.Lists.ListEntryInfo l in lc)
                                        {
                                            sb.Append("{");
                                            sb.Append(Utilities.JSON.Pair("itemId", l.Value));
                                            sb.Append(",");
                                            sb.Append(Utilities.JSON.Pair("itemName", l.Text));
                                            sb.Append("}");
                                            il += 1;
                                            if (il < lc.Count)
                                            {
                                                sb.Append(",");
                                            }
                                        }
                                    }
                                    sb.Append("]");
                                }
                                sb.Append("}");
                                i += 1;
                                if (i < f.Properties.Count)
                                {
                                    sb.Append(",");
                                }
                            }
                        }



                        sb.Append("],\"categories\":[");
                        sCats = string.Empty;
                        using (IDataReader dr = DataProvider.Instance().Tags_List(PortalId, f.ModuleId, true, 0, 200, "ASC", "TagName", forumId, f.ForumGroupId))
                        {
                            dr.NextResult();
                            while (dr.Read())
                            {
                                sCats += "{";
                                sCats += Utilities.JSON.Pair("id", dr["TagId"].ToString());
                                sCats += ",";
                                sCats += Utilities.JSON.Pair("name", dr["TagName"].ToString());
                                sCats += ",";
                                sCats += Utilities.JSON.Pair("selected", IsSelected(dr["TagName"].ToString(), t.Categories).ToString());
                                sCats += "},";
                            }
                            dr.Close();
                        }
                        if (!(string.IsNullOrEmpty(sCats)))
                        {
                            sCats = sCats.Substring(0, sCats.Length - 1);
                        }
                        sb.Append(sCats);
                        sb.Append("]");
                        sb.Append("}");
                        return(BuildOutput(sb.ToString(), OutputCodes.Success, true, true));
                    }
                }
            }
            return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
        }
예제 #13
0
        private string DeletePost()
        {
            int replyId = -1;
            int TopicId = -1;

            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                TopicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            int forumId = -1;

            Data.ForumsDB db = new Data.ForumsDB();
            forumId = db.Forum_GetByTopicId(TopicId);
            ForumController fc = new ForumController();
            Forum           f  = fc.Forums_Get(forumId, this.UserId, true);

            // Need to get the list of attachments BEFORE we remove the post recods
            var attachmentController = new Data.AttachController();
            var attachmentList       = (MainSettings.DeleteBehavior == 0)
                                             ? attachmentController.ListForPost(TopicId, replyId)
                                             : null;


            if (TopicId > 0 & replyId < 1)
            {
                TopicsController tc = new TopicsController();
                TopicInfo        ti = tc.Topics_Get(PortalId, ModuleId, TopicId);

                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ti.Content.AuthorId == UserId && ti.IsLocked == false))
                {
                    DataProvider.Instance().Topics_Delete(forumId, TopicId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}", forumId.ToString(), TopicId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
                }
            }
            else
            {
                ReplyController rc = new ReplyController();
                ReplyInfo       ri = rc.Reply_Get(PortalId, ModuleId, TopicId, replyId);
                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ri.Content.AuthorId == UserId))
                {
                    DataProvider.Instance().Reply_Delete(forumId, TopicId, replyId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}:{2}", forumId.ToString(), TopicId.ToString(), replyId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
                }
            }

            // If it's a hard delete, delete associated attachments
            // attachmentList will only be populated if the DeleteBehavior is 0
            if (attachmentList != null)
            {
                var fileManager      = FileManager.Instance;
                var folderManager    = FolderManager.Instance;
                var attachmentFolder = folderManager.GetFolder(PortalId, "activeforums_Attach");

                foreach (var attachment in attachmentList)
                {
                    attachmentController.Delete(attachment.AttachmentId);

                    var file = attachment.FileId.HasValue
                                   ? fileManager.GetFile(attachment.FileId.Value)
                                   : fileManager.GetFile(attachmentFolder, attachment.FileName);

                    // Only delete the file if it exists in the attachment folder
                    if (file != null && file.FolderId == attachmentFolder.FolderID)
                    {
                        fileManager.DeleteFile(file);
                    }
                }
            }

            // Return the result
            string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);

            DataCache.CacheClearPrefix(cachekey);
            return(BuildOutput(TopicId + "|" + replyId, OutputCodes.Success, true));
        }
예제 #14
0
        private string DeletePost()
        {
            int replyId = -1;
            int TopicId = -1;
            if (Params.ContainsKey("topicid") && SimulateIsNumeric.IsNumeric(Params["topicid"]))
            {
                TopicId = int.Parse(Params["topicid"].ToString());
            }
            if (Params.ContainsKey("replyid") && SimulateIsNumeric.IsNumeric(Params["replyid"]))
            {
                replyId = int.Parse(Params["replyid"].ToString());
            }
            int forumId = -1;
            Data.ForumsDB db = new Data.ForumsDB();
            forumId = db.Forum_GetByTopicId(TopicId);
            ForumController fc = new ForumController();
            Forum f = fc.Forums_Get(forumId, this.UserId, true);
            if (TopicId > 0 & replyId < 1)
            {
                TopicsController tc = new TopicsController();
                TopicInfo ti = tc.Topics_Get(PortalId, ModuleId, TopicId);

                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ti.Content.AuthorId == UserId && ti.IsLocked == false))
                {
                    DataProvider.Instance().Topics_Delete(forumId, TopicId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}", forumId.ToString(), TopicId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);
                }
                else
                {
                    return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
                }
            }
            else
            {
                ReplyController rc = new ReplyController();
                ReplyInfo ri = rc.Reply_Get(PortalId, ModuleId, TopicId, replyId);
                if (Permissions.HasAccess(f.Security.ModDelete, ForumUser.UserRoles) || (Permissions.HasAccess(f.Security.Delete, ForumUser.UserRoles) && ri.Content.AuthorId == UserId))
                {
                    DataProvider.Instance().Reply_Delete(forumId, TopicId, replyId, MainSettings.DeleteBehavior);
                    string journalKey = string.Format("{0}:{1}:{2}", forumId.ToString(), TopicId.ToString(), replyId.ToString());
                    JournalController.Instance.DeleteJournalItemByKey(PortalId, journalKey);

                }
                else
                {
                    return BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false);
                }

            }
            string cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
            DataCache.CacheClearPrefix(cachekey);
            return BuildOutput(TopicId + "|" + replyId, OutputCodes.Success, true);
        }