Beispiel #1
0
        private void RenderRss()
        {
            if (pageSettings == null) { return; }

            RssForum rssForum = new RssForum();
            rssForum.SiteId = siteSettings.SiteId;
            rssForum.ModuleId = moduleId;
            rssForum.PageId = pageId;
            rssForum.ItemId = itemId;
            rssForum.ThreadId = threadId;
            rssForum.MaximumDays = maxDaysOld;

            Argotic.Syndication.RssFeed feed = new Argotic.Syndication.RssFeed();
            RssChannel channel = new RssChannel();
            channel.Generator = "mojoPortal Forum module";

            string channelLink = WebUtils.ResolveServerUrl(SiteUtils.GetPageUrl(pageSettings));
            channel.Link = new System.Uri(channelLink);

            // if (config.ChannelDescription.Length > 0) { channel.Description = config.ChannelDescription; }

            feed.Channel = channel;

            string target = navigationSiteRoot + "/Forums/Thread.aspx?pageid=";

            using (IDataReader posts = rssForum.GetPostsForRss())
            {
                while ((posts.Read()) && (entryCount <= entriesLimit))
                {

                    string pageViewRoles = posts["AuthorizedRoles"].ToString();
                    string moduleViewRoles = posts["ViewRoles"].ToString();
                    bool include = (bypassPageSecurity ||
                        (pageViewRoles.Contains("All Users"))
                        && ((moduleViewRoles.Length == 0) || (moduleViewRoles.Contains("All Users")))
                        )
                        ;

                    if (!include) { continue; }

                    RssItem item = new RssItem();

                    item.Title = posts["Subject"].ToString();
                    item.Description = SiteUtils.ChangeRelativeUrlsToFullyQualifiedUrls(navigationSiteRoot, imageSiteRoot, posts["Post"].ToString());
                    item.PublicationDate = Convert.ToDateTime(posts["PostDate"]);

                    int p = Convert.ToInt32(posts["PageID"]);
                    int t = Convert.ToInt32(posts["ThreadID"]);

                    //if (target.IndexOf("&thread=") < 0 && target.IndexOf("?thread=") < 0)
                    //{
                    //    if (target.IndexOf("?") < 0)
                    //    {
                    //        target += "?thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString();
                    //    }
                    //    else
                    //    {
                    //        target += "&thread=" + posts["ThreadID"].ToString() + "#post" + posts["PostID"].ToString();
                    //    }
                    //}

                    //https://www.mojoportal.com/Forums/Thread.aspx?pageid=5&t=11417~1#post47516
                    if ((isGoogleFeedReader) && (ForumConfiguration.UseOldParamsForGoogleReader))
                    {

                        //item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString() + "#post" + posts["PostID"].ToString());
                        item.Link = new System.Uri(target + p.ToInvariantString() + "&thread=" + t.ToInvariantString());
                    }
                    else
                    {
                        item.Link = new System.Uri(target + p.ToInvariantString() + "&t=" + t.ToInvariantString() + "~-1#post" + posts["PostID"].ToString());
                    }

                    RssGuid g = new RssGuid(target, true);
                    item.Guid = g;

                    item.Author = posts["StartedBy"].ToString();

                    channel.AddItem(item);
                    entryCount += 1;

                }
            }

            Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
            Response.Cache.SetCacheability(HttpCacheability.Public);
            Response.ContentType = "application/xml";

            Encoding encoding = new UTF8Encoding();
            Response.ContentEncoding = encoding;

            using (XmlTextWriter xmlTextWriter = new XmlTextWriter(Response.OutputStream, encoding))
            {
                xmlTextWriter.Formatting = Formatting.Indented;

                //////////////////
                // style for RSS Feed viewed in browsers
                if (ConfigurationManager.AppSettings["RSSCSS"] != null)
                {
                    string rssCss = ConfigurationManager.AppSettings["RSSCSS"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/css\" href=\"" + cssBaseUrl + rssCss + "\" ?>");

                }

                if (ConfigurationManager.AppSettings["RSSXsl"] != null)
                {
                    string rssXsl = ConfigurationManager.AppSettings["RSSXsl"].ToString();
                    xmlTextWriter.WriteWhitespace(" ");
                    xmlTextWriter.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + cssBaseUrl + rssXsl + "\" ?>");

                }
                ///////////////////////////

                feed.Save(xmlTextWriter);

            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads this <see cref="RssItem"/> using the supplied <see cref="XPathNavigator"/> and <see cref="SyndicationResourceLoadSettings"/>.
        /// </summary>
        /// <param name="source">The <see cref="XPathNavigator"/> to extract information from.</param>
        /// <param name="settings">The <see cref="SyndicationResourceLoadSettings"/> used to configure the load operation.</param>
        /// <returns><b>true</b> if the <see cref="RssItem"/> was initialized using the supplied <paramref name="source"/>, otherwise <b>false</b>.</returns>
        /// <remarks>
        ///     This method expects the supplied <paramref name="source"/> to be positioned on the XML element that represents a <see cref="RssItem"/>.
        /// </remarks>
        /// <exception cref="ArgumentNullException">The <paramref name="source"/> is a null reference (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentNullException">The <paramref name="settings"/> is a null reference (Nothing in Visual Basic).</exception>
        public bool Load(XPathNavigator source, SyndicationResourceLoadSettings settings)
        {
            //------------------------------------------------------------
            //	Local members
            //------------------------------------------------------------
            bool wasLoaded              = false;

            //------------------------------------------------------------
            //	Validate parameter
            //------------------------------------------------------------
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(settings, "settings");

            //------------------------------------------------------------
            //	Create namespace resolver
            //------------------------------------------------------------
            XmlNamespaceManager manager = new XmlNamespaceManager(source.NameTable);

            //------------------------------------------------------------
            //	Attempt to extract syndication information
            //------------------------------------------------------------
            XPathNavigator authorNavigator      = source.SelectSingleNode("author", manager);
            XPathNavigator commentsNavigator    = source.SelectSingleNode("comments", manager);
            XPathNavigator descriptionNavigator = source.SelectSingleNode("description", manager);
            XPathNavigator guidNavigator        = source.SelectSingleNode("guid", manager);
            XPathNavigator linkNavigator        = source.SelectSingleNode("link", manager);
            XPathNavigator publicationNavigator = source.SelectSingleNode("pubDate", manager);
            XPathNavigator sourceNavigator      = source.SelectSingleNode("source", manager);
            XPathNavigator titleNavigator       = source.SelectSingleNode("title", manager);

            XPathNodeIterator categoryIterator  = source.Select("category", manager);
            XPathNodeIterator enclosureIterator = source.Select("enclosure", manager);

            //------------------------------------------------------------
            //	Load required/common item elements
            //------------------------------------------------------------
            if (titleNavigator != null)
            {
                this.Title          = titleNavigator.Value;
                wasLoaded           = true;
            }

            if (descriptionNavigator != null)
            {
                this.Description    = descriptionNavigator.Value;
                wasLoaded           = true;
            }

            if (linkNavigator != null)
            {
                Uri link;
                if (Uri.TryCreate(linkNavigator.Value, UriKind.RelativeOrAbsolute, out link))
                {
                    this.Link       = link;
                    wasLoaded       = true;
                }
            }

            //------------------------------------------------------------
            //	Load optional item elements
            //------------------------------------------------------------
            if (authorNavigator != null)
            {
                this.Author         = authorNavigator.Value;
                wasLoaded           = true;
            }

            if (commentsNavigator != null)
            {
                Uri comments;
                if (Uri.TryCreate(commentsNavigator.Value, UriKind.RelativeOrAbsolute, out comments))
                {
                    this.Comments   = comments;
                    wasLoaded       = true;
                }
            }

            if (guidNavigator != null)
            {
                RssGuid guid = new RssGuid();
                if (guid.Load(guidNavigator, settings))
                {
                    this.Guid       = guid;
                    wasLoaded       = true;
                }
            }

            if (publicationNavigator != null)
            {
                DateTime publicationDate;
                if (SyndicationDateTimeUtility.TryParseRfc822DateTime(publicationNavigator.Value, out publicationDate))
                {
                    this.PublicationDate    = publicationDate;
                    wasLoaded               = true;
                }
            }

            if (sourceNavigator != null)
            {
                RssSource sourceFeed    = new RssSource();
                if (sourceFeed.Load(sourceNavigator, settings))
                {
                    this.Source     = sourceFeed;
                    wasLoaded       = true;
                }
            }

            //------------------------------------------------------------
            //	Load item collection elements
            //------------------------------------------------------------
            if (categoryIterator != null && categoryIterator.Count > 0)
            {
                while (categoryIterator.MoveNext())
                {
                    RssCategory category = new RssCategory();
                    if (category.Load(categoryIterator.Current, settings))
                    {
                        this.Categories.Add(category);
                    }
                }
            }

            if (enclosureIterator != null && enclosureIterator.Count > 0)
            {
                while (enclosureIterator.MoveNext())
                {
                    RssEnclosure enclosure  = new RssEnclosure();
                    if (enclosure.Load(enclosureIterator.Current, settings))
                    {
                        this.Enclosures.Add(enclosure);
                    }
                }
            }

            //------------------------------------------------------------
            //	Attempt to extract syndication extension information
            //------------------------------------------------------------
            SyndicationExtensionAdapter adapter = new SyndicationExtensionAdapter(source, settings);
            adapter.Fill(this);

            return wasLoaded;
        }