コード例 #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            // remove the thread from the search index
            ForumThread forumThread = new ForumThread(threadId);

            ForumThread.Delete(threadId);
            Forum.UpdateUserStats(-1); // updates all users

            ForumThreadIndexBuilderProvider.RemoveForumIndexItem(
                moduleId,
                forumThread.ForumId,
                threadId,
                -1);

            SiteUtils.QueueIndexing();

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
コード例 #2
0
ファイル: EditPost.aspx.cs プロジェクト: saiesh86/TravelBlog
        private void btnDelete_Click(object sender, EventArgs e)
        {
            ForumThread thread = new ForumThread(threadId,postId);
            bool userCanEditPost = false;
            if (isModerator
                   || ((this.theUser != null) && (this.theUser.UserId == thread.PostUserId) && (thread.ForumId == forumId))
               )
              {
                  userCanEditPost = true;
              }

            if (!userCanEditPost)
            {
                WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                return;

            }

            thread.ContentChanged += new ContentChangedEventHandler(thread_ContentChanged);

            if(thread.DeletePost(postId))
            {
                CurrentPage.UpdateLastModifiedTime();

                if (thread.PostUserId > -1)
                {
                    Forum.UpdateUserStats(thread.PostUserId);
                }

                SiteUtils.QueueIndexing();
            }

            if (hdnReturnUrl.Value.Length > 0)
            {
                WebUtils.SetupRedirect(this, hdnReturnUrl.Value);
                return;
            }

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
コード例 #3
0
ファイル: EditPost.aspx.cs プロジェクト: saiesh86/TravelBlog
        private void PopulateControls()
        {
            ForumThread thread = null;
            if(threadId == -1)
            {
                this.btnDelete.Visible = false;
                postList.Visible = false;
                postListAlt.Visible = false;
                Title = SiteUtils.FormatPageTitle(siteSettings, CurrentPage.PageName + " - " + ForumResources.NewTopicLabel);

            }
            else
            {

                if(postId > -1)
                {
                    thread = new ForumThread(threadId, postId);
                    if (isModerator
                        || ((this.theUser != null) && (this.theUser.UserId == thread.PostUserId))
                        )
                    {
                        this.txtSubject.Text = thread.PostSubject;
                        edMessage.Text = thread.PostMessage;
                    }
                    else
                    {
                        //user has no permission to edit this post
                        WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                        return;

                    }

                    if (isModerator)
                    {
                        divSortOrder.Visible = true;
                        txtSortOrder.Text = thread.PostSortOrder.ToInvariantString();
                    }
                    else if ((config.AllowEditingPostsLessThanMinutesOld != -1)&&(thread.CurrentPostDate < DateTime.UtcNow.AddMinutes(-config.AllowEditingPostsLessThanMinutesOld)))
                    {
                        // not allowing edit of older posts
                        WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                        return;
                    }
                }
                else
                {
                    thread = new ForumThread(threadId);
                    this.txtSubject.Text
                        = ResourceHelper.GetMessageTemplate(SiteUtils.GetDefaultUICulture(), "ForumPostReplyPrefix.config")
                        + SecurityHelper.RemoveMarkup(thread.Subject);
                }

                if ((thread.IsLocked || thread.IsClosed(config.CloseThreadsOlderThanDays)) && (!isModerator))
                {
                    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                    return;
                }

                if ((forum != null) && (thread != null))
                {
                    Title = SiteUtils.FormatPageTitle(siteSettings, forum.Title + " - " + SecurityHelper.RemoveMarkup(thread.Subject));
                }

                if (forumId == -1)
                {
                    forumId = thread.ForumId;
                }

                postList.Forum = forum;
                postListAlt.Forum = forum;

                postList.Thread = thread;
                postListAlt.Thread = thread;

            }

            if (forum != null)
            {
                heading.Text = forum.Title;
                litForumDescription.Text = forum.Description;
                divDescription.Visible = (forum.Description.Length > 0) && (!displaySettings.HideForumDescriptionOnPostEdit);
            }

            if (threadId == -1) //only focus the subject on new threads
            {
                string hookupInputScript = "<script type=\"text/javascript\">"
                     + "document.getElementById('" + this.txtSubject.ClientID + "').focus();</script>";

                if (!Page.ClientScript.IsStartupScriptRegistered("finitscript"))
                {
                    this.Page.ClientScript.RegisterStartupScript(
                        typeof(Page),
                        "finitscript", hookupInputScript);
                }

                edMessage.WebEditor.SetFocusOnStart = false;
            }
            else
            {

                edMessage.WebEditor.SetFocusOnStart = true;
            }

            chkNotifyOnReply.Checked = isSubscribedToThread;

            lnkPageCrumb.Text = CurrentPage.PageName;
            lnkPageCrumb.NavigateUrl = SiteUtils.GetCurrentPageUrl();

            if (ForumConfiguration.CombineUrlParams)
            {
                lnkForum.HRef = SiteRoot + "/Forums/ForumView.aspx?pageid=" + pageId.ToInvariantString()
                    + "&amp;f=" + forum.ItemId.ToInvariantString() + "~1" ;
            }
            else
            {
                lnkForum.HRef = SiteRoot + "/Forums/ForumView.aspx?ItemID="
                    + forum.ItemId.ToInvariantString()
                    + "&amp;pageid=" + pageId.ToInvariantString()
                    + "&amp;mid=" + forum.ModuleId.ToInvariantString();
            }

            lnkForum.InnerHtml = forum.Title;
            if (thread != null) { lblThreadDescription.Text = SecurityHelper.RemoveMarkup(thread.Subject); }
        }
コード例 #4
0
ファイル: EditPost.aspx.cs プロジェクト: saiesh86/TravelBlog
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (forum == null) { forum = new Forum(forumId); }

            if (WebUser.IsInRoles(forum.RolesThatCanPost))
            {
                if (Request.IsAuthenticated)
                {
                    captcha.Enabled = false;
                    pnlAntiSpam.Visible = false;
                }

            }
            else
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            Page.Validate("Forum");
            if(!Page.IsValid)
            {
                PopulateControls();
                return;
            }
            else
            {
                if ((config.UseSpamBlockingForAnonymous) && (pnlAntiSpam.Visible)&&(captcha.Enabled))
                {
                    if (!captcha.IsValid)
                    {
                        PopulateControls();
                        return;
                    }
                }

                ForumThread thread;
                bool userIsAllowedToUpdateThisPost = false;
                if(threadId == -1)
                {
                    //new thread
                    thread = new ForumThread();
                    thread.ForumId = forumId;
                    thread.IncludeInSiteMap = forum.IncludeInGoogleMap;
                    thread.SetNoIndexMeta = forum.AddNoIndexMeta;
                }
                else
                {

                    if(postId > -1)
                    {
                        thread = new ForumThread(threadId,postId);
                        if (isModerator || (this.theUser.UserId == thread.PostUserId))
                        {
                            userIsAllowedToUpdateThisPost = true;
                        }

                        if ((isModerator) && (divSortOrder.Visible))
                        {
                            int sort = thread.PostSortOrder;
                            int.TryParse(txtSortOrder.Text, out sort);
                            thread.PostSortOrder = sort;
                        }

                    }
                    else
                    {
                        thread = new ForumThread(threadId);
                    }

                    //existing thread but it does not belong to this forum
                    if (forumId != thread.ForumId)
                    {
                        SiteUtils.RedirectToAccessDeniedPage(this);
                        return;
                    }

                }

                thread.ContentChanged += new ContentChangedEventHandler(thread_ContentChanged);
                thread.PostSubject = this.txtSubject.Text;
                thread.PostMessage = edMessage.Text;

                bool isNewPost = (thread.PostId == -1);

                SiteUser siteUser = null;

                if(Request.IsAuthenticated)
                {
                    siteUser = SiteUtils.GetCurrentSiteUser();
                    if (siteUser != null)
                    thread.PostUserId = siteUser.UserId;
                    if (chkSubscribeToForum.Checked)
                    {
                        forum.Subscribe(siteUser.UserId);
                    }
                    else
                    {
                        thread.SubscribeUserToThread = this.chkNotifyOnReply.Checked;
                    }

                }
                else
                {
                    thread.PostUserId = -1; //guest
                }

                string threadViewUrl;
                if (ForumConfiguration.CombineUrlParams)
                {
                    threadViewUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + pageId.ToInvariantString()
                        + "&t=" + thread.ThreadId.ToInvariantString()
                        + "~" + this.pageNumber.ToInvariantString();
                }
                else
                {
                    threadViewUrl = SiteRoot + "/Forums/Thread.aspx?thread="
                        + thread.ThreadId.ToInvariantString()
                        + "&mid=" + moduleId.ToInvariantString()
                        + "&pageid=" + pageId.ToInvariantString()
                        + "&ItemID=" + forumId.ToInvariantString()
                        + "&pagenumber=" + this.pageNumber.ToInvariantString();
                }

                if((thread.PostId == -1)||(userIsAllowedToUpdateThisPost))
                {
                    thread.Post();
                    CurrentPage.UpdateLastModifiedTime();

                    if (ForumConfiguration.CombineUrlParams)
                    {
                        threadViewUrl = SiteRoot + "/Forums/Thread.aspx?pageid=" + pageId.ToInvariantString()
                            + "&t=" + thread.ThreadId.ToInvariantString()
                            + "~" + pageNumber.ToInvariantString()
                            + "#post" + thread.PostId.ToInvariantString();
                    }
                    else
                    {
                        threadViewUrl = SiteRoot + "/Forums/Thread.aspx?thread="
                            + thread.ThreadId.ToInvariantString()
                            + "&mid=" + moduleId.ToInvariantString()
                            + "&pageid=" + pageId.ToInvariantString()
                            + "&ItemID=" + forum.ItemId.ToInvariantString()
                            + "&pagenumber=" + pageNumber.ToInvariantString()
                            + "#post" + thread.PostId.ToInvariantString();
                    }

                    if ((isNewPost) || (!config.SuppressNotificationOfPostEdits))
                    {

                        bool notifyModeratorOnly = false;

                        if (forum.RequireModForNotify)
                        {
                            notifyModeratorOnly = true;

                            if(forum.AllowTrustedDirectNotify && (siteUser != null) && siteUser.Trusted)
                            {
                                notifyModeratorOnly = false;

                            }

                        }

                        Module m = GetModule(moduleId, Forum.FeatureGuid);

                        ForumNotification.NotifySubscribers(
                            forum,
                            thread,
                            m,
                            siteUser,
                            siteSettings,
                            config,
                            SiteRoot,
                            pageId,
                            pageNumber,
                            SiteUtils.GetDefaultCulture(),
                            ForumConfiguration.GetSmtpSettings(),
                            notifyModeratorOnly
                            );

                        if(!notifyModeratorOnly)
                        {

                            thread.NotificationSent = true;
                            thread.UpdatePost();
                        }

                    }

                    //String cacheDependencyKey = "Module-" + moduleId.ToInvariantString();
                    //CacheHelper.TouchCacheDependencyFile(cacheDependencyKey);
                    CacheHelper.ClearModuleCache(moduleId);
                    SiteUtils.QueueIndexing();

                }

                Response.Redirect(threadViewUrl);
            }
        }
コード例 #5
0
        public static void SendForumNotificationEmail(
            object oNotificationInfo)
        {
            if (oNotificationInfo == null) return;
            if (!(oNotificationInfo is ForumNotificationInfo)) return;

            ForumNotificationInfo notificationInfo = oNotificationInfo as ForumNotificationInfo;

            if (notificationInfo.Subscribers == null) return;

            //if (debugLog) log.Debug("In SendForumNotificationEmail()");
            if (notificationInfo.Subscribers.Tables.Count > 0)
            {
                if (notificationInfo.Subscribers.Tables[0].Rows.Count > 0)
                {
                    int timeoutBetweenMessages = ConfigHelper.GetIntProperty("SmtpTimeoutBetweenMessages", 1000);
                    // use the same setting as newsletter to throttle the send rate, sending too fast can make you appear as a spammer
                    int maxPerMinute = ConfigHelper.GetIntProperty("Forum:NotificationMaxToSendPerMinute", 0);

                    int sentSoFar = 0;

                    notificationInfo.SmtpSettings.AddBulkMailHeader = true;

                    foreach (DataRow row in notificationInfo.Subscribers.Tables[0].Rows)
                    {
                        int threadsubId = Convert.ToInt32(row["ThreadSubID"]);
                        int forumsubId = Convert.ToInt32(row["ForumSubID"]);
                        Guid threadSubGuid = new Guid(row["ThreadSubGuid"].ToString());
                        Guid forumSubGuid = new Guid(row["ForumSubGuid"].ToString());

                        StringBuilder body = new StringBuilder();

                        body.Append(notificationInfo.MessageBody);

                        if ((threadsubId > -1) && (forumsubId > -1))
                        {
                            body.Append(notificationInfo.BodyTemplate);
                        }
                        else if (forumsubId > -1)
                        {
                            body.Append(notificationInfo.ForumOnlyTemplate);
                        }
                        else if (threadsubId > -1)
                        {
                            body.Append(notificationInfo.ThreadOnlyTemplate);
                        }

                        body.Replace("{SiteName}", notificationInfo.SiteName);
                        body.Replace("{ModuleName}", notificationInfo.ModuleName);
                        body.Replace("{ForumName}", notificationInfo.ForumName);
                        body.Replace("{AdminEmail}", notificationInfo.FromEmail);
                        body.Replace("{MessageLink}", notificationInfo.MessageLink);
                        body.Replace("{UnsubscribeForumThreadLink}", notificationInfo.UnsubscribeForumThreadLink + "?ts=" + threadSubGuid.ToString());
                        body.Replace("{UnsubscribeForumLink}", notificationInfo.UnsubscribeForumLink + "?fs=" + forumSubGuid.ToString());

                        StringBuilder emailSubject = new StringBuilder();
                        if (notificationInfo.SubjectTemplate.Length == 0)
                        {
                            notificationInfo.SubjectTemplate = "[{SiteName} - {ForumName}] {Subject}";
                        }
                        emailSubject.Append(notificationInfo.SubjectTemplate);
                        emailSubject.Replace("{SiteName}", notificationInfo.SiteName);
                        emailSubject.Replace("{ModuleName}", notificationInfo.ModuleName);
                        emailSubject.Replace("{ForumName}", notificationInfo.ForumName);
                        emailSubject.Replace("{Subject}", notificationInfo.Subject);

                        Email.Send(
                            notificationInfo.SmtpSettings,
                            notificationInfo.FromEmail,
                            notificationInfo.FromAlias,
                            string.Empty,
                            row["Email"].ToString(),
                            string.Empty,
                            string.Empty,
                            emailSubject.ToString(),
                            body.ToString(),
                            false,
                            "Normal");

                        sentSoFar += 1;

                        if (sentSoFar == maxPerMinute)
                        {
                            Thread.Sleep(60000); //sleep 1 minute
                            sentSoFar = 0; //reset counter
                        }
                        else
                        {

                            Thread.Sleep(timeoutBetweenMessages);
                        }
                    } // end for each row

                }
            }

            if((notificationInfo.PostId > -1)&&(notificationInfo.ThreadId > -1))
            {
                ForumThread thread = new ForumThread(notificationInfo.ThreadId, notificationInfo.PostId);
                if (thread.PostId > -1)
                {
                    thread.NotificationSent = true;
                    thread.UpdatePost();
                }

            }
        }
コード例 #6
0
        public static void NotifySubscribers(
            Forum forum,
            ForumThread thread,
            Module module,
            SiteUser siteUser,
            SiteSettings siteSettings,
            ForumConfiguration config,
            string siteRoot,
            int pageId,
            int pageNumber,
            CultureInfo defaultCulture,
            SmtpSettings smtpSettings,
            bool notifyModeratorOnly)
        {
            string threadViewUrl;

            if (ForumConfiguration.CombineUrlParams)
            {
                threadViewUrl = siteRoot + "/Forums/Thread.aspx?pageid=" + pageId.ToInvariantString()
                    + "&t=" + thread.ThreadId.ToInvariantString()
                    + "~" + pageNumber.ToInvariantString()
                    + "#post" + thread.PostId.ToInvariantString();
            }
            else
            {
                threadViewUrl = siteRoot + "/Forums/Thread.aspx?thread="
                    + thread.ThreadId.ToInvariantString()
                    + "&mid=" + module.ModuleId.ToInvariantString()
                    + "&pageid=" + pageId.ToInvariantString()
                    + "&ItemID=" + forum.ItemId.ToInvariantString()
                    + "&pagenumber=" + pageNumber.ToInvariantString()
                    + "#post" + thread.PostId.ToInvariantString();
            }

            ForumNotificationInfo notificationInfo = new ForumNotificationInfo();

            notificationInfo.ThreadId = thread.ThreadId;
            notificationInfo.PostId = thread.PostId;

            notificationInfo.SubjectTemplate
                = ResourceHelper.GetMessageTemplate(defaultCulture,
                "ForumNotificationEmailSubject.config");

            if (config.IncludePostBodyInNotification)
            {
                string postedBy = string.Empty;
                if (siteUser != null)
                {
                    string sigFormat = ResourceHelper.GetResourceString("ForumResources", "PostedByFormat", defaultCulture, true);
                    postedBy = string.Format(CultureInfo.InvariantCulture, sigFormat, siteUser.Name) + "\r\n\r\n"; ;
                }

                string bodyWithFullLinks = SiteUtils.ChangeRelativeLinksToFullyQualifiedLinks(
                    siteRoot,
                    thread.PostMessage);

                List<string> urls = SiteUtils.ExtractUrls(bodyWithFullLinks);

                notificationInfo.MessageBody = System.Web.HttpUtility.HtmlDecode(SecurityHelper.RemoveMarkup(thread.PostMessage));

                if (urls.Count > 0)
                {
                    notificationInfo.MessageBody += "\r\n" + ResourceHelper.GetResourceString("ForumResources", "PostedLinks", defaultCulture, true);
                    foreach (string s in urls)
                    {
                        notificationInfo.MessageBody += "\r\n" + s.Replace("&amp;", "&"); // html decode url params
                    }

                    notificationInfo.MessageBody += "\r\n\r\n";
                }

                notificationInfo.MessageBody += "\r\n\r\n" + postedBy;
            }

            notificationInfo.BodyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "ForumNotificationEmail.config");
            notificationInfo.ForumOnlyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "ForumNotificationEmail-ForumOnly.config");
            notificationInfo.ThreadOnlyTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "ForumNotificationEmail-ThreadOnly.config");
            notificationInfo.ModeratorTemplate = ResourceHelper.GetMessageTemplate(defaultCulture, "ForumModeratorNotificationEmail.config");

            notificationInfo.FromEmail = siteSettings.DefaultEmailFromAddress;
            notificationInfo.FromAlias = siteSettings.DefaultFromEmailAlias;

            if (config.OverrideNotificationFromAddress.Length > 0)
            {
                notificationInfo.FromEmail = config.OverrideNotificationFromAddress;
                notificationInfo.FromAlias = config.OverrideNotificationFromAlias;
            }

            notificationInfo.SiteName = siteSettings.SiteName;
            notificationInfo.ModuleName = module.ModuleTitle;
            notificationInfo.ForumName = forum.Title;
            notificationInfo.Subject = SecurityHelper.RemoveMarkup(thread.PostSubject);

            notificationInfo.MessageLink = threadViewUrl;

            notificationInfo.UnsubscribeForumThreadLink = siteRoot + "/Forums/UnsubscribeThread.aspx";
            notificationInfo.UnsubscribeForumLink = siteRoot + "/Forums/UnsubscribeForum.aspx";

            notificationInfo.SmtpSettings = smtpSettings;

            if (notifyModeratorOnly)
            {
                // just send notification to moderator
                List<string> moderatorsEmails = forum.ModeratorNotifyEmail.SplitOnChar(',');
                if (moderatorsEmails.Count > 0)
                {
                    notificationInfo.ModeratorEmailAddresses = moderatorsEmails;
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ForumNotification.SendForumModeratorNotificationEmail), notificationInfo);
                }

            }
            else
            {

                // Send notification to subscribers
                DataSet dsThreadSubscribers = thread.GetThreadSubscribers(config.IncludeCurrentUserInNotifications);
                notificationInfo.Subscribers = dsThreadSubscribers;

                ThreadPool.QueueUserWorkItem(new WaitCallback(ForumNotification.SendForumNotificationEmail), notificationInfo);
            }
        }
コード例 #7
0
        public void InstallContent(Module module, string configInfo)
        {
            if (string.IsNullOrEmpty(configInfo)) { return; }

            int userId = SiteUser.GetNewestUserId(module.SiteId);

            XmlDocument xml = new XmlDocument();

            using (StreamReader stream = File.OpenText(HostingEnvironment.MapPath(configInfo)))
            {
                xml.LoadXml(stream.ReadToEnd());
            }

            foreach (XmlNode node in xml.DocumentElement.ChildNodes)
            {
                if (node.Name == "forum")
                {
                    Forum forum = new Forum();
                    forum.ModuleId = module.ModuleId;

                    XmlAttributeCollection attributeCollection = node.Attributes;

                    if (attributeCollection["title"] != null)
                    {
                        forum.Title = attributeCollection["title"].Value;
                    }

                    if (attributeCollection["sortOrder"] != null)
                    {
                        int sort = 1;
                        if (int.TryParse(attributeCollection["sortOrder"].Value,
                            out sort))
                        {
                            forum.SortOrder = sort;
                        }
                    }

                    foreach (XmlNode descriptionNode in node.ChildNodes)
                    {
                        if (descriptionNode.Name == "description")
                        {
                            forum.Description = descriptionNode.InnerText;
                            break;
                        }
                    }

                    forum.CreatedByUserId = userId;

                    forum.Save();

                    foreach (XmlNode threadsNode in node.ChildNodes)
                    {
                        if (threadsNode.Name == "threads")
                        {

                            foreach (XmlNode threadNode in threadsNode.ChildNodes)
                            {
                                if (threadNode.Name == "thread")
                                {
                                    XmlAttributeCollection threadAttributes = threadNode.Attributes;

                                    ForumThread thread = new ForumThread();
                                    thread.ForumId = forum.ItemId;
                                    thread.PostUserId = userId;

                                    if (threadAttributes["subject"] != null)
                                    {
                                        thread.PostSubject = threadAttributes["subject"].Value;
                                    }

                                    foreach (XmlNode postNode in threadNode.ChildNodes)
                                    {
                                        if (postNode.Name == "post")
                                        {
                                            thread.PostMessage = postNode.InnerText;
                                            break; //TODO: this is limited to one post when creating a thread. could support more but just making it for the demo site
                                        }
                                    }

                                    thread.Post();

                                }
                            }

                            break; //there should only be one threads node
                        }
                    }

                }
            }
        }
コード例 #8
0
        private static void IndexItem(ForumThread forumThread)
        {
            if (WebConfigSettings.DisableSearchIndex) { return; }

            if (forumThread == null)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("forumThread object passed in ForumThreadIndexBuilderProvider.IndexItem was null");
                }
                return;

            }

            Forum forum = new Forum(forumThread.ForumId);
            Module module = new Module(forum.ModuleId);
            Guid forumFeatureGuid = new Guid("38aa5a84-9f5c-42eb-8f4c-105983d419fb");
            ModuleDefinition forumFeature = new ModuleDefinition(forumFeatureGuid);

            // get list of pages where this module is published
            List<PageModule> pageModules
                = PageModule.GetPageModulesByModule(forum.ModuleId);

            // must update index for all pages containing
            // this module
            foreach (PageModule pageModule in pageModules)
            {
                PageSettings pageSettings
                    = new PageSettings(
                    forumThread.SiteId,
                    pageModule.PageId);

                //don't index pending/unpublished pages
                if (pageSettings.IsPending) { continue; }

                mojoPortal.SearchIndex.IndexItem indexItem = new mojoPortal.SearchIndex.IndexItem();
                if (forumThread.SearchIndexPath.Length > 0)
                {
                    indexItem.IndexPath = forumThread.SearchIndexPath;
                }
                indexItem.SiteId = forumThread.SiteId;
                indexItem.PageId = pageModule.PageId;
                indexItem.PageName = pageSettings.PageName;
                // permissions are kept in sync in search index
                // so that results are filtered by role correctly
                indexItem.ViewRoles = pageSettings.AuthorizedRoles;
                indexItem.ModuleViewRoles = module.ViewRoles;
                indexItem.ItemId = forumThread.ForumId;
                indexItem.ModuleId = forum.ModuleId;
                indexItem.ModuleTitle = module.ModuleTitle;
                indexItem.FeatureId = forumFeatureGuid.ToString();
                indexItem.FeatureName = forumFeature.FeatureName;
                indexItem.FeatureResourceFile = forumFeature.ResourceFile;
                indexItem.Title = forumThread.Subject;

                indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                indexItem.PublishEndDate = pageModule.PublishEndDate;
                indexItem.ViewPage = "Forums/Thread.aspx";

                indexItem.CreatedUtc = forumThread.ThreadDate;
                indexItem.LastModUtc = forumThread.MostRecentPostDate;

                if (ForumConfiguration.AggregateSearchIndexPerThread)
                {
                    indexItem.PublishBeginDate = forumThread.MostRecentPostDate;
                    StringBuilder threadContent = new StringBuilder();

                    DataTable threadPosts = ForumThread.GetPostsByThread(forumThread.ThreadId);

                    foreach (DataRow r in threadPosts.Rows)
                    {
                        threadContent.Append(r["Post"].ToString());
                    }

                    //aggregate contents of posts into one indexable content item
                    indexItem.Content = threadContent.ToString();

                    if (ForumConfiguration.CombineUrlParams)
                    {
                        indexItem.ViewPage = "Forums/Thread.aspx?pageid=" + pageModule.PageId.ToInvariantString()
                            + "&t=" + forumThread.ThreadId.ToInvariantString() + "~1";
                        indexItem.UseQueryStringParams = false;
                    }

                    indexItem.QueryStringAddendum = "&thread=" + forumThread.ThreadId.ToInvariantString();

                }
                else
                {
                    //older implementation

                    indexItem.Content = forumThread.PostMessage;

                    indexItem.QueryStringAddendum = "&thread="
                        + forumThread.ThreadId.ToString()
                        + "&postid=" + forumThread.PostId.ToString();
                }

                mojoPortal.SearchIndex.IndexHelper.RebuildIndex(indexItem);

                if (debugLog) { log.Debug("Indexed " + forumThread.Subject); }

            }
        }
コード例 #9
0
        public void ThreadMovedHandler(object sender, ForumThreadMovedArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex) { return; }

            ForumThread forumThread = (ForumThread)sender;
            DataTable postIDList = forumThread.GetPostIdList();

            Forum origForum = new Forum(e.OriginalForumId);
            foreach (DataRow row in postIDList.Rows)
            {
                int postID = Convert.ToInt32(row["PostID"]);
                ForumThread post = new ForumThread(forumThread.ThreadId, postID);

                RemoveForumIndexItem(
                    origForum.ModuleId,
                    e.OriginalForumId,
                    forumThread.ThreadId,
                    postID);

                IndexItem(post);

            }
        }
コード例 #10
0
ファイル: ForumMod.cs プロジェクト: joedavis01/mojoportal
        private bool IsAllowed(ModerationRequest modReq)
        {
            siteSettings = CacheHelper.GetCurrentSiteSettings();
            if (siteSettings == null)
            {
                //log.Info("SiteSettings was null");
                return false;
            }
            currentPage = CacheHelper.GetPage(modReq.PageId);
            if (
                (currentPage.PageId != modReq.PageId)
                || (currentPage.SiteId != siteSettings.SiteId)
                )
            {
                log.Info("request rejected - pageid did not match");
                return false;
            }

            thread = new ForumThread(modReq.ThreadId, modReq.PostId);

            if (thread.ModuleId != modReq.ModuleId)
            {
                log.Info("thread module id did not match");
                return false;
            }
            forum = new Forum(thread.ForumId);

            module = GetModule(currentPage, thread.ModuleId);
            if (module == null)
            {
                log.Info("module not found in page modules");
                return false;
            }

            config = new ForumConfiguration(ModuleSettings.GetModuleSettings(module.ModuleId));
            if (thread.PostUserId > -1)
            {
                postUser = new SiteUser(siteSettings, thread.PostUserId);
            }

            return UserCanModerate(currentPage, module, forum);
        }
コード例 #11
0
ファイル: ForumThread.cs プロジェクト: joedavis01/mojoportal
        public static bool Delete(int threadId)
        {
            bool status = false;

            ForumThread forumThread = new ForumThread(threadId);

            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("PostID", typeof(int));

            using (IDataReader reader = DBForums.ForumThreadGetPosts(threadId))
            {
                while (reader.Read())
                {
                    DataRow row = dataTable.NewRow();
                    row["PostID"] = reader["PostID"];
                    dataTable.Rows.Add(row);
                }
            }

            foreach (DataRow row in dataTable.Rows)
            {
                forumThread.DeletePost(Convert.ToInt32(row["PostID"]));
            }

            status = DBForums.ForumThreadDelete(threadId);

            return status;
        }
コード例 #12
0
        private void Page_Load(object sender, EventArgs e)
        {
            SecurityHelper.DisableBrowserCache();

            LoadParams();

            userCanEdit = UserCanEditModule(moduleId, Forum.FeatureGuid);
            if (!userCanEdit)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            forumThread = new ForumThread(threadId);
            if (forumThread.ModuleId != moduleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            if (SiteUtils.IsFishyPost(this))
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            ForumThreadIndexBuilderProvider indexBuilder
                = (ForumThreadIndexBuilderProvider)IndexBuilderManager.Providers["ForumThreadIndexBuilderProvider"];

            if (indexBuilder != null)
            {
                forumThread.ThreadMoved += new ForumThread.ThreadMovedEventHandler(indexBuilder.ThreadMovedHandler);
            }

            siteUser = SiteUtils.GetCurrentSiteUser();

            PopulateLabels();

            if (!IsPostBack)
            {
                PopulateControls();
                if ((Request.UrlReferrer != null) && (hdnReturnUrl.Value.Length == 0))
                {
                    hdnReturnUrl.Value = Request.UrlReferrer.ToString();
                    lnkCancel.NavigateUrl = hdnReturnUrl.Value;

                }
            }

            AnalyticsSection = ConfigHelper.GetStringProperty("AnalyticsForumSection", "forums");
        }
コード例 #13
0
        public void Parse()
        {
            if (BasePage == null) { return; }

            pageId = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId = WebUtils.ParseInt32FromQueryString("mid", -1);
            itemId = WebUtils.ParseInt32FromQueryString("ItemID", -1);
            threadId = WebUtils.ParseInt32FromQueryString("thread", -1);
            pageNumber = WebUtils.ParseInt32FromQueryString("pagenumber", 1);

            // new option to combine params for better seo
            // we don't need moduleid or the forumid (ItemID) in the url we can get it from the thread
            // but we still need to validate that the page contains the moduleid of the forum
            // pageid must remain a separate param but we can combine thread and page number into one param
            // that can be split to get the individual params
            // so we can use ?pageid=x&t=y~z where y is threadid and z is pagenumber
            string f = WebUtils.ParseStringFromQueryString("t", string.Empty);

            if ((f.Length > 0) && (f.Contains("~")))
            {
                List<string> parms = f.SplitOnCharAndTrim('~');
                if (parms.Count == 2)
                {
                    int.TryParse(parms[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out threadId);
                    int.TryParse(parms[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out pageNumber);
                }
            }

            thread = new ForumThread(threadId);
            if (thread.ForumId == -1)
            {
                thread = null;
                return;
            }

            itemId = thread.ForumId;

            forum = new Forum(ItemId);
            if (forum.ModuleId == -1)
            {
                forum = null;
                return;
            }

            Module m = BasePage.GetModule(forum.ModuleId, Forum.FeatureGuid);

            if (m != null)
            { //module exists on the page and matches the forum module id
                moduleId = forum.ModuleId;
                paramsAreValid = true;
            }
        }
コード例 #14
0
ファイル: Thread.aspx.cs プロジェクト: joedavis01/mojoportal
        private void LoadSettings()
        {
            thread = threadParams.Thread;

            if (thread.ThreadId == -1)
            {
                //thread does not exist, probably just got deleted
                //redirect back to thread list
                string redirectUrl;
                if (ForumConfiguration.CombineUrlParams)
                {
                    redirectUrl = SiteRoot + "/Forums/ForumView.aspx?pageid=" + PageId.ToInvariantString()
                    + "&f=" + ItemId.ToInvariantString() + "~1";
                }
                else
                {
                    redirectUrl = SiteRoot + "/Forums/ForumView.aspx?ItemID="
                    + ItemId.ToInvariantString()
                    + "&pageid=" + PageId.ToInvariantString()
                    + "&mid=" + moduleId.ToInvariantString();
                }

                WebUtils.SetupRedirect(this, redirectUrl);

                return;

            }

            if (thread.ModuleId != moduleId)
            {
                //SiteUtils.RedirectToAccessDeniedPage(this);
                WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
                return;
            }

            forum = threadParams.Forum;

            //if (forum.ModuleId != moduleId)
            //{
            //    //SiteUtils.RedirectToAccessDeniedPage(this);
            //    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
            //    return;
            //}

            postList.Forum = forum;
            postList.Thread = thread;

            postListAlt.Forum = forum;
            postListAlt.Thread = thread;

            if (ForumConfiguration.TrackFakeTopicUrlInAnalytics) { SetupAnalytics(); }

            if ((IsEditable)||(WebUser.IsInRoles(forum.RolesThatCanModerate)))
            {
                SetupNotifyScript();
            }
        }
コード例 #15
0
ファイル: Thread.aspx.cs プロジェクト: joedavis01/mojoportal
        private string FormatTitle(ForumThread thread)
        {
            if (thread.TotalPages > 1)
            {
                return string.Format(CultureInfo.InvariantCulture,
                    ForumResources.ThreadPageTitleFormat,
                    thread.Subject, PageNumber.ToInvariantString());
            }

            return thread.Subject;
        }