예제 #1
0
        private string normalizeTagName(string tagName)
        {
            if (expressions != null)
            {
                return(expressions.Clean("TagReplace", tagName));
            }

            return(tagName);
        }
예제 #2
0
        public ModelResult <Post> AddPost(PostInput postInput, EntityState postState)
        {
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPost", new PluginPostInput(postInput)).ToPostInput();
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPostOnAdd", new PluginPostInput(postInput)).ToPostInput();

            ModelResult <Post> results = addPost(postInput, () => postInput.ToPost(postState, context.User.Cast <User>(), t => expressions.Clean("TagReplace", t)));

            if (results.IsValid)
            {
                Post   newPost = results.Item;
                string postUrl = urlHelper.AbsolutePath(urlHelper.Post(newPost));

                //TODO: (erikpo) Move this into a module
                addCreatorSubscription(newPost);

                //TODO: (erikpo) Move this into a module
                if (newPost.State == EntityState.Normal && newPost.Published.HasValue)
                {
                    IEnumerable <TrackbackOutbound> trackbacksToAdd    = extractTrackbacks(newPost, postUrl, newPost.Blog.DisplayName);
                    IEnumerable <TrackbackOutbound> unsentTrackbacks   = trackbackOutboundRepository.GetUnsent(newPost.ID);
                    IEnumerable <TrackbackOutbound> trackbacksToRemove = trackbacksToAdd.Where(tb => !unsentTrackbacks.Contains(tb) && !tb.Sent.HasValue);

                    trackbackOutboundRepository.Remove(trackbacksToRemove);
                    trackbackOutboundRepository.Save(trackbacksToAdd);
                }
                else
                {
                    //TODO: (erikpo) Remove all outbound trackbacks
                }

                pluginEngine.ExecuteAll("PostSaved", new { context, post = new PostReadOnly(newPost, postUrl) });
                pluginEngine.ExecuteAll("PostAdded", new { context, post = new PostReadOnly(newPost, postUrl) });

                if (newPost.State == EntityState.Normal && newPost.Published.HasValue && newPost.Published.Value <= DateTime.UtcNow)
                {
                    pluginEngine.ExecuteAll("PostPublished", new { context, post = new PostReadOnly(newPost, postUrl) });
                }
            }

            return(results);
        }