Example #1
0
        public override void LoadDataFromXmlNode(XmlNode node)
        {
            base.LoadDataFromXmlNode(node);

            try { this.rssFeedUrl = node.SelectSingleNode("Url").InnerText; }
            catch { }
            try { this.rssChannelPriority = (RssChannelPriority)FormUtil.GetNumber(node.SelectSingleNode("Pri").InnerText, 0, (int)RssChannelPriority.Max); }
            catch { }
            try { this.renderChannelImage = FormUtil.GetBoolean(node.SelectSingleNode("RCI").InnerText); }
            catch { }
            try { this.renderChannelTitle = FormUtil.GetBoolean(node.SelectSingleNode("RCT").InnerText); }
            catch { }
            try { this.renderItemTitles = FormUtil.GetBoolean(node.SelectSingleNode("RIT").InnerText); }
            catch { }
            try { this.renderItemDescriptions = FormUtil.GetBoolean(node.SelectSingleNode("RID").InnerText); }
            catch { }
            try { this.renderAd = FormUtil.GetBoolean(node.SelectSingleNode("RAD").InnerText); }
            catch { }

            // Data cached from the feed fetch
            try { this.channelTitle = node.SelectSingleNode("Title").InnerText; }
            catch { }
            try { this.channelImageUrl = node.SelectSingleNode("ImageUrl").InnerText; }
            catch { }
        }
Example #2
0
        private void AddRssFeed(List <FeedItem> items, string rssFeedUrl, RssChannelPriority priority, DateTime dateContext)
        {
            try
            {
                // Load the xml document
                XmlDocumentEx xmlDocument = new XmlDocumentEx();
                xmlDocument.Load(rssFeedUrl);
                xmlDocument.LoadNamespaces();

                // Determine if an atom or rss feed
                bool    atom    = false;
                XmlNode xmlNode = xmlDocument.SelectSingleNode("rss");
                if (xmlNode == null)
                {
                    xmlNode = xmlDocument.SelectSingleNode("dfltns:feed", xmlDocument.NamespaceManager);
                    if (xmlNode == null)
                    {
                        return;
                    }

                    atom = true;
                }

                if (atom)
                {
                    this.title = xmlDocument.SelectSingleNode("dfltns:feed/dfltns:title", xmlDocument.NamespaceManager).InnerText;

                    try
                    {
                        this.logoUrl = xmlDocument.SelectSingleNode("dfltns:feed/dfltnslogo", xmlDocument.NamespaceManager).InnerText;
                    }
                    catch { }

                    AddRssItems(xmlDocument, items, dateContext, atom, priority);
                }
                else
                {
                    this.title = xmlDocument.SelectSingleNode("rss/channel/title").InnerText;

                    try
                    {
                        this.logoUrl = xmlDocument.SelectSingleNode("rss/channel/image/url").InnerText;
                    }
                    catch { }

                    AddRssItems(xmlDocument, items, dateContext, atom, priority);
                }
            }
            catch (Exception)
            {
            }
        }
Example #3
0
        public override void LoadDataFromQueryString(HttpRequest request)
        {
            base.LoadDataFromQueryString(request);

            try { this.rssFeedUrl = request.QueryString["Url"]; }
            catch { }
            try { this.rssChannelPriority = (RssChannelPriority)FormUtil.GetNumber(request.QueryString["Pri"], 0, (int)RssChannelPriority.Max); }
            catch { }
            try { this.renderChannelImage = FormUtil.GetBoolean(request.QueryString["RCI"]); }
            catch { }
            try { this.renderChannelTitle = FormUtil.GetBoolean(request.QueryString["RCT"]); }
            catch { }
            try { this.renderItemTitles = FormUtil.GetBoolean(request.QueryString["RIT"]); }
            catch { }
            try { this.renderItemDescriptions = FormUtil.GetBoolean(request.QueryString["RID"]); }
            catch { }
            try { this.renderAd = FormUtil.GetBoolean(request.QueryString["RAD"]); }
            catch { }
        }
Example #4
0
 public static Feed LoadRssFeed(string rssUrl, RssChannelPriority priority)
 {
     return(Load(FeedType.Rss, rssUrl + "|" + ((int)priority).ToString()));
 }
Example #5
0
        private static void AddRssItems(XmlDocumentEx xmlDocument, List <FeedItem> items, DateTime dateContext, bool atom, RssChannelPriority priority)
        {
            XmlNodeList xmlNodes;

            if (atom)
            {
                xmlNodes = xmlDocument.SelectNodes("dfltns:feed/dfltns:entry", xmlDocument.NamespaceManager);
            }
            else
            {
                xmlNodes = xmlDocument.SelectNodes("rss/channel/item");
            }

            foreach (XmlNode node in xmlNodes)
            {
                ProcessItem(node, items, dateContext, atom, priority);
            }
        }
Example #6
0
        private static void ProcessItem(XmlNode node, List <FeedItem> items, DateTime dateContext, bool atom, RssChannelPriority priority)
        {
            XmlDocumentEx xmlDocument = (XmlDocumentEx)node.OwnerDocument;

            // Get the item title
            string itemTitle = null;

            if (atom)
            {
                itemTitle = node.SelectSingleNode("dfltns:title", xmlDocument.NamespaceManager).InnerText;
            }
            else
            {
                itemTitle = node.SelectSingleNode("title").InnerText;
            }

            // Get the item description
            string itemDescription = null;

            if (atom)
            {
                try
                {
                    itemDescription = node.SelectSingleNode("dfltns:content[@type=\"html\"]", xmlDocument.NamespaceManager).InnerText;
                }
                catch { }

                if (itemDescription == null)
                {
                    try
                    {
                        itemDescription = node.SelectSingleNode("dfltns:subtitle", xmlDocument.NamespaceManager).InnerText;
                    }
                    catch { }
                }
            }
            else
            {
                if (xmlDocument.NamespaceManager.HasNamespace("content"))
                {
                    try
                    {
                        itemDescription = node.SelectSingleNode(".//content:encoded", xmlDocument.NamespaceManager).InnerText;
                    }
                    catch { }
                }

                if (itemDescription == null)
                {
                    try
                    {
                        itemDescription = node.SelectSingleNode(".//description").InnerText;
                    }
                    catch { }
                }
            }

            // Get the item published date (if there is one)
            DateTime pubDate = dateContext;

            try
            {
                string pubDateString;
                if (atom)
                {
                    pubDateString = node.SelectSingleNode("dfltns:published", xmlDocument.NamespaceManager).InnerText;
                }
                else
                {
                    pubDateString = node.SelectSingleNode("pubDate").InnerText;
                }
                if (!String.IsNullOrEmpty(pubDateString))
                {
                    pubDate = Convert.ToDateTime(pubDateString);
                }
            }
            catch { }

            // Get the image width, height of the item
            XmlNodeList contentNodes = null;
            XmlNode     content = null;
            string      imageUrl = null;
            int         width = -1, height = -1;

            if (atom)
            {
                content = node.SelectSingleNode(".//dfltns:link[@rel=\"enclosure\"][@type=\"image/jpeg\"]", xmlDocument.NamespaceManager);

                if (content != null)
                {
                    imageUrl = content.Attributes["href"].Value;
                }
            }
            else
            {
                // See if there is a media tag
                if (xmlDocument.NamespaceManager.HasNamespace("media"))
                {
                    contentNodes = node.SelectNodes(".//media:content[@type=\"image/jpeg\"]", xmlDocument.NamespaceManager);
                }



                // Try the enclosure variant
                if (contentNodes == null)
                {
                    contentNodes = node.SelectNodes(".//enclosure[@type=\"image/jpeg\"]", xmlDocument.NamespaceManager);
                }

                if (contentNodes != null)
                {
                    int maxFileSize = -1;

                    foreach (XmlNode contentNode in contentNodes)
                    {
                        int fileSize = 0;
                        try
                        {
                            fileSize = Convert.ToInt32(contentNode.Attributes["fileSize"].Value);
                        }
                        catch { }
                        if (fileSize > maxFileSize)
                        {
                            content = contentNode;
                        }
                    }

                    imageUrl = content.Attributes["url"].Value;
                    if (!String.IsNullOrEmpty(imageUrl))
                    {
                        try
                        {
                            string widthString = content.Attributes["width"].Value;
                            if (!String.IsNullOrEmpty(widthString))
                            {
                                width = Convert.ToInt32(widthString);
                            }
                        }
                        catch { }

                        try
                        {
                            string heightString = content.Attributes["height"].Value;
                            if (!String.IsNullOrEmpty(heightString))
                            {
                                height = Convert.ToInt32(heightString);
                            }
                        }
                        catch { }
                    }
                }
            }

            // Only save the data we need based on the priority
            if (priority == RssChannelPriority.Image && imageUrl != null)
            {
                itemTitle       = null;
                itemDescription = null;
            }
            else if (priority == RssChannelPriority.Text && itemDescription != null)
            {
                imageUrl = null;
                width    = -1;
                height   = -1;
            }

            FeedItem feedItem = new FeedItem();

            feedItem.title       = itemTitle;
            feedItem.description = itemDescription;
            feedItem.pubDate     = pubDate;
            feedItem.imageUrl    = imageUrl;
            feedItem.imageWidth  = width;
            feedItem.imageHeight = height;
            items.Add(feedItem);
        }
Example #7
0
        public List <FeedItem> GetFeedItems(DateTime dateContext, bool bypassCaches)
        {
            if (this.items == null ||
                bypassCaches ||
                this.itemsInvalidDate > dateContext)
            {
                List <FeedItem> items = new List <FeedItem>();

                if (this.feedType == FeedType.Rss)
                {
                    string[] fields = this.data.Split('|');

                    string             rssFeedUrl = fields[0];
                    RssChannelPriority priority   = (RssChannelPriority)Convert.ToInt32(fields[1]);

                    AddRssFeed(items, rssFeedUrl, priority, dateContext);
                }
                else if (this.feedType == FeedType.Facebook)
                {
                    string sessionKey = this.data;

                    AddFacebookFeed(items, sessionKey, dateContext);
                }
                else if (this.feedType == FeedType.WebPage)
                {
                    string url = this.data;

                    AddWebPageItems(items, url, dateContext);
                }
                else if (this.feedType == FeedType.SmugMug)
                {
                    string[] fields = this.data.Split('|');

                    string          userName        = fields[0];
                    SmugMugFeedType smugMugFeedType = (SmugMugFeedType)Convert.ToInt32(fields[1]);
                    string          rssFeedUrl;

                    if (smugMugFeedType == SmugMugFeedType.Popular)
                    {
                        rssFeedUrl = "http://api.smugmug.com/hack/feed.mg?Type=nicknamePopular&Data=" + userName + "&format=rss";
                    }
                    else // default is most recent
                    {
                        rssFeedUrl = "http://api.smugmug.com/hack/feed.mg?Type=nicknameRecent&Data=" + userName + "&format=rss";
                    }

                    AddRssFeed(items, rssFeedUrl, RssChannelPriority.Image, dateContext);
                }
                else if (this.feedType == FeedType.Flickr)
                {
                    string userName = this.data;

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load("http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&username="******"&api_key=9c870e813907c4a318a0941e70d2fa7a");

                    string rssFeedUrl = "http://api.flickr.com/services/feeds/photos_public.gne?id=" + xmlDoc.SelectSingleNode("rsp/user/@nsid").Value + "&lang=en-us&format=rss_200";

                    AddRssFeed(items, rssFeedUrl, RssChannelPriority.Image, dateContext);
                }
                else if (this.feedType == FeedType.Space)
                {
                    string[] fields = this.data.Split('|');

                    string spaceName = fields[0];
                    string albumId   = fields[1];

                    if (!String.IsNullOrEmpty(albumId))
                    {
                        AddAlbumId(items, spaceName, albumId, dateContext);
                    }
                    else
                    {
                        Dictionary <string, string> albums = SpaceChannel.GetAlbums(spaceName);

                        foreach (string key in albums.Keys)
                        {
                            string albumId2 = albums[key];

                            AddAlbumId(items, spaceName, albumId2, dateContext);
                        }
                    }
                }

                this.isDirty = true;

                this.itemsDate        = dateContext;
                this.itemsInvalidDate = dateContext.AddMinutes(defaultFetchItemsTTL);

                this.items = items;
            }

            return(this.items);
        }