예제 #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="RssSearchResult" /> class.
        /// </summary>
        /// <param name="item">A valid SyndicationItem.</param>
        /// <param name="feedImage">Source feed image</param>
        public RssSearchResult(SyndicationItem item, string feedImage)
            : this()
        {
            Author = item.Authors.Count > 0 ? item.Authors[0].Name : string.Empty;
            Id     = item.Id;
            Title  = item.Title != null?HttpUtility.HtmlDecode(item.Title.Text) : string.Empty;

            Content = HttpUtility.HtmlDecode(RssUtil.GetSummary(item));
            Summary = string.IsNullOrEmpty(Content) ? string.Empty : Content;
            if (Summary.Length > 140)
            {
                Summary = HtmlUtil.TruncateHtml(Summary, 137, "...");
            }
            PublishDate   = item.PublishDate.DateTime;
            ImageUrl      = RssUtil.GetImage(item, true);
            ExtraImageUrl = RssUtil.GetExtraImage(item);
            if (string.IsNullOrEmpty(ImageUrl) && !string.IsNullOrEmpty(ExtraImageUrl))
            {
                ImageUrl = ExtraImageUrl;
            }
            if (string.IsNullOrEmpty(ImageUrl))
            {
                ImageUrl = feedImage;
            }
            MediaUrl = RssUtil.GetMediaVideoURL(item);
            FeedUrl  = RssUtil.GetItemFeedLink(item);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="RssSearchResult" /> class.
        /// </summary>
        /// <param name="item">A valid SyndicationItem.</param>
        /// <param name="feedImage">Source feed image</param>
        public RssSearchResult(SyndicationItem item, string feedImage)
            : this()
        {
            Author = item.Authors.Count > 0 ? item.Authors[0].Name : string.Empty;

            if (string.IsNullOrEmpty(Author))
            {
                if (item.ElementExtensions.Count(p => p.OuterName == "creator") != 0)
                {
                    var creator = item.ElementExtensions.FirstOrDefault(p => p.OuterName == "creator");
                    if (creator != null)
                    {
                        Author = creator.GetObject <XElement>().Value;
                    }
                }
            }

            Id    = item.Id;
            Title = item.Title != null?HttpUtility.HtmlDecode(item.Title.Text) : string.Empty;

            Content = HttpUtility.HtmlDecode(RssUtil.SanitizeHtml(RssUtil.GetSummary(item)));
            Summary = RssUtil.SanitizeHtml(string.IsNullOrEmpty(Content) ? string.Empty : Content);
            if (Summary.Length > 140)
            {
                Summary = HtmlUtil.TruncateHtml(Summary, 137, "...");
            }
            PublishDate   = item.PublishDate.DateTime;
            ImageUrl      = RssUtil.GetImage(item, true);
            ExtraImageUrl = RssUtil.GetExtraImage(item);
            if (string.IsNullOrEmpty(ImageUrl) && !string.IsNullOrEmpty(ExtraImageUrl))
            {
                ImageUrl = ExtraImageUrl;
            }
            if (string.IsNullOrEmpty(ImageUrl))
            {
                ImageUrl = feedImage;
            }

            if (String.IsNullOrEmpty(ImageUrl))
            {
                var    encoded     = item.ElementExtensions.FirstOrDefault(p => p.OuterName == "encoded");
                string encodedText = string.Empty;

                if (encoded != null)
                {
                    encodedText = encoded.GetObject <XElement>().Value;
                }

                var imageUrl =
                    Regex.Match(encodedText, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
                ImageUrl = !string.IsNullOrEmpty(imageUrl) ? imageUrl : string.Empty;
            }

            MediaUrl = RssUtil.GetMediaVideoURL(item);
            FeedUrl  = RssUtil.GetItemFeedLink(item);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="FlickrSearchResult" /> class.
        /// </summary>
        /// <param name="item">A valid SyndicationItem.</param>
        public FlickrSearchResult(SyndicationItem item)
            : this()
        {
            Id    = item.Id;
            Title = item.Title != null?HttpUtility.HtmlDecode(item.Title.Text) : string.Empty;

            Summary   = RssUtil.GetSummary(item);
            Image     = RssUtil.GetImage(item, true);
            Published = item.PublishDate.DateTime;
        }