Exemple #1
0
        public static EntryItem CreateNewEntry(BlogHomeItem blogItem, string name, string tags = null, ID[] categories = null, DateTime?entryDate = null)
        {
            using (new UserSwitcher("sitecore\\admin", true))
            {
                var entry = blogItem.InnerItem.Add(name, Constants.Templates.EntryTemplateId);

                if (tags != null)
                {
                    using (new EditContext(entry))
                    {
                        entry["Tags"] = tags;
                    }
                }

                if (categories != null)
                {
                    using (new EditContext(entry))
                    {
                        entry["Category"] = string.Join <ID>("|", categories);
                    }
                }

                if (entryDate != null)
                {
                    using (new EditContext(entry))
                    {
                        entry["Entry Date"] = DateUtil.ToIsoDate(entryDate.Value);
                    }
                }

                return(entry);
            }
        }
 public CommentsListCore(BlogHomeItem currentBlogHomeItem, EntryItem currentEntry, IWeBlogSettings settings = null, ICommentManager commentManager = null)
 {
     CurrentBlog    = currentBlogHomeItem;
     CurrentEntry   = currentEntry;
     Settings       = settings ?? WeBlogSettings.Instance;
     CommentManager = commentManager ?? ManagerFactory.CommentManagerInstance;
 }
Exemple #3
0
        private void ImportBlog()
        {
            LogMessage("Reading import file");
            string        fileLocation       = string.Format("{0}\\{1}", ApplicationContext.PackagePath, WordpressXmlFile.Value);
            List <WpPost> listWordpressPosts = WpImportManager.Import(fileLocation, ImportComments.Checked, ImportCategories.Checked, ImportTags.Checked);

            LogMessage("Creating blog");
            Item root = db.GetItem(litSummaryPath.Text);

            BranchItem   newBlog  = db.Branches.GetMaster(Settings.BlogBranchID);
            BlogHomeItem blogItem = root.Add(ItemUtil.ProposeValidItemName(litSettingsName.Value), newBlog);

            blogItem.BeginEdit();
            blogItem.Email.Field.Value = litSettingsEmail.Value;
            blogItem.EndEdit();

            LogMessage("Importing posts");
            LogTotal(listWordpressPosts.Count);

            WpImportManager.ImportPosts(blogItem, listWordpressPosts, db, (itemName, count) =>
            {
                LogMessage("Importing entry " + itemName);
                LogProgress(count);
            });
        }
Exemple #4
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);
            }
        }
Exemple #5
0
        public string newPost(string blogid, string username, string password, XmlRpcStruct rpcstruct, bool publish)
        {
            Authenticate(username, password);
            CheckUserRights(blogid, username);

            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)
            {
                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);
            }
        }
Exemple #6
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="currentBlog">The blog being listed.</param>
 /// <param name="settings">The settings to use. If null, the default settings will be used.</param>
 /// <param name="authorsCore">The <see cref="IAuthorsCore"/> component to use to retrieve author information.</param>
 /// <param name="entryManager">The <see cref="IEntryManager"/> to use to access entries.</param>
 /// <param name="templateManager">The <see cref="BaseTemplateManager"/> to use to access templates.</param>
 public PostListCore(BlogHomeItem currentBlog, IWeBlogSettings settings = null, IAuthorsCore authorsCore = null, IEntryManager entryManager = null, BaseTemplateManager templateManager = null)
 {
     CurrentBlog     = currentBlog;
     Settings        = settings ?? WeBlogSettings.Instance;
     AuthorsCore     = authorsCore ?? new AuthorsCore(CurrentBlog);
     EntryManager    = entryManager ?? ManagerFactory.EntryManagerInstance;
     TemplateManager = templateManager ?? ServiceLocator.ServiceProvider.GetService(typeof(BaseTemplateManager)) as BaseTemplateManager;
 }
Exemple #7
0
 public static CategoryItem CreateNewCategory(BlogHomeItem blogItem, string name)
 {
     using (new UserSwitcher("sitecore\\admin", true))
     {
         var categoryRoot = blogItem.InnerItem.Children["Categories"];
         return(categoryRoot.Add(name, Constants.Templates.CategoryTemplateId));
     }
 }
Exemple #8
0
        /// <summary>
        /// Checks if emails should be displayed with comments
        /// </summary>
        /// /// <param name="blog">The blog to read the setting from</param>
        /// <returns>True if email should be shown, otherwise False</returns>
        public bool ShowEmailWithinComments(BlogHomeItem blog)
        {
            if (blog == null)
            {
                return(false);
            }

            return(blog.ShowEmailWithinComments.Checked);
        }
Exemple #9
0
 protected virtual void AddLinkToOutput(HtmlTextWriter output, BlogHomeItem blogItem)
 {
     output.AddAttribute(HtmlTextWriterAttribute.Rel, "EditURI");
     output.AddAttribute(HtmlTextWriterAttribute.Type, "application/rsd+xml");
     output.AddAttribute(HtmlTextWriterAttribute.Title, "RSD");
     output.AddAttribute(HtmlTextWriterAttribute.Href, "http://" + WebUtil.GetHostName() + "/sitecore modules/WeBlog/rsd.ashx?blogid=" + blogItem.ID);
     output.RenderBeginTag(HtmlTextWriterTag.Link);
     output.RenderEndTag();
 }
Exemple #10
0
        protected virtual IEnumerable <Tag> GetSourceItems(BlogHomeItem currentBlog)
        {
            var sources = ManagerFactory.TagManagerInstance.GetTagsForBlog(currentBlog).ToList();

            sources.Sort((tag, tag1) => tag1.Count - tag.Count);
            var sourceItems = sources.Take(_settings.TagFieldMaxItemCount);

            return(sourceItems);
        }
Exemple #11
0
        /// <summary>
        /// Checks if the current blog has RSS enabled
        /// </summary>
        /// <param name="blog">The blog to read the setting from</param>
        /// <returns>True if RSS is enabled, otherwise False</returns>
        public bool EnableRSS(BlogHomeItem blog)
        {
            if (blog == null)
            {
                return(false);
            }

            return(blog.EnableRss.Checked);
        }
Exemple #12
0
        /// <summary>
        /// Gets blog entries for the given blog up to the maximum number given
        /// </summary>
        /// <param name="blog">The blog item to get the entries for</param>
        /// <param name="maxNumber">The maximum number of entries to retrieve</param>
        /// <param name="tag">A tag the entry must contain</param>
        /// <param name="category">A category the entry must contain</param>
        /// <returns></returns>
        public EntryItem[] GetBlogEntries(Item blog, int maxNumber, string tag, string category, string datePrefix = null)
        {
            if (blog == null || maxNumber <= 0)
            {
                return(new EntryItem[0]);
            }

            BlogHomeItem customBlogItem = null;

            if (blog.TemplateIsOrBasedOn(Settings.BlogTemplateID))
            {
                customBlogItem = blog;
            }
            else
            {
                customBlogItem = blog.GetCurrentItem(Settings.BlogTemplateIDString);
            }
            if (customBlogItem == null)
            {
                return(new EntryItem[0]);
            }

            var query = new CombinedQuery();

            //query.Add(new FieldQuery(Constants.Index.Fields.BlogID, blog.ID.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            query.Add(new FieldQuery(Sitecore.Search.BuiltinFields.Path, customBlogItem.ID.ToShortID().ToString()), QueryOccurance.Must);
            query.Add(new FieldQuery(Constants.Index.Fields.Template, customBlogItem.BlogSettings.EntryTemplateID.ToShortID().ToString().ToLower()), QueryOccurance.Must);

            if (!string.IsNullOrEmpty(tag))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Tags, DatabaseCrawler.TransformCSV(tag)), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(category))
            {
                var categoryItem = ManagerFactory.CategoryManagerInstance.GetCategory(blog, category);
                ID  id           = ID.Null;

                if (categoryItem != null)
                {
                    id = categoryItem.ID;
                }

                query.Add(new FieldQuery(Constants.Index.Fields.Category, id.ToShortID().ToString().ToLower()), QueryOccurance.Must);
            }

            if (!string.IsNullOrEmpty(datePrefix))
            {
                query.Add(new FieldQuery(Constants.Index.Fields.Created, datePrefix + "*"), QueryOccurance.Must);
            }

            var searcher = new Searcher();
            var result   = searcher.Execute <EntryItem>(query, maxNumber, (list, item) => list.Add((EntryItem)item), Constants.Index.Fields.EntryDate, true);

            return(result);
        }
Exemple #13
0
 public SyndicationLink(IFeedResolver feedResolver)
 {
     Blog       = ManagerFactory.BlogManagerInstance.GetCurrentBlog();
     Feeds      = feedResolver.Resolve(Blog);
     Attributes = new Dictionary <HtmlTextWriterAttribute, string>
     {
         { HtmlTextWriterAttribute.Rel, "alternate" },
         { HtmlTextWriterAttribute.Type, "application/rsd+xml" },
     };
 }
Exemple #14
0
        /// <summary>
        /// Gets the tags for the blog
        /// </summary>
        /// <param name="blogItem">The blog to get the tags for</param>
        /// <returns>An array of unique tags</returns>
        public Tag[] GetTagsForBlog(BlogHomeItem blog)
        {
            if (blog != null)
            {
                var entries = EntryManager.GetBlogEntries(blog.InnerItem);
                return(ExtractAndSortTags(entries));
            }

            return(new Tag[0]);
        }
Exemple #15
0
 public ThemeLink()
 {
     Blog       = ManagerFactory.BlogManagerInstance.GetCurrentBlog();
     Attributes = new Dictionary <HtmlTextWriterAttribute, string>
     {
         { HtmlTextWriterAttribute.Href, GetThemeUrl() },
         { HtmlTextWriterAttribute.Rel, "stylesheet" },
         { HtmlTextWriterAttribute.Type, "text/css" }
     };
 }
Exemple #16
0
        public BlogHomeItem CreateBlogRoot(Item root, string name, string email, ID blogRootTemplate)
        {
            BlogHomeItem blogItem = root.Add(ItemUtil.ProposeValidItemName(name), new TemplateID(blogRootTemplate));

            blogItem.BeginEdit();
            blogItem.Email.Field.Value = email;
            blogItem.EndEdit();

            return(blogItem);
        }
Exemple #17
0
        /// <summary>
        /// Process to return RSD page.
        /// </summary>
        /// <param name="context">context</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            using (XmlTextWriter rsd = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
            {
                Database web             = Factory.GetDatabase("web");
                Item     currentBlogItem = web.GetItem(new ID(HttpContext.Current.Request.QueryString["blogid"].ToString()));

                BlogHomeItem currentBlog = new BlogHomeItem(currentBlogItem);

                rsd.Formatting = Formatting.Indented;
                rsd.WriteStartDocument();

                // Rsd tag
                rsd.WriteStartElement("rsd");
                rsd.WriteAttributeString("version", "1.0");

                // Service
#if FEATURE_URL_BUILDERS
                var urlOptions = new ItemUrlBuilderOptions();
#else
                var urlOptions = UrlOptions.DefaultOptions;
#endif

                urlOptions.AlwaysIncludeServerUrl = true;
                var url = LinkManager.GetItemUrl(currentBlog, urlOptions);

                rsd.WriteStartElement("service");
                rsd.WriteElementString("engineName", "Sitecore WeBlog Module");
                rsd.WriteElementString("engineLink", WebUtil.GetServerUrl());
                rsd.WriteElementString("homePageLink", url);

                // APIs
                rsd.WriteStartElement("apis");

                // MetaWeblog
                rsd.WriteStartElement("api");
                rsd.WriteAttributeString("name", "MetaWeblog");
                rsd.WriteAttributeString("preferred", "true");
                rsd.WriteAttributeString("apiLink", WebUtil.GetServerUrl() + "/sitecore modules/web/WeBlog/MetaBlogApi.ashx");
                rsd.WriteAttributeString("blogID", currentBlog.ID.ToString());
                rsd.WriteEndElement();

                // End APIs
                rsd.WriteEndElement();

                // End Service
                rsd.WriteEndElement();

                // End Rsd
                rsd.WriteEndElement();

                rsd.WriteEndDocument();
            }
        }
Exemple #18
0
        /// <summary>
        /// Gets the tags for the blog
        /// </summary>
        /// <param name="blogItem">The blog to get the tags for</param>
        /// <returns>An array of unique tags</returns>
        public Tag[] GetTagsForBlog(BlogHomeItem blog)
        {
            if (blog != null)
            {
                // TODO: Index tags as separate terms and use faceting rather than iterating every entry.
                var entries = EntryManager.GetBlogEntries(blog.InnerItem, EntryCriteria.AllEntries, ListOrder.Descending).Results;
                return(ExtractAndSortTags(entries));
            }

            return(new Tag[0]);
        }
Exemple #19
0
 public RsdLink()
 {
     Blog       = ManagerFactory.BlogManagerInstance.GetCurrentBlog();
     Attributes = new Dictionary <HtmlTextWriterAttribute, string>
     {
         { HtmlTextWriterAttribute.Href, WebUtil.GetServerUrl() + "/sitecore modules/web/WeBlog/rsd.ashx?blogid=" + Blog.ID },
         { HtmlTextWriterAttribute.Rel, "EditURI" },
         { HtmlTextWriterAttribute.Type, "application/rsd+xml" },
         { HtmlTextWriterAttribute.Title, "RSD" }
     };
 }
Exemple #20
0
        /// <summary>
        /// Process to return RSD page.
        /// </summary>
        /// <param name="context">context</param>
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            using (XmlTextWriter rsd = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8))
            {
                Database web             = Factory.GetDatabase("web");
                Item     currentBlogItem = web.GetItem(new ID(HttpContext.Current.Request.QueryString["blogid"].ToString()));

                BlogHomeItem currentBlog = new BlogHomeItem(currentBlogItem);

                rsd.Formatting = Formatting.Indented;
                rsd.WriteStartDocument();

                // Rsd tag
                rsd.WriteStartElement("rsd");
                rsd.WriteAttributeString("version", "1.0");

                // Service
                rsd.WriteStartElement("service");
                rsd.WriteElementString("engineName", "Sitecore WeBlog Module");
                rsd.WriteElementString("engineLink", "http://" + WebUtil.GetHostName());
                rsd.WriteElementString("homePageLink", currentBlog.AbsoluteUrl);

                // APIs
                rsd.WriteStartElement("apis");

                // MetaWeblog
                rsd.WriteStartElement("api");
                rsd.WriteAttributeString("name", "MetaWeblog");
                rsd.WriteAttributeString("preferred", "true");
                rsd.WriteAttributeString("apiLink", "http://" + WebUtil.GetHostName() + "/sitecore modules/WeBlog/MetaBlogApi.ashx");
                rsd.WriteAttributeString("blogID", currentBlog.ID.ToString());
                rsd.WriteEndElement();

                //// BlogML
                //rsd.WriteStartElement("api");
                //rsd.WriteAttributeString("name", "BlogML");
                //rsd.WriteAttributeString("preferred", "false");
                //rsd.WriteAttributeString("apiLink", Utils.AbsoluteWebRoot + "api/BlogImporter.asmx");
                //rsd.WriteAttributeString("blogID", Utils.AbsoluteWebRoot.ToString());
                //rsd.WriteEndElement();

                // End APIs
                rsd.WriteEndElement();

                // End Service
                rsd.WriteEndElement();

                // End Rsd
                rsd.WriteEndElement();

                rsd.WriteEndDocument();
            }
        }
Exemple #21
0
        internal static void ImportPosts(Item blogItem, List <WpPost> listWordpressPosts, Database db, Action <string, int> logger = null)
        {
            BlogHomeItem customBlogItem = blogItem;
            var          entryTemplate  = TemplateManager.GetTemplate(customBlogItem.BlogSettings.EntryTemplateID, db);

            var processCount = 0;

            foreach (WpPost post in listWordpressPosts)
            {
                processCount++;

                if (!string.IsNullOrEmpty(post.Content))
                {
                    var name = ItemUtil.ProposeValidItemName(post.Title);

                    if (logger != null)
                    {
                        logger(name, processCount);
                    }

                    EntryItem entry = ItemManager.AddFromTemplate(name, entryTemplate.ID, blogItem);

                    entry.BeginEdit();
                    entry.Title.Field.Value        = post.Title;
                    entry.Introduction.Field.Value = string.Empty;
                    entry.Content.Field.Value      = post.Content;
                    entry.Tags.Field.Value         = string.Join(", ", post.Tags.ToArray());

                    var categorieItems = new List <string>();

                    foreach (string categoryName in post.Categories)
                    {
                        var categoryItem = ManagerFactory.CategoryManagerInstance.Add(categoryName, blogItem);
                        categorieItems.Add(categoryItem.ID.ToString());
                    }

                    if (categorieItems.Count > 0)
                    {
                        entry.Category.Field.Value = string.Join("|", categorieItems.ToArray());
                    }

                    foreach (WpComment wpComment in post.Comments)
                    {
                        ManagerFactory.CommentManagerInstance.AddCommentToEntry(entry.ID, wpComment);
                    }

                    var publicationDate = DateUtil.ToIsoDate(post.PublicationDate);
                    entry.InnerItem.Fields[FieldIDs.Created].Value = publicationDate;
                    entry.InnerItem.Fields["Entry Date"].Value     = publicationDate;
                    entry.EndEdit();
                }
            }
        }
Exemple #22
0
        public BlogSettings Resolve(BlogHomeItem blogItem)
        {
            var blogSettings = new BlogSettings(WeBlogSettings);

            if (blogItem != null && TemplateManager.TemplateIsOrBasedOn(blogItem.InnerItem, WeBlogSettings.BlogTemplateIds))
            {
                blogSettings.CategoryTemplateID = blogItem.DefinedCategoryTemplate.Field.TargetID;
                blogSettings.EntryTemplateID    = blogItem.DefinedEntryTemplate.Field.TargetID;
                blogSettings.CommentTemplateID  = blogItem.DefinedCommentTemplate.Field.TargetID;
            }

            return(blogSettings);
        }
Exemple #23
0
        /// <summary>
        /// Returns the dictionary item.
        /// </summary>
        /// <returns>Returns standard dictionary item if there is no custom item selected</returns>
        public Item GetDictionaryItem()
        {
            BlogHomeItem currentBlog = GetCurrentBlog();

            if (currentBlog != null)
            {
                return(currentBlog.DictionaryItem);
            }
            else
            {
                return(null);
            }
        }
Exemple #24
0
        public static void SetupCustomBlogs(this Database database, string testRoot)
        {
            var templateRoot = database.GetItem("/sitecore/templates/user defined");

            using (new SecurityDisabler())
            {
                templateRoot.Paste(File.ReadAllText(HttpContext.Current.Server.MapPath(@"~\test data\custom blog templates.xml")), false, PasteMode.Overwrite);
            }

            var home             = database.GetItem("/sitecore/content/home");
            var testRootItem     = home.Axes.GetChild(testRoot);
            var blogTemplate     = Sitecore.Context.Database.GetTemplate("user defined/test templates/CustomBlog");
            var entryTemplate    = Sitecore.Context.Database.GetTemplate("user defined/test templates/CustomEntry");
            var commentTemplate  = Sitecore.Context.Database.GetTemplate("user defined/test templates/CustomComment");
            var categoryTemplate = Sitecore.Context.Database.GetTemplate("user defined/test templates/CustomCategory");

            var items = testRootItem.Axes.GetDescendants();

            foreach (var item in items)
            {
                using (new SecurityDisabler())
                {
                    if (item.TemplateID == Settings.BlogTemplateID)
                    {
                        item.ChangeTemplate(blogTemplate);
                        using (new EditContext(item))
                        {
                            BlogHomeItem blogItem = item;
                            blogItem.DefinedEntryTemplate.Field.Value    = entryTemplate.InnerItem.ID.ToString();
                            blogItem.DefinedCommentTemplate.Field.Value  = commentTemplate.InnerItem.ID.ToString();
                            blogItem.DefinedCategoryTemplate.Field.Value = categoryTemplate.InnerItem.ID.ToString();
                        }
                    }
                    else if (item.TemplateID == Settings.EntryTemplateID)
                    {
                        item.ChangeTemplate(entryTemplate);
                    }
                    else if (item.TemplateID == Settings.CommentTemplateID)
                    {
                        item.ChangeTemplate(commentTemplate);
                    }
                    else if (item.TemplateID == Settings.CategoryTemplateID)
                    {
                        item.ChangeTemplate(categoryTemplate);
                    }
                }
            }
        }
        private (Dictionary <string, Item> Items, IBlogManager BlogManager, IEntryManager EntryManager) SetupManagerMocks(
            bool returnBlogItem,
            Entry[] page1Entries,
            Entry[] page2Entries = null,
            Entry[] page3Entries = null
            )
        {
            var entries = page1Entries.AsEnumerable();

            if (page2Entries != null)
            {
                entries = entries.Concat(page2Entries);
            }

            if (page3Entries != null)
            {
                entries = entries.Concat(page3Entries);
            }

            var items = new Dictionary <string, Item>();

            foreach (var entry in entries)
            {
                var itemMock  = ItemFactory.CreateItem(entry.Uri.ItemID);
                var dateField = FieldFactory.CreateField(itemMock.Object, ID.NewID, "Entry Date", DateUtil.ToIsoDate(entry.EntryDate));
                ItemFactory.AddFields(itemMock, new[] { dateField });

                items.Add(entry.Title, itemMock.Object);
            }

            var blogItem     = ItemFactory.CreateItem();
            var blogHomeItem = new BlogHomeItem(blogItem.Object);

            var blogManager = Mock.Of <IBlogManager>(x =>
                                                     x.GetCurrentBlog(It.IsAny <Item>()) == (returnBlogItem ? blogHomeItem : null)
                                                     );

            var entryManager = Mock.Of <IEntryManager>(x =>
                                                       x.GetBlogEntries(blogHomeItem, It.IsAny <EntryCriteria>(), It.IsAny <ListOrder>()) == new SearchResults <Entry>(entries.ToList(), false)
                                                       );

            return(items, blogManager, entryManager);
        }
Exemple #26
0
        /// <summary>
        /// Populates the velocity template context. Only the objects that were
        /// added in this method will be accessible in the mail template.
        /// </summary>
        /// <remarks>Override this to add your own data to the context</remarks>
        protected virtual void PopulateContext(WorkflowPipelineArgs args)
        {
            velocityContext.Put("args", args);
            velocityContext.Put("item", args.DataItem);
            velocityContext.Put("processor", args.ProcessorItem);
            velocityContext.Put("user", Sitecore.Context.User);
            velocityContext.Put("history", args.DataItem.State.GetWorkflow().GetHistory(args.DataItem));
            velocityContext.Put("state", args.DataItem.State.GetWorkflowState());
            velocityContext.Put("nextState", GetNextState(args));
            velocityContext.Put("site", Sitecore.Context.Site);
            velocityContext.Put("time", DateTime.Now);

            EntryItem entryItem = null;

            if (args.DataItem.TemplateIsOrBasedOn(Settings.EntryTemplateID))
            {
                entryItem = new EntryItem(args.DataItem);
            }
            else if (args.DataItem.TemplateIsOrBasedOn(Settings.CommentTemplateID))
            {
                CommentItem commentItem = new CommentItem(args.DataItem);
                entryItem = ManagerFactory.EntryManagerInstance.GetBlogEntryByComment(commentItem);
                velocityContext.Put("comment", commentItem);
            }

            if (entryItem != null)
            {
                velocityContext.Put("entry", entryItem);
                if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.CreatedBy))
                {
                    UserProfile createdBy = User.FromName(entryItem.InnerItem.Statistics.CreatedBy, false).Profile;
                    velocityContext.Put("entryCreatedBy", createdBy);
                }
                if (!string.IsNullOrEmpty(entryItem.InnerItem.Statistics.UpdatedBy))
                {
                    UserProfile updatedBy = User.FromName(entryItem.InnerItem.Statistics.UpdatedBy, false).Profile;
                    velocityContext.Put("entryUpdatedBy", updatedBy);
                }

                BlogHomeItem blog = ManagerFactory.BlogManagerInstance.GetCurrentBlog(entryItem);
                velocityContext.Put("blog", blog);
            }
        }
Exemple #27
0
        /// <summary>
        /// Returns the dictionary item.
        /// </summary>
        /// <returns>Returns standard dictionary item if there is no custom item selected</returns>
        public Item GetDictionaryItem()
        {
            BlogHomeItem currentBlog = GetCurrentBlog();

            if (currentBlog != null)
            {
                var dictionaryFolder = currentBlog.CustomDictionaryFolder;

                if (dictionaryFolder.Item != null)
                {
                    return(dictionaryFolder.Item);
                }

                return(ItemManager.GetItem(Settings.DictionaryPath, Context.Language, Sitecore.Data.Version.Latest, Context.Database));
            }
            else
            {
                return(null);
            }
        }
Exemple #28
0
        public IEnumerable <RssFeedItem> Resolve(BlogHomeItem blogItem)
        {
            if (blogItem == null)
            {
                yield break;
            }

            if (blogItem.EnableRss.Checked)
            {
                var children = blogItem.InnerItem.GetChildren();
                if (children == null)
                {
                    yield break;
                }

                foreach (Item child in children)
                {
                    if (TemplateManager.TemplateIsOrBasedOn(child, WeBlogSettings.RssFeedTemplateIds))
                    {
                        yield return(new RssFeedItem(child));
                    }
                }
            }
        }
Exemple #29
0
        public void AddCommentToEntry()
        {
            // Perform this test in master DB as comments get created there
            var db           = Sitecore.Configuration.Factory.GetDatabase("master");
            var blogSettings = new BlogHomeItem(m_blog1).BlogSettings;

            var originalCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);
            ID  commentId     = null;

            try
            {
                var comment = new Sitecore.Modules.WeBlog.Model.Comment()
                {
                    AuthorEmail = "*****@*****.**",
                    AuthorName  = "commentor",
                    Text        = "My Comment"
                };

                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.IpAddress] = "127.0.0.1";
                comment.Fields[Sitecore.Modules.WeBlog.Constants.Fields.Website]   = "website";

                commentId = new Mod.CommentManager().AddCommentToEntry(m_entry12.ID, comment);
                var childCount = m_entry12.Axes.GetDescendants().Count(i => i.TemplateID == blogSettings.CommentTemplateID);

                Assert.IsTrue(commentId != ID.Null);
                Assert.AreEqual(originalCount + 1, childCount);

                var commentItem = db.GetItem(commentId);
                Assert.IsNotNull(commentItem);

                var commentAsComment = new Sitecore.Modules.WeBlog.Items.WeBlog.CommentItem(commentItem);
                Assert.AreEqual("*****@*****.**", commentAsComment.Email.Text);
                Assert.AreEqual("commentor", commentAsComment.Name.Text);
                Assert.AreEqual("127.0.0.1", commentAsComment.IPAddress.Text);
                Assert.AreEqual("website", commentAsComment.Website.Text);
                Assert.AreEqual("My Comment", StringUtil.RemoveTags(commentAsComment.Comment.Text));
            }
            finally
            {
                var webDb = Sitecore.Configuration.Factory.GetDatabase("web");
                if (commentId != (ID)null)
                {
                    var commentItem = db.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }

                    commentItem = webDb.GetItem(commentId);
                    if (commentItem != null)
                    {
                        using (new SecurityDisabler())
                        {
                            commentItem.Delete();
                        }
                    }
                }
            }
        }
Exemple #30
0
 public AuthorsCore(BlogHomeItem currentBlog)
 {
     CurrentBlog = currentBlog;
 }