コード例 #1
0
ファイル: RSS.cs プロジェクト: niemyjski/GraffitiCMS
        protected PostCollection GetTaggedPosts(string tagName)
        {
            PostCollection pc = ZCache.Get <PostCollection>("Tags-ForRSS-" + tagName);

            if (pc == null)
            {
                pc = Post.FetchPostsByTag(TagName);

                PostCollection permissionsFiltered = new PostCollection();
                foreach (Post post in pc)
                {
                    permissionsFiltered.Add(post);
                }
                permissionsFiltered.AddRange(pc);
                foreach (Post p in pc)
                {
                    if (!RolePermissionManager.GetPermissions(p.Category.Id, GraffitiUsers.Current).Read)
                    {
                        permissionsFiltered.Remove(p);
                    }
                }
                pc.Clear();
                int ctr = 0;
                foreach (Post post in permissionsFiltered)
                {
                    if (ctr < Util.PageSize)
                    {
                        pc.Add(post);
                        ctr++;
                    }
                }
                ZCache.InsertCache("Tags-ForRSS-" + tagName, pc, 120);
            }
            return(pc);
        }
コード例 #2
0
ファイル: RSS.cs プロジェクト: chartek/graffiticms
        protected PostCollection GetTaggedPosts(string tagName)
        {
            PostCollection pc = ZCache.Get<PostCollection>("Tags-ForRSS-" + tagName);
            if (pc == null)
            {
                pc = Post.FetchPostsByTag(TagName);

                PostCollection permissionsFiltered = new PostCollection();
                foreach (Post post in pc)
                {
                    permissionsFiltered.Add(post);
                }
                permissionsFiltered.AddRange(pc);
                foreach (Post p in pc) {
                    if (!RolePermissionManager.GetPermissions(p.Category.Id, GraffitiUsers.Current).Read)
                        permissionsFiltered.Remove(p);
                }
                pc.Clear();
                int ctr = 0;
                foreach (Post post in permissionsFiltered)
                {
                    if (ctr < Util.PageSize)
                    {
                        pc.Add(post);
                        ctr++;
                    }
                }
                ZCache.InsertCache("Tags-ForRSS-" + tagName, pc, 120);
            }
            return pc;
        }
コード例 #3
0
		protected override void Establish_context()
		{
			_posts = new PostCollection();
			_originalPosts = new PostCollection();

			for (int i = 0; i < PostSetsToGenerate; i++)
			{
				// Create set of four posts on a given date (CreatedOn), two with the same event data, two without event dates at all.
				_posts.Add(CreatePost(String.Format("A (Has date) {0}", i),
				                      DateTime.Now.Date.Add(TimeSpan.FromDays(i)),
				                      DateTime.Now.Date.Add(TimeSpan.FromDays(i))));
				_posts.Add(CreatePost(String.Format("B (Has date) {0}", i),
				                      DateTime.Now.Date.Add(TimeSpan.FromDays(i)),
				                      DateTime.Now.Date.Add(TimeSpan.FromDays(i))));
				_posts.Add(CreatePost(String.Format("A (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null));
				_posts.Add(CreatePost(String.Format("B (No date) {0}", i), DateTime.Now.Date.Add(TimeSpan.FromDays(i)), null));
			}

			_originalPosts.AddRange(_posts);
		}
コード例 #4
0
ファイル: RSS.cs プロジェクト: niemyjski/GraffitiCMS
        protected override void OnLoad(EventArgs e)
        {
            Initialize();

            SiteSettings settings = SiteSettings.Get();

            string baseUrl = SiteSettings.BaseUrl;

            if (string.IsNullOrEmpty(TagName))
            {
                Category category = null;
                if (CategoryID > -1)
                {
                    category = new CategoryController().GetCachedCategory(CategoryID, false);
                }

                if (category == null)
                {
                    if (!string.IsNullOrEmpty(settings.ExternalFeedUrl) &&
                        Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        Context.Response.RedirectLocation = settings.ExternalFeedUrl;
                        Context.Response.StatusCode       = 301;
                        Context.Response.End();
                    }
                }
                else if (!string.IsNullOrEmpty(category.FeedUrlOverride) &&
                         Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                {
                    Context.Response.RedirectLocation = category.FeedUrlOverride;
                    Context.Response.StatusCode       = 301;
                    Context.Response.End();
                }
                else if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName))
                {
                    Context.Response.RedirectLocation = new Uri(Context.Request.Url, category.Url).ToString();
                    Context.Response.StatusCode       = 301;
                    Context.Response.End();
                }

                string cacheKey = CategoryID > -1
                                                          ? "Posts-Index-" + Util.PageSize + "-" + CategoryID.ToString()
                                                          : string.Format("Posts-Categories-P:{0}-C:{1}-T:{2}-PS:{3}", 1, CategoryID,
                                                                          SortOrderType.Descending, Util.PageSize);

                PostCollection pc = ZCache.Get <PostCollection>(cacheKey);

                if (pc == null)
                {
                    Query q = PostCollection.DefaultQuery();
                    q.Top = Util.PageSize.ToString();

                    if (SiteSettings.Get().IncludeChildPosts&& macros.IsNotNull(category))
                    {
                        if (category.ParentId > 0)
                        {
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                        }
                        else
                        {
                            var ids = new List <int>(category.Children.Count + 1);
                            foreach (Category child in category.Children)
                            {
                                ids.Add(child.Id);
                            }

                            ids.Add(category.Id);

                            q.AndInWhere(Post.Columns.CategoryId, ids.ToArray());
                        }
                    }
                    else
                    {
                        if (CategoryID > 0)
                        {
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                        }
                    }

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

                    PostCollection permissionsFiltered = new PostCollection();

                    permissionsFiltered.AddRange(pc);

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

                    ZCache.InsertCache(cacheKey, permissionsFiltered, 90);
                    pc = permissionsFiltered;
                }

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                // Allow plugins to add additional xml namespaces
                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, category, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc)
                {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    // Allow plugins to add additional xml to the <item>
                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement();                     // End Item
                }

                writer.WriteEndElement();                 // End Channel
                writer.WriteEndElement();                 // End Document

                // save XML into response
                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.ContentType     = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
            else
            {
                PostCollection pc = GetTaggedPosts(TagName);

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, TagName, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc)
                {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement();                     // End Item
                }

                writer.WriteEndElement();                 // End Channel
                writer.WriteEndElement();                 // End Document

                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.ContentType     = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
        }
コード例 #5
0
ファイル: RSS.cs プロジェクト: chartek/graffiticms
        protected override void OnLoad(EventArgs e)
        {
            Initialize();

            SiteSettings settings = SiteSettings.Get();

            string baseUrl = SiteSettings.BaseUrl;

            if (string.IsNullOrEmpty(TagName))
            {
                Category category = null;
                if (CategoryID > -1)
                    category = new CategoryController().GetCachedCategory(CategoryID, false);

                if (category == null)
                {
                    if (!string.IsNullOrEmpty(settings.ExternalFeedUrl) &&
                        Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                    {
                        Context.Response.RedirectLocation = settings.ExternalFeedUrl;
                        Context.Response.StatusCode = 301;
                        Context.Response.End();
                    }
                }
                else if (!string.IsNullOrEmpty(category.FeedUrlOverride) &&
                         Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1)
                {
                    Context.Response.RedirectLocation = category.FeedUrlOverride;
                    Context.Response.StatusCode = 301;
                    Context.Response.End();
                }
                else if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName))
                {
                    Context.Response.RedirectLocation = new Uri(Context.Request.Url, category.Url).ToString();
                    Context.Response.StatusCode = 301;
                    Context.Response.End();
                }

                string cacheKey = CategoryID > -1
                                      ? "Posts-Index-" + Util.PageSize + "-" + CategoryID.ToString()
                                      : string.Format("Posts-Categories-P:{0}-C:{1}-T:{2}-PS:{3}", 1, CategoryID,
                                                      SortOrderType.Descending, Util.PageSize);

                PostCollection pc = ZCache.Get<PostCollection>(cacheKey);

                if (pc == null)
                {
                    Query q = PostCollection.DefaultQuery();
                    q.Top = Util.PageSize.ToString();

                    if (SiteSettings.Get().IncludeChildPosts && macros.IsNotNull(category))
                    {
                        if (category.ParentId > 0)
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                        else
                        {
                            List<int> ids = new List<int>(category.Children.Count + 1);
                            foreach (Category child in category.Children)
                                ids.Add(child.Id);

                            ids.Add(category.Id);

                            q.AndInWhere(Post.Columns.CategoryId, ids.ToArray());
                        }
                    }
                    else
                    {
                        if (CategoryID > 0)
                            q.AndWhere(Post.Columns.CategoryId, CategoryID);
                    }

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

                    PostCollection permissionsFiltered = new PostCollection();

                    permissionsFiltered.AddRange(pc);

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

                    ZCache.InsertCache(cacheKey, permissionsFiltered, 90);
                    pc = permissionsFiltered;
                }

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                // Allow plugins to add additional xml namespaces
                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, category, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc)
                {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    // Allow plugins to add additional xml to the <item>
                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement(); // End Item
                }

                writer.WriteEndElement(); // End Channel
                writer.WriteEndElement(); // End Document

                // save XML into response
                Context.Response.ContentEncoding = System.Text.Encoding.UTF8;
                Context.Response.ContentType = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
            else
            {
                PostCollection pc = GetTaggedPosts(TagName);

                ValidateAndSetHeaders(pc, settings, Context);

                StringWriter sw = new StringWriter();
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/");
                writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/");

                Core.Events.Instance().ExecuteRssNamespace(writer);

                writer.WriteStartElement("channel");
                WriteChannel(writer, TagName, settings);

                // Allow plugins to add additional xml to the <channel>
                Core.Events.Instance().ExecuteRssChannel(writer);

                foreach (Post p in pc) {
                    writer.WriteStartElement("item");
                    WriteItem(writer, p, settings, baseUrl);

                    Core.Events.Instance().ExecuteRssItem(writer, p);

                    writer.WriteEndElement(); // End Item
                }

                writer.WriteEndElement(); // End Channel
                writer.WriteEndElement(); // End Document

                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.ContentType = "application/rss+xml";
                Context.Response.Write(sw.ToString());
            }
        }
コード例 #6
0
ファイル: Default.aspx.cs プロジェクト: chartek/graffiticms
    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)
            {
                List<CategoryCount> temp = new List<CategoryCount>();
                temp.AddRange((List<CategoryCount>)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;

                List<CategoryCount> 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 += new RepeaterItemEventHandler(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;

            }
        }
    }