public virtual PingbackResult ReceivePingback(Id entryId, Uri sourceUrl, Uri targetUrl, string ip, Uri referrer) { LogService.Info("TrackbackService.ReceivePingback entryId={0} sourceUrl={1} targetUrl={2}", entryId, sourceUrl, targetUrl); if (!IsEnabled(AtomEntryRepository.GetEntry(entryId))) { PingbackResult result = new PingbackResult(); result.SetFault(49, "Pingbacks are turned off."); return result; } try { string page = string.Empty; string contentType = "text/html"; using (WebClient client = new WebClient()) { page = client.DownloadString(sourceUrl); if (client.ResponseHeaders["Content-Type"] != null) contentType = client.ResponseHeaders["Content-Type"]; } //validate page has a link back //if (!ContainsLink(page, RouteService.IdToWebHref(entryId, null))) // throw new AnnotationNotAllowedException(entryId, "trackback", "it does not link back"); AtomEntry pingback = new AtomEntry(); //content pingback.Content = new AtomContent() { Src = sourceUrl, Type = contentType }; //title string title = null; if (title == null) title = WebHelper.ExtractTitleForPage(page); if (title == null) title = "Pingback"; pingback.Title = new AtomTitle() { Text = title }; //summary string summary = WebHelper.ExtractDescriptionForPage(page); if (summary == null) summary = string.Empty; pingback.Summary = new AtomSummary() { Text = summary }; //author pingback.Authors = new List<AtomPerson>() { new AtomAuthor() { Name = string.Empty, Uri = referrer } }; //add extension data? pingback.SetValue<string>(Atom.SvcNs + "ip", ip); pingback.AnnotationType = "pingback"; //TODO: turn this into dependency AnnotateService.Annotate(entryId, pingback, null); return new PingbackResult() { Success = "Success" }; } catch (Exception ex) { LogService.Error(ex); PingbackResult r = new PingbackResult(); r.SetFault(0, ex.Message); return r; } }
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 }; } }