示例#1
0
        public void TopicMovedHandler(object sender, GroupTopicMovedArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            GroupTopic groupTopic = (GroupTopic)sender;
            DataTable  postIDList = groupTopic.GetPostIdList();

            Group origGroup = new Group(e.OriginalGroupId);

            foreach (DataRow row in postIDList.Rows)
            {
                int        postID = Convert.ToInt32(row["PostID"]);
                GroupTopic post   = new GroupTopic(groupTopic.TopicId, postID);

                RemoveGroupIndexItem(
                    origGroup.ModuleId,
                    e.OriginalGroupId,
                    groupTopic.TopicId,
                    postID);

                IndexItem(post);
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            GroupTopic topic = new GroupTopic(topicId, postId);

            topic.ContentChanged += new ContentChangedEventHandler(topic_ContentChanged);



            if (topic.DeletePost(postId))
            {
                CurrentPage.UpdateLastModifiedTime();
                //if (Request.IsAuthenticated)
                //{
                //    SiteUser user = SiteUtils.GetCurrentSiteUser();
                //    if(user != null)
                //    SiteUser.DecrementTotalPosts(user.UserId);
                //}
                if (topic.PostUserId > -1)
                {
                    Group.UpdateUserStats(topic.PostUserId);
                }

                SiteUtils.QueueIndexing();
            }

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

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
示例#3
0
        private void UnsubscribeUserFromAll(string userEmail)
        {
            if (string.IsNullOrEmpty(userEmail))
            {
                return;
            }
            if (!Email.IsValidEmailAddressSyntax(userEmail))
            {
                return;
            }


            SiteUser user = SiteUser.GetByEmail(siteSettings, userEmail);

            if (user == null)
            {
                return;
            }
            if (user.UserGuid == Guid.Empty)
            {
                return;
            }

            GroupTopic.UnsubscribeAll(user.UserId);
            Group.UnsubscribeAll(user.UserId);

            lblUnsubscribe.Text = Resources.GroupResources.AdminUnsubscribeUserComplete;
        }
示例#4
0
        public ActionResult EditTopic(int id = 0, int groupId = 0)
        {
            var model = new GroupTopic {
                GroupId = groupId
            };

            if (id > 0)
            {
                model = _groupService.GetGroupTopic(id);
            }
            return(View(model));
        }
示例#5
0
        public static void RemoveGroupIndexItem(object oGroupTopic)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            if (!(oGroupTopic is GroupTopic))
            {
                return;
            }

            GroupTopic groupTopic = oGroupTopic as GroupTopic;

            //SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            //if (siteSettings == null)
            //{
            //    if (log.IsErrorEnabled)
            //    {
            //        log.Error("siteSettings object retrieved in GroupTopicIndexBuilderProvider.RemoveGroupIndexItem was null");
            //    }
            //    return;
            //}

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

            // must update index for all pages containing
            // this module
            foreach (PageModule pageModule in pageModules)
            {
                IndexItem indexItem = new IndexItem();
                // note we are just assigning the properties
                // needed to derive the key so it can be found and
                // deleted from the index
                indexItem.SiteId              = groupTopic.SiteId;
                indexItem.PageId              = pageModule.PageId;
                indexItem.ModuleId            = groupTopic.ModuleId;
                indexItem.ItemId              = groupTopic.GroupId;
                indexItem.QueryStringAddendum = "&topic="
                                                + groupTopic.TopicId.ToString(CultureInfo.InvariantCulture)
                                                + "&postid=" + groupTopic.PostId.ToString(CultureInfo.InvariantCulture);

                IndexHelper.RemoveIndex(indexItem);
            }

            if (log.IsDebugEnabled)
            {
                log.Debug("Removed Index ");
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            GroupTopic.Delete(this.topicId);
            Group.UpdateUserStats(-1); // updates all users

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

            WebUtils.SetupRedirect(this, SiteUtils.GetCurrentPageUrl());
        }
        private void UnsubscribeUser(int topicId)
        {
            SiteUser siteUser = SiteUtils.GetCurrentSiteUser();

            if (siteUser == null)
            {
                return;
            }
            if (!GroupTopic.Unsubscribe(topicId, siteUser.UserId))
            {
                log.ErrorFormat("GroupTopic.UnSubscribe({0}, {1}) failed", topicId, siteUser.UserId);
                lblUnsubscribe.Text = Resources.GroupResources.GroupTopicUnsubscribeFailed;
                return;
            }
            lblUnsubscribe.Text = Resources.GroupResources.GroupTopicUnsubscribeCompleted;
        }
示例#8
0
        private void PopulateControls()
        {
            if (groupUser == null)
            {
                return;
            }

            litTitle.Text = string.Format(CultureInfo.InvariantCulture,
                                          GroupResources.GroupUserTopicHeading,
                                          groupUser.Name);

            Title = SiteUtils.FormatPageTitle(siteSettings, string.Format(CultureInfo.InvariantCulture,
                                                                          GroupResources.UserTopicTitleFormat, groupUser.Name));

            MetaDescription = string.Format(CultureInfo.InvariantCulture,
                                            GroupResources.UserTopicMetaFormat, groupUser.Name);

            using (IDataReader reader = GroupTopic.GetPageByUser(
                       userId,
                       pageNumber,
                       pageSize,
                       out totalPages))
            {
                string pageUrl = siteSettings.SiteRoot
                                 + "/Groups/UserTopics.aspx?"
                                 + "userid=" + userId.ToString(CultureInfo.InvariantCulture)
                                 + "&amp;pagenumber={0}";

                pgrTop.PageURLFormat = pageUrl;
                pgrTop.ShowFirstLast = true;
                pgrTop.CurrentIndex  = pageNumber;
                pgrTop.PageSize      = pageSize;
                pgrTop.PageCount     = totalPages;
                pgrTop.Visible       = (pgrTop.PageCount > 1);

                pgrBottom.PageURLFormat = pageUrl;
                pgrBottom.ShowFirstLast = true;
                pgrBottom.CurrentIndex  = pageNumber;
                pgrBottom.PageSize      = pageSize;
                pgrBottom.PageCount     = totalPages;
                pgrBottom.Visible       = (pgrBottom.PageCount > 1);


                rptGroups.DataSource = reader;
                rptGroups.DataBind();
            }
        }
示例#9
0
        private static void IndexItem(object oGroupTopic)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }
            if (oGroupTopic == null)
            {
                return;
            }
            if (!(oGroupTopic is GroupTopic))
            {
                return;
            }

            GroupTopic groupTopic = oGroupTopic as GroupTopic;

            IndexItem(groupTopic);
        }
示例#10
0
        /// <summary>
        /// 获取指定机构群/公共群话题列表
        /// </summary>
        /// <param name="groupId">群ID</param>
        /// <param name="page">页码(默认1)</param>
        /// <param name="count">每页数据量(默认15,最大30)</param>
        /// <param name="order">排序方式(默认1,1-发表时间倒序;2-最后评论时间倒序;3-回帖数倒序)</param>
        /// <returns></returns>
        public GroupTopic GetGroupTopics(int groupId, int page = 1, int count = 15, int order = 1)
        {
            if (count > 30)
            {
                throw new YbException("	每页数据量不可超过30");
            }
            var request = CreateRequest(RestSharp.Method.GET, "group/group_topic");

            request.AddParameter("access_token", context.Token.access_token, RestSharp.ParameterType.QueryString);
            request.AddParameter("group_id", groupId, RestSharp.ParameterType.QueryString);
            request.AddParameter("page", page, RestSharp.ParameterType.QueryString);
            request.AddParameter("count", count, RestSharp.ParameterType.QueryString);
            request.AddParameter("order", order, RestSharp.ParameterType.QueryString);
            var response = restClient.Execute(request);

            if (CheckError(response))
            {
                throw GenerateError(response);
            }
            GroupTopic result = null;

            try
            {
                result = Deserialize <GroupTopic>(response.Content);
            }
            catch (System.InvalidOperationException)
            {
                result = new GroupTopic()
                {
                    status = "success",
                    info   = new GroupTopic.Info()
                };
                return(result);
            }
            return(result);
        }
        private void Page_Load(object sender, EventArgs e)
        {
            isSiteEditor = SiteUtils.UserIsSiteEditor();
            if ((!WebUser.IsAdminOrContentAdmin) && (!isSiteEditor))
            {
                SiteUtils.RedirectToEditAccessDeniedPage();
                return;
            }

            SecurityHelper.DisableBrowserCache();

            LoadParams();
            groupTopic = new GroupTopic(topicId);

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

            if (indexBuilder != null)
            {
                groupTopic.TopicMoved += new GroupTopic.TopicMovedEventHandler(indexBuilder.TopicMovedHandler);
            }

            siteUser = SiteUtils.GetCurrentSiteUser();

            PopulateLabels();

            if (!IsPostBack)
            {
                PopulateControls();
                if ((Request.UrlReferrer != null) && (hdnReturnUrl.Value.Length == 0))
                {
                    hdnReturnUrl.Value    = Request.UrlReferrer.ToString();
                    lnkCancel.NavigateUrl = hdnReturnUrl.Value;
                }
            }
        }
示例#12
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int AddGroupTopic(GroupTopic model)
 {
     model.TopicId = _dataAccess.AddEntity(model);
     _dataAccess.ExecuteSql("update Int_Group set TopicCount = TopicCount + 1 where GroupId = " + model.GroupId);
     return(model.TopicId);
 }
示例#13
0
        private static void IndexItem(GroupTopic groupTopic)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }
            //SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            //if (siteSettings == null)
            //{
            //    if (log.IsErrorEnabled)
            //    {
            //        log.Error("siteSettings object retrieved in GroupTopicIndexBuilderProvider.IndexItem was null");
            //    }
            //    return;
            //}

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

            Group            group            = new Group(groupTopic.GroupId);
            Module           module           = new Module(group.ModuleId);
            Guid             groupFeatureGuid = new Guid("E75BAF8C-7079-4d10-A122-1AA3624E26F2");
            ModuleDefinition groupFeature     = new ModuleDefinition(groupFeatureGuid);

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

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

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

                IndexItem indexItem = new IndexItem();
                if (groupTopic.SearchIndexPath.Length > 0)
                {
                    indexItem.IndexPath = groupTopic.SearchIndexPath;
                }
                indexItem.SiteId   = groupTopic.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              = groupTopic.GroupId;
                indexItem.ModuleId            = group.ModuleId;
                indexItem.ModuleTitle         = module.ModuleTitle;
                indexItem.ViewPage            = "Groups/Topic.aspx";
                indexItem.QueryStringAddendum = "&topic="
                                                + groupTopic.TopicId.ToString()
                                                + "&postid=" + groupTopic.PostId.ToString();
                indexItem.FeatureId           = groupFeatureGuid.ToString();
                indexItem.FeatureName         = groupFeature.FeatureName;
                indexItem.FeatureResourceFile = groupFeature.ResourceFile;
                indexItem.Title            = groupTopic.Subject;
                indexItem.Content          = groupTopic.PostMessage;
                indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                indexItem.PublishEndDate   = pageModule.PublishEndDate;

                IndexHelper.RebuildIndex(indexItem);

                if (log.IsDebugEnabled)
                {
                    log.Debug("Indexed "
                              + groupTopic.Subject);
                }
            }
        }
示例#14
0
        public override void ContentChangedHandler(
            object sender,
            ContentChangedEventArgs e)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }
            if (sender == null)
            {
                return;
            }
            if (!(sender is GroupTopic))
            {
                return;
            }


            GroupTopic   groupTopic   = (GroupTopic)sender;
            SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings();

            groupTopic.SiteId          = siteSettings.SiteId;
            groupTopic.SearchIndexPath = IndexHelper.GetSearchIndexPath(siteSettings.SiteId);

            if (e.IsDeleted)
            {
                if (ThreadPool.QueueUserWorkItem(new WaitCallback(RemoveGroupIndexItem), groupTopic))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("GroupTopicIndexBuilderProvider.RemoveGroupIndexItem queued");
                    }
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Failed to queue a topic for GroupTopicIndexBuilderProvider.RemoveGroupIndexItem");
                    }
                }

                //RemoveGroupIndexItem(groupTopic);
            }
            else
            {
                if (ThreadPool.QueueUserWorkItem(new WaitCallback(IndexItem), groupTopic))
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("GroupTopicIndexBuilderProvider.IndexItem queued");
                    }
                }
                else
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("Failed to queue a topic for GroupTopicIndexBuilderProvider.IndexItem");
                    }
                }

                //IndexItem(groupTopic);
            }
        }
示例#15
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool UpdateGroupTopic(GroupTopic model)
 {
     return(_dataAccess.UpdateEntity(model) > 0);
 }
示例#16
0
        public override void RebuildIndex(
            PageSettings pageSettings,
            string indexPath)
        {
            if (WebConfigSettings.DisableSearchIndex)
            {
                return;
            }

            if ((pageSettings == null) || (indexPath == null))
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("pageSettings object or index path passed to GroupTopicIndexBuilderProvider.RebuildIndex was null");
                }
                return;
            }

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

            log.Info("GroupTopicIndexBuilderProvider indexing page - "
                     + pageSettings.PageName);

            try
            {
                List <PageModule> pageModules
                    = PageModule.GetPageModulesByPage(pageSettings.PageId);

                Guid             groupFeatureGuid = new Guid("E75BAF8C-7079-4d10-A122-1AA3624E26F2");
                ModuleDefinition groupFeature     = new ModuleDefinition(groupFeatureGuid);

                DataTable dataTable = GroupTopic.GetPostsByPage(
                    pageSettings.SiteId,
                    pageSettings.PageId);

                foreach (DataRow row in dataTable.Rows)
                {
                    IndexItem indexItem = new IndexItem();
                    indexItem.SiteId              = pageSettings.SiteId;
                    indexItem.PageId              = pageSettings.PageId;
                    indexItem.PageName            = pageSettings.PageName;
                    indexItem.ViewRoles           = pageSettings.AuthorizedRoles;
                    indexItem.ModuleViewRoles     = row["ViewRoles"].ToString();
                    indexItem.FeatureId           = groupFeatureGuid.ToString();
                    indexItem.FeatureName         = groupFeature.FeatureName;
                    indexItem.FeatureResourceFile = groupFeature.ResourceFile;

                    indexItem.ItemId              = Convert.ToInt32(row["ItemID"]);
                    indexItem.ModuleId            = Convert.ToInt32(row["ModuleID"]);
                    indexItem.ModuleTitle         = row["ModuleTitle"].ToString();
                    indexItem.Title               = row["Subject"].ToString();
                    indexItem.Content             = row["Post"].ToString();
                    indexItem.ViewPage            = "Groups/Topic.aspx";
                    indexItem.QueryStringAddendum = "&topic="
                                                    + row["TopicID"].ToString()
                                                    + "&postid=" + row["PostID"].ToString();

                    // lookup publish dates
                    foreach (PageModule pageModule in pageModules)
                    {
                        if (indexItem.ModuleId == pageModule.ModuleId)
                        {
                            indexItem.PublishBeginDate = pageModule.PublishBeginDate;
                            indexItem.PublishEndDate   = pageModule.PublishEndDate;
                        }
                    }

                    IndexHelper.RebuildIndex(indexItem, indexPath);

                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Indexed " + indexItem.Title);
                    }
                }
            }
            catch (System.Data.Common.DbException ex)
            {
                log.Error(ex);
            }
        }
示例#17
0
        protected void btnStartNewTopic_Click(object sender, EventArgs e)
        {
            string topicName = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtTopicName.Text.Trim()) : txtTopicName.Text.Trim();
            string post = Config.Misc.EnableBadWordsFilterGroups ? Parsers.ProcessBadWords(txtPost.Text.Trim()) : txtPost.Text.Trim();

            if (topicName.Length == 0)
            {
                type = eType.AddTopic;

                lblError.Text = Lang.Trans("Please enter topic name.");
                return;
            }

            if (post.Length == 0)
            {
                type = eType.AddTopic;

                lblError.Text = Lang.Trans("Please enter post text.");
                return;
            }

            #region Find unclosed [quote] tags

            int openQuotesCount = Regex.Matches(post, @"\[quote", RegexOptions.IgnoreCase).Count;
            int closedQuotesCount = Regex.Matches(post, @"\[/quote", RegexOptions.IgnoreCase).Count;
            if (openQuotesCount != closedQuotesCount)
            {
                type = eType.AddTopic;
                this.post = post;

                lblError.Text = Lang.Trans("Please close all [quote] tags with a [/quote] tag!");
                return;
            }

            #endregion

            if (CurrentUserSession != null)
            {
                var groupTopic = new GroupTopic(GroupID, CurrentUserSession.Username)
                                     {
                                         Name = topicName,
                                         Posts = 1,
                                         Locked = cbLocked.Checked
                                     };

                if (cbCreatePoll.Checked)
                {
                    if (validatePollsChoices())
                    {
                        groupTopic.IsPoll = true;
                    }
                    else
                    {
                        lblError.Text = Lang.Trans("Please enter at least one choice!");
                        return;
                    }
                }

                if (cbSticky.Checked)
                {
                    if (!DatePicker1.ValidDateEntered)
                    {
                        lblError.Text = Lang.Trans("Please select date!");
                        return;
                    }
                    groupTopic.StickyUntil = DatePicker1.SelectedDate;
                }

                groupTopic.Save();

                User.AddScore(CurrentUserSession.Username, Config.UserScores.NewTopic, "NewTopic");

                var groupPost = new GroupPost(groupTopic.ID, CurrentUserSession.Username) {Post = post};
                groupPost.Save();

                #region Subscribe automatically for this topic

                GroupTopicSubscription groupTopicSubscription = new GroupTopicSubscription(CurrentUserSession.Username, groupTopic.ID, GroupID);
                groupTopicSubscription.DateUpdated = groupTopic.DateUpdated;
                groupTopicSubscription.Save();

                #endregion

                #region create a poll

                if (cbCreatePoll.Checked)
                {
                    foreach (RepeaterItem item in rptChoices.Items)
                    {
                        TextBox txtChoice = item.FindControl("txtChoice") as TextBox;

                        if (txtChoice != null && txtChoice.Text.Trim() != String.Empty)
                        {
                            GroupPollsChoice choice = new GroupPollsChoice(groupTopic.ID);
                            choice.Answer = txtChoice.Text.Trim();
                            choice.Save();
                        }
                    }
                }

                #endregion

                #region Add NewGroupTopic Event

                Event newEvent = new Event(CurrentUserSession.Username);

                newEvent.FromGroup = GroupID;
                newEvent.Type = Event.eType.NewGroupTopic;
                NewGroupTopic newGroupTopic = new NewGroupTopic();
                newGroupTopic.GroupTopicID = groupTopic.ID;
                newEvent.DetailsXML = Misc.ToXml(newGroupTopic);

                newEvent.Save();

                Group group = Group.Fetch(groupTopic.GroupID);

                string[] usernames = User.FetchMutuallyFriends(CurrentUserSession.Username);

                foreach (string friendUsername in usernames)
                {
                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                String.Format("Your friend {0} has posted a new topic {1} in the {2} group".Translate(),
                                              "<b>" + CurrentUserSession.Username + "</b>",
                                              Server.HtmlEncode(groupTopic.Name), Server.HtmlEncode(group.Name));
                            int imageID = 0;
                            try
                            {
                                imageID = Photo.GetPrimary(CurrentUserSession.Username).Id;
                            }
                            catch (NotFoundException)
                            {
                                imageID = ImageHandler.GetPhotoIdByGender(CurrentUserSession.Gender);
                            }
                            string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, friendUsername, text,
                                                             thumbnailUrl,
                                                             UrlRewrite.CreateShowGroupTopicsUrl(
                                                                 groupTopic.ID.ToString()));
                        }
                    }
                }

                GroupMember[] groupMembers = GroupMember.Fetch(GroupID, true);

                foreach (GroupMember groupMember in groupMembers)
                {
                    // A user should not receive events for their topics
                    if (groupMember.Username == CurrentUserSession.Username) continue;

                    if (Config.Users.NewEventNotification)
                    {
                        if (group != null)
                        {
                            string text =
                                String.Format("There is a new topic {0} in the {1} group".Translate(),
                                              "<b>" + Server.HtmlEncode(groupTopic.Name) + "</b>",
                                              Server.HtmlEncode(group.Name));
                            string thumbnailUrl = GroupIcon.CreateImageUrl(group.ID, 50, 50, true);
                            User.SendOnlineEventNotification(CurrentUserSession.Username, groupMember.Username, text,
                                                             thumbnailUrl, UrlRewrite.CreateShowGroupUrl(group.ID.ToString()));
                        }
                    }
                }

                #endregion
            }

            Response.Redirect(UrlRewrite.CreateShowGroupTopicsUrl(GroupID.ToString()));
        }
示例#18
0
        private void LoadSettings()
        {
            virtualRoot = WebUtils.GetApplicationRoot();

            pageId                = WebUtils.ParseInt32FromQueryString("pageid", -1);
            moduleId              = WebUtils.ParseInt32FromQueryString("mid", -1);
            groupId               = WebUtils.ParseInt32FromQueryString("groupid", -1);
            topicId               = WebUtils.ParseInt32FromQueryString("topic", -1);
            postId                = WebUtils.ParseInt32FromQueryString("postid", -1);
            pageNumber            = WebUtils.ParseInt32FromQueryString("pagenumber", 1);
            lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl();
            timeOffset            = SiteUtils.GetUserTimeOffset();

            switch (siteSettings.AvatarSystem)
            {
            case "gravatar":
                allowGravatars = true;
                disableAvatars = true;
                break;

            case "internal":
                allowGravatars = false;
                disableAvatars = false;
                break;

            case "none":
            default:
                allowGravatars = false;
                disableAvatars = true;
                break;
            }

            if (Request.IsAuthenticated)
            {
                theUser = SiteUtils.GetCurrentSiteUser();
                if (groupId > -1)
                {
                    isSubscribedToGroup = Group.IsSubscribed(groupId, theUser.UserId);
                }
                if (topicId > -1)
                {
                    isSubscribedToTopic = GroupTopic.IsSubscribed(topicId, theUser.UserId);
                }
            }

            if (WebUser.IsAdminOrContentAdmin)
            {
                edMessage.WebEditor.ToolBar = ToolBar.FullWithTemplates;
            }
            else if ((Request.IsAuthenticated) && (WebUser.IsInRoles(siteSettings.UserFilesBrowseAndUploadRoles)))
            {
                edMessage.WebEditor.ToolBar = ToolBar.GroupWithImages;
            }
            else
            {
                edMessage.WebEditor.ToolBar = ToolBar.Group;
            }

            edMessage.WebEditor.SetFocusOnStart = true;
            edMessage.WebEditor.Height          = Unit.Parse("350px");

            moduleSettings = ModuleSettings.GetModuleSettings(moduleId);

            useSpamBlockingForAnonymous = WebUtils.ParseBoolFromHashtable(
                moduleSettings, "GroupEnableAntiSpamSetting", useSpamBlockingForAnonymous);

            includePostBodyInNotification = WebUtils.ParseBoolFromHashtable(
                moduleSettings, "IncludePostBodyInNotificationEmail", includePostBodyInNotification);



            if (useSpamBlockingForAnonymous)
            {
                captcha.ProviderName        = siteSettings.CaptchaProvider;
                captcha.Captcha.ControlID   = "captcha" + moduleId.ToString(CultureInfo.InvariantCulture);
                captcha.RecaptchaPrivateKey = siteSettings.RecaptchaPrivateKey;
                captcha.RecaptchaPublicKey  = siteSettings.RecaptchaPublicKey;
            }
        }
示例#19
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (group == null)
            {
                group = new Group(groupId);
            }

            if (!group.AllowAnonymousPosts)
            {
                captcha.Enabled     = false;
                pnlAntiSpam.Visible = false;
                pnlEdit.Controls.Remove(pnlAntiSpam);
            }

            Page.Validate();
            if (!Page.IsValid)
            {
                PopulateControls();
                return;
            }
            else
            {
                if ((useSpamBlockingForAnonymous) && (pnlAntiSpam.Visible))
                {
                    if (!captcha.IsValid)
                    {
                        PopulateControls();
                        return;
                    }
                }

                GroupTopic topic;
                bool       userIsAllowedToUpdateThisPost = false;
                if (topicId == -1)
                {
                    topic         = new GroupTopic();
                    topic.GroupId = groupId;
                }
                else
                {
                    if (postId > -1)
                    {
                        topic = new GroupTopic(topicId, postId);
                        if (WebUser.IsAdmin ||
                            WebUser.IsInRoles(CurrentPage.EditRoles) ||
                            (this.theUser.UserId == topic.PostUserId)
                            )
                        {
                            userIsAllowedToUpdateThisPost = true;
                        }
                    }
                    else
                    {
                        topic = new GroupTopic(topicId);
                    }
                    groupId = topic.GroupId;
                }

                topic.ContentChanged += new ContentChangedEventHandler(topic_ContentChanged);
                topic.PostSubject     = this.txtSubject.Text;
                topic.PostMessage     = edMessage.Text;

                if (Request.IsAuthenticated)
                {
                    SiteUser siteUser = SiteUtils.GetCurrentSiteUser();
                    if (siteUser != null)
                    {
                        topic.PostUserId = siteUser.UserId;
                    }
                    if (chkSubscribeToGroup.Checked)
                    {
                        group.Subscribe(siteUser.UserId);
                    }
                    else
                    {
                        topic.SubscribeUserToTopic = this.chkNotifyOnReply.Checked;
                    }
                }
                else
                {
                    topic.PostUserId = 0;                     //guest
                }

                string topicViewUrl = SiteRoot + "/Groups/Topic.aspx?topic="
                                      + topic.TopicId.ToInvariantString()
                                      + "&mid=" + moduleId.ToInvariantString()
                                      + "&pageid=" + pageId.ToInvariantString()
                                      + "&ItemID=" + groupId.ToInvariantString()
                                      + "&pagenumber=" + this.pageNumber.ToInvariantString();

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

                    topicViewUrl = SiteRoot + "/Groups/Topic.aspx?topic="
                                   + topic.TopicId.ToInvariantString()
                                   + "&mid=" + moduleId.ToInvariantString()
                                   + "&pageid=" + pageId.ToInvariantString()
                                   + "&ItemID=" + groupId.ToInvariantString()
                                   + "&pagenumber=" + this.pageNumber.ToInvariantString()
                                   + "#post" + topic.PostId.ToInvariantString();

                    // Send notification to subscribers
                    // this doesn't make sense it only gets topic subscribers not group subscribers and yet I get the emails
                    DataSet dsTopicSubscribers = topic.GetTopicSubscribers();

                    //ConfigurationManager.AppSettings["DefaultEmailFrom"]
                    GroupNotificationInfo notificationInfo = new GroupNotificationInfo();

                    CultureInfo defaultCulture = SiteUtils.GetDefaultCulture();

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

                    if (includePostBodyInNotification)
                    {
                        notificationInfo.BodyTemplate = Server.HtmlDecode(SecurityHelper.RemoveMarkup(topic.PostMessage)) + "\n\n\n";
                    }

                    notificationInfo.BodyTemplate
                        += ResourceHelper.GetMessageTemplate(defaultCulture,
                                                             "GroupNotificationEmail.config");

                    notificationInfo.FromEmail   = siteSettings.DefaultEmailFromAddress;
                    notificationInfo.SiteName    = siteSettings.SiteName;
                    notificationInfo.ModuleName  = new Module(moduleId).ModuleTitle;
                    notificationInfo.GroupName   = new Group(groupId).Title;
                    notificationInfo.Subject     = topic.PostSubject;
                    notificationInfo.Subscribers = dsTopicSubscribers;
                    notificationInfo.MessageLink = topicViewUrl;
                    notificationInfo.UnsubscribeGroupTopicLink = SiteRoot + "/Groups/UnsubscribeTopic.aspx?topicid=" + topic.TopicId;
                    notificationInfo.UnsubscribeGroupLink      = SiteRoot + "/Groups/UnsubscribeGroup.aspx?mid=" + moduleId + "&itemid=" + topic.GroupId;
                    notificationInfo.SmtpSettings = SiteUtils.GetSmtpSettings();

                    ThreadPool.QueueUserWorkItem(new WaitCallback(Notification.SendGroupNotificationEmail), notificationInfo);


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

                //WebUtils.SetupRedirect(this, topicViewUrl);
                Response.Redirect(topicViewUrl);
            }
        }
示例#20
0
        private void PopulateControls()
        {
            GroupTopic topic = new GroupTopic(topicId);

            if (topic.TopicId == -1)
            {
                //topic does not exist, probably just got deleted
                //redirect back to topic list
                WebUtils.SetupRedirect(this, SiteRoot + "/Groups/GroupView.aspx?ItemID="
                                       + ItemId.ToInvariantString()
                                       + "&amp;pageid=" + PageId.ToInvariantString()
                                       + "&amp;mid=" + moduleId.ToInvariantString());

                return;
            }

            Group group = new Group(topic.GroupId);

            if (group.ModuleId != moduleId)
            {
                SiteUtils.RedirectToAccessDeniedPage(this);
                return;
            }

            Title = SiteUtils.FormatPageTitle(siteSettings, CurrentPage.PageName + " - " + topic.Subject);

            litGroupDescription.Text = group.Description;

            MetaDescription = string.Format(CultureInfo.InvariantCulture, GroupResources.GroupTopicMetaDescriptionFormat, SecurityHelper.RemoveMarkup(topic.Subject));

            if ((topic.TotalReplies + 1) == group.PostsPerPage)
            {
                nextPageNumber = PageNumber + 1;
            }
            else
            {
                nextPageNumber = PageNumber;
            }

            lnkGroup.HRef = SiteRoot + "/Groups/GroupView.aspx?ItemID="
                            + group.ItemId.ToInvariantString()
                            + "&amp;pageid=" + PageId.ToInvariantString()
                            + "&amp;mid=" + group.ModuleId.ToInvariantString();

            lnkGroup.InnerHtml       = group.Title;
            lblTopicDescription.Text = Server.HtmlEncode(topic.Subject);
            lblHeading.Text          = lblTopicDescription.Text;

            string pageUrl = SiteRoot
                             + "/Groups/Topic.aspx?pageid="
                             + PageId.ToInvariantString()
                             + "&amp;mid=" + moduleId.ToInvariantString()
                             + "&amp;ItemID=" + ItemId.ToInvariantString()
                             + "&amp;topic=" + topicId.ToInvariantString()
                             + "&amp;pagenumber={0}";

            pgrTop.PageURLFormat = pageUrl;
            pgrTop.ShowFirstLast = true;
            pgrTop.CurrentIndex  = PageNumber;
            pgrTop.PageSize      = group.TopicsPerPage;
            pgrTop.PageCount     = topic.TotalPages;
            pgrTop.Visible       = (pgrTop.PageCount > 1);

            pgrBottom.PageURLFormat = pageUrl;
            pgrBottom.ShowFirstLast = true;
            pgrBottom.CurrentIndex  = PageNumber;
            pgrBottom.PageSize      = group.TopicsPerPage;
            pgrBottom.PageCount     = topic.TotalPages;
            pgrBottom.Visible       = (pgrBottom.PageCount > 1);


            if ((Request.IsAuthenticated) || (group.AllowAnonymousPosts))
            {
                lnkNewTopic.InnerHtml = "<img alt='' src='" + ImageSiteRoot + "/Data/SiteImages/" + NewTopicImage + "'  />&nbsp;"
                                        + GroupResources.GroupTopicViewReplyLabel;

                lnkNewTopic.HRef = siteSettings.SiteRoot
                                   + "/Groups/EditPost.aspx?"
                                   + "topic=" + topicId.ToString()
                                   + "&amp;groupid=" + group.ItemId.ToInvariantString()
                                   + "&amp;mid=" + moduleId.ToInvariantString()
                                   + "&amp;pageid=" + PageId.ToString()
                                   + "&amp;pagenumber=" + nextPageNumber.ToInvariantString();

                lnkNewTopicBottom.InnerHtml = "<img alt='' src='" + ImageSiteRoot + "/Data/SiteImages/" + NewTopicImage + "'  />&nbsp;"
                                              + GroupResources.GroupTopicViewReplyLabel;

                lnkNewTopicBottom.HRef = SiteRoot
                                         + "/Groups/EditPost.aspx?"
                                         + "topic=" + topicId.ToInvariantString()
                                         + "&amp;groupid=" + group.ItemId.ToString()
                                         + "&amp;mid=" + moduleId.ToInvariantString()
                                         + "&amp;pageid=" + PageId.ToInvariantString()
                                         + "&amp;pagenumber=" + nextPageNumber.ToInvariantString();

                lnkLogin.Visible       = false;
                lnkLoginBottom.Visible = false;
            }

            lnkLogin.NavigateUrl = SiteRoot + "/Secure/Login.aspx";
            lnkLogin.Text        = GroupResources.GroupsLoginRequiredLink;

            lnkLoginBottom.NavigateUrl = SiteRoot + "/Secure/Login.aspx";
            lnkLoginBottom.Text        = GroupResources.GroupsLoginRequiredLink;



            using (IDataReader reader = topic.GetPosts(PageNumber))
            {
                rptMessages.DataSource = reader;
                rptMessages.DataBind();
            }

            if (
                (rptMessages.Items.Count == 0) &&
                (ItemId > -1)
                )
            {
                // when the last post in a topic is deleted
                // the GroupPostEditPage redirects to this page
                // but it will hit this code and go back to the group instead of showing
                // the empty topic
                String redirectUrl = SiteRoot
                                     + "/Groups/GroupView.aspx?"
                                     + "ItemID=" + ItemId.ToInvariantString()
                                     + "&pageid=" + PageId.ToInvariantString()
                                     + "&mid=" + moduleId.ToInvariantString();

                WebUtils.SetupRedirect(this, redirectUrl);
            }
            else
            {
                topic.UpdateTopicViewStats();
            }
        }
示例#21
0
        private void PopulateControls()
        {
            GroupTopic topic = null;

            if (topicId == -1)
            {
                this.btnDelete.Visible   = false;
                this.rptMessages.Visible = false;
                Title = SiteUtils.FormatPageTitle(siteSettings, CurrentPage.PageName + " - " + GroupResources.NewTopicLabel);
            }
            else
            {
                if (postId > -1)
                {
                    topic = new GroupTopic(topicId, postId);
                    if (WebUser.IsAdmin ||
                        (isSiteEditor) ||
                        (WebUser.IsInRoles(CurrentPage.EditRoles)) ||
                        ((this.theUser != null) && (this.theUser.UserId == topic.PostUserId))
                        )
                    {
                        this.txtSubject.Text = topic.PostSubject;
                        edMessage.Text       = topic.PostMessage;
                    }
                }
                else
                {
                    topic = new GroupTopic(topicId);
                    this.txtSubject.Text
                        = ResourceHelper.GetMessageTemplate(ResourceHelper.GetDefaultCulture(), "GroupPostReplyPrefix.config")
                          + topic.Subject;
                }

                if ((group != null) && (topic != null))
                {
                    Title = SiteUtils.FormatPageTitle(siteSettings, group.Title + " - " + topic.Subject);
                }

                if (groupId == -1)
                {
                    groupId = topic.GroupId;
                }

                using (IDataReader reader = topic.GetPostsReverseSorted())
                {
                    this.rptMessages.DataSource = reader;
                    this.rptMessages.DataBind();
                }
            }

            if (group != null)
            {
                litGroupPostLabel.Text   = group.Title;
                litGroupDescription.Text = group.Description;
            }

            if (postId == -1)
            {
                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);
                }
            }

            chkNotifyOnReply.Checked = isSubscribedToTopic;

            lnkPageCrumb.Text        = CurrentPage.PageName;
            lnkPageCrumb.NavigateUrl = SiteUtils.GetCurrentPageUrl();
            lnkGroup.HRef            = SiteRoot + "/Groups/GroupView.aspx?ItemID="
                                       + group.ItemId.ToInvariantString()
                                       + "&amp;pageid=" + pageId.ToInvariantString()
                                       + "&amp;mid=" + group.ModuleId.ToInvariantString();

            lnkGroup.InnerHtml = group.Title;
            if (topic != null)
            {
                lblTopicDescription.Text = Server.HtmlEncode(topic.Subject);
            }
        }