コード例 #1
0
        public SiteUrl Delete(ItemDto item)
        {
            string[] segments = item == null ? null : new[]
                                                          {
                                                              item.Id.ToString(CultureInfo.InvariantCulture)
                                                          };

            return new SiteUrl(this.Domain, this.HttpPort, false, "Dxt-Admin", "Post", "ConfirmDelete", segments, null);
        }
コード例 #2
0
        public SiteUrl Edit(ItemDto item)
        {
            string id = item != null ? item.Id.ToString(CultureInfo.InvariantCulture) : null;

            string[] segments = new[]
                                    {
                                        id
                                    };

            return new SiteUrl(this.Domain, this.HttpPort, false, "Dxt-Admin", "Post", "Manage", segments, null);
        }
コード例 #3
0
        public SiteUrl Permalink(ItemDto item)
        {
            string[] segments = new[]
                                    {
                                        item.PublishAt.Date.Year.ToString(CultureInfo.InvariantCulture),
                                        item.PublishAt.Date.Month.ToString(CultureInfo.InvariantCulture),
                                        item.PublishAt.Date.Day.ToString(CultureInfo.InvariantCulture),
                                        item.Slug
                                    };

            return new SiteUrl(this.Domain, this.HttpPort, false, null, "Blog", "Post", segments, null);
        }
コード例 #4
0
		public static async Task<bool> Notify(ItemDto item, Uri uri)
		{
			BlogConfigurationDto configuration = configurationService.GetConfiguration();

			using (HttpClient client = new HttpClient())
			{
				string content = await client.GetStringAsync(uri);
				Uri trackbackUrl = GetTrackBackUrlFromPage(content);

				if (trackbackUrl != null)
				{
					SiteUrl itemUrl = item is PostDto
						                  ? urlBuilder.Post.Permalink(item)
						                  : urlBuilder.Page.Permalink(item);

					Dictionary<string, string> form = new Dictionary<string, string>
						                                  {
							                                  { "title", item.Title }, 
							                                  { "url", itemUrl.ToString() }, 
							                                  { "excerpt", item.Excerpt }, 
							                                  { "blog_name", configuration.Name }
						                                  };

					try
					{
						await client.PostAsync(trackbackUrl.ToString(), new FormUrlEncodedContent(form));
						return true;
					}
					catch (Exception ex)
					{
						logger.WarnFormat("Unable to send trackback to '{0}'", ex, uri);
					}

					return false;
				}

				return false;
			}
		}
コード例 #5
0
		public static async Task Notify(ItemDto item, Uri uri)
		{
			SiteUrl itemUrl = item is PostDto
				                  ? urlBuilder.Post.Permalink(item)
				                  : urlBuilder.Page.Permalink(item);

			using (HttpClient client = new HttpClient())
			{
				HttpResponseMessage response = await client.GetAsync(uri);

				KeyValuePair<string, IEnumerable<string>> header = response.Headers.SingleOrDefault(h => h.Key.Equals("x-pingback", StringComparison.OrdinalIgnoreCase) || h.Key.Equals("pingback", StringComparison.OrdinalIgnoreCase));

				string urlToPing = header.Value.FirstOrDefault();

				if (string.IsNullOrEmpty(urlToPing))
				{
					return;
				}

				var xmlRequest = GetXmlRequest(itemUrl, uri);

				await client.PostAsXmlAsync(urlToPing, xmlRequest);
			}
		}
コード例 #6
0
 public SiteUrl Edit(ItemDto item)
 {
     return this.pageUrlBuilder.Edit(item);
 }
コード例 #7
0
 public SiteUrl Delete(ItemDto item)
 {
     return this.pageUrlBuilder.Delete(item);
 }
コード例 #8
0
        private string GetAuthorId(ItemDto item, IEnumerable<WpAuthor> authors)
        {
            string authorId = null;

            // take into account a deleted author
            WpAuthor auth = authors.FirstOrDefault(a => a.user_login == item.Author);
            if (auth.user_id > 0)
            {
                authorId = auth.user_id.ToString();
            }

            return authorId;
        }
コード例 #9
0
        private void ConvertAllowCommentsForItem(int allowComments, ItemDto item)
        {
            // SiteConfiguration conf;

            switch (allowComments)
            {
                case 0:

                    // none and default seem to have the same value...so I return the default
                    // and comments are enabled by default on the posts, the moderation shuould be another thing
                    item.AllowComments = true;
                    break;
                case 1:
                    item.AllowComments = true;
                    break;
                case 2:
                    item.AllowComments = false;
                    break;
                default:

                    // comments are enabled by default on posts
                    item.AllowComments = true;
                    break;
            }
        }
コード例 #10
0
		public PublishedBackgroundTask(ItemDto item, IConfigurationDataService configurationDataService)
		{
			this.configuration = configurationDataService.GetConfiguration();
			this.item = item;
		}
コード例 #11
0
		public PublishedBackgroundTask(ItemDto item)
			: this(item, DexterContainer.Resolve<IConfigurationDataService>())
		{
		}
コード例 #12
0
 public SiteUrl TrackBack(ItemDto item)
 {
     return new SiteUrl(this.Domain, this.HttpPort, false, null, "Services", "Trackback", null, new Dictionary<string, string>
                                                                                                    {
                                                                                                        { "id", item.Id.ToString(CultureInfo.InvariantCulture) },
                                                                                                        { "itemType", "Post" }
                                                                                                    });
 }
コード例 #13
0
		private async Task<bool> IsSpam(TrackBackDto trackBack, ItemDto item)
		{
			string response;
			using (HttpClient client = new HttpClient())
			{
				response = await client.GetStringAsync(trackBack.Url);
			}

			if (string.IsNullOrEmpty(response))
			{
				return false;
			}

			SiteUrl postUrl = this.urlBuilder.Post.Permalink(item);

			return !response.ToLowerInvariant().Contains(postUrl);
		}
コード例 #14
0
 public SiteUrl Permalink(ItemDto item)
 {
     return new SiteUrl(this.Domain, this.HttpPort, false, null, "Blog", "Page", new[] { item.Slug }, null);
 }