Пример #1
0
        public static Func <QueryOverProjectionBuilder <Revision>, QueryOverProjectionBuilder <Revision> > FromRevision(Entry entryAlias)
        {
            var entryRevision = new EntryRevision();

            return(list =>
            {
                list
                .Select(e => e.Id).WithAlias(() => entryRevision.Id)
                .Select(() => entryAlias.Author).WithAlias(() => entryRevision.Author)
                .Select(e => e.Author).WithAlias(() => entryRevision.RevisionAuthor)
                .Select(e => e.Body).WithAlias(() => entryRevision.Body)
                .Select(() => entryAlias.CommentCount).WithAlias(() => entryRevision.CommentCount)
                .Select(e => e.Format).WithAlias(() => entryRevision.Format)
                .Select(() => entryAlias.HideChrome).WithAlias(() => entryRevision.HideChrome)
                .Select(() => entryAlias.IsDiscussionEnabled).WithAlias(() => entryRevision.IsDiscussionEnabled)
                .Select(() => entryAlias.LatestRevision.RevisionNumber).WithAlias(() => entryRevision.LatestRevisionNumber)
                .Select(e => e.RevisionNumber).WithAlias(() => entryRevision.RevisionNumber)
                .Select(() => entryAlias.MetaDescription).WithAlias(() => entryRevision.MetaDescription)
                .Select(() => entryAlias.MetaTitle).WithAlias(() => entryRevision.MetaTitle)
                .Select(() => entryAlias.Name).WithAlias(() => entryRevision.Name)
                .Select(() => entryAlias.PageTemplate).WithAlias(() => entryRevision.PageTemplate)
                .Select(() => entryAlias.Published).WithAlias(() => entryRevision.Published)
                .Select(() => entryAlias.LatestRevision.Revised).WithAlias(() => entryRevision.Revised)
                .Select(() => entryAlias.Status).WithAlias(() => entryRevision.Status)
                .Select(() => entryAlias.Summary).WithAlias(() => entryRevision.Summary)
                .Select(() => entryAlias.Title).WithAlias(() => entryRevision.Title);

                return list;
            });
        }
Пример #2
0
        public virtual ActionResult Edit(PageName page, int?revertToRevision)
        {
            var allTags = Repository.FindAll <Tag>();

            var entry =
                revertToRevision == null
                    ? Repository.FindFirstOrDefault(new EntryByNameQuery(page))
                    : Repository.FindFirstOrDefault(new EntryByNameAndRevisionQuery(page, revertToRevision.Value));

            if (entry == null)
            {
                entry = new EntryRevision
                {
                    Title     = "New post",
                    MetaTitle = "New post",
                    Name      = page
                };
            }

            entry.ChangeSummary = entry.Id == 0
                                      ? "Initial create"
                                      : (revertToRevision == null ? "" : "Reverted to version " + revertToRevision);
            entry.AllTags = allTags;

            if (revertToRevision != null)
            {
                return(View("Edit", entry).AndFlash("You are editing an old version of this page. This will become the current version when you save."));
            }
            return(View("Edit", entry));
        }
Пример #3
0
        private List <Tag> GetEditTags(EntryRevision model)
        {
            var tagList = new List <Tag>();

            foreach (var tagName in model.TagsCommaSeparated.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(s => s != "0"))
            {
                int id;
                var tag = int.TryParse(tagName, out id) ? Repository.Get <Tag>(id) : new Tag {
                    Name = tagName
                };
                tagList.Add(tag);
            }

            return(tagList);
        }
Пример #4
0
 private static Post ConvertToPost(EntryRevision entry)
 {
     return(new Post
     {
         dateCreated = entry.Revised,
         categories = entry.TagsCommaSeparated.Split(',').ToArray(),
         description = entry.Body,
         permalink = entry.Name.ToString(),
         postid = entry.Id,
         title = entry.Title,
         userid = "FunnelWeb",
         wp_slug = entry.Name.ToString(),
         mt_excerpt = entry.MetaDescription
     });
 }
Пример #5
0
        private string BuildFeedItemBody(Uri itemUri, Uri viaFeedUri, EntryRevision latestRevision)
        {
            var result =
                Renderer.RenderTrusted(latestRevision.Body, latestRevision.Format, CreateHelper())
                + string.Format("<img src=\"{0}\" />", viaFeedUri);

            if (Settings.GetSettings <FunnelWebSettings>().FacebookLike)
            {
                var facebook = string.Format(@"  <div class='facebook'>
                      <iframe src='http://www.facebook.com/plugins/like.php?href={0}&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:450px; height:80px;' allowTransparency='true'></iframe>
                    </div>", Url.Encode(itemUri.AbsoluteUri));
                result += facebook;
            }

            return(result);
        }
Пример #6
0
        private List <Tag> GetEditTags(EntryRevision model)
        {
            var tagList = new List <Tag>();

            foreach (var tagName in model.TagsCommaSeparated.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Where(s => s != "0"))
            {
                Tag tagDb = Repository.FindAll <Tag>().FirstOrDefault <Tag>(t => t.Name == tagName);

                Tag tag = tagDb ?? new Tag {
                    Name = tagName
                };
                tagList.Add(tag);
            }

            return(tagList);
        }
Пример #7
0
        public double Prioritize(EntryRevision entry)
        {
            // I use the number of comments as an indicator of the popularity. For example:
            //  15+ comments => 0.5 + (1*0.5) = 1.0
            //   10 comments => 0.5 + (2/3*0.5) = 8.333
            //    2 comments => 0.5 + (2/3*0.5) = 5.667
            // New posts get a high initial ranking for the first 7 days
            var priority = 0.5 + ((double)Math.Min(entry.Comments.Count, 15) / 15) * 0.5;

            if (entry.Published.Date.AddDays(7) > DateTime.Now)
            {
                priority = 1.0;
            }

            return(priority);
        }
Пример #8
0
        public void WikiControllerTestsPageReturnsFoundPage()
        {
            var entry = new EntryRevision {
                Name = "page"
            };

            Repository.FindFirstOrDefault(Arg.Any <EntryByNameQuery>()).Returns(entry);

            Controller.Page(entry.Name, (int?)null);

            Assert.IsNotNull(Controller.ViewData.Model);
            Assert.IsInstanceOf <PageModel>(Controller.ViewData.Model);

            var model = (PageModel)Controller.ViewData.Model;

            Assert.AreEqual(entry, model.Entry);
            Repository.Received().FindFirstOrDefault(Arg.Is <EntryByNameQuery>(q => q.PageName == entry.Name));
        }
Пример #9
0
        public void EditReturnsExistingPageWhenFound()
        {
            var entry = new EntryRevision {
                Name = "awesome-post"
            };

            Repository.FindFirstOrDefault(Arg.Any <EntryByNameQuery>()).Returns(entry);

            var feeds = new List <Tag>().AsQueryable();

            Repository.FindAll <Tag>().Returns(feeds);

            var result = (ViewResult)AdminController.Edit(entry.Name, null);

            Assert.AreEqual("Edit", result.ViewName);
            Assert.AreEqual(feeds, ((EntryRevision)result.ViewData.Model).AllTags);
            Assert.AreEqual(entry.Name.ToString(), ((EntryRevision)result.ViewData.Model).Name.ToString());

            Repository.Received().FindFirstOrDefault(Arg.Any <EntryByNameQuery>());
            Repository.Received().FindAll <Tag>();
        }
Пример #10
0
        public virtual ActionResult Edit(EntryRevision model)
        {
            model.AllTags = Repository.FindAll <Tag>();

            if (!ModelState.IsValid)
            {
                model.SelectedTags = GetEditTags(model);
                return(View(model));
            }

            var author = Authenticator.GetName();
            var entry  = Repository.Get <Entry>(model.Id);

            if (entry == null && CurrentEntryExistsWithName(model.Name))
            {
                model.SelectedTags = GetEditTags(model);
                ModelState.AddModelError("PageExists", string.Format("A page with SLUG '{0}' already exists. You should edit that page instead", model.Name));
                return(View(model));
            }

            if (entry == null && CurrentEntryExistsWithName(model.Title) && model.Name == "")
            {
                model.SelectedTags = GetEditTags(model);
                ModelState.AddModelError("PageExists", string.Format("A page with SLUG '{0}' already exists. Please add a unique SLUG here.", model.Title));
                return(View(model));
            }

            entry = entry ?? new Entry {
                Author = author
            };
            entry.Name                = string.IsNullOrWhiteSpace(model.Name) ? model.Title.Slugify() : model.Name.ToString();
            entry.PageTemplate        = string.IsNullOrEmpty(model.PageTemplate) ? null : model.PageTemplate;
            entry.Title               = model.Title ?? string.Empty;
            entry.Summary             = model.Summary ?? string.Empty;
            entry.MetaTitle           = string.IsNullOrWhiteSpace(model.MetaTitle) ? model.Title : model.MetaTitle;
            entry.IsDiscussionEnabled = !model.DisableComments;
            entry.MetaDescription     = model.MetaDescription ?? string.Empty;
            entry.HideChrome          = model.HideChrome;

            //Only change the publish date if the dates no longer match, this means that
            //time changes wont be tracked.
            var published = DateTime.Parse(model.PublishDate + " " + DateTime.Now.ToShortTimeString(), CultureInfo.CurrentCulture).ToUniversalTime();

            if (entry.Published.Date != published.Date)
            {
                entry.Published = published;
            }

            entry.Status = model.Status;

            var revision = entry.Revise();

            revision.Author = author;
            revision.Body   = model.Body;
            revision.Reason = model.ChangeSummary ?? string.Empty;
            revision.Format = model.Format;

            var editTags = GetEditTags(model);
            var toDelete = entry.Tags.Where(t => !editTags.Contains(t)).ToList();
            var toAdd    = editTags.Where(t => !entry.Tags.Contains(t)).ToList();

            foreach (var tag in toDelete)
            {
                tag.Remove(entry);
            }
            foreach (var tag in toAdd)
            {
                if (tag.Id == 0)
                {
                    Repository.Add(tag);
                }
                tag.Add(entry);
            }

            EventPublisher.Publish(new EntrySavedEvent(entry));

            if (model.IsNew)
            {
                Repository.Add(entry);
            }

            return(RedirectToAction("Page", "Wiki", new { Area = "", page = entry.Name }));
        }
Пример #11
0
 public PageModel(PageName page, EntryRevision entry)
 {
     Page  = page;
     Entry = entry;
 }
Пример #12
0
 public static IEnumerable <MvcHtmlString> CssKeywordsFor(this HtmlHelper html, EntryRevision entry)
 {
     return(html.CssKeywordsFor(entry.Tags));
 }
Пример #13
0
        public static IHtmlString CommentedAtRevision(this HtmlHelper html, Comment comment, EntryRevision revision)
        {
            if (Settings(html).EnablePublicHistory == false)
            {
                return(MvcHtmlString.Empty);
            }

            if (comment.EntryRevisionNumber != revision.RevisionNumber)
            {
                if (comment.EntryRevisionNumber == comment.Entry.LatestRevision.RevisionNumber)
                {
                    return(MvcHtmlString.Create("@ " +
                                                html.ActionLink("latest",
                                                                "Page", "Wiki",
                                                                new { page = comment.Entry.Name },
                                                                new { })));
                }
                return(MvcHtmlString.Create("@ " +
                                            html.ActionLink(string.Format("version {0}", comment.EntryRevisionNumber),
                                                            "Page", "Wiki",
                                                            new { page = comment.Entry.Name, revision = comment.EntryRevisionNumber },
                                                            new { })));
            }
            return(MvcHtmlString.Empty);
        }
Пример #14
0
 public string GetChangeFrequency(EntryRevision entry)
 {
     return(entry.Published.Date.AddDays(7) > DateTime.Now
         ? "daily"
         : "weekly");
 }
Пример #15
0
        public static Func <QueryOverProjectionBuilder <Entry>, QueryOverProjectionBuilder <Entry> > FromEntry()
        {
            var entryRevision = new EntryRevision();

            return(FromEntry(entryRevision));
        }
Пример #16
0
        public static Func <QueryOverProjectionBuilder <Entry>, QueryOverProjectionBuilder <Entry> > FromEntry(EntryRevision entryRevisionAlias)
        {
            return(list =>
            {
                list
                .Select(e => e.Id).WithAlias(() => entryRevisionAlias.Id)
                .Select(e => e.Author).WithAlias(() => entryRevisionAlias.Author)
                .Select(e => e.LatestRevision.Author).WithAlias(() => entryRevisionAlias.RevisionAuthor)
                .Select(e => e.LatestRevision.Body).WithAlias(() => entryRevisionAlias.Body)
                .Select(e => e.CommentCount).WithAlias(() => entryRevisionAlias.CommentCount)
                .Select(e => e.LatestRevision.Format).WithAlias(() => entryRevisionAlias.Format)
                .Select(e => e.HideChrome).WithAlias(() => entryRevisionAlias.HideChrome)
                .Select(e => e.IsDiscussionEnabled).WithAlias(() => entryRevisionAlias.IsDiscussionEnabled)
                .Select(e => e.LatestRevision.RevisionNumber).WithAlias(() => entryRevisionAlias.LatestRevisionNumber)
                .Select(e => e.LatestRevision.RevisionNumber).WithAlias(() => entryRevisionAlias.RevisionNumber)
                .Select(e => e.MetaDescription).WithAlias(() => entryRevisionAlias.MetaDescription)
                .Select(e => e.MetaTitle).WithAlias(() => entryRevisionAlias.MetaTitle)
                .Select(e => e.Title).WithAlias(() => entryRevisionAlias.Title)
                .Select(e => e.Name).WithAlias(() => entryRevisionAlias.Name)
                .Select(e => e.PageTemplate).WithAlias(() => entryRevisionAlias.PageTemplate)
                .Select(e => e.Published).WithAlias(() => entryRevisionAlias.Published)
                .Select(e => e.LatestRevision.Revised).WithAlias(() => entryRevisionAlias.Revised)
                .Select(e => e.Status).WithAlias(() => entryRevisionAlias.Status)
                .Select(e => e.Summary).WithAlias(() => entryRevisionAlias.Summary)
                .Select(e => e.TagsCommaSeparated).WithAlias(() => entryRevisionAlias.TagsCommaSeparated);

                return list;
            });
        }