Example #1
0
    private void TrySaveBlog()
    {
        if (_blog == null)
            return;
        try
        {
            int userId;
            if (!int.TryParse(FindUserAutocomplete.HiddenValue, out userId))
            {
                Bitrix.Security.BXUser owner=null;
                if (!Bitrix.Services.Text.BXStringUtility.IsNullOrTrimEmpty(FindUserAutocomplete.TextBoxValue))
                {
                    BXUserCollection owners = 
                        Bitrix.Security.BXUser.GetList(new BXFilter(
                                                            new BXFilterItem(
                                                                    Bitrix.Security.BXUser.Fields.UserName,
                                                                    BXSqlFilterOperators.Equal,
                                                                    FindUserAutocomplete.TextBoxValue
                                                                    )), 
                                                       null);
                    if (owners.Count > 0) owner = owners[0];
                }

                _blog.OwnerId = owner==null ? 0 : owner.UserId;
            }
            else
            {
                BXUser user = Bitrix.Security.BXUser.GetById(userId);
                if (user != null)
                    _blog.OwnerId = userId;
                else
                {
                    _errorMessage = string.Format(GetMessageRaw("Error.UnableToFindUser"), userId);
                    _editorError = BlogEditorError.BlogOwnerIsNotFound;
                }
            }

			_blog.Active = BlogActive.Checked;
			_blog.Name = BlogName.Text;
			_blog.Slug = BlogSlug.Text;
			_blog.Description = BlogDescription.Text;
			if (string.IsNullOrEmpty(BlogSort.Text))
				_blog.Sort = 0;
			else
			{
				try
				{
					_blog.Sort = Convert.ToInt32(BlogSort.Text);
				}
				catch
                {
                }
			}

			_blog.NotifyOfComments = BlogNotifyOfComments.Checked;
			_blog.IsTeam = BlogIsTeam.Checked;
			_blog.XmlId = BlogXmlId.Text;

			List<int> categoryIdList = null;
			ListItemCollection categoryItems = BlogCategories.Items;
			foreach (ListItem categoryItem in categoryItems)
			{
				if (!categoryItem.Selected)
					continue;
				try
				{
                    (categoryIdList ?? (categoryIdList = new List<int>())).Add(Convert.ToInt32(categoryItem.Value));
				}
				catch
				{
				}
			}
            _blog.SetCategoryIds(categoryIdList != null ? categoryIdList.ToArray() : new int[0]);
		
			if (BXModuleManager.IsModuleInstalled("Search"))
			{
				_blog.IndexContent = BXBlogIndexContentMode.All;
				try
				{
					if (Enum.IsDefined(typeof(BXBlogIndexContentMode), BlogIndexContent.SelectedValue))
						_blog.IndexContent = (BXBlogIndexContentMode)Enum.Parse(typeof(BXBlogIndexContentMode), BlogIndexContent.SelectedValue);
				}
				catch
				{
				}
			}

			if (CustomFieldList1.HasItems)
				_blog.CustomValues.Override(CustomFieldList1.Save());

			BXBlogSettings settings = _blog.Settings;
			if(settings == null)
				_blog.Settings = settings = new BXBlogSettings(_blog.Id);

			settings.EnableCommentModeration = EnableCommentModeration.Checked;

			try
			{
				settings.CommentModerationMode = (BXBlogCommentModerationMode)Enum.Parse(typeof(BXBlogCommentModerationMode), CommentModerationMode.SelectedValue, true);
			}
			catch(ArgumentException)
			{
			}

			int linkThreshold;
			if(!int.TryParse(CommentPremoderationFilterLinkThresholdTbx.Text, out linkThreshold))
				linkThreshold = 0;

			settings.CommentModerationFilter.LinkThreshold = linkThreshold;

			if(string.IsNullOrEmpty(CommentPremoderationFilterStopListTbx.Text))
				settings.CommentModerationFilter.SetStopList(null);
			else
				settings.CommentModerationFilter.SetStopList(CommentPremoderationFilterStopListTbx.Text.Replace("\r", string.Empty).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries));

            _blog.Save();
			_blogId = _blog.Id;

            /*
             * Если синдикация уже есть или пользователь инициировал её создание в этом запросе
             */
            if (!Syndication.IsNew || EnableSyndication.Checked)
            {
                Syndication.Enabled = EnableSyndication.Checked;
                Syndication.FeedUrl = SyndicationRssFeedUrl.Text.TrimStart();
                Syndication.Updateable = SyndicationUpdateable.Checked;
                Syndication.RedirectToComments = SyndicationRedirectToComments.Checked;
                Syndication.Save();
            }


			Permissions.BlogId = _blog.Id;
			Permissions.Save(null);
        }
        catch (Exception exc)
        {
            _errorMessage = exc.Message;
            _editorError = EditorMode == BlogEditorMode.Creation ? BlogEditorError.BlogCreation : BlogEditorError.BlogModification; 
        }
    }
Example #2
0
	protected void OnToolBarButtonClick(object sender, CommandEventArgs e)
	{
		if (e.CommandName == "delete")
		{
			try
			{
                BXBlog blog = Blog;
                if (blog != null)
                    blog.Delete();

				GoBack();
			}
			catch (Exception ex)
			{
                _errorMessage = ex.Message;
                _editorError = BlogEditorError.BlogDeleting;
			}
		}
	}
Example #3
0
	private void TryLoadBlog()
	{
        int id = BlogId;
        if (id <= 0)
        {
            _editorMode = BlogEditorMode.Creation;
            _blog = new BXBlog();
        }
        else
        {
            _editorMode = BlogEditorMode.Modification;
            #region OLD
            //if ((_blog = BXBlog.GetById(id, BXTextEncoder.EmptyTextEncoder)) == null)
            //{
            //    _errorMessage = string.Format(GetMessageRaw("Error.UnableToFindBlog"), id);
            //    _editorError = BlogEditorError.BlogIsNotFound;
            //    return;
            //}
            #endregion
            BXBlogCollection blogCol = BXBlog.GetList(
                new BXFilter(new BXFilterItem(BXBlog.Fields.Id, BXSqlFilterOperators.Equal, id)),
                null,
                new BXSelectAdd(
					BXBlog.Fields.CustomFields.DefaultFields,
					BXBlog.Fields.Settings),
                null);

            if ((_blog = blogCol.Count > 0 ? blogCol[0] : null) == null)
            {
                _errorMessage = string.Format(GetMessageRaw("Error.UnableToFindBlog"), id);
                _editorError = BlogEditorError.BlogIsNotFound;
                return;
            }
        }

		if (_editorMode == BlogEditorMode.Modification)
        {
            BlogActive.Checked = _blog.Active;
            BlogName.Text = _blog.TextEncoder.Decode(_blog.Name);
            BlogSlug.Text = _blog.Slug;
            BlogDescription.Text = _blog.TextEncoder.Decode(_blog.Description);
            BlogSort.Text = _blog.Sort.ToString();
            BlogNotifyOfComments.Checked = _blog.NotifyOfComments;
			BlogIsTeam.Checked = _blog.IsTeam;
            BlogXmlId.Text = _blog.TextEncoder.Decode(_blog.XmlId);
			BlogIndexContent.SelectedValue = _blog.IndexContent.ToString();
            ListItemCollection categoryItems = BlogCategories.Items;
            int[] categoryIds = _blog.GetCategoryIds();
            foreach (int categoryId in categoryIds)
            {
                ListItem li = categoryItems.FindByValue(categoryId.ToString());
                if (li != null)
                    li.Selected = true;
            }

            #region OLD
            /*
            if (!_blog.IsNew)
            {
                ListItemCollection userItems = BlogOwner.Items;
                ListItem userItem = userItems.FindByValue(_blog.OwnerId.ToString());
                if (userItem != null)
                    userItem.Selected = true;
            }
            */
            #endregion

            if (!_blog.IsNew)
            {
                BXBlogUser owner = _blog.Owner;
                FindUserAutocomplete.HiddenValue = _blog.OwnerId.ToString();
				string firstName = owner.User.TextEncoder.Decode(owner.User.FirstName);
				firstName = (String.IsNullOrEmpty(firstName)) ? String.Empty : firstName.Trim();

				string lastName = owner.User.TextEncoder.Decode(owner.User.LastName);
                lastName = 
					String.IsNullOrEmpty(lastName)
					? String.Empty 
					: (
						string.IsNullOrEmpty(firstName) 
						? lastName.Trim() + " " 
						: " " + lastName + " "
					);
                FindUserAutocomplete.TextBoxValue = firstName + lastName + "(" + owner.TextEncoder.Decode(owner.GetUserName()) + ")";
            }

            EnableSyndication.Checked = Syndication.Enabled;
            SyndicationRssFeedUrl.Text = Syndication.FeedUrl;
            SyndicationUpdateable.Checked = Syndication.Updateable;
            SyndicationRedirectToComments.Checked = Syndication.RedirectToComments;

            SyndicationRssFeedUrlRequired.Enabled = Syndication.Enabled;
            SyndicationRssFeedUrlRegex.Enabled = Syndication.Enabled;

            #region DEFERRED
            /*
            ListItem postVisibilityModeItem = BlogPostVisibilityMode.Items.FindByValue(_blog.PostVisibilityMode.ToString("G"));
            if (postVisibilityModeItem != null)
                postVisibilityModeItem.Selected = true;

            ListItem addCommentPermissionItem = BlogAddCommentPermission.Items.FindByValue(_blog.AddCommentPermission.ToString("G"));
            if (addCommentPermissionItem != null)
                addCommentPermissionItem.Selected = true;

            ListItem commentApprovalItem = BlogCommentApproval.Items.FindByValue(_blog.CommentApproval.ToString("G"));
            if (commentApprovalItem != null)
                commentApprovalItem.Selected = true;
            */
            #endregion

			BXBlogSettings settings = _blog.Settings ?? new BXBlogSettings(_blog.Id);

			EnableCommentModeration.Checked = settings.EnableCommentModeration;
			ListItem moderationMode = CommentModerationMode.Items.FindByValue(settings.CommentModerationMode.ToString("G").ToUpperInvariant());
			if(moderationMode != null)
				moderationMode.Selected = true;
			CommentPremoderationFilterLinkThresholdTbx.Text = settings.CommentModerationFilter.LinkThreshold.ToString();
			StringBuilder sb = new StringBuilder();
			foreach(string stopListItem in settings.CommentModerationFilter.StopList)
				sb.AppendLine(stopListItem);
			CommentPremoderationFilterStopListTbx.Text = sb.ToString();
        }
        else
        {
			BlogActive.Checked = true;
			BlogSort.Text = "10";
			BlogNotifyOfComments.Checked = true;
			BlogIndexContent.SelectedValue = BXBlogIndexContentMode.All.ToString();
			EnableCommentModeration.Checked = false;
			ListItem moderationMode = CommentModerationMode.Items.FindByValue(BXBlogCommentModerationMode.All.ToString("G").ToUpperInvariant());
			if(moderationMode != null)
				moderationMode.Selected = true;
			CommentPremoderationFilterLinkThresholdTbx.Text = "0";
			CommentPremoderationFilterStopListTbx.Text = string.Empty;
        }
	}