Beispiel #1
0
        protected override void PopulateRss(string channelName, string userName)
        {
            Rss.Channel = new RssChannel();
            Rss.Version = "2.0";
            Rss.Channel.Title = SettingsIO.GetSetting("SiteName") + " - " + SettingsIO.GetSetting("NewsTitle");
            Rss.Channel.PubDate = DateTime.Now.ToUniversalTime().ToString();
            Rss.Channel.LastBuildDate = DateTime.Now.ToUniversalTime().ToString();
            Rss.Channel.WebMaster = SettingsIO.GetSetting("SupportMail");
            Rss.Channel.Description = "The RSS feed for " + SettingsIO.GetSetting("SiteName");
            Rss.Channel.Link = "~/feed.ashx";

            Rss.Channel.Items = new List<RssItem>();

            int pageSize = 5;
            int.TryParse(SettingsIO.GetSetting("NewsItemsPerPage"), out pageSize);
            List<NewsIO> posts = NewsIO.GetRecentNews(pageSize, false);

            foreach (NewsIO post in posts)
            {
                RssItem item = new RssItem();
                item.Title = post.Title;
                string body = "";
                int newsLength = 2000;
                int.TryParse(SettingsIO.GetSetting("TruncatedNews"), out newsLength);
                post.GetBodyAsHTML(newsLength, out body);
                item.Description = body;
                item.Link = "/NewsItem.aspx?id=" + post.ID + "&title=" + Encoder.XmlEncode(Encoder.UrlEncode(post.Title));
                Rss.Channel.Items.Add(item);
            }
        }
Beispiel #2
0
 public static DTRssItem RssItemToDT(RssItem rssItem)
 {
     DTRssItem dtRssItem = new DTRssItem();
     dtRssItem.title = rssItem.Title;
     //dtRssItem.description = Regex.Replace(rssItem.Description, @"</?(a|img|div|p|strong) ?[^>]*?>", string.Empty);
     // Le puse para que quite todas las tags, sino quedaba el br y me movia todo de lugar
     dtRssItem.description = Regex.Replace(rssItem.Description, "<(.|\\n)*?>", string.Empty);
     dtRssItem.itemUrl = (rssItem.Link == null) ? "" : rssItem.Link;
     dtRssItem.sourceUrl = "";
     dtRssItem.sourceTitle = "";
     // Le agregue jpg para que no capture unos gifs transparentes que no mostraban nada
     dtRssItem.image = Regex.Match(rssItem.Description, @"<img[^>]*jpg.*?/>").Value;
     dtRssItem.image = (dtRssItem.image == null) ? null : Regex.Match(dtRssItem.image, @"src\=\"".*?\""").Value;
     dtRssItem.image = (dtRssItem.image == null) || (dtRssItem.image.Length < 5) ? null : dtRssItem.image.Substring(5);
     dtRssItem.image = (dtRssItem.image == null) || (dtRssItem.image.Length < 5) ? null : dtRssItem.image.Substring (0, dtRssItem.image.Length - 1);
     dtRssItem.date = rssItem.PubDateParsed;
     return dtRssItem;
 }
Beispiel #3
0
        /// <summary>
        /// Generates the list channel items.
        /// </summary>
        /// <param name="rssChannel">The RSS channel.</param>
        /// <returns></returns>
        private string GenerateListChannelItems(RssChannel rssChannel)
        {
            DateTime lastBuildDate = DateTime.MinValue;

            MetaClass listMetaClass = DataContext.Current.GetMetaClass(this.Parameters.ClassName);

            foreach(EntityObject item in BusinessManager.List(this.Parameters.ClassName,
                this.CurrentProfile.Filters.ToArray(),
                this.CurrentProfile.Sorting.ToArray()))
            {
                RssItem rssItem = new RssItem();
                rssItem.Guid = new RssGuid();

                rssItem.Title = string.IsNullOrEmpty(listMetaClass.TitleFieldName) ?
                    ("#" + item.PrimaryKeyId.Value.ToString()) :
                    (string)item[listMetaClass.TitleFieldName];

                rssItem.Link = MakeFullLink(this.Page.ResolveUrl(string.Format(CultureInfo.CurrentUICulture, "~/Apps/MetaUIEntity/Pages/EntityList.aspx?ClassName={0}", listMetaClass.Name)));
                rssItem.Guid.IsPermaLink = "false";
                rssItem.Guid.Text = item.PrimaryKeyId.Value.ToString();

                rssItem.Description = RenderListEntityObjectDescription(listMetaClass, item);

                DateTime modified = (DateTime)item["Modified"];

                if (modified > lastBuildDate)
                    lastBuildDate = modified;

                rssItem.PubDate = RssXmlHelper.ToRfc822(modified);
                UserLight author = UserLight.Load((int)item["ModifierId"]);
                if(author!=null)
                    rssItem.Author = string.Format("{0} <{1}>", author.DisplayName, author.Email);

                rssChannel.Items.Add(rssItem);
            }

            if (lastBuildDate == DateTime.MinValue)
                lastBuildDate = DateTime.Now;

            return RssXmlHelper.ToRfc822(lastBuildDate);
        }
        public static VideoInfo VideoInfoFromRssItem(RssItem rssItem, bool useLink, System.Predicate<string> isPossibleVideo)
        {
            VideoInfo video = new VideoInfo() { PlaybackOptions = new Dictionary<string, string>() };

            // Title - prefer from MediaTitle tag if available
            if (!String.IsNullOrEmpty(rssItem.MediaTitle)) video.Title = rssItem.MediaTitle;
            else video.Title = rssItem.Title;

            // Description - prefer MediaDescription tag if available
            if (!String.IsNullOrEmpty(rssItem.MediaDescription)) video.Description = rssItem.MediaDescription;
            else video.Description = rssItem.Description;

            // Try to find a thumbnail
            if (!string.IsNullOrEmpty(rssItem.GT_Image))
            {
                video.Thumb = rssItem.GT_Image;
            }
            else if (rssItem.MediaThumbnails.Count > 0)
            {
                video.Thumb = rssItem.MediaThumbnails[0].Url;
            }
            else if (rssItem.MediaContents.Count > 0 && rssItem.MediaContents[0].MediaThumbnails.Count > 0)
            {
                video.Thumb = rssItem.MediaContents[0].MediaThumbnails[0].Url;
            }
            else if (rssItem.MediaGroups.Count > 0 && rssItem.MediaGroups[0].MediaThumbnails.Count > 0)
            {
                video.Thumb = rssItem.MediaGroups[0].MediaThumbnails[0].Url;
            }
            else if (rssItem.Enclosure != null && rssItem.Enclosure.Type != null && rssItem.Enclosure.Type.ToLower().StartsWith("image"))
            {
                video.Thumb = rssItem.Enclosure.Url;
            }

            if (!string.IsNullOrEmpty(rssItem.Blip_Runtime)) video.Length = Helpers.TimeUtils.TimeFromSeconds(rssItem.Blip_Runtime);
            if (string.IsNullOrEmpty(video.Length)) video.Length = Helpers.TimeUtils.TimeFromSeconds(rssItem.iT_Duration);

            // if we are forced to use the Link of the RssItem, just set the video link
            if (useLink) video.VideoUrl = rssItem.Link;

            //get the video and the length
            if (rssItem.Enclosure != null && rssItem.Enclosure.Url != null && (rssItem.Enclosure.Type == null || !rssItem.Enclosure.Type.ToLower().StartsWith("image")) && (isPossibleVideo(rssItem.Enclosure.Url.Trim()) || useLink))
            {
                video.VideoUrl = useLink ? rssItem.Link : rssItem.Enclosure.Url.Trim();

                if (string.IsNullOrEmpty(video.Length) && !string.IsNullOrEmpty(rssItem.Enclosure.Length))
                {
                    int bytesOrSeconds = 0;
                    if (int.TryParse(rssItem.Enclosure.Length, out bytesOrSeconds))
                    {
                        if (bytesOrSeconds > 18000) // won't be longer than 5 hours if Length is guessed as seconds, so it's bytes
                            video.Length = (bytesOrSeconds / 1024).ToString("N0") + " KB";
                        else
                            video.Length = TimeSpan.FromSeconds(bytesOrSeconds).ToString();
                    }
                    else
                    {
                        video.Length = rssItem.Enclosure.Length;
                    }
                }
            }
            if (rssItem.MediaContents.Count > 0) // try to get the first MediaContent
            {
                foreach (RssItem.MediaContent content in rssItem.MediaContents)
                {
                    if (!useLink && content.Url != null && isPossibleVideo(content.Url.Trim())) AddToPlaybackOption(video.PlaybackOptions, content);
                    if (string.IsNullOrEmpty(video.Length)) video.Length = Helpers.TimeUtils.TimeFromSeconds(content.Duration);
                }
            }
            if (rssItem.MediaGroups.Count > 0) // videos might be wrapped in groups, try to get the first MediaContent
            {
                foreach (RssItem.MediaGroup grp in rssItem.MediaGroups)
                {
                    foreach (RssItem.MediaContent content in grp.MediaContents)
                    {
                        if (!useLink && content.Url != null && isPossibleVideo(content.Url.Trim())) AddToPlaybackOption(video.PlaybackOptions, content);
                        if (string.IsNullOrEmpty(video.Length)) video.Length = Helpers.TimeUtils.TimeFromSeconds(content.Duration);
                    }
                }
            }

            // PubDate in localized form if possible
            if (!string.IsNullOrEmpty(rssItem.PubDate))
            {
                try
                {
                    video.Airdate = rssItem.PubDateParsed.ToString("g", OnlineVideoSettings.Instance.Locale);
                }
                catch
                {
                    video.Airdate = rssItem.PubDate;
                }
            }

            // if no VideoUrl but PlaybackOptions are set -> put the first option as VideoUrl
            if (string.IsNullOrEmpty(video.VideoUrl) && video.PlaybackOptions.Count > 0)
            {
                var enumer = video.PlaybackOptions.GetEnumerator();
                enumer.MoveNext();
                video.VideoUrl = enumer.Current.Value;
                if (video.PlaybackOptions.Count == 1) video.PlaybackOptions = null; // no need for options with only one url
            }

            if (string.IsNullOrEmpty(video.VideoUrl) && isPossibleVideo(rssItem.Link) && !useLink) video.VideoUrl = rssItem.Link;

            return video;
        }
        static void AddToPlaybackOption(Dictionary<string, string> playbackOptions, RssItem.MediaContent content)
        {
            int sizeInBytes = 0;
            if (!string.IsNullOrEmpty(content.FileSize))
            {
                if (!int.TryParse(content.FileSize, out sizeInBytes))
                {
                    // with . inside the string -> already in KB
                    if (int.TryParse(content.FileSize, System.Globalization.NumberStyles.AllowThousands, null, out sizeInBytes)) sizeInBytes *= 1000;
                }
            }

            if (!playbackOptions.ContainsValue(content.Url.Trim()))
            {
                string baseInfo = string.Format("{0}({1}) | {2}:// | {3}",
                        content.Width > 0 || content.Height > 0 ?
                            string.Format("{0}x{1} ", content.Width, content.Height) :
                            "",
                        content.Bitrate != 0 ?
                            content.Bitrate.ToString() + " kbps" :
                            (sizeInBytes != 0 ? (sizeInBytes / 1024).ToString("N0") + " KB" : ""),
                        new Uri(content.Url).Scheme,
                        System.IO.Path.GetExtension(content.Url));
                string info = baseInfo;
                int i = 1;
                while (playbackOptions.ContainsKey(info))
                {
                    info = string.Format("{0} ({1})", baseInfo, i.ToString().PadLeft(2, ' '));
                }
                playbackOptions.Add(info, content.Url.Trim());
            }
        }