コード例 #1
0
        public void OnBeginRequest(object s, EventArgs e)
        {
            _forumId      = -1;
            _tabId        = -1;
            _moduleId     = -1;
            _topicId      = -1;
            _page         = 1;
            _contentId    = -1;
            _archived     = 0;
            _forumgroupId = -1;
            _mainSettings = null;
            _categoryId   = -1;
            _tagId        = -1;

            HttpApplication   app           = (HttpApplication)s;
            HttpServerUtility Server        = app.Server;
            HttpRequest       Request       = app.Request;
            HttpResponse      Response      = app.Response;
            string            requestedPath = app.Request.Url.AbsoluteUri;
            HttpContext       Context       = ((HttpApplication)s).Context;
            int PortalId = -1;

            DotNetNuke.Entities.Portals.PortalAliasInfo objPortalAliasInfo = null;
            string sUrl = HttpContext.Current.Request.RawUrl.Replace("http://", string.Empty).Replace("https://", string.Empty);

            objPortalAliasInfo = PortalAliasController.Instance.GetPortalAlias(HttpContext.Current.Request.Url.Host);
            if (Request.RawUrl.ToLowerInvariant().Contains("404.aspx"))
            {
                string sEx = ".jpg,.gif,.png,.swf,.js,.css,.html,.htm,desktopmodules,portals,.ashx,.ico,.txt,.doc,.docx,.pdf,.xml,.xls,.xlsx,.ppt,.pptx,.csv,.zip,.asmx,.aspx";
                foreach (string sn in sEx.Split(','))
                {
                    if (sUrl.Contains(sn))
                    {
                        // IO.File.AppendAllText(sPath, Request.RawUrl & "165<br />")
                        return;
                    }
                }
            }
            if (Request.Url.LocalPath.ToLower().Contains("scriptresource.axd") || Request.Url.LocalPath.ToLower().Contains("webresource.axd") || Request.Url.LocalPath.ToLower().Contains("viewer.aspx") || Request.Url.LocalPath.ToLower().Contains("cb.aspx") || Request.Url.LocalPath.ToLower().Contains("filesupload.aspx") || Request.Url.LocalPath.ToLower().Contains(".gif") || Request.Url.LocalPath.ToLower().Contains(".jpg") || Request.Url.LocalPath.ToLower().Contains(".css") || Request.Url.LocalPath.ToLower().Contains(".png") || Request.Url.LocalPath.ToLower().Contains(".swf") || Request.Url.LocalPath.ToLower().Contains(".htm") || Request.Url.LocalPath.ToLower().Contains(".html") || Request.Url.LocalPath.ToLower().Contains(".ashx") || Request.Url.LocalPath.ToLower().Contains(".cur") || Request.Url.LocalPath.ToLower().Contains(".ico") || Request.Url.LocalPath.ToLower().Contains(".txt") || Request.Url.LocalPath.ToLower().Contains(".pdf") || Request.Url.LocalPath.ToLower().Contains(".xml") || Request.Url.LocalPath.ToLower().Contains("/portals/") || Request.Url.LocalPath.ToLower().Contains("/desktopmodules/") || Request.Url.LocalPath.ToLower().Contains("evexport.aspx") || Request.Url.LocalPath.ToLower().Contains("signupjs.aspx") || Request.Url.LocalPath.ToLower().Contains("evsexport.aspx") || Request.Url.LocalPath.ToLower().Contains("fbcomm.aspx") || Request.Url.LocalPath.ToLower().Contains(".aspx") || Request.Url.LocalPath.ToLower().Contains(".js"))
            {
                return;
            }
            if (Request.Url.LocalPath.ToLower().Contains("install.aspx") || Request.Url.LocalPath.ToLower().Contains("installwizard.aspx") || Request.Url.LocalPath.ToLower().Contains("captcha.aspx") || Request.RawUrl.Contains("viewer.aspx") || Request.RawUrl.Contains("blank.html") || Request.RawUrl.Contains("default.htm") || Request.RawUrl.Contains("autosuggest.aspx"))
            {
                return;
            }
            PortalId = objPortalAliasInfo.PortalID;
            string searchURL = sUrl;

            searchURL = searchURL.Replace(objPortalAliasInfo.HTTPAlias, string.Empty);
            if (searchURL.Length < 2)
            {
                return;
            }
            string query = string.Empty;

            if (searchURL.Contains("?"))
            {
                query     = searchURL.Substring(searchURL.IndexOf("?"));
                searchURL = searchURL.Substring(0, searchURL.IndexOf("?") - 1);
            }
            string newSearchURL = string.Empty;

            foreach (string up in searchURL.Split('/'))
            {
                if (!(string.IsNullOrEmpty(up)))
                {
                    if (!(SimulateIsNumeric.IsNumeric(up)))
                    {
                        newSearchURL += up + "/";
                    }
                }
            }
            bool canContinue = false;

            Data.Common db      = new Data.Common();
            string      tagName = string.Empty;
            string      catName = string.Empty;

            if (newSearchURL.Contains("/category/") || newSearchURL.Contains("/tag/"))
            {
                if (newSearchURL.Contains("/category/"))
                {
                    string cat       = "/category/";
                    int    iEnd      = newSearchURL.IndexOf("/", newSearchURL.IndexOf(cat) + cat.Length + 1);
                    string catString = newSearchURL.Substring(newSearchURL.IndexOf(cat), iEnd - newSearchURL.IndexOf(cat));
                    catName      = catString.Replace(cat, string.Empty);
                    catName      = catName.Replace("/", string.Empty);
                    newSearchURL = newSearchURL.Replace(catString, string.Empty);
                }
                if (newSearchURL.Contains("/tag/"))
                {
                    string tag       = "/tag/";
                    int    iEnd      = newSearchURL.IndexOf("/", newSearchURL.IndexOf(tag) + tag.Length + 1);
                    string tagString = newSearchURL.Substring(newSearchURL.IndexOf(tag), iEnd - newSearchURL.IndexOf(tag));
                    tagName      = tagString.Replace(tag, string.Empty);
                    tagName      = tagName.Replace("/", string.Empty);
                    newSearchURL = newSearchURL.Replace(tagString, string.Empty);
                }
            }
            if ((sUrl.Contains("afv") && sUrl.Contains("post")) | (sUrl.Contains("afv") && sUrl.Contains("confirmaction")) | (sUrl.Contains("afv") && sUrl.Contains("sendto")) | (sUrl.Contains("afv") && sUrl.Contains("modreport")) | (sUrl.Contains("afv") && sUrl.Contains("search")) | sUrl.Contains("dnnprintmode") || sUrl.Contains("asg") || (sUrl.Contains("afv") && sUrl.Contains("modtopics")))
            {
                return;
            }
            try
            {
                using (IDataReader dr = db.URLSearch(PortalId, newSearchURL))
                {
                    while (dr.Read())
                    {
                        _tabId        = int.Parse(dr["TabID"].ToString());
                        _moduleId     = int.Parse(dr["ModuleId"].ToString());
                        _forumgroupId = int.Parse(dr["ForumGroupId"].ToString());
                        _forumId      = int.Parse(dr["ForumId"].ToString());
                        _topicId      = int.Parse(dr["TopicId"].ToString());
                        _archived     = int.Parse(dr["Archived"].ToString());
                        _otherId      = int.Parse(dr["OtherId"].ToString());
                        _urlType      = int.Parse(dr["UrlType"].ToString());
                        canContinue   = true;
                    }
                    dr.Close();
                }
            }
            catch (Exception ex)
            {
            }
            if (!(string.IsNullOrEmpty(catName)))
            {
                _categoryId = db.Tag_GetIdByName(PortalId, _moduleId, catName, true);
                _otherId    = _categoryId;
                _urlType    = 2;
            }
            if (!(string.IsNullOrEmpty(tagName)))
            {
                _tagId   = db.Tag_GetIdByName(PortalId, _moduleId, tagName, false);
                _otherId = _tagId;
                _urlType = 3;
            }

            if (_archived == 1)
            {
                sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
                if (!(string.IsNullOrEmpty(sUrl)))
                {
                    string sHost = objPortalAliasInfo.HTTPAlias;
                    if (sUrl.StartsWith("/"))
                    {
                        sUrl = sUrl.Substring(1);
                    }
                    if (!(sHost.EndsWith("/")))
                    {
                        sHost += "/";
                    }
                    sUrl = sHost + sUrl;
                    if (!(sUrl.EndsWith("/")))
                    {
                        sUrl += "/";
                    }
                    if (!(sUrl.StartsWith("http")))
                    {
                        if (Request.IsSecureConnection)
                        {
                            sUrl = "https://" + sUrl;
                        }
                        else
                        {
                            sUrl = "http://" + sUrl;
                        }
                    }
                    Response.Clear();
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", sUrl);
                    Response.End();
                }
            }
            if (_moduleId > 0)
            {
                Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController();
                SettingsInfo objSettings = new SettingsInfo();
                objSettings.MainSettings = objModules.GetModuleSettings(_moduleId);
                _mainSettings            = objSettings;      // DataCache.MainSettings(_moduleId)
            }
            if (_mainSettings == null)
            {
                return;
            }
            if (!_mainSettings.URLRewriteEnabled)
            {
                return;
            }
            if (!canContinue && (Request.RawUrl.Contains(ParamKeys.TopicId) || Request.RawUrl.Contains(ParamKeys.ForumId) || Request.RawUrl.Contains(ParamKeys.GroupId)))
            {
                sUrl = HandleOldUrls(Request.RawUrl, objPortalAliasInfo.HTTPAlias);
                if (!(string.IsNullOrEmpty(sUrl)))
                {
                    if (!(sUrl.StartsWith("http")))
                    {
                        if (Request.IsSecureConnection)
                        {
                            sUrl = "https://" + sUrl;
                        }
                        else
                        {
                            sUrl = "http://" + sUrl;
                        }
                    }
                    Response.Clear();
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", sUrl);
                    Response.End();
                }
            }
            if (!canContinue)
            {
                string topicUrl = string.Empty;
                if (newSearchURL.EndsWith("/"))
                {
                    newSearchURL = newSearchURL.Substring(0, newSearchURL.Length - 1);
                }
                if (newSearchURL.Contains("/"))
                {
                    topicUrl = newSearchURL.Substring(newSearchURL.LastIndexOf("/"));
                }
                topicUrl = topicUrl.Replace("/", string.Empty);
                if (!(string.IsNullOrEmpty(topicUrl)))
                {
                    Data.Topics topicsDb = new Data.Topics();
                    _topicId = topicsDb.TopicIdByUrl(PortalId, _moduleId, topicUrl.ToLowerInvariant());
                    if (_topicId > 0)
                    {
                        sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
                    }
                    else
                    {
                        sUrl = string.Empty;
                    }
                    if (!(string.IsNullOrEmpty(sUrl)))
                    {
                        string sHost = objPortalAliasInfo.HTTPAlias;
                        if (sHost.EndsWith("/") && sUrl.StartsWith("/"))
                        {
                            sUrl = sHost.Substring(0, sHost.Length - 1) + sUrl;
                        }
                        else if (!(sHost.EndsWith("/")) && !(sUrl.StartsWith("/")))
                        {
                            sUrl = sHost + "/" + sUrl;
                        }
                        else
                        {
                            sUrl = sHost + sUrl;
                        }
                        if (sUrl.StartsWith("/"))
                        {
                            sUrl = sUrl.Substring(1);
                        }
                        if (!(sUrl.StartsWith("http")))
                        {
                            if (Request.IsSecureConnection)
                            {
                                sUrl = "https://" + sUrl;
                            }
                            else
                            {
                                sUrl = "http://" + sUrl;
                            }
                        }
                        if (!(string.IsNullOrEmpty(sUrl)))
                        {
                            Response.Clear();
                            Response.Status = "301 Moved Permanently";
                            Response.AddHeader("Location", sUrl);
                            Response.End();
                        }
                    }
                }
            }

            if (canContinue)
            {
                if (searchURL != newSearchURL)
                {
                    string urlTail = searchURL.Replace(newSearchURL, string.Empty);
                    if (urlTail.StartsWith("/"))
                    {
                        urlTail = urlTail.Substring(1);
                    }
                    if (urlTail.EndsWith("/"))
                    {
                        urlTail = urlTail.Substring(0, urlTail.Length - 1);
                    }
                    if (urlTail.Contains("/"))
                    {
                        urlTail = urlTail.Substring(0, urlTail.IndexOf("/") - 1);
                    }
                    if (SimulateIsNumeric.IsNumeric(urlTail))
                    {
                        _page = Convert.ToInt32(urlTail);
                    }
                }

                string sPage = string.Empty;
                sPage = "&afpg=" + _page.ToString();
                string qs = string.Empty;
                if (sUrl.Contains("?"))
                {
                    qs = "&" + sUrl.Substring(sUrl.IndexOf("?") + 1);
                }
                string catQS = string.Empty;
                if (_categoryId > 0)
                {
                    catQS = "&act=" + _categoryId.ToString();
                }
                string sendTo = string.Empty;
                if ((_topicId > 0) || (_forumId > 0) || (_forumgroupId > 0))
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId +
                                        (_forumgroupId > 0 ? "&afg=" + _forumgroupId : string.Empty) +
                                        (_forumId > 0 ? "&aff=" + _forumId : string.Empty) +
                                        (_topicId > 0 ? "&aft=" + _topicId : string.Empty) +
                                        sPage + qs +
                                        ((_forumgroupId > 0 || _forumId > 0) ? catQS : string.Empty));
                }
                else if (_urlType == 2 && _otherId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&act=" + _otherId + sPage + qs);
                }
                else if (_urlType == 3 && _otherId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=tags&aftg=" + _otherId + sPage + qs);
                }
                else if (_urlType == 1)
                {
                    string v = string.Empty;
                    switch (_otherId)
                    {
                    case 1:
                        v = "unanswered";
                        break;

                    case 2:
                        v = "notread";
                        break;

                    case 3:
                        v = "mytopics";
                        break;

                    case 4:
                        v = "activetopics";
                        break;

                    case 5:
                        v = "afprofile";
                        break;
                    }
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=" + v + sPage + qs);
                }
                else if (_tabId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + sPage + qs);
                }

                RewriteUrl(app.Context, sendTo);
            }
        }
コード例 #2
0
        private void SaveTopic()
        {
            var subject = ctlForm.Subject;
            var body = ctlForm.Body;
            subject = Utilities.CleanString(PortalId, subject, false, EditorTypes.TEXTBOX, ForumInfo.UseFilter, false, ForumModuleId, _themePath, false);
            body = Utilities.CleanString(PortalId, body, _allowHTML, _editorType, ForumInfo.UseFilter, ForumInfo.AllowScript, ForumModuleId, _themePath, ForumInfo.AllowEmoticons);
            var summary = ctlForm.Summary;
            int authorId;
            string authorName;
            if (Request.IsAuthenticated)
            {
                authorId = UserInfo.UserID;
                switch (MainSettings.UserNameDisplay.ToUpperInvariant())
                {
                    case "USERNAME":
                        authorName = UserInfo.Username.Trim(' ');
                        break;
                    case "FULLNAME":
                        authorName = Convert.ToString(UserInfo.FirstName + " " + UserInfo.LastName).Trim(' ');
                        break;
                    case "FIRSTNAME":
                        authorName = UserInfo.FirstName.Trim(' ');
                        break;
                    case "LASTNAME":
                        authorName = UserInfo.LastName.Trim(' ');
                        break;
                    case "DISPLAYNAME":
                        authorName = UserInfo.DisplayName.Trim(' ');
                        break;
                    default:
                        authorName = UserInfo.DisplayName;
                        break;
                }
            }
            else
            {
                authorId = -1;
                authorName = Utilities.CleanString(PortalId, ctlForm.AuthorName, false, EditorTypes.TEXTBOX, true, false, ForumModuleId, _themePath, false);
                if (authorName.Trim() == string.Empty)
                    return;
            }

            var tc = new TopicsController();
            TopicInfo ti;

            if (TopicId > 0)
            {
                ti = tc.Topics_Get(PortalId, ForumModuleId, TopicId);
                ti.Content.DateUpdated = DateTime.Now;
                authorId = ti.Author.AuthorId;
            }
            else
            {
                ti = new TopicInfo();
                var dt = DateTime.Now;
                ti.Content.DateCreated = dt;
                ti.Content.DateUpdated = dt;
            }

            ti.AnnounceEnd = ctlForm.AnnounceEnd;
            ti.AnnounceStart = ctlForm.AnnounceStart;
            ti.Priority = ctlForm.TopicPriority;

            if (!_isEdit)
            {
                ti.Content.AuthorId = authorId;
                ti.Content.AuthorName = authorName;
                ti.Content.IPAddress = Request.UserHostAddress;
            }

            if (Regex.IsMatch(body, "<CODE([^>]*)>", RegexOptions.IgnoreCase))
            {
                foreach (Match m in Regex.Matches(body, "<CODE([^>]*)>(.*?)</CODE>", RegexOptions.IgnoreCase))
                    body = body.Replace(m.Value, m.Value.Replace("<br>", System.Environment.NewLine));
            }

            if (!(string.IsNullOrEmpty(ForumInfo.PrefixURL)))
            {
                var cleanSubject = Utilities.CleanName(subject).ToLowerInvariant();
                if (SimulateIsNumeric.IsNumeric(cleanSubject))
                    cleanSubject = "Topic-" + cleanSubject;

                var topicUrl = cleanSubject;
                var urlPrefix = "/";

                if (!(string.IsNullOrEmpty(ForumInfo.ForumGroup.PrefixURL)))
                    urlPrefix += ForumInfo.ForumGroup.PrefixURL + "/";

                if (!(string.IsNullOrEmpty(ForumInfo.PrefixURL)))
                    urlPrefix += ForumInfo.PrefixURL + "/";

                var urlToCheck = urlPrefix + cleanSubject;

                var topicsDb = new Data.Topics();
                for (var u = 0; u <= 200; u++)
                {
                    var tid = topicsDb.TopicIdByUrl(PortalId, ModuleId, urlToCheck);
                    if (tid > 0 && tid == TopicId)
                        break;

                    if (tid <= 0)
                        break;

                    topicUrl = (u + 1) + "-" + cleanSubject;
                    urlToCheck = urlPrefix + topicUrl;
                }
                if (topicUrl.Length > 150)
                {
                    topicUrl = topicUrl.Substring(0, 149);
                    topicUrl = topicUrl.Substring(0, topicUrl.LastIndexOf("-", StringComparison.Ordinal));
                }

                ti.TopicUrl = topicUrl;
            }
            else
            {
                //.URL = String.Empty
                ti.TopicUrl = string.Empty;
            }

            ti.Content.Body = body; //Utilities.CleanString(PortalId, Body, fi.AllowHTML, fi.EditorType, fi.UseFilter, fi.AllowScript, ForumModuleId, String.Empty)
            ti.Content.Subject = subject;
            ti.Content.Summary = summary;
            ti.IsAnnounce = ti.AnnounceEnd != Utilities.NullDate() && ti.AnnounceStart != Utilities.NullDate();

            if (_canModApprove && _fi.IsModerated)
                ti.IsApproved = ctlForm.IsApproved;
            else
                ti.IsApproved = _isApproved;

            bool bSend = ti.IsApproved;

            ti.IsArchived = false;
            ti.IsDeleted = false;
            ti.IsLocked = _canLock && ctlForm.Locked;
            ti.IsPinned = _canPin && ctlForm.Pinned;
            ti.StatusId = ctlForm.StatusId;
            ti.TopicIcon = ctlForm.TopicIcon;
            ti.TopicType = 0;
            if (ForumInfo.Properties != null)
            {
                var tData = new StringBuilder();
                tData.Append("<topicdata>");
                tData.Append("<properties>");
                foreach (var p in ForumInfo.Properties)
                {
                    var pkey = "afprop-" + p.PropertyId.ToString();

                    tData.Append("<property id=\"" + p.PropertyId.ToString() + "\">");
                    tData.Append("<name><![CDATA[");
                    tData.Append(p.Name);
                    tData.Append("]]></name>");
                    if (Request.Form[pkey] != null)
                    {
                        tData.Append("<value><![CDATA[");
                        tData.Append(Utilities.XSSFilter(Request.Form[pkey]));
                        tData.Append("]]></value>");
                    }
                    else
                    {
                        tData.Append("<value></value>");
                    }
                    tData.Append("</property>");
                }
                tData.Append("</properties>");
                tData.Append("</topicdata>");
                ti.TopicData = tData.ToString();
            }

            TopicId = tc.TopicSave(PortalId, ti);
            ti = tc.Topics_Get(PortalId, ForumModuleId, TopicId, ForumId, -1, false);
            if (ti != null)
            {
                tc.Topics_SaveToForum(ForumId, TopicId, PortalId, ModuleId);
                SaveAttachments(ti.ContentId);
                if (ti.IsApproved && ti.Author.AuthorId > 0)
                {
                    var uc = new Data.Profiles();
                    uc.Profile_UpdateTopicCount(PortalId, ti.Author.AuthorId);
                }
            }

            if (Permissions.HasPerm(ForumInfo.Security.Tag, ForumUser.UserRoles))
            {
                DataProvider.Instance().Tags_DeleteByTopicId(PortalId, ForumModuleId, TopicId);
                var tagForm = string.Empty;
                if (Request.Form["txtTags"] != null)
                    tagForm = Request.Form["txtTags"];

                if (tagForm != string.Empty)
                {
                    var tags = tagForm.Split(',');
                    foreach (var tag in tags)
                    {
                        var sTag = Utilities.CleanString(PortalId, tag.Trim(), false, EditorTypes.TEXTBOX, false, false, ForumModuleId, string.Empty, false);
                        DataProvider.Instance().Tags_Save(PortalId, ForumModuleId, -1, sTag, 0, 1, 0, TopicId, false, -1, -1);
                    }
                }
            }

            if (Permissions.HasPerm(ForumInfo.Security.Categorize, ForumUser.UserRoles))
            {
                if (Request.Form["amaf-catselect"] != null)
                {
                    var cats = Request.Form["amaf-catselect"].Split(';');
                    DataProvider.Instance().Tags_DeleteTopicToCategory(PortalId, ForumModuleId, -1, TopicId);
                    foreach (var c in cats)
                    {
                        if (string.IsNullOrEmpty(c) || !SimulateIsNumeric.IsNumeric(c))
                            continue;

                        var cid = Convert.ToInt32(c);
                        if (cid > 0)
                            DataProvider.Instance().Tags_AddTopicToCategory(PortalId, ForumModuleId, cid, TopicId);
                    }
                }
            }

            if (!String.IsNullOrEmpty(ctlForm.PollQuestion) && !String.IsNullOrEmpty(ctlForm.PollOptions))
            {
                //var sPollQ = ctlForm.PollQuestion.Trim();
                //sPollQ = Utilities.CleanString(PortalId, sPollQ, false, EditorTypes.TEXTBOX, true, false, ForumModuleId, string.Empty, false);
                var pollId = DataProvider.Instance().Poll_Save(-1, TopicId, UserId, ctlForm.PollQuestion.Trim(), ctlForm.PollType);
                if (pollId > 0)
                {
                    var options = ctlForm.PollOptions.Split(new[] { System.Environment.NewLine }, StringSplitOptions.None);

                    foreach (string opt in options)
                    {
                        if (opt.Trim() != string.Empty)
                        {
                            var value = Utilities.CleanString(PortalId, opt, false, EditorTypes.TEXTBOX, true, false, ForumModuleId, string.Empty, false);
                            DataProvider.Instance().Poll_Option_Save(-1, pollId, value.Trim(), TopicId);
                        }
                    }
                }

                ti = tc.Topics_Get(PortalId, ForumModuleId, TopicId, ForumId, -1, false);
                ti.TopicType = TopicTypes.Poll;
                tc.TopicSave(PortalId, ti);
            }

            try
            {
                var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                DataCache.CacheClearPrefix(cachekey);
                if (ctlForm.Subscribe && authorId == UserId)
                {
                    if (!(Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, authorId)))
                    {
                        var sc = new SubscriptionController();
                        sc.Subscription_Update(PortalId, ForumModuleId, ForumId, TopicId, 1, authorId, ForumUser.UserRoles);
                    }
                }
                else if (_isEdit)
                {
                    bool isSub = Subscriptions.IsSubscribed(PortalId, ForumModuleId, ForumId, TopicId, SubscriptionTypes.Instant, authorId);
                    if (isSub && !ctlForm.Subscribe)
                    {
                        var sc = new SubscriptionController();
                        sc.Subscription_Update(PortalId, ForumModuleId, ForumId, TopicId, 1, authorId, ForumUser.UserRoles);
                    }
                }

                if (bSend && !_isEdit)
                    Subscriptions.SendSubscriptions(PortalId, ForumModuleId, ForumTabId, _fi, TopicId, 0, ti.Content.AuthorId);

                if (ti.IsApproved == false)
                {
                    var mods = Utilities.GetListOfModerators(PortalId, ForumId);
                    var notificationType = NotificationsController.Instance.GetNotificationType("AF-ForumModeration");

                    var notifySubject = Utilities.GetSharedResource("NotificationSubjectTopic");
                    notifySubject = notifySubject.Replace("[DisplayName]", UserInfo.DisplayName);
                    notifySubject = notifySubject.Replace("[TopicSubject]", ti.Content.Subject);

                    var notifyBody = Utilities.GetSharedResource("NotificationBodyTopic");
                    notifyBody = notifyBody.Replace("[Post]", ti.Content.Body);

                    var notificationKey = string.Format("{0}:{1}:{2}:{3}:{4}", TabId, ForumModuleId, ForumId, TopicId, ReplyId);

                    var notification = new Notification
                                           {
                                               NotificationTypeID = notificationType.NotificationTypeId,
                                               Subject = notifySubject,
                                               Body = notifyBody,
                                               IncludeDismissAction = false,
                                               SenderUserID = UserInfo.UserID,
                                               Context = notificationKey
                                           };

                    NotificationsController.Instance.SendNotification(notification, PortalId, null, mods);

                    string[] @params = { ParamKeys.ForumId + "=" + ForumId, ParamKeys.ViewType + "=confirmaction", ParamKeys.ConfirmActionId + "=" + ConfirmActions.MessagePending };
                    Response.Redirect(NavigateUrl(ForumTabId, "", @params), false);
                }
                else
                {
                    if (ti != null)
                        ti.TopicId = TopicId;

                    var ctlUtils = new ControlUtils();

                    var sUrl = ctlUtils.BuildUrl(ForumTabId, ForumModuleId, ForumInfo.ForumGroup.PrefixURL, ForumInfo.PrefixURL, ForumInfo.ForumGroupId, ForumInfo.ForumID, TopicId, ti.TopicUrl, -1, -1, string.Empty, 1, -1, SocialGroupId);

                    if (sUrl.Contains("~/") || Request.QueryString["asg"] != null)
                        sUrl = Utilities.NavigateUrl(ForumTabId, "", ParamKeys.TopicId + "=" + TopicId);

                    if (!_isEdit)
                    {
                        try
                        {
                            var amas = new Social();
                            amas.AddTopicToJournal(PortalId, ForumModuleId, ForumId, TopicId, UserId, sUrl, subject, summary, body, ForumInfo.ActiveSocialSecurityOption, ForumInfo.Security.Read, SocialGroupId);
                            if (Request.QueryString["asg"] == null && !(string.IsNullOrEmpty(MainSettings.ActiveSocialTopicsKey)) && ForumInfo.ActiveSocialEnabled)
                            {
                                // amas.AddTopicToJournal(PortalId, ForumModuleId, ForumId, UserId, sUrl, Subject, Summary, Body, ForumInfo.ActiveSocialSecurityOption, ForumInfo.Security.Read)
                            }
                            else
                            {
                                amas.AddForumItemToJournal(PortalId, ForumModuleId, UserId, "forumtopic", sUrl, subject, body);
                            }
                        }
                        catch (Exception ex)
                        {
                            Services.Exceptions.Exceptions.LogException(ex);
                        }
                    }

                    Response.Redirect(sUrl, false);
                }
            }
            catch (Exception ex)
            {
                Services.Exceptions.Exceptions.LogException(ex);
            }
        }
コード例 #3
0
ファイル: ReWriter.cs プロジェクト: allanedk/ActiveForums
		public void OnBeginRequest(object s, EventArgs e)
		{
			_forumId = -1;
			_tabId = -1;
			_moduleId = -1;
			_topicId = -1;
			_page = 1;
			_contentId = -1;
			_archived = 0;
			_forumgroupId = -1;
			_mainSettings = null;
			_categoryId = -1;
			_tagId = -1;

			HttpApplication app = (HttpApplication)s;
			HttpServerUtility Server = app.Server;
			HttpRequest Request = app.Request;
			HttpResponse Response = app.Response;
			string requestedPath = app.Request.Url.AbsoluteUri;
			HttpContext Context = ((HttpApplication)s).Context;
			int PortalId = -1;
			DotNetNuke.Entities.Portals.PortalAliasInfo objPortalAliasInfo = null;
			string sUrl = HttpContext.Current.Request.RawUrl.Replace("http://", string.Empty).Replace("https://", string.Empty);
			objPortalAliasInfo = DotNetNuke.Entities.Portals.PortalSettings.GetPortalAliasInfo(HttpContext.Current.Request.Url.Host);
			if (Request.RawUrl.ToLowerInvariant().Contains("404.aspx"))
			{
				string sEx = ".jpg,.gif,.png,.swf,.js,.css,.html,.htm,desktopmodules,portals,.ashx,.ico,.txt,.doc,.docx,.pdf,.xml,.xls,.xlsx,.ppt,.pptx,.csv,.zip,.asmx,.aspx";
				foreach (string sn in sEx.Split(','))
				{
					if (sUrl.Contains(sn))
					{
						// IO.File.AppendAllText(sPath, Request.RawUrl & "165<br />")
						return;
					}
				}
			}
			if (Request.Url.LocalPath.ToLower().Contains("scriptresource.axd") || Request.Url.LocalPath.ToLower().Contains("webresource.axd") || Request.Url.LocalPath.ToLower().Contains("viewer.aspx") || Request.Url.LocalPath.ToLower().Contains("cb.aspx") || Request.Url.LocalPath.ToLower().Contains("filesupload.aspx") || Request.Url.LocalPath.ToLower().Contains(".gif") || Request.Url.LocalPath.ToLower().Contains(".jpg") || Request.Url.LocalPath.ToLower().Contains(".css") || Request.Url.LocalPath.ToLower().Contains(".png") || Request.Url.LocalPath.ToLower().Contains(".swf") || Request.Url.LocalPath.ToLower().Contains(".htm") || Request.Url.LocalPath.ToLower().Contains(".html") || Request.Url.LocalPath.ToLower().Contains(".ashx") || Request.Url.LocalPath.ToLower().Contains(".cur") || Request.Url.LocalPath.ToLower().Contains(".ico") || Request.Url.LocalPath.ToLower().Contains(".txt") || Request.Url.LocalPath.ToLower().Contains(".pdf") || Request.Url.LocalPath.ToLower().Contains(".xml") || Request.Url.LocalPath.ToLower().Contains("/portals/") || Request.Url.LocalPath.ToLower().Contains("/desktopmodules/") || Request.Url.LocalPath.ToLower().Contains("evexport.aspx") || Request.Url.LocalPath.ToLower().Contains("signupjs.aspx") || Request.Url.LocalPath.ToLower().Contains("evsexport.aspx") || Request.Url.LocalPath.ToLower().Contains("fbcomm.aspx") || Request.Url.LocalPath.ToLower().Contains(".aspx") || Request.Url.LocalPath.ToLower().Contains(".js"))
			{
				return;
			}
			if (Request.Url.LocalPath.ToLower().Contains("install.aspx") || Request.Url.LocalPath.ToLower().Contains("installwizard.aspx") || Request.Url.LocalPath.ToLower().Contains("captcha.aspx") || Request.RawUrl.Contains("viewer.aspx") || Request.RawUrl.Contains("blank.html") || Request.RawUrl.Contains("default.htm") || Request.RawUrl.Contains("autosuggest.aspx"))
			{
				return;
			}
			PortalId = objPortalAliasInfo.PortalID;
			string searchURL = sUrl;
			searchURL = searchURL.Replace(objPortalAliasInfo.HTTPAlias, string.Empty);
			if (searchURL.Length < 2)
			{
				return;
			}
			string query = string.Empty;
			if (searchURL.Contains("?"))
			{
				query = searchURL.Substring(searchURL.IndexOf("?"));
				searchURL = searchURL.Substring(0, searchURL.IndexOf("?") - 1);
			}
			string newSearchURL = string.Empty;
			foreach (string up in searchURL.Split('/'))
			{
				if (! (string.IsNullOrEmpty(up)))
				{
					if (! (SimulateIsNumeric.IsNumeric(up)))
					{
						newSearchURL += up + "/";
					}
				}
			}
			bool canContinue = false;
			Data.Common db = new Data.Common();
			string tagName = string.Empty;
			string catName = string.Empty;
			if (newSearchURL.Contains("/category/") || newSearchURL.Contains("/tag/"))
			{
				if (newSearchURL.Contains("/category/"))
				{
					string cat = "/category/";
					int iEnd = newSearchURL.IndexOf("/", newSearchURL.IndexOf(cat) + cat.Length + 1);
					string catString = newSearchURL.Substring(newSearchURL.IndexOf(cat), iEnd - newSearchURL.IndexOf(cat));
					catName = catString.Replace(cat, string.Empty);
					catName = catName.Replace("/", string.Empty);
					newSearchURL = newSearchURL.Replace(catString, string.Empty);
				}
				if (newSearchURL.Contains("/tag/"))
				{
					string tag = "/tag/";
					int iEnd = newSearchURL.IndexOf("/", newSearchURL.IndexOf(tag) + tag.Length + 1);
					string tagString = newSearchURL.Substring(newSearchURL.IndexOf(tag), iEnd - newSearchURL.IndexOf(tag));
					tagName = tagString.Replace(tag, string.Empty);
					tagName = tagName.Replace("/", string.Empty);
					newSearchURL = newSearchURL.Replace(tagString, string.Empty);
				}
			}
			if ((sUrl.Contains("afv") && sUrl.Contains("post")) | (sUrl.Contains("afv") && sUrl.Contains("confirmaction")) | (sUrl.Contains("afv") && sUrl.Contains("sendto")) | (sUrl.Contains("afv") && sUrl.Contains("modreport")) | (sUrl.Contains("afv") && sUrl.Contains("search")) | sUrl.Contains("dnnprintmode") || sUrl.Contains("asg") || (sUrl.Contains("afv") && sUrl.Contains("modtopics")))
			{
				return;
			}
			try
			{
				using (IDataReader dr = db.URLSearch(PortalId, newSearchURL))
				{
					while (dr.Read())
					{
						_tabId = int.Parse(dr["TabID"].ToString());
						_moduleId = int.Parse(dr["ModuleId"].ToString());
						_forumgroupId = int.Parse(dr["ForumGroupId"].ToString());
						_forumId = int.Parse(dr["ForumId"].ToString());
						_topicId = int.Parse(dr["TopicId"].ToString());
						_archived = int.Parse(dr["Archived"].ToString());
						_otherId = int.Parse(dr["OtherId"].ToString());
						_urlType = int.Parse(dr["UrlType"].ToString());
						canContinue = true;
					}
					dr.Close();
				}
			}
			catch (Exception ex)
			{

			}
			if (! (string.IsNullOrEmpty(catName)))
			{
				_categoryId = db.Tag_GetIdByName(PortalId, _moduleId, catName, true);
				_otherId = _categoryId;
				_urlType = 2;
			}
			if (! (string.IsNullOrEmpty(tagName)))
			{
				_tagId = db.Tag_GetIdByName(PortalId, _moduleId, tagName, false);
				_otherId = _tagId;
				_urlType = 3;
			}

			if (_archived == 1)
			{
				sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
				if (! (string.IsNullOrEmpty(sUrl)))
				{
					string sHost = objPortalAliasInfo.HTTPAlias;
					if (sUrl.StartsWith("/"))
					{
						sUrl = sUrl.Substring(1);
					}
					if (! (sHost.EndsWith("/")))
					{
						sHost += "/";
					}
					sUrl = sHost + sUrl;
					if (! (sUrl.EndsWith("/")))
					{
						sUrl += "/";
					}
					if (! (sUrl.StartsWith("http")))
					{
						if (Request.IsSecureConnection)
						{
							sUrl = "https://" + sUrl;
						}
						else
						{
							sUrl = "http://" + sUrl;
						}
					}
					Response.Clear();
					Response.Status = "301 Moved Permanently";
					Response.AddHeader("Location", sUrl);
					Response.End();

				}
			}
			if (_moduleId > 0)
			{
				Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController();
				SettingsInfo objSettings = new SettingsInfo();
				objSettings.MainSettings = objModules.GetModuleSettings(_moduleId);
				_mainSettings = objSettings; // DataCache.MainSettings(_moduleId)
			}
			if (_mainSettings == null)
			{
				return;
			}
			if (! _mainSettings.URLRewriteEnabled)
			{
				return;
			}
			if (! canContinue && (Request.RawUrl.Contains(ParamKeys.TopicId) || Request.RawUrl.Contains(ParamKeys.ForumId) || Request.RawUrl.Contains(ParamKeys.GroupId)))
			{
				sUrl = HandleOldUrls(Request.RawUrl, objPortalAliasInfo.HTTPAlias);
				if (! (string.IsNullOrEmpty(sUrl)))
				{
					if (! (sUrl.StartsWith("http")))
					{
						if (Request.IsSecureConnection)
						{
							sUrl = "https://" + sUrl;
						}
						else
						{
							sUrl = "http://" + sUrl;
						}
					}
					Response.Clear();
					Response.Status = "301 Moved Permanently";
					Response.AddHeader("Location", sUrl);
					Response.End();
				}
			}
			if (! canContinue)
			{
				string topicUrl = string.Empty;
				if (newSearchURL.EndsWith("/"))
				{
					newSearchURL = newSearchURL.Substring(0, newSearchURL.Length - 1);
				}
				if (newSearchURL.Contains("/"))
				{
					topicUrl = newSearchURL.Substring(newSearchURL.LastIndexOf("/"));
				}
				topicUrl = topicUrl.Replace("/", string.Empty);
				if (! (string.IsNullOrEmpty(topicUrl)))
				{
					Data.Topics topicsDb = new Data.Topics();
					_topicId = topicsDb.TopicIdByUrl(PortalId, _moduleId, topicUrl.ToLowerInvariant());
					if (_topicId > 0)
					{
						sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
					}
					else
					{
						sUrl = string.Empty;
					}
					if (! (string.IsNullOrEmpty(sUrl)))
					{
						string sHost = objPortalAliasInfo.HTTPAlias;
						if (sHost.EndsWith("/") && sUrl.StartsWith("/"))
						{
							sUrl = sHost.Substring(0, sHost.Length - 1) + sUrl;
						}
						else if (! (sHost.EndsWith("/")) && ! (sUrl.StartsWith("/")))
						{
							sUrl = sHost + "/" + sUrl;
						}
						else
						{
							sUrl = sHost + sUrl;
						}
						if (sUrl.StartsWith("/"))
						{
							sUrl = sUrl.Substring(1);
						}
						if (! (sUrl.StartsWith("http")))
						{
							if (Request.IsSecureConnection)
							{
								sUrl = "https://" + sUrl;
							}
							else
							{
								sUrl = "http://" + sUrl;
							}
						}
						if (! (string.IsNullOrEmpty(sUrl)))
						{
							Response.Clear();
							Response.Status = "301 Moved Permanently";
							Response.AddHeader("Location", sUrl);
							Response.End();
						}
					}
				}

			}

			if (canContinue)
			{
				if (searchURL != newSearchURL)
				{
					string urlTail = searchURL.Replace(newSearchURL, string.Empty);
					if (urlTail.StartsWith("/"))
					{
						urlTail = urlTail.Substring(1);
					}
					if (urlTail.EndsWith("/"))
					{
						urlTail = urlTail.Substring(0, urlTail.Length - 1);
					}
					if (urlTail.Contains("/"))
					{
						urlTail = urlTail.Substring(0, urlTail.IndexOf("/") - 1);
					}
					if (SimulateIsNumeric.IsNumeric(urlTail))
					{
						_page = Convert.ToInt32(urlTail);
					}
				}

				string sPage = string.Empty;
				sPage = "&afpg=" + _page.ToString();
				string qs = string.Empty;
				if (sUrl.Contains("?"))
				{
					qs = "&" + sUrl.Substring(sUrl.IndexOf("?") + 1);
				}
				string catQS = string.Empty;
				if (_categoryId > 0)
				{
					catQS = "&act=" + _categoryId.ToString();
				}
				string sendTo = string.Empty;
				if (_topicId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aft=" + _topicId + sPage + qs);
				}
				else if (_forumId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aff=" + _forumId + sPage + qs + catQS);
				}
				else if (_forumgroupId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afg=" + _forumgroupId + sPage + qs + catQS);
				}
				else if (_urlType == 2 && _otherId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&act=" + _otherId + sPage + qs);
				}
				else if (_urlType == 3 && _otherId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=tags&aftg=" + _otherId + sPage + qs);
				}
				else if (_urlType == 1)
				{
					string v = string.Empty;
					switch (_otherId)
					{
						case 1:
							v = "unanswered";
							break;
						case 2:
							v = "notread";
							break;
						case 3:
							v = "mytopics";
							break;
						case 4:
							v = "activetopics";
							break;
					}
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=" + v + sPage + qs);
				}
				else if (_tabId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + sPage + qs);
				}

				RewriteUrl(app.Context, sendTo);
			}
		}