Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ItemDataBound(object sender, AnswersEventArgs <Literal, PostInfo, Literal, Voting, Image, HtmlGenericControl, Literal, Literal, LinkButton, Literal, DnnBinaryImage, Comments, Literal, DnnBinaryImage> e)
        {
            var control = (Control)sender;

            e.BodyLiteral.Text = Utils.ProcessDisplayPostBody(e.ObjPost.Body);

            var objUser     = DotNetNuke.Entities.Users.UserController.GetUserById(ModuleContext.PortalId, e.ObjPost.CreatedUserId);
            var authorScore = Controller.GetUserScore(e.ObjPost.CreatedUserId, ModuleContext.PortalId);

            e.UserImage.ImageUrl      = control.ResolveUrl("~/profilepic.ashx?userid=" + objUser.UserID + "&w=" + 50 + "&h=" + 50);
            e.UserImage.AlternateText = objUser.DisplayName;
            e.UserImage.ToolTip       = objUser.DisplayName;

            if (e.ObjPost.CreatedDate != e.ObjPost.LastModifiedDate)
            {
                var objEditUser     = DotNetNuke.Entities.Users.UserController.GetUserById(ModuleContext.PortalId, e.ObjPost.LastModifiedUserId);
                var editedUserScore = Controller.GetUserScore(e.ObjPost.LastModifiedUserId, ModuleContext.PortalId);

                e.EditUserImage.ImageUrl      = control.ResolveUrl("~/profilepic.ashx?userid=" + objEditUser.UserID + "&w=" + 50 + "&h=" + 50);
                e.EditUserImage.AlternateText = objEditUser.DisplayName + Localization.GetString("PhotoTitle");
                e.EditUserImage.ToolTip       = objEditUser.DisplayName + Localization.GetString("PhotoTitle");

                e.EditedLiteral.Text = Localization.GetString("edited", LocalResourceFile) + Utils.CalculateDateForDisplay(e.ObjPost.LastModifiedDate) + @" " + @"<br /><a href=" + Globals.UserProfileURL(objEditUser.UserID) + @">" + objEditUser.DisplayName + @"</a><span title='" + Localization.GetString("ReputationScore", Constants.SharedResourceFileName) + @"'><strong>" + editedUserScore.Score + @"</strong></span>";
            }
            else
            {
                e.EditUserImage.Visible = false;
            }

            e.DateLiteral.Text = Localization.GetString("answered", LocalResourceFile) +
                                 Utils.CalculateDateForDisplay(e.ObjPost.CreatedDate) + @" " + @" <a href=" +
                                 Globals.UserProfileURL(e.ObjPost.CreatedUserId) + @">" + objUser.DisplayName +
                                 @" </a><span title='" +
                                 Localization.GetString("ReputationScore", Constants.SharedResourceFileName) + @"'><strong>" +
                                 authorScore.Score + @"</strong></span>";

            e.Voting.CurrentPostID = e.ObjPost.PostId;
            e.Voting.QuestionID    = e.ObjPost.ParentId;
            e.Voting.ModContext    = ModuleContext;
            e.Voting.TermId        = -1;
            e.Voting.RelatedTermId = -1;

            //Comments
            e.AnswerComment.ID               = "CommentArea_" + e.ObjPost.PostId;
            e.AnswerComment.ModContext       = ModuleContext;
            e.AnswerComment.ObjPost          = e.ObjPost;
            e.AnswerComment.CurrentUserScore = UserScore.Score;
            e.AnswerComment.Privileges       = View.Model.Privileges;
            e.AnswerComment.Question         = View.Model.Question;
            e.AnswerComment.DataBind();

            var colPostVotes = (from t in Controller.GetPostVotes(e.ObjPost.PostId) where t.VoteTypeId == (int)Constants.VoteType.FlagPost select t).ToList();

            if (e.ObjPost.PostId == View.Model.Question.AnswerId)
            {
                e.AcceptedImage.Visible              = true;
                e.AcceptedImage.ImageUrl             = control.ResolveUrl("~/DesktopModules/DNNQA/images/accepted_large.png");
                e.AcceptedImage.ToolTip              = Localization.GetString("AcceptedAnswer", LocalResourceFile);
                e.AcceptedImage.AlternateText        = Localization.GetString("AcceptedAnswer", LocalResourceFile);
                e.AnswerAcceptButton.CommandArgument = e.ObjPost.PostId.ToString();
                e.AnswerAcceptButton.Visible         = false;
            }
            else
            {
                // it's not the accepted answer
                e.AcceptedImage.Visible      = false;
                e.AnswerAcceptButton.Visible = false;

                e.AnswerAcceptButton.CommandArgument = e.ObjPost.PostId.ToString();
                // if user is question author, they should see accept button
                if ((View.Model.Question.CreatedUserId == ModuleContext.PortalSettings.UserId) && (e.ObjPost.CreatedUserId != ModuleContext.PortalSettings.UserId))
                {
                    e.AnswerAcceptButton.Visible = true;
                }
            }

            if (View.Model.Question.Protected == false)
            {
                if (e.ObjPost.CreatedUserId == ModuleContext.PortalSettings.UserId)
                {
                    var objRemoveNewUser = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.RemoveNewUser.ToString());
                    if (Utils.HasPrivilege(objRemoveNewUser, UserScore.Score, ModuleContext.IsEditable))
                    {
                        // make sure the user has the privilege to edit their own post
                        e.AnswersMenu.Visible    = true;
                        e.AnswerEditLiteral.Text = @"<li><a href='" + Links.EditPost(ModuleContext, e.ObjPost.PostId) + @"' class='editAnswer' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("editATitle", LocalResourceFile) + @"'>" + Localization.GetString("edit", LocalResourceFile) + @"</a></li>";
                    }
                }
                else
                {
                    var objEditQa = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.EditQuestionsAndAnswers.ToString());

                    if (Utils.HasPrivilege(objEditQa, UserScore.Score, ModuleContext.IsEditable))
                    {
                        // the user is allowed to edit any question and answer
                        e.AnswerEditLiteral.Text = @"<li><a href='" + Links.EditPost(ModuleContext, e.ObjPost.PostId) + @"' class='editAnswer' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("editATitle", LocalResourceFile) + @"'>" + Localization.GetString("edit", LocalResourceFile) + @"</a></li>";
                    }
                }

                // show delete only to moderators
                if (ModuleContext.IsEditable)
                {
                    e.AnswerDelete.Text = @"<li><a href='#' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("deleteTitle", LocalResourceFile) + @"' class='deleteAnswer'>" + Localization.GetString("delete", LocalResourceFile) + @"</a></li>";
                }

                if (ModuleContext.PortalSettings.UserId > 0)
                {
                    e.AnswersMenu.Visible = true;
                }

                var objFlag = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.Flag.ToString());
                if (Utils.HasPrivilege(objFlag, UserScore.Score, ModuleContext.IsEditable))
                {
                    var objUserVote = (from t in Controller.GetPostVotes(e.ObjPost.PostId) where ((t.CreatedByUserId == ModuleContext.PortalSettings.UserId) && (t.VoteTypeId == (int)Constants.VoteType.FlagPost)) select t).SingleOrDefault();

                    if (objUserVote != null)
                    {
                        e.AnswerFlagLiteral.Text = @"<li><a href='#' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("flagTitle", LocalResourceFile) + @"' class='undoFlag'>" + Localization.GetString("flag", LocalResourceFile) + @" (" + colPostVotes.Count() + @")</a></li>";
                    }
                    else
                    {
                        e.AnswerFlagLiteral.Text = @"<li><a href='#' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("flagTitle", LocalResourceFile) + @"' class='flagAnswer'>" + Localization.GetString("flag", LocalResourceFile) + @" (" + colPostVotes.Count() + @")</a></li>";
                    }

                    //e.AnswerFlagLiteral.Text = @"<li><a href='#' postid='" + e.ObjPost.PostId + @"' title='" + Localization.GetString("flagTitle", LocalResourceFile) + @"' class='flagAnswer'>" + Localization.GetString("flag", LocalResourceFile) + @" (" + colPostVotes.Count() + @")</a></li>";
                }
            }
            //else
            //{
            //    // the question is protected
            //}
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void QuestionDataBound(object sender, QuestionEventArgs <Literal, Voting, Literal, DnnBinaryImage, Literal, DnnBinaryImage, Literal, Controls.Tags, HtmlGenericControl, Literal, Literal, Literal, Literal, Literal, Comments, Literal, Literal> e)
        {
            var control = (Control)sender;

            e.VotingControl.CurrentPostID = QuestionID;
            e.VotingControl.QuestionID    = QuestionID;
            e.VotingControl.ModContext    = ModuleContext;
            e.VotingControl.TermId        = -1;
            e.VotingControl.RelatedTermId = -1;

            e.TagsControl.ModContext = ModuleContext;
            e.TagsControl.ModuleTab  = ModuleContext.PortalSettings.ActiveTab;
            e.TagsControl.DataSource = View.Model.Question.QaTerms(VocabularyId);
            e.TagsControl.DataBind();

            e.TitleLiteral.Text = View.Model.Question.Title.Trim();
            e.BodyLiteral.Text  = Utils.ProcessDisplayPostBody(View.Model.Question.Body);

            var objUser = DotNetNuke.Entities.Users.UserController.GetUserById(ModuleContext.PortalId, View.Model.Question.CreatedUserId);

            e.AuthorImage.ImageUrl      = control.ResolveUrl("~/profilepic.ashx?userid=" + objUser.UserID + "&w=" + 50 + "&h=" + 50);
            e.AuthorImage.AlternateText = objUser.DisplayName + Localization.GetString("PhotoTitle");
            e.AuthorImage.ToolTip       = objUser.DisplayName + Localization.GetString("PhotoTitle");

            e.AskedLiteral.Text = Localization.GetString("asked", LocalResourceFile) + Utils.CalculateDateForDisplay(View.Model.Question.CreatedDate) + @" " + @"<br /><a href=" + Globals.UserProfileURL(objUser.UserID) + @">" + objUser.DisplayName + @"</a><span title='" + Localization.GetString("ReputationScore", Constants.SharedResourceFileName) + @"'><strong>" + View.Model.QuestionAuthorScore + @"</strong></span>";

            // because we imediately update a question's last modified date (due to content item integration), we need to allow for a small variance between the two dates
            if (View.Model.Question.LastModifiedDate >= View.Model.Question.CreatedDate.AddMinutes(1))
            {
                var objEditUser = DotNetNuke.Entities.Users.UserController.GetUserById(ModuleContext.PortalId, View.Model.Question.LastModifiedUserId);
                e.EditorImage.ImageUrl      = control.ResolveUrl("~/profilepic.ashx?userid=" + objEditUser.UserID + "&w=" + 50 + "&h=" + 50);
                e.EditorImage.AlternateText = objEditUser.DisplayName + Localization.GetString("PhotoTitle");
                e.EditorImage.ToolTip       = objEditUser.DisplayName + Localization.GetString("PhotoTitle");

                e.EditedLiteral.Text = Localization.GetString("edited", LocalResourceFile) + Utils.CalculateDateForDisplay(View.Model.Question.LastModifiedDate) + @" " + @"<br /><a href=" + Globals.UserProfileURL(objEditUser.UserID) + @">" + objEditUser.DisplayName + @"</a><span title='" + Localization.GetString("ReputationScore", Constants.SharedResourceFileName) + @"'><strong>" + View.Model.QuestionEditedUserScore + @"</strong></span>";
            }
            else
            {
                e.EditorImage.Visible = false;
            }

            if (View.Model.Question.Protected == false)
            {
                if ((View.Model.Question.CreatedUserId == ModuleContext.PortalSettings.UserId))
                {
                    var objRemoveNewUser = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.RemoveNewUser.ToString());
                    if (Utils.HasPrivilege(objRemoveNewUser, UserScore.Score, ModuleContext.IsEditable))
                    {
                        // the user is the question author
                        e.EditLiteral.Text = @"<li><a href='" + Links.EditPost(ModuleContext, QuestionID) + @"' id='editQuestion' title='" + Localization.GetString("editTitle", LocalResourceFile) + @"'>" + Localization.GetString("edit", LocalResourceFile) + @"</a></li>";
                    }
                }
                else
                {
                    var objEditQa = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.EditQuestionsAndAnswers.ToString());

                    if (Utils.HasPrivilege(objEditQa, UserScore.Score, ModuleContext.IsEditable))
                    {
                        e.EditLiteral.Text = @"<li><a href='" + Links.EditPost(ModuleContext, QuestionID) + @"' id='editQuestion' title='" + Localization.GetString("editTitle", LocalResourceFile) + @"'>" + Localization.GetString("edit", LocalResourceFile) + @"</a></li>";
                    }
                    else
                    {
                        // see if the user has the retag option
                        var objRetag = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.RetagQuestion.ToString());

                        if (Utils.HasPrivilege(objRetag, UserScore.Score, ModuleContext.IsEditable))
                        {
                            e.EditLiteral.Text = @"<li><a href='" + Links.EditPost(ModuleContext, QuestionID) + @"' id='editQuestion' title='" + Localization.GetString("editTitle", LocalResourceFile) + @"'>" + Localization.GetString("edit", LocalResourceFile) + @"</a></li>";
                        }
                    }
                }

                if (ModuleContext.IsEditable)
                {
                    e.DeleteLiteral.Text = @"<li><a href='#' id='deleteQuestion' title='" + Localization.GetString("deleteTitle", LocalResourceFile) + @"'>" + Localization.GetString("delete", LocalResourceFile) + @"</a></li>";
                }

                if (ModuleContext.PortalSettings.UserId > 0)
                {
                    e.UnorderedList.Visible = true;
                }

                var objFlag = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.Flag.ToString());
                if (Utils.HasPrivilege(objFlag, UserScore.Score, ModuleContext.IsEditable))
                {
                    var flaggedVotes = (from t in View.Model.QuestionVotes where t.VoteTypeId == (int)Constants.VoteType.FlagPost select t).ToList();
                    var objUserVote  = (from t in View.Model.QuestionVotes where ((t.CreatedByUserId == ModuleContext.PortalSettings.UserId) && (t.VoteTypeId == (int)Constants.VoteType.FlagPost)) select t).SingleOrDefault();

                    if (objUserVote != null)
                    {
                        e.FlagLiteral.Text = @"<li><a href='#' postid='" + View.Model.Question.PostId + @"' title='" + Localization.GetString("flagTitle", LocalResourceFile) + @"' class='undoFlag'>" + Localization.GetString("flag", LocalResourceFile) + @" (" + flaggedVotes.Count() + @")</a></li>";
                    }
                    else
                    {
                        e.FlagLiteral.Text = @"<li><a href='#' id='flagQuestion' title='" + Localization.GetString("flagTitle", LocalResourceFile) + @"'>" + Localization.GetString("flag", LocalResourceFile) + @" (" + flaggedVotes.Count() + @")</a></li>";
                    }
                }

                var objProtect = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.ProtectQuestions.ToString());
                if (objProtect.Value > 0)
                {
                    if (Utils.HasPrivilege(objProtect, UserScore.Score, ModuleContext.IsEditable))
                    {
                        // TODO: Remove display:none;
                        e.ProtectLiteral.Text = @"<li style='display:none;'><a href='#' id='protectQuestion' title='" + Localization.GetString("protectTitle", LocalResourceFile) + @"'>" + Localization.GetString("protect", LocalResourceFile) + @"</a></li>";
                    }
                }

                var objClose = View.Model.Privileges.Single(s => s.Key == Constants.Privileges.CloseQuestion.ToString());
                if (objClose.Value > 0)
                {
                    if (Utils.HasPrivilege(objClose, UserScore.Score, ModuleContext.IsEditable))
                    {
                        // TODO: Remove display:none;
                        var closeVotes = (from t in View.Model.QuestionVotes where t.VoteTypeId == (int)Constants.VoteType.CloseQuestion select t).ToList();
                        e.CloseLiteral.Text = @"<li style='display:none;'><a href='#' id='closeQuestion' title='" + Localization.GetString("closeTitle", LocalResourceFile) + @"'>" + Localization.GetString("close", LocalResourceFile) + @" (" + closeVotes.Count() + @")</a></li>";
                    }
                }
            }
            //else
            //{
            //    // the way this is setup now, once a question is protected it cannot be undone
            //    var objProtect = Model.Privileges.Single(s => s.Key == Constants.Privileges.ProtectQuestions.ToString());

            //    // add below: OR user is moderator
            //    if (Model.CurrentUserScore >= objProtect.Value || Entities.Users.UserController.GetCurrentUserInfo().IsSuperUser)
            //    {
            //        litProtect.Text = @"<li><a href='#' id='protectQuestion'>" + Localization.GetString("protect", LocalResourceFile) + @"</a></li>";
            //    }
            //}

            e.CommentControl.ModContext       = ModuleContext;
            e.CommentControl.ObjPost          = View.Model.Question;
            e.CommentControl.CurrentUserScore = UserScore.Score;
            e.CommentControl.Privileges       = View.Model.Privileges;
            e.CommentControl.Question         = View.Model.Question;
            e.CommentControl.DataBind();

            e.ACountLiteral.Text = View.Model.Question.TotalAnswers == 1
                                                ? View.Model.Question.TotalAnswers + @" " + Localization.GetString("Answer", LocalResourceFile)
                                                : View.Model.Question.TotalAnswers + @" " + Localization.GetString("Answers", LocalResourceFile);

            var facebookContent = "";
            var googleContent   = "";
            var twitterContent  = "";
            var linkedInContent = "";

            if (ModuleContext.Settings.ContainsKey(Constants.SettingsFacebookAppId))
            {
                if (Convert.ToString(ModuleContext.Settings[Constants.SettingsFacebookAppId]).Length > 0)
                {
                    facebookContent = "<li><div class=\"fb-like\" data-send=\"false\" data-width=\"46\" data-show-faces=\"false\" data-layout=\"button_count\"></div></li>";
                }
            }

            if (ModuleContext.Settings.ContainsKey(Constants.SettingsEnablePlusOne))
            {
                if (Convert.ToBoolean(ModuleContext.Settings[Constants.SettingsEnablePlusOne]))
                {
                    googleContent = "<li><g:plusone annotation=\"none\" size=\"medium\"></g:plusone></li>";
                }
            }

            if (ModuleContext.Settings.ContainsKey(Constants.SettingsEnableTwitter))
            {
                if (Convert.ToBoolean(ModuleContext.Settings[Constants.SettingsEnableTwitter]))
                {
                    twitterContent = "<li><a href=\"https://twitter.com/share\" data-lang=\"en\" data-count=\"none\" class=\"twitter-share-button\" data-size=\"small\"" + "\"></a></li>";                     // target=\"_blank\" ; counturl=\"  url=\"" + View.Model.CurrentPage
                }
            }

            if (ModuleContext.Settings.ContainsKey(Constants.SettingsEnableLinkedIn))
            {
                if (Convert.ToBoolean(ModuleContext.Settings[Constants.SettingsEnableLinkedIn]))
                {
                    linkedInContent = "<li><script type=\"IN/Share\"></script></li>";
                }
            }

            var socialContent = facebookContent + googleContent + twitterContent + linkedInContent;

            //var facebookLike = "<a class=\"addthis_button_facebook_like\" fb:like:layout=\"button_count\"></a>";
            //var googlePlusOne = "<a class=\"addthis_button_google_plusone\" g:plusone:size=\"medium\"></a>";
            //var twitter = "<a class=\"addthis_button_tweet\"></a>";
            //var linkedIn = "";

            //var socialContent = "<div class=\"addthis_toolbox addthis_default_style\">" + twitter + facebookLike + googlePlusOne + linkedIn + "</div>";

            e.SocialSharingLiteral.Text = socialContent;
        }