コード例 #1
0
ファイル: BlogFunctions.cs プロジェクト: LuckyN/test
    /// <summary>
    /// Returns number of comments of given blog.
    /// </summary>
    /// <param name="postId">Post document id</param>
    /// <param name="postAliasPath">Post alias path</param>
    /// <param name="includingTrackbacks">Indicates if trackback comments should be included</param>
    public static int GetBlogCommentsCount(object postId, object postAliasPath, bool includingTrackbacks)
    {
        int             docId       = ValidationHelper.GetInteger(postId, 0);
        string          aliasPath   = ValidationHelper.GetString(postAliasPath, "");
        CurrentUserInfo currentUser = MembershipContext.AuthenticatedUser;

        // There has to be the current site
        if (SiteContext.CurrentSite == null)
        {
            throw new Exception("[BlogFunctions.GetBlogCommentsCount]: There is no current site!");
        }

        bool isOwner = false;

        // Is user authorized to manage comments?
        bool     selectOnlyPublished = (PortalContext.ViewMode == ViewModeEnum.LiveSite);
        TreeNode blogNode            = BlogHelper.GetParentBlog(aliasPath, SiteContext.CurrentSiteName, selectOnlyPublished);

        if (blogNode != null)
        {
            isOwner = (currentUser.UserID == ValidationHelper.GetInteger(blogNode.GetValue("NodeOwner"), 0));
        }

        bool isUserAuthorized = (currentUser.IsAuthorizedPerResource("cms.blog", "Manage") || isOwner || BlogHelper.IsUserBlogModerator(currentUser.UserName, blogNode));

        // Get post comments
        return(BlogCommentInfoProvider.GetPostCommentsCount(docId, !isUserAuthorized, isUserAuthorized, includingTrackbacks));
    }