Пример #1
0
        public virtual ActionResult ArticleEditor(long? articleId, ArticleEditorVM model, string submitType)
        {
            model.SaveButton = submitType;

            PartialPostVM returnValue = null;
            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;

            ProviderArticle anArticle;
            if (articleId.HasValue)
            {
                anArticle = new ProviderArticle(articleId.Value);
            }
            else
            {
                anArticle = new ProviderArticle();
            }

            List<string> errorList = new List<string>();

            // Validate that the model is fine first and foremost to make sure we're not trying to work with bad data
            if (ModelState.IsValid)
            {
                ContentCheck result = null;
                if (!currentMember.IsSuperAdmin && anArticle.IsNew)
                {
                    string email = string.Empty;
                    string domain = string.Empty;

                    if (currentMember.HasValidAltId(ProviderAlternateMemberId.AlternateType.Email))
                    {
                        email = currentMember.Emails[0].Email.Address;
                    }
                    else if (!string.IsNullOrWhiteSpace(model.ArticleEmail))
                    {
                        email = model.ArticleEmail;
                    }

                    if (currentMember.HasValidAltId(ProviderAlternateMemberId.AlternateType.Domain))
                    {
                        domain = currentMember.Domains[0].Domain.AbsoluteUri;
                    }

                    // The mollom client crashes if passed in nbsp so strip those before sending it over
                    string cleanedArticleBody = HtmlParser.StripSpecialChars(model.ArticleBody);
                    MollomClient client = new MollomClient(InsideWordWebSettings.MollomPrivateKey, InsideWordWebSettings.MollomPublicKey);
                    result = client.CheckContent(model.Title, cleanedArticleBody,
                                                                currentMember.DisplayAdministrativeName,
                                                                email,
                                                                domain,
                                                                HttpContext.Request.UserHostAddress);
                }

                if (result != null && result.Classification == ContentClassification.Spam)
                {
                    ModelState.AddModelError("", "Your article has been blocked as spam.");
                }
                else if (result != null && result.Quality < InsideWordWebSettings.MollomArticleQuality)
                {
                    ModelState.AddModelError("", "The quality of your article is too low. Try improving things such as spelling and grammar.");
                }
                else if (!currentMember.CanEdit(anArticle))
                {
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Message = string.Empty,
                        Content = Url.Action(MVC.Error.Index(401))
                    };
                }
                else if (ArticleBL.Save(model, anArticle, ProviderCurrentMember.Instance, ref errorList) &&
                         (model.SaveState == ArticleEditorVM.SaveStates.DraftAndPreview || model.SaveState == ArticleEditorVM.SaveStates.Published))
                {
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Message = string.Empty,
                        Content = Url.Action(MVC.Article.ArticleDetails(anArticle.Id.Value))
                    };
                }
            }

            if (returnValue == null)
            {
                foreach (string error in errorList)
                {
                    ModelState.AddModelError("", error);
                }

                model.Refresh(anArticle, currentMember, ProviderCategory.Root.Children());
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = string.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Article.Views.ArticleEditor, (object)model)
                };
            }

            return Json(returnValue);
        }
Пример #2
0
        public static bool Save(ArticleEditorVM model, ProviderArticle anArticle, ProviderCurrentMember currentMember, ref List<string> errorList)
        {
            bool returnValue = false;

            ProviderMember owningMember = GetArticleOwner(model, anArticle, currentMember);

            // IsNowClaimedArticle indicates if an article's state changed from unclaimed to now claimed
            bool IsNowClaimedArticle = anArticle.MemberId == null && owningMember.Id.HasValue;
            anArticle.MemberId = owningMember.Id;

            if (AssociatePhotos(model.ArticleBody, anArticle, ref errorList))
            {
                if (owningMember.IsActive && !currentMember.IsLoggedOn)
                {
                    // The owner is an active member but the current member is not logged in?! We're not sure if the member was lazy
                    // and didn't bother to login or if this is a malicious person, so we will set IsPublished to false and treat
                    // the article as a draft just to be safe.
                    anArticle.IsPublished = false;
                }
                else if (model.SaveState == ArticleEditorVM.SaveStates.Published)
                {
                    anArticle.IsPublished = true;
                }
                else if (model.SaveState == ArticleEditorVM.SaveStates.DraftAndContinue ||
                         model.SaveState == ArticleEditorVM.SaveStates.DraftAndPreview)
                {
                    anArticle.IsPublished = false;
                }
                else
                {
                    // defensive programming
                    anArticle.IsPublished = false;
                }

                anArticle.Title = model.Title;
                anArticle.Blurb = model.Blurb;
                anArticle.RawText = model.ArticleBody;

                if (anArticle.IsNew)
                {
                    anArticle.CreateDate = DateTime.UtcNow;
                }
                anArticle.EditDate = DateTime.UtcNow;

                // remove previous categories before adding new ones
                anArticle.RemoveAllCategories();
                anArticle.AddCategory(model.ArticleCategoryId);

                // important that we fetch this info before we save because then the article is no longer new.
                bool isNew = anArticle.IsNew;

                anArticle.Save();

                // if the current member is not logged on then save it in their workspace
                if (!currentMember.IsLoggedOn)
                {
                    currentMember.CurrentWorkSpace.ArticleIdList.Add(anArticle.Id.Value);
                }

                // Send out an e-mail for the article only if it was claimed for the first time through e-mail
                // and the member is not active
                if (IsNowClaimedArticle && !string.IsNullOrEmpty(model.ArticleEmail) && !currentMember.IsActive)
                {
                    EmailManager.Instance.SendEditArticleEmail(new MailAddress(model.ArticleEmail), anArticle, owningMember);
                }
                returnValue = true;
            }

            return returnValue;
        }
Пример #3
0
        public virtual ActionResult ArticleEditor(long? articleId)
        {
            ActionResult returnValue = null;
            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;

            if (!articleId.HasValue)
            {
                if (!currentMember.IsLoggedOn)
                {
                    // Tried as hard as I could but we can't seem to use Outputcache for this controller
                    // so we will cache it our way with a static.
                    if (InsideWordWebStaticCache.Instance.NewArticleEditorView == null)
                    {
                        ArticleEditorVM viewModel = new ArticleEditorVM();
                        viewModel.Parse(ProviderCurrentMember.Instance, ProviderCategory.Root.Children());
                        InsideWordWebStaticCache.Instance.NewArticleEditorView = PartialView(viewModel);
                    }
                    returnValue = InsideWordWebStaticCache.Instance.NewArticleEditorView;
                }
                else
                {
                    ArticleEditorVM viewModel = new ArticleEditorVM();
                    viewModel.Parse(ProviderCurrentMember.Instance, ProviderCategory.Root.Children());
                    returnValue = PartialView(viewModel);
                }
            }
            else
            {
                ProviderArticle anArticle = new ProviderArticle(articleId.Value);
                ArticleEditorVM viewModel = new ArticleEditorVM();
                viewModel.Parse(anArticle, ProviderCurrentMember.Instance, ProviderCategory.Root.Children());
                returnValue = PartialView(viewModel);
            }

            return returnValue;
        }
Пример #4
0
        /// <summary>
        /// Function to help determine the owner of an article. If sufficient information is
        /// provided and the owner does not exist in the system then they will be created.
        /// </summary>
        /// <param name="model">view model containing the data of the new article</param>
        /// <param name="currentMember">the current member using the site</param>
        /// <returns>Returns a ProviderMember who is the owner of the article</returns>
        public static ProviderMember GetArticleOwner(ArticleEditorVM model, ProviderArticle anArticle, ProviderCurrentMember currentMember)
        {
            ProviderMember owningMember;

            if (anArticle.MemberId.HasValue)
            {
                owningMember = new ProviderMember(anArticle.MemberId.Value);
            }
            else if (anArticle.IsNew || !string.IsNullOrEmpty(model.ArticleEmail))
            {
                // Have we been provided with an e-mail of the owner?
                if (!string.IsNullOrEmpty(model.ArticleEmail))
                {
                    MailAddress email = new MailAddress(model.ArticleEmail);
                    long? memberId = ProviderEmail.FindOwner(email, true);
                    if (memberId.HasValue)
                    {
                        // The owner already exists in our system so just retrieve them
                        owningMember = new ProviderMember(memberId.Value);
                    }
                    else
                    {
                        // the owner doesn't exists so create them
                        owningMember = new ProviderMember();
                        owningMember.CreateDate = DateTime.UtcNow;
                        owningMember.EditDate = DateTime.UtcNow;
                        owningMember.Save();

                        // attach the e-mail to this member
                        ProviderEmail anEmail = new ProviderEmail();
                        anEmail.MemberId = owningMember.Id.Value;
                        anEmail.IsValidated = false;
                        anEmail.CreateDate = DateTime.UtcNow;
                        anEmail.EditDate = DateTime.UtcNow;
                        anEmail.Email = email;
                        anEmail.Save();
                    }
                }
                else
                {
                    // no e-mail provided so just use whoever is currently logged on, whether they be anonymous or not
                    owningMember = currentMember;
                }
            }
            else
            {
                // this article has no owner so just return a blank member
                owningMember = new ProviderMember();
            }

            return owningMember;
        }