public bool editPost(string postid, string username, string password, XmlRpcStruct rpcstruct, bool publish) { Authenticate(username, password); CheckUserRights(postid); var item = GetContentDatabase().GetItem(new ID(postid)); if (item != null) { SetItemData(item, rpcstruct); if (publish) { ContentHelper.PublishItemAndRequiredAncestors(item.ID); } return(true); } return(false); }
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); }
/// <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); }
public string newPost(string blogid, string username, string password, XmlRpcStruct rpcstruct, bool publish) { Authenticate(username, password); CheckUserRights(blogid); var entryTitleRaw = rpcstruct["title"]; if (entryTitleRaw == null) { throw new ArgumentException("'title' must be provided"); } var entryTitle = entryTitleRaw.ToString(); var currentBlog = GetContentDatabase().GetItem(blogid); if (currentBlog != null) { var blogItem = new BlogHomeItem(currentBlog); var settings = BlogSettingsResolver.Resolve(blogItem); var template = new TemplateID(settings.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); } }
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"); } }
/// <summary> /// Gets the database where content is authored /// </summary> /// <returns>The contenet database</returns> protected virtual Database GetContentDatabase() { return(ContentHelper.GetContentDatabase()); }