Exemplo n.º 1
0
        private string LockTopic()
        {
            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.ModLock, ForumUser.UserRoles) || (t.Author.AuthorId == this.UserId && Permissions.HasAccess(f.Security.Lock, ForumUser.UserRoles)))
                    {
                        if (t.IsLocked)
                        {
                            t.IsLocked = false;
                        }
                        else
                        {
                            t.IsLocked = true;
                        }
                        tc.TopicSave(PortalId, t);
                        return(BuildOutput(string.Empty, OutputCodes.Success, true));
                    }
                }
            }
            return(BuildOutput(string.Empty, OutputCodes.UnsupportedRequest, false));
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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));
        }