GetContentDatabase() public static method

Gets the content database
public static GetContentDatabase ( ) : Database
return Database
Esempio n. 1
0
        public string newPost(string blogid, string username, string password, XmlRpcStruct rpcstruct, bool publish)
        {
            Authenticate(username, password);
            CheckUserRights(blogid, username);

            var entryTitle  = rpcstruct["title"].ToString();
            var currentBlog = ContentHelper.GetContentDatabase().GetItem(blogid);

            if (currentBlog != null)
            {
                // test
                var access = Sitecore.Security.AccessControl.AuthorizationManager.GetAccess(currentBlog, Sitecore.Context.User, Sitecore.Security.AccessControl.AccessRight.ItemCreate);
                // end test

                BlogHomeItem blogItem = currentBlog;
                var          template = new TemplateID(blogItem.BlogSettings.EntryTemplateID);
                var          newItem  = ItemManager.AddFromTemplate(entryTitle, template, currentBlog);

                SetItemData(newItem, rpcstruct);

                if (publish)
                {
                    ContentHelper.PublishItemAndRequiredAncestors(newItem.ID);
                }

                return(newItem.ID.ToString());
            }
            else
            {
                return(string.Empty);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the categories as string.
        /// </summary>
        /// <param name="BlogID">The blog ID.</param>
        /// <param name="rpcstruct">The rpcstruct.</param>
        /// <returns></returns>
        private static string GetCategoriesAsString(ID BlogID, XmlRpcStruct rpcstruct)
        {
            var blog = ContentHelper.GetContentDatabase().GetItem(BlogID);

            if (blog != null)
            {
                var categoryList = ManagerFactory.CategoryManagerInstance.GetCategories(blog);

                var selectedCategories = string.Empty;

                if (rpcstruct["categories"] != null && ((object[])rpcstruct["categories"]).Count() != 0)
                {
                    var categories = (string[])rpcstruct["categories"];

                    foreach (string category in categories)
                    {
                        foreach (CategoryItem cat in categoryList)
                        {
                            if (category == cat.Title.Raw)
                            {
                                selectedCategories += cat.ID.ToString();
                            }
                        }
                    }

                    var result = selectedCategories.Replace("}{", "}|{");

                    return(result);
                }
            }

            return(string.Empty);
        }
Esempio n. 3
0
        public XmlRpcStruct[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            int ii = 0;

            Authenticate(username, password);

            var blog = ContentHelper.GetContentDatabase().GetItem(blogid);

            if (blog != null)
            {
                var entryList = ManagerFactory.EntryManagerInstance.GetBlogEntries(blog, numberOfPosts, null, null, (DateTime?)null);

                XmlRpcStruct[] posts = new XmlRpcStruct[entryList.Length];

                //Populate structure with post entities
                foreach (EntryItem entry in entryList)
                {
                    XmlRpcStruct rpcstruct = new XmlRpcStruct();
                    rpcstruct.Add("title", entry.Title.Raw);
                    rpcstruct.Add("link", entry.AbsoluteUrl);
                    rpcstruct.Add("description", entry.Content.Text);
                    rpcstruct.Add("pubDate", entry.EntryDate.DateTime);
                    rpcstruct.Add("guid", entry.ID.ToString());
                    rpcstruct.Add("postid", entry.ID.ToString());
                    rpcstruct.Add("keywords", entry.Tags.Raw);
                    rpcstruct.Add("author", entry.InnerItem.Statistics.CreatedBy);
                    posts[ii] = rpcstruct;
                    ii++;
                }
                return(posts);
            }

            return(new XmlRpcStruct[0]);
        }
Esempio n. 4
0
        public XmlRpcStruct[] getCategories(string blogid, string username, string password)
        {
            int ii = 0;

            Authenticate(username, password);

            var blog = ContentHelper.GetContentDatabase().GetItem(blogid);

            if (blog != null)
            {
                var categoryList = ManagerFactory.CategoryManagerInstance.GetCategories(blog);

                XmlRpcStruct[] categories = new XmlRpcStruct[categoryList.Length];

                foreach (CategoryItem category in categoryList)
                {
                    XmlRpcStruct rpcstruct = new XmlRpcStruct();
                    rpcstruct.Add("categoryid", category.ID.ToString());          // Category ID
                    rpcstruct.Add("title", category.Title.Raw);                   // Category Title
                    rpcstruct.Add("description", "Description is not available"); // Category Description
                    categories[ii] = rpcstruct;
                    ii++;
                }

                return(categories);
            }

            return(new XmlRpcStruct[0]);
        }
Esempio n. 5
0
        public bool deletePost(string appKey, string postid, string userName, string password, bool publish)
        {
            Authenticate(userName, password);
            CheckUserRights(postid, userName);

            try
            {
                return(ManagerFactory.EntryManagerInstance.DeleteEntry(postid, ContentHelper.GetContentDatabase()));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 6
0
        public XmlRpcStruct newMediaObject(string blogid, string username, string password, XmlRpcStruct rpcstruct)
        {
            // Check user validation
            Authenticate(username, password);

            var name     = rpcstruct["name"].ToString();
            var type     = rpcstruct["type"].ToString();
            var media    = (byte[])rpcstruct["bits"];
            var blogName = string.Empty;

            var currentBlog = ContentHelper.GetContentDatabase().GetItem(blogid);

            blogName = currentBlog.Name;

            // Get filename
            var fileName  = Path.GetFileName(name);
            var imageName = ItemUtil.ProposeValidItemName(Path.GetFileNameWithoutExtension(fileName));

            // Create strem from byte array
            var memStream = new MemoryStream(media);
            var md        = new MediaCreatorOptions();

            md.Destination   = string.Join("/", new string[] { Constants.Paths.WeBlogMedia, blogName, imageName });
            md.Database      = ContentHelper.GetContentDatabase();
            md.AlternateText = imageName;

            // Create mediaitem
            var mediaItem = MediaManager.Creator.CreateFromStream(memStream, fileName, md);

            // Publish mediaitem to web database
            ContentHelper.PublishItemAndRequiredAncestors(mediaItem.ID);

            // Close stream
            memStream.Close();
            memStream.Dispose();

            // Get the mediaitem url and return it
            var rstruct = new XmlRpcStruct();

            var options = new MediaUrlOptions()
            {
                AbsolutePath = false,
                UseItemPath  = false
            };

            rstruct.Add("url", MediaManager.GetMediaUrl(mediaItem, options));
            return(rstruct);
        }
Esempio n. 7
0
        public XmlRpcStruct getPost(string postid, string username, string password)
        {
            Authenticate(username, password);

            CheckUserRights(postid, username);

            var rpcstruct = new XmlRpcStruct();
            var entryItem = ContentHelper.GetContentDatabase().GetItem(postid);

            if (entryItem != null)
            {
                var entry = new EntryItem(entryItem);

                rpcstruct.Add("title", entry.Title.Raw);
                rpcstruct.Add("link", entry.AbsoluteUrl);
                rpcstruct.Add("description", entry.Introduction.Raw);
                rpcstruct.Add("pubDate", entry.InnerItem.Statistics.Created.ToString());
                rpcstruct.Add("guid", entry.ID.ToString());
                rpcstruct.Add("author", entry.InnerItem.Statistics.CreatedBy);
            }

            return(rpcstruct);
        }
Esempio n. 8
0
        public bool editPost(string postid, string username, string password, XmlRpcStruct rpcstruct, bool publish)
        {
            Authenticate(username, password);
            CheckUserRights(postid, username);

            var item = ContentHelper.GetContentDatabase().GetItem(new ID(postid));

            if (item != null)
            {
                SetItemData(item, rpcstruct);

                if (publish)
                {
                    ContentHelper.PublishItemAndRequiredAncestors(item.ID);
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets the categories as string.
        /// </summary>
        /// <param name="postid">The postid.</param>
        /// <param name="rpcstruct">The rpcstruct.</param>
        /// <returns></returns>
        private static string GetCategoriesAsString(string postid, XmlRpcStruct rpcstruct)
        {
            var  postItem     = ContentHelper.GetContentDatabase().GetItem(postid);
            Item blog         = ManagerFactory.BlogManagerInstance.GetCurrentBlog(postItem).SafeGet(x => x.InnerItem);
            var  categoryList = ManagerFactory.CategoryManagerInstance.GetCategories(blog);

            if (categoryList.Length != 0)
            {
                string selectedCategories = string.Empty;

                try
                {
                    string[] categories = (string[])rpcstruct["categories"];

                    foreach (string category in categories)
                    {
                        foreach (CategoryItem cat in categoryList)
                        {
                            if (category == cat.Title.Raw)
                            {
                                selectedCategories += cat.ID.ToString();
                            }
                        }
                    }

                    string result = selectedCategories.Replace("}{", "}|{");

                    return(result);
                }
                catch
                {
                    return(string.Empty);
                }
            }
            return(string.Empty);
        }
Esempio n. 10
0
        private static void CheckUserRights(string blogid, string username)
        {
            var blog = ItemManager.GetItem(blogid, Sitecore.Context.Language, Sitecore.Data.Version.Latest, ContentHelper.GetContentDatabase());

            if (blog != null && !blog.Security.CanWrite(Sitecore.Context.User))
            {
                throw new System.Security.Authentication.InvalidCredentialException("You do not have sufficient user rights");
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Gets the database where content is authored
 /// </summary>
 /// <returns>The contenet database</returns>
 protected virtual Database GetContentDatabase()
 {
     return(ContentHelper.GetContentDatabase());
 }