Exemplo n.º 1
0
        /// <summary>
        /// Gets a specified number of pages from the blog with the spefied blogId 
        /// </summary>
        /// <param name="blogid">The blogid.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="numberOfItems">The number of pages.</param>
        /// <returns></returns>
        public wpPage[] getPages(string blogid, string username, string password, int numberOfItems)
        {
            if (User.validateCredentials(username, password, false))
            {
                ArrayList blogPosts = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User u = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                    rootDoc = new Document(userChannel.StartNode);
                else
                    rootDoc = new Document(u.StartNodeId);

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfItems, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    wpPage p = new wpPage();
                    p.dateCreated = d.CreateDateTime;
                    p.title = d.Text;
                    p.page_id = d.Id;
                    p.wp_page_parent_id = d.Parent.Id;
                    p.wp_page_parent_title = d.Parent.Text;
                    p.permalink = library.NiceUrl(d.Id);
                    p.description = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link = library.NiceUrl(d.Id);

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        ((string)d.getProperty(userChannel.FieldCategoriesAlias).Value) != "")
                    {
                        String categories = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[] splitter = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }


                    blogPostsObjects.Add(p);
                }


                return (wpPage[])blogPostsObjects.ToArray(typeof(wpPage));
            }
            else
            {
                return null;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a specified number of pages from the blog with the spefied blogId
        /// </summary>
        /// <param name="blogid">The blogid.</param>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        /// <param name="numberOfItems">The number of pages.</param>
        /// <returns></returns>
        public wpPage[] getPages(string blogid, string username, string password, int numberOfItems)
        {
            if (User.validateCredentials(username, password, false))
            {
                ArrayList blogPosts        = new ArrayList();
                ArrayList blogPostsObjects = new ArrayList();

                User    u           = new User(username);
                Channel userChannel = new Channel(u.Id);


                Document rootDoc;
                if (userChannel.StartNode > 0)
                {
                    rootDoc = new Document(userChannel.StartNode);
                }
                else
                {
                    rootDoc = new Document(u.StartNodeId);
                }

                //store children array here because iterating over an Array object is very inneficient.
                var c = rootDoc.Children;
                foreach (Document d in c)
                {
                    int count = 0;
                    blogPosts.AddRange(
                        findBlogPosts(userChannel, d, u.Name, ref count, numberOfItems, userChannel.FullTree));
                }

                blogPosts.Sort(new DocumentSortOrderComparer());

                foreach (Object o in blogPosts)
                {
                    Document d = (Document)o;
                    wpPage   p = new wpPage();
                    p.dateCreated          = d.CreateDateTime;
                    p.title                = d.Text;
                    p.page_id              = d.Id;
                    p.wp_page_parent_id    = d.Parent.Id;
                    p.wp_page_parent_title = d.Parent.Text;
                    p.permalink            = library.NiceUrl(d.Id);
                    p.description          = d.getProperty(userChannel.FieldDescriptionAlias).Value.ToString();
                    p.link = library.NiceUrl(d.Id);

                    if (userChannel.FieldCategoriesAlias != null && userChannel.FieldCategoriesAlias != "" &&
                        d.getProperty(userChannel.FieldCategoriesAlias) != null &&
                        ((string)d.getProperty(userChannel.FieldCategoriesAlias).Value) != "")
                    {
                        String   categories  = d.getProperty(userChannel.FieldCategoriesAlias).Value.ToString();
                        char[]   splitter    = { ',' };
                        String[] categoryIds = categories.Split(splitter);
                        p.categories = categoryIds;
                    }


                    blogPostsObjects.Add(p);
                }


                return((wpPage[])blogPostsObjects.ToArray(typeof(wpPage)));
            }
            else
            {
                return(null);
            }
        }