Beispiel #1
0
        /// <summary>
        /// Functions generates the Try Create Review Forum Builder XML
        /// </summary>
        /// <param name="ID">ID of the review forum to get</param>
        /// <param name="skip">Number to skip</param>
        /// <param name="show">Number to show</param>
        /// <param name="orderBy">Ordering of the review forum</param>
        /// <param name="direction">Direction of ordering </param>
        /// <param name="entry">Whether we need to add a description at the top</param>
        public void TryCreateReviewForumBuilderXML(int ID, int skip, int show, ReviewForum.OrderBy orderBy, bool direction, bool entry)
        {
            ReviewForum reviewForum = new ReviewForum(InputContext);

            reviewForum.InitialiseViaReviewForumID(ID, false);

            if (SwitchSites(reviewForum.SiteID, ID, skip, show, orderBy, direction, entry))
            {
                return;
            }

            reviewForum.GetReviewForumThreadList(show, skip, orderBy, direction);
            //add the entry 
            if (entry)
            {
                GuideEntrySetup guideEntrySetup = new GuideEntrySetup(reviewForum.H2G2ID);
                //guideEntrySetup.ShowReferences = true;
                guideEntrySetup.SafeToCache = true;

                GuideEntry guideEntry = new GuideEntry(InputContext, guideEntrySetup);
                guideEntry.Initialise();

                _GuideEntryElement = CreateElement("ROOT");
                _GuideEntryElement.AppendChild(ImportNode(guideEntry.RootElement.FirstChild));
            }
            //add the fact that we don't want/have an entry
            else
            {
                _GuideEntryElement = CreateElement("ROOT");
                AddElementTag(_GuideEntryElement, "NOGUIDE");
            }

            AddInside(reviewForum);
        }
        /// <summary>
        /// Remove the thread from the Forum
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="rFID"></param>
        /// <param name="H2G2ID"></param>
        /// <param name="threadID"></param>
        /// <param name="forumID"></param>
        /// <param name="hasPermission"></param>
        public void RemoveThreadFromForum(int userID, int rFID, int H2G2ID, ref int threadID, ref int forumID, bool hasPermission)
        {
            XmlElement submitReviewForum = AddElementTag(RootElement, "SUBMIT-REVIEW-FORUM");
            if (rFID <= 0 || H2G2ID <= 0)
            {
                AddErrorXml("RMBADID", "Bad arguments for this action", submitReviewForum);
                return;
            }

            //Initialise the article
            GuideEntrySetup guideSetup = new GuideEntrySetup(H2G2ID);
            guideSetup.ShowEntryData = true;
            guideSetup.ShowPageAuthors = false;
            guideSetup.ShowReferences = false;

            GuideEntry guideEntry = new GuideEntry(InputContext, guideSetup);
            guideEntry.Initialise();

            int postID = 0;

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("fetchreviewforummemberdetails"))
            {
                dataReader.AddParameter("h2g2id", H2G2ID);
                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    int submitterID = dataReader.GetInt32NullAsZero("SubmitterID");
                    postID = dataReader.GetInt32NullAsZero("PostID");
                    threadID = dataReader.GetInt32NullAsZero("ThreadID");
                    forumID = dataReader.GetInt32NullAsZero("ForumID");
                    int actualReviewForumID = dataReader.GetInt32NullAsZero("ReviewForumID");

	                //make sure that we are in the right review forum for the article
                    if (rFID != actualReviewForumID)
                    {
                        AddErrorXml("BADRFID", "The article is in a different review forum.", submitReviewForum);
                        return;
                    }

                	//Permission has been verified by the caller so don't check
                    if (!hasPermission)
                    {
 		                //ok if you're an editor
                        if (!InputContext.ViewingUser.IsEditor)
                        {
                            //ok if you are the author
                            if (!(guideEntry.AuthorsUserID == InputContext.ViewingUser.UserID))
                            {
                                //ok if you are the submitter
                                if (!(InputContext.ViewingUser.UserID == submitterID))
                                {
                                    AddErrorXml("BADUSER", "You do not have permission to move the thread", submitReviewForum);
                                }
                            }
                        }
                   }
                }
                else
                {
                    AddErrorXml("BADH2G2ID", "The article is not in a review forum.", submitReviewForum);
                    return;
                }
            }

            ReviewForum reviewForum = new ReviewForum(InputContext);
            reviewForum.InitialiseViaReviewForumID(rFID, false);
            if (!reviewForum.IsInitialised)
            {
                AddErrorXml("NOREVIEW", "Invalid Review Forum ID", submitReviewForum);
                return;
            }

            bool movedThread = false;

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("MoveThread2"))
            {
                dataReader.AddParameter("ThreadID", threadID);
                dataReader.AddParameter("ForumID", guideEntry.ForumID);
                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    movedThread = dataReader.GetBoolean("Success");
                }
            }
            if(!movedThread)
            {
                AddErrorXml("NOMOVE", "Failed to move thread to article", submitReviewForum);
                return;
            }

            int removedFromPeerReview = 0;
            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("removearticlefrompeerreview"))
            {
                dataReader.AddParameter("H2G2ID", H2G2ID);
                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    removedFromPeerReview = dataReader.GetInt32NullAsZero("Success");
                }
            }

            bool undoneThread = false;
            if (removedFromPeerReview == 0)
            {
                using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("UndoThreadMove"))
                {
                    dataReader.AddParameter("ThreadID", threadID);
                    dataReader.AddParameter("PostID", 0);
                    dataReader.Execute();
                    // Check to see if we found anything
                    if (dataReader.HasRows && dataReader.Read())
                    {
                        undoneThread = dataReader.GetBoolean("Success");
                    }
                }
                if (!undoneThread)
                {
                    AddErrorXml("HALFMOVE", "The thread has been moved, but not from review", submitReviewForum);
                    return;
                }
                else
                {
                    AddErrorXml("NOMOVE", "Failed to move thread to article", submitReviewForum);
                    return;
                }
            }

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("ForceUpdateEntry"))
            {
                dataReader.AddParameter("H2G2ID", H2G2ID);
                dataReader.Execute();
            }

            string postSubject = String.Empty;
            string postText = String.Empty;
            string newSubject = String.Empty;

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("FetchPostDetails"))
            {
                dataReader.AddParameter("PostID", postID);
                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    postSubject = dataReader.GetStringNullAsEmpty("Subject");
                    postText = dataReader.GetStringNullAsEmpty("Text");

                    newSubject = reviewForum.ReviewForumName + ": " + postSubject;
                }
            }
            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("UpdatePostDetails"))
            {
                dataReader.AddParameter("UserID", 0);
                dataReader.AddParameter("PostID", postID);
                dataReader.AddParameter("Subject", newSubject);
                dataReader.AddParameter("Text", postText);
                dataReader.AddParameter("SetLastUpdated", false);
                dataReader.AddParameter("ForceModerateAndHide", false);
                dataReader.AddParameter("IgnoreModeration", true);
                dataReader.Execute();
            }
            //update the thread first subject details
            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("updatethreadfirstsubject"))
            {
                dataReader.AddParameter("ThreadID", threadID);
                dataReader.AddParameter("firstsubject", newSubject);
                dataReader.Execute();
            }
            //post the success story
            XmlElement movedThreadXml = AddElementTag(submitReviewForum, "MOVEDTHREAD");
            AddIntElement(movedThreadXml, "H2G2ID", H2G2ID);
            AddTextTag(movedThreadXml, "SUBJECT", guideEntry.Subject);
            XmlElement reviewForumXml = AddElementTag(movedThreadXml, "REVIEWFORUM");
            AddAttribute(reviewForumXml, "ID", rFID);
            AddTextTag(reviewForumXml, "REVIEWFORUMNAME", reviewForum.ReviewForumName);
            AddTextTag(reviewForumXml, "URLFRIENDLYNAME", reviewForum.UrlFriendlyName);

        }
Beispiel #3
0
        private bool CreatePageArticle(int userID, User pageOwner, out GuideEntry masthead)
        {
            bool gotMasthead = false;
            masthead = null;

            if (pageOwner.UserID > 0 && pageOwner.Masthead > 0)
            {
                GuideEntrySetup setup = new GuideEntrySetup(pageOwner.Masthead);
                setup.ShowEntryData = true;
                setup.ShowPageAuthors = true;
                setup.ShowReferences = true;
                setup.SafeToCache = true;

                masthead = new GuideEntry(InputContext, setup);
                masthead.Initialise();

                //TODO do we need to do the XSLT parsing here if so how???
                gotMasthead = true;
            }
            return gotMasthead;
        }
        /// <summary>
        /// Submits an article to a review forum
        /// </summary>
        /// <param name="user"></param>
        /// <param name="H2G2ID"></param>
        /// <param name="siteID"></param>
        /// <param name="response"></param>
        /// <param name="reviewForumID"></param>
        public void SubmitArticle(IUser user, int H2G2ID, int siteID, string response, int reviewForumID)
        {
            XmlElement submitReviewForum = AddElementTag(RootElement, "SUBMIT-REVIEW-FORUM");
            if (user.UserID == 0)
            {
                AddGracefulErrorXml("NO_USERID", "You have not logged in!", "Login", "Login", submitReviewForum);
            }

            if (response == String.Empty)
            {
                AddErrorXml("NO_COMMENT", "There should be comments with this click back to back", submitReviewForum);
            }

            GuideEntrySetup guideSetup = new GuideEntrySetup(H2G2ID);
            guideSetup.ShowEntryData = true;
            guideSetup.ShowPageAuthors = true;
            guideSetup.ShowReferences = false;

            GuideEntry guideEntry = new GuideEntry(InputContext, guideSetup);
            guideEntry.Initialise();

            if (guideEntry.IsSubmittable && !user.IsEditor)
            {
                AddGracefulErrorXml("NO_SUBMIT", "This article is not for review", "FRONTPAGE", "Back to frontpage", submitReviewForum);
            }

            string subjectName = String.Empty;
            XmlElement subjectNameElement = (XmlElement) guideEntry.RootElement.SelectSingleNode("ARTICLE/SUBJECT");
            if (subjectNameElement != null)
            {
                subjectName = subjectNameElement.InnerText;
            }
            int editorID = 0;
            XmlElement editorIDElement = (XmlElement)guideEntry.RootElement.SelectSingleNode("PAGEAUTHOR/EDITOR/USERID");
            if (editorIDElement != null)
            {
                Int32.TryParse(editorIDElement.InnerText, out editorID);
            }

            string subject = "A" + H2G2ID.ToString() + " - " + subjectName;
            string aNumber = "A" + H2G2ID.ToString();

            User editor = new User(InputContext);
            editor.CreateUser(editorID);

            string editedComments = "Entry: " + subjectName + " - A" + H2G2ID + "\n";
            editedComments += "Author: " + editor.UserName + " - U" + editorID + "\n\n";
            editedComments += response;

            string hash = String.Empty;
            string hashString = subject + "<:>" + editedComments + "<:>" + user.UserID + "<:>0<:>0<:>0<:>ToReviewForum";

            using (IDnaDataReader dataReader = InputContext.CreateDnaDataReader("addarticletoreviewforummembers"))
            {
                dataReader.AddParameter("h2g2id", H2G2ID);
                dataReader.AddParameter("reviewforumid", reviewForumID);
                dataReader.AddParameter("submitterid", user.UserID);
                dataReader.AddParameter("subject", subject);
                dataReader.AddParameter("content", editedComments);
                dataReader.AddParameter("Hash", DnaHasher.GenerateHash(hashString));

                dataReader.Execute();
                // Check to see if we found anything
                if (dataReader.HasRows && dataReader.Read())
                {
                    XmlElement article = AddTextTag(submitReviewForum, "ARTICLE", subjectName);
                    AddAttribute(article, "H2G2ID", H2G2ID);
                    XmlElement newThread = AddElementTag(submitReviewForum, "NEW-THREAD");
                    AddAttribute(newThread, "postid", dataReader.GetInt32NullAsZero("PostID"));
                    AddAttribute(newThread, "threadid", dataReader.GetInt32NullAsZero("ThreadID"));
                    AddAttribute(newThread, "forumid", dataReader.GetInt32NullAsZero("ForumID"));

                    ReviewForum reviewForum = new ReviewForum(InputContext);
                    reviewForum.InitialiseViaReviewForumID(reviewForumID, false);
                    AddInside(newThread, reviewForum);
                }
            }
        }