protected void SetLinks(AtomEntry e) { LogService.Debug("AnnotateService.SetLinks entryId={0}", e.Id); var links = e.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); //atom threading extension if (e.InReplyTo != null) { e.InReplyTo.Href = url.RouteIdUri("AtomPubResource", e.InReplyTo.Ref, AbsoluteMode.Force); links.Merge(new AtomLink { Rel = "related", Type = "text/html", Href = url.RouteIdUri("AtomPubResource", e.InReplyTo.Ref, AbsoluteMode.Force) }); } //atom threading extension links.Merge(new AtomLink { Href = url.RouteIdUri("AnnotateEntryAnnotationsFeed", e.Id, AbsoluteMode.Force), Rel = "replies", Type = Atom.ContentType, Count = e.Total, Updated = DateTimeOffset.UtcNow }); e.Links = links; }
protected void SetLinks(AtomEntry e) { if (!new BlogAppCollection(AppService.GetCollection(e.Id)).BloggingOn) return; LogService.Debug("BlogService.SetLinks entryId={0}", e.Id); var links = e.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); if (e.InReplyTo == null) { links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = url.RouteIdUri("BlogEntry", e.Id, AbsoluteMode.Force) }); } else // annotation { links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = new System.Uri(url.RouteIdUri("BlogEntry", e.InReplyTo.Ref, AbsoluteMode.Force).ToString() + "#" + e.Id.ToWebId()) }); e.InReplyTo.Href = url.RouteIdUri("BlogEntry", e.InReplyTo.Ref, AbsoluteMode.Force); links.Merge(new AtomLink { Rel = "related", Type = "text/html", Href = url.RouteIdUri("BlogEntry", e.InReplyTo.Ref, AbsoluteMode.Force) }); if (AnnotateService.GetAnnotationState(AppService.GetCollection(e.Id), e.Id) == AnnotationState.On) { links.Merge(new AtomLink { Rel = "reply", Type = "text/html", Href = new System.Uri(url.RouteIdUri("BlogEntry", e.InReplyTo.Ref, AbsoluteMode.Force).ToString() + "#addcommentform") }); } } e.Links = links; }
public RaterModel GetRaterModel(string ip, UrlHelper url) { return new RaterModel() { PostHref = url.RouteIdUri("RaterRateEntry", Theme.Id), EntryId = Theme.Id, Rating = Theme.Rating, RatingCount = Theme.RatingCount, CanRate = false }; }
protected void SetLinks(AtomFeed f) { LogService.Debug("AnnotateService.SetLinks feedId={0}", f.Id); var links = f.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); //atom threading extension if (f.Id != null && f.Id.Scheme == "tag") { links.Merge(new AtomLink { Href = url.RouteIdUri("AnnotateAnnotationsFeed", f.Id, AbsoluteMode.Force), Rel = "replies", Type = Atom.ContentType, Updated = DateTimeOffset.UtcNow }); } f.Links = links; }
public virtual AtomEntry Annotate(Id entryId, AtomEntry entry, string slug) { LogService.Info("AnnotateService.Annotate entryId={0} slug={1}", entryId, slug); //authorization if (!AuthorizeService.IsAuthorized(GetUser(), entryId.ToScope(), AuthAction.Annotate)) throw new UserNotAuthorizedException(GetUser().Name, AuthAction.Annotate.ToString()); AppCollection coll = AppService.GetCollection(entryId); //make sure type is accepted if (!coll.CanAccept(Atom.ContentTypeEntry)) throw new InvalidContentTypeException(Atom.ContentTypeEntry); entry.SetNamespaces(); //TODO: is there a better place for this? //build id onto parent's id AtomEntry parent = AtomPubService.GetEntry(entryId); entry.Id = new Id(parent.Id.Owner, parent.Id.Date, parent.Id.Collection, entry.BuildPath(parent.Id.EntryPath, slug)); var url = new UrlHelper(Container.GetInstance<RequestContext>()); //this annotation is a reply to the parent entry, TODO: leave off href for later calc based on id? entry.InReplyTo = new ThreadInReplyTo() { Ref = parent.Id, Href = parent.IsExternal ? parent.Content.Src : url.RouteIdUri("AtomPubEntry", entry.Id, AbsoluteMode.Force), Type = parent.IsExternal ? parent.Content.Type : Atom.ContentTypeEntry }; if (!entry.Published.HasValue) entry.Published = DateTimeOffset.UtcNow; entry.Updated = DateTimeOffset.UtcNow; entry.Edited = DateTimeOffset.UtcNow; if (entry.Authors.Count() == 0) entry.SetPerson(AuthorizeService, true); //entry.IdChanged += (e) => e.UpdateLinks(UrlHelper.RouteIdUri); //OnAnnotate(parent, entryId, entry, slug); if (AnnotatingEntry != null) AnnotatingEntry(entryId, entry, slug); if (entry.Authors.Count() == 0 || entry.Authors.First().Name == null) throw new AnnotationNotAllowedException(entry.Id, entry.AnnotationType, "the author cannot be determined"); entry = AtomEntryRepository.CreateEntry(entry); if (EntryAnnotated != null) EntryAnnotated(entry); return entry; }
protected void SetLinks(AtomFeed feed) { LogService.Debug("AtomPubService.SetLinks collectionId={0}", feed.Id); if (feed.Links == null) feed.Links = new List<AtomLink>(); var links = feed.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); links.Merge(new AtomLink() { Rel = "service", Type = Atom.ContentTypeService, Href = url.RouteUriEx("AtomPubService", AbsoluteMode.Force) }); if (feed.Id != null && feed.Id.Scheme == "tag") { links.Merge(new AtomLink() { Rel = "self", Type = Atom.ContentTypeFeed, Href = url.RouteIdUri("AtomPubFeed", feed.Id, AbsoluteMode.Force) }); links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = url.RouteIdUri("AtomPubCollectionIndex", feed.Id, AbsoluteMode.Force) }); } feed.Links = links; foreach (AtomEntry entry in feed.Entries) SetLinks(entry); if (SettingFeedLinks != null) SettingFeedLinks(feed); }
protected void SetLinks(AtomEntry entry) { LogService.Debug("AtomPubService.SetLinks entryId={0}", entry.Id); if (entry.Links == null) entry.Links = new List<AtomLink>(); var links = entry.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); if (AuthorizeService.IsAuthorized(GetUser(), entry.Id.ToScope(), AuthAction.UpdateEntryOrMedia)) { links.Merge(new AtomLink { Rel = "edit", Href = url.RouteIdUri("AtomPubEntryEdit", entry.Id, AbsoluteMode.Force ), }); } links.Merge(new AtomLink { Rel = "self", Href = url.RouteIdUri("AtomPubEntry", entry.Id, AbsoluteMode.Force) }); if (entry.Media) { if (entry.Content == null) entry.Content = new AtomContent(); entry.Content.Src = url.RouteIdUri("AtomPubMedia", entry.Id, AbsoluteMode.Force); if (AuthorizeService.IsAuthorized(GetUser(), entry.Id.ToScope(), AuthAction.UpdateEntryOrMedia)) { links.Merge(new AtomLink { Rel = "edit-media", Href = url.RouteIdUri("AtomPubMediaEdit", entry.Id, AbsoluteMode.Force) }); } } else { links.Merge(new AtomLink { Rel = "alternate", Type="text/html", Href = url.RouteIdUri("AtomPubResource", entry.Id, AbsoluteMode.Force) }); } if (AuthorizeService.IsAuthorized(GetUser(), entry.Id.ToScope(), AuthAction.ApproveEntryOrMedia)) { links.RemoveAll(l => l.Rel == "unapprove" || l.Rel == "approve"); links.Add(new AtomLink { Rel = entry.Approved ? "unapprove" : "approve", Href = url.RouteIdUri("AtomPubApproveEntry", entry.Id, AbsoluteMode.Force) }); } entry.Links = links; if (SettingEntryLinks != null) SettingEntryLinks(entry); }
public virtual TrackbackResult ReceiveTrackback(Id entryId, string title, string excerpt, string url, string blogName, string ip, Uri referrer) { LogService.Info("TrackbackService.ReceiveTrackback entryId={0} title={1} url={2}", entryId, title, url); if (!IsEnabled(AtomEntryRepository.GetEntry(entryId))) return new TrackbackResult() { Error = true, Message = "Trackbacks are disabled." }; try { string page = string.Empty; string contentType = "text/html"; using (WebClient client = new WebClient()) { page = client.DownloadString(url); if (client.ResponseHeaders["Content-Type"] != null) contentType = client.ResponseHeaders["Content-Type"]; } var uh = new UrlHelper(Container.GetInstance<RequestContext>()); //validate page has a link back if (!ContainsLink(page, uh.RouteIdUri("BlogEntry", entryId, AbsoluteMode.Force))) throw new AnnotationNotAllowedException(entryId, "trackback", "it does not link back"); AtomEntry trackback = new AtomEntry(); //content trackback.Content = new AtomContent() { Src = new Uri(url), Type = contentType }; //title if (title == null) title = WebHelper.ExtractTitleForPage(page); if (title == null) title = "Trackback"; trackback.Title = new AtomTitle() { Text = title }; //summary if (excerpt == null) excerpt = WebHelper.ExtractDescriptionForPage(page); trackback.Summary = new AtomSummary() { Text = excerpt }; //author trackback.Authors = new List<AtomPerson>() { new AtomAuthor() { Name = blogName == null ? string.Empty : blogName, Uri = referrer } }; //add extension data? trackback.SetValue<string>(Atom.SvcNs + "ip", ip); trackback.AnnotationType = "trackback"; AnnotateService.Annotate(entryId, trackback, null); return new TrackbackResult() { Error = false }; } catch (Exception ex) { LogService.Error(ex); return new TrackbackResult() { Error = true, Message = ex.Message }; } }
protected void SetLinks(AtomFeed f) { if (f.Id != null && f.Id.Scheme == "tag") { if (!new BlogAppCollection(AppService.GetCollection(f.Id)).BloggingOn) return; LogService.Debug("BlogService.SetLinks feedId={0}", f.Id); var links = f.Links.ToList(); var url = new UrlHelper(Container.GetInstance<RequestContext>()); links.Merge(new AtomLink() { Rel = "alternate", Type = "text/html", Href = url.RouteIdUri("BlogListing", f.Id, AbsoluteMode.Force) }); f.Links = links; } }