예제 #1
0
    private void PostList_NoneItemsDataBound(object sender, RepeaterItemEventArgs e)
    {
        StatusMessage sm = e.Item.FindControl("NoneMessage") as StatusMessage;

        if (sm != null)
        {
            string page = Request.QueryString["status"] ?? "1";

            switch (page)
            {
            case "1":                     // published
                sm.Text = "Sorry, there are no published posts. Why not add a <a href=\"write/\">new one</a>?";
                PostsLinks.SetActiveView(Published);
                break;

            case "2":                     // draft
                sm.Text = "Sorry, there are no drafts for you to edit.";
                break;

            case "3":                     // pending review
                sm.Text = "Sorry, there are no posts pending review.";
                break;

            case "4":                     // requires changes
                sm.Text = "Sorry, there are no posts with required changes.";
                break;

            case "-1":                     // deleted
                sm.Text = "Sorry, there are no deleted posts.";
                break;
            }
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            Post the_Post = new Post(Request.QueryString["id"]);
            switch (the_Post.PostStatus)
            {
            case PostStatus.Publish:

                if (the_Post.Published > SiteSettings.CurrentUserTime)
                {
                    PostUpdateStatus.Text = "The post, <em>&quot;<a title=\"click to view the post\" href=\"" + the_Post.Url +
                                            "\">" + the_Post.Title +
                                            "</a>&quot;</em>, was published. However, since this is a forward dated post, only site administrators can view it until " +
                                            the_Post.Published.ToLongDateString() + " " + the_Post.Published.ToShortTimeString();
                }
                else
                {
                    PostUpdateStatus.Text = "The post, <em>&quot;<a title=\"click to view the post\" href=\"" + the_Post.Url +
                                            "\">" + the_Post.Title +
                                            "</a>&quot;</em>, was published. If this was a revision, the new version is now live.";
                }
                PostUpdateStatus.Type = StatusType.Success;
                break;

            case PostStatus.Draft:

                PostUpdateStatus.Text = "The post, <em>&quot;" + the_Post.Title +
                                        "&quot;</em>, was saved as a draft.";
                PostUpdateStatus.Type = StatusType.Success;

                break;

            case PostStatus.PendingApproval:
                PostUpdateStatus.Text = "The post, <em>&quot;" + the_Post.Title +
                                        "&quot;</em>, was saved, but requires approval before it can be published. The site editors and publishers have been notified by email about this post. Once they publish it, you will be able to view it live.";

                PostUpdateStatus.Type = StatusType.Warning;
                break;

            case PostStatus.RequiresChanges:
                PostUpdateStatus.Text = "The post, <em>&quot;" + the_Post.Title +
                                        "&quot;</em>, was saved. An email has been sent to the original author with the change notification. You will receive an email once the author sets the post status to <em>Request Approval</em>.";

                PostUpdateStatus.Type = StatusType.Warning;
                break;
            }
        }


        if (!IsPostBack)
        {
            string page     = Request.QueryString["status"] ?? "1";
            string category = Request.QueryString["category"];
            string author   = Request.QueryString["author"];

            Master.FindControl("SideBarRegion").Visible = true;

            List <AuthorCount> auts = null;


            switch (page)
            {
            case "1":                     // published
                PostsLinks.SetActiveView(Published);
                cats = Post.GetCategoryCountForStatus(PostStatus.Publish, author);
                auts = Post.GetAuthorCountForStatus(PostStatus.Publish, category);
                break;

            case "2":                     // draft
                PostsLinks.SetActiveView(Draft);
                cats = Post.GetCategoryCountForStatus(PostStatus.Draft, author);
                auts = Post.GetAuthorCountForStatus(PostStatus.Draft, category);
                break;

            case "3":                     // pending review
                PostsLinks.SetActiveView(PendingReview);
                cats = Post.GetCategoryCountForStatus(PostStatus.PendingApproval, author);
                auts = Post.GetAuthorCountForStatus(PostStatus.PendingApproval, category);
                break;

            case "4":                     // requires changes
                PostsLinks.SetActiveView(RequiresChanges);
                cats = Post.GetCategoryCountForStatus(PostStatus.RequiresChanges, author);
                auts = Post.GetAuthorCountForStatus(PostStatus.RequiresChanges, category);
                break;

            case "-1":                     // deleted
                PostsLinks.SetActiveView(Deleted);
                Master.FindControl("SideBarRegion").Visible = false;
                break;
            }

            if (auts != null)
            {
                rptAuthors.DataSource = auts;
                rptAuthors.DataBind();
            }

            if (cats != null)
            {
                var temp = new List <CategoryCount>();
                temp.AddRange(cats.FindAll(
                                  delegate(CategoryCount ca)
                {
                    return(ca.ParentId <= 0);                                    // only want the parents
                    // the repeater below will handle the children
                }));

                temp.Sort(
                    delegate(CategoryCount c, CategoryCount c1) { return(c.Name.CompareTo(c1.Name)); });

                rptCategories.DataSource = temp;

                var toRemove = new List <CategoryCount>();

                foreach (CategoryCount cc in temp)
                {
                    if (!RolePermissionManager.GetPermissions(cc.ID, GraffitiUsers.Current).Read)
                    {
                        toRemove.Add(cc);
                    }
                }

                foreach (CategoryCount cc in toRemove)
                {
                    temp.Remove(cc);
                }

                rptCategories.DataBind();
            }

            User user = null;

            if (!String.IsNullOrEmpty(author))
            {
                user   = new User(Convert.ToInt32(author));
                author = user.Name;
            }

            Query q = Post.CreateQuery();


            if (Request.QueryString["category"] != null && Request.QueryString["category"] != "-1")
            {
                q.AndWhere(Post.Columns.CategoryId, Request.QueryString["category"]);
            }

            if (!String.IsNullOrEmpty(author))
            {
                q.AndWhere(Post.Columns.CreatedBy, author);
            }

            if (Request.QueryString["status"] == "-1")
            {
                q.AndWhere(Post.Columns.IsDeleted, true);
            }
            else
            {
                q.AndWhere(Post.Columns.IsDeleted, false);
                q.AndWhere(Post.Columns.Status, Request.QueryString["status"] ?? "1");
            }

            q.OrderByDesc(Post.Columns.Published);

            PostCollection tempPC = new PostCollection();
            tempPC.LoadAndCloseReader(q.ExecuteReader());

            PostCollection permissionsFilteredCount = new PostCollection();
            permissionsFilteredCount.AddRange(tempPC);

            foreach (Post p in tempPC)
            {
                if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read)
                {
                    permissionsFilteredCount.Remove(p);
                }
            }

            q.PageSize  = 15;
            q.PageIndex = Int32.Parse(Request.QueryString["p"] ?? "1");

            PostCollection pc = new PostCollection();
            pc.LoadAndCloseReader(q.ExecuteReader());

            PostList.NoneItemsDataBound += PostList_NoneItemsDataBound;

            PostCollection permissionsFiltered = new PostCollection();
            permissionsFiltered.AddRange(pc);

            foreach (Post p in pc)
            {
                if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read)
                {
                    permissionsFiltered.Remove(p);
                }
            }

            PostList.DataSource = permissionsFiltered;
            PostList.DataBind();

            string catID = Request.QueryString["category"] ?? "0";
            string autID = Request.QueryString["author"] ?? "0";

            if (pc.Count > 0)
            {
                string qs = "?status=" + page;
                if (catID != "0")
                {
                    qs += "&category=" + catID;
                }
                if (autID != "0")
                {
                    qs += "&author=" + autID;
                }

                Pager.Text = Util.Pager(q.PageIndex, q.PageSize, permissionsFilteredCount.Count, null, qs);
            }

            SetCounts(Int32.Parse(catID));

            #region build the page title

            StringBuilder sb = new StringBuilder();

            sb.Append("Posts ");

            switch (page)
            {
            case "1":
                sb.Append("Published ");
                break;

            case "2":
                sb.Append("Drafted ");
                break;

            case "3":
                sb.Append("Pending Review ");
                break;

            case "4":
                sb.Append("Requiring Changes ");
                break;

            case "5":
                sb.Append("Deleted ");
                break;
            }

            sb.Append("in ");

            if (Request.QueryString["category"] != null)
            {
                CategoryCollection categories = new CategoryController().GetAllCachedCategories();

                Category temp = categories.Find(
                    delegate(Category c) { return(c.Id == Int32.Parse(Request.QueryString["category"])); });

                if (temp != null)
                {
                    sb.Append(temp.Name);
                }
            }
            else
            {
                sb.Append("All Categories");
            }

            if (!String.IsNullOrEmpty(author))
            {
                sb.Append(" for " + user.ProperName);
            }

            lblPageTitle.Text = sb.ToString();

            #endregion

            if (Request.QueryString["dstry"] != null)
            {
                PostUpdateStatus.Text = Server.UrlDecode(Request.QueryString["dstry"]) +
                                        " has been permanently deleted.";
                PostUpdateStatus.Type = StatusType.Success;
            }
        }
    }