Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="YafSyndicationFeed" /> class.
        /// </summary>
        /// <param name="subTitle">The sub title.</param>
        /// <param name="feedType">The feed source.</param>
        /// <param name="sf">The feed type Atom/RSS.</param>
        /// <param name="urlAlphaNum">The alphanumerically encoded base site Url.</param>
        public YafSyndicationFeed([NotNull] string subTitle, YafRssFeeds feedType, int sf, [NotNull] string urlAlphaNum)
        {
            this.Copyright =
                new TextSyndicationContent(
                    "Copyright {0} {1}".FormatWith(DateTime.Now.Year, YafContext.Current.BoardSettings.Name));
            this.Description =
                new TextSyndicationContent(
                    "{0} - {1}".FormatWith(
                        YafContext.Current.BoardSettings.Name,
                        sf == YafSyndicationFormats.Atom.ToInt()
              ? YafContext.Current.Get <ILocalization>().GetText("ATOMFEED")
              : YafContext.Current.Get <ILocalization>().GetText("RSSFEED")));
            this.Title =
                new TextSyndicationContent(
                    "{0} - {1} - {2}".FormatWith(
                        sf == YafSyndicationFormats.Atom.ToInt()
              ? YafContext.Current.Get <ILocalization>().GetText("ATOMFEED")
              : YafContext.Current.Get <ILocalization>().GetText("RSSFEED"),
                        YafContext.Current.BoardSettings.Name,
                        subTitle));

            // Alternate link
            this.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(BaseUrlBuilder.BaseUrl)));

            // Self Link
            var slink =
                new Uri(
                    YafBuildLink.GetLinkNotEscaped(ForumPages.rsstopic, true, "pg={0}&ft={1}".FormatWith(feedType.ToInt(), sf)));

            this.Links.Add(SyndicationLink.CreateSelfLink(slink));

            this.Generator       = "YetAnotherForum.NET";
            this.LastUpdatedTime = DateTime.UtcNow;
            this.Language        = YafContext.Current.Get <ILocalization>().LanguageCode;
            this.ImageUrl        =
                new Uri("{0}/YAFLogo.png".FormatWith(Path.Combine(YafForumInfo.ForumBaseUrl, YafBoardFolders.Current.Images)));

            this.Id =
                "urn:{0}:{1}:{2}:{3}:{4}".FormatWith(
                    urlAlphaNum,
                    sf == YafSyndicationFormats.Atom.ToInt()
            ? YafContext.Current.Get <ILocalization>().GetText("ATOMFEED")
            : YafContext.Current.Get <ILocalization>().GetText("RSSFEED"),
                    YafContext.Current.BoardSettings.Name,
                    subTitle,
                    YafContext.Current.PageBoardID).Unidecode();

            this.Id = this.Id.Replace(" ", string.Empty);

            // this.Id = "urn:uuid:{0}".FormatWith(Guid.NewGuid().ToString("D"));
            this.BaseUri = slink;
            this.Authors.Add(
                new SyndicationPerson(YafContext.Current.BoardSettings.ForumEmail, "Forum Admin", BaseUrlBuilder.BaseUrl));
            this.Categories.Add(new SyndicationCategory(FeedCategories));

            // writer.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + YafForumInfo.ForumClientFileRoot + "rss.xsl\" media=\"screen\"?>");
        }
Beispiel #2
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topic announcements.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        private void GetLatestAnnouncementsFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (var dt = LegacyDb.topic_announcements(this.PageContext.PageBoardID, 10, this.PageContext.PageUserID))
            {
                var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("POSTMESSAGE", "ANNOUNCEMENT"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    // don't render moved topics
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType <long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType <long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        row["Message"].ToString(),
                        null,
                        YafBuildLink.GetLinkNotEscaped(
                            ForumPages.posts, true, "t={0}", this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t")),
                        "urn:{0}:ft{1}:st{2}:tid{3}:lmid{4}:{5}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t"),
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #3
0
    /// <summary>
    /// Initializes a new instance of the <see cref="YafSyndicationFeed" /> class.
    /// </summary>
    /// <param name="subTitle">The sub title.</param>
    /// <param name="feedType">The feed source.</param>
    /// <param name="sf">The feed type Atom/RSS.</param>
    /// <param name="urlAlphaNum">The alphanumerically encoded base site Url.</param>
    public YafSyndicationFeed([NotNull] string subTitle, YafRssFeeds feedType, int sf, [NotNull] string urlAlphaNum)
    {
      this.Copyright =
        new TextSyndicationContent(
          "Copyright {0} {1}".FormatWith(DateTime.Now.Year, YafContext.Current.BoardSettings.Name));
      this.Description =
        new TextSyndicationContent(
          "{0} - {1}".FormatWith(
            YafContext.Current.BoardSettings.Name, 
            sf == YafSyndicationFormats.Atom.ToInt()
              ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED")
              : YafContext.Current.Get<ILocalization>().GetText("RSSFEED")));
      this.Title =
        new TextSyndicationContent(
          "{0} - {1} - {2}".FormatWith(
            sf == YafSyndicationFormats.Atom.ToInt()
              ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED")
              : YafContext.Current.Get<ILocalization>().GetText("RSSFEED"), 
            YafContext.Current.BoardSettings.Name, 
            subTitle));

      // Alternate link
      this.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(BaseUrlBuilder.BaseUrl)));

      // Self Link
      var slink =
        new Uri(
          YafBuildLink.GetLinkNotEscaped(ForumPages.rsstopic, true, "pg={0}&ft={1}".FormatWith(feedType.ToInt(), sf)));
      this.Links.Add(SyndicationLink.CreateSelfLink(slink));

      this.Generator = "YetAnotherForum.NET";
      this.LastUpdatedTime = DateTime.UtcNow;
      this.Language = YafContext.Current.Get<ILocalization>().LanguageCode;
      this.ImageUrl =
        new Uri("{0}/YAFLogo.png".FormatWith(Path.Combine(YafForumInfo.ForumBaseUrl, YafBoardFolders.Current.Images)));

      this.Id =
        "urn:{0}:{1}:{2}:{3}:{4}".FormatWith(
          urlAlphaNum, 
          sf == YafSyndicationFormats.Atom.ToInt()
            ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED")
            : YafContext.Current.Get<ILocalization>().GetText("RSSFEED"), 
          YafContext.Current.BoardSettings.Name, 
          subTitle, 
          YafContext.Current.PageBoardID).Unidecode();

      this.Id = this.Id.Replace(" ", string.Empty);

      // this.Id = "urn:uuid:{0}".FormatWith(Guid.NewGuid().ToString("D"));
      this.BaseUri = slink;
      this.Authors.Add(
        new SyndicationPerson(YafContext.Current.BoardSettings.ForumEmail, "Forum Admin", BaseUrlBuilder.BaseUrl));
      this.Categories.Add(new SyndicationCategory(FeedCategories));

      // writer.WriteRaw("<?xml-stylesheet type=\"text/xsl\" href=\"" + YafForumInfo.ForumClientFileRoot + "rss.xsl\" media=\"screen\"?>");
    }
Beispiel #4
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="forumId">The forum id.</param>
        private void GetTopicsFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, string lastPostIcon, string lastPostName, int forumId)
        {
            var syndicationItems = new List <SyndicationItem>();

            // vzrus changed to separate DLL specific code
            using (DataTable dt = DB.rsstopic_list(forumId))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(this.PageContext.Localization.GetText("DEFAULT", "FORUM") + ":" + this.PageContext.PageForumName, feedType, atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) +
                                          this.Get <YafDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                        Convert.ToInt64(
                                                                                            row["LastUserID"])));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <YafDateTime>().TimeOffset;

                        // Alternate Link
                        //  feed.Links.Add(new SyndicationLink(new Uri(YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true))));
                    }

                    feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                         Convert.ToInt64(
                                                                                             row["LastUserID"])));


                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        GetPostLatestContent(
                            YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}",
                                                           row["LastMessageID"]), lastPostIcon, lastPostName,
                            lastPostName, String.Empty,
                            !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                ? Convert.ToInt32(row["LastMessageFlags"])
                                : 22, false),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", row["TopicID"]),
                        "urn:{0}:ft{1}:st{2}:tid{3}:lmid{4}:{5}".FormatWith(urlAlphaNum,
                                                                            feedType,
                                                                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                                                            row["TopicID"], row["LastMessageID"], PageContext.PageBoardID),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #5
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        private void GetPostLatestFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, string lastPostIcon, string lastPostName)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (DataTable dataTopics = DB.rss_topic_latest(this.PageContext.PageBoardID, this.PageContext.BoardSettings.ActiveDiscussionsCount <= 50 ? this.PageContext.BoardSettings.ActiveDiscussionsCount : 50, PageContext.PageUserID, PageContext.BoardSettings.UseStyledNicks, PageContext.BoardSettings.NoCountForumsInActiveDiscussions))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(this.PageContext.Localization.GetText("ACTIVE_DISCUSSIONS"), feedType, atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);
                bool altItem = false;
                foreach (DataRow row in dataTopics.Rows)
                {
                    // don't render moved topics
                    if (row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <YafDateTime>().TimeOffset;
                        if (syndicationItems.Count <= 0)
                        {
                            feed.LastUpdatedTime = lastPosted + this.Get <YafDateTime>().TimeOffset;
                            feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                            Convert.ToInt64(row["UserID"])));
                        }

                        feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                             Convert.ToInt64(
                                                                                                 row["LastUserID"])));

                        string messageLink = YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}",
                                                                            row["LastMessageID"]);

                        syndicationItems.AddSyndicationItem(
                            row["Topic"].ToString(),
                            GetPostLatestContent(messageLink, lastPostIcon, lastPostName, lastPostName, row["LastMessage"].ToString(),
                                                 !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                                     ? Convert.ToInt32(row["LastMessageFlags"])
                                                     : 22, altItem),
                            null,
                            YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", Convert.ToInt32(row["TopicID"])),
                            "urn:{0}:ft{1}:st{2}:tid{3}:mid{4}:{5}".FormatWith(urlAlphaNum,
                                                                               feedType,
                                                                               atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                                                               row["TopicID"],
                                                                               row["LastMessageID"], PageContext.PageBoardID),
                            lastPosted,
                            feed);
                    }

                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="YafSyndicationFeed" /> class.
        /// </summary>
        /// <param name="subTitle">The sub title.</param>
        /// <param name="feedType">The feed source.</param>
        /// <param name="sf">The feed type Atom/RSS.</param>
        /// <param name="urlAlphaNum">The alphanumerically encoded base site Url.</param>
        public YafSyndicationFeed([NotNull] string subTitle, YafRssFeeds feedType, int sf, [NotNull] string urlAlphaNum)
        {
            this.Copyright =
                new TextSyndicationContent($"Copyright {DateTime.Now.Year} {YafContext.Current.BoardSettings.Name}");
            this.Description = new TextSyndicationContent(
                $"{YafContext.Current.BoardSettings.Name} - {(sf == YafSyndicationFormats.Atom.ToInt() ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED") : YafContext.Current.Get<ILocalization>().GetText("RSSFEED"))}");
            this.Title = new TextSyndicationContent(
                $"{(sf == YafSyndicationFormats.Atom.ToInt() ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED") : YafContext.Current.Get<ILocalization>().GetText("RSSFEED"))} - {YafContext.Current.BoardSettings.Name} - {subTitle}");

            // Alternate link
            this.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(BaseUrlBuilder.BaseUrl)));

            // Self Link
            var slink = new Uri(
                BuildLink.GetLinkNotEscaped(ForumPages.rsstopic, true, $"pg={feedType.ToInt()}&ft={sf}"));

            this.Links.Add(SyndicationLink.CreateSelfLink(slink));

            this.Generator       = "YetAnotherForum.NET";
            this.LastUpdatedTime = DateTime.UtcNow;
            this.Language        = YafContext.Current.Get <ILocalization>().LanguageCode;
            this.ImageUrl        = new Uri(
                $"{BaseUrlBuilder.BaseUrl}{BoardInfo.ForumClientFileRoot}{BoardFolders.Current.Logos}/{YafContext.Current.BoardSettings.ForumLogo}");

            this.Id =
                $"urn:{urlAlphaNum}:{(sf == YafSyndicationFormats.Atom.ToInt() ? YafContext.Current.Get<ILocalization>().GetText("ATOMFEED") : YafContext.Current.Get<ILocalization>().GetText("RSSFEED"))}:{YafContext.Current.BoardSettings.Name}:{subTitle}:{YafContext.Current.PageBoardID}"
                .Unidecode();

            this.Id = this.Id.Replace(" ", string.Empty);

            // this.Id = "urn:uuid:{0}".FormatWith(Guid.NewGuid().ToString("D"));
            this.BaseUri = slink;
            this.Authors.Add(
                new SyndicationPerson(
                    YafContext.Current.BoardSettings.ForumEmail,
                    "Forum Admin",
                    BaseUrlBuilder.BaseUrl));
            this.Categories.Add(new SyndicationCategory(FeedCategories));
        }
Beispiel #7
0
        /// <summary>
        /// The method creates YafSyndicationFeed for posts.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="topicId">
        /// The TopicID
        /// </param>
        private void GetPostsFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, int topicId)
        {
            var syndicationItems = new List <SyndicationItem>();

            var showDeleted = false;
            var userId      = 0;

            if (this.Get <BoardSettings>().ShowDeletedMessagesToAll)
            {
                showDeleted = true;
            }

            if (!showDeleted
                &&
                (this.Get <BoardSettings>().ShowDeletedMessages &&
                 !this.Get <BoardSettings>().ShowDeletedMessagesToAll || this.PageContext.IsAdmin ||
                 this.PageContext.IsForumModerator))
            {
                userId = this.PageContext.PageUserID;
            }

            using (
                var dt = this.GetRepository <Message>().PostListAsDataTable(
                    topicId,
                    this.PageContext.PageUserID,
                    userId,
                    0,
                    showDeleted,
                    true,
                    false,
                    DateTimeHelper.SqlDbMinTime(),
                    DateTime.UtcNow,
                    DateTimeHelper.SqlDbMinTime(),
                    DateTime.UtcNow,
                    0,
                    this.Get <BoardSettings>().PostsPerPage,
                    2,
                    0,
                    0,
                    false,
                    -1))
            {
                // convert to linq...
                var rowList = dt.AsEnumerable();

                // last page posts
                var dataRows = rowList.Take(this.Get <BoardSettings>().PostsPerPage);

                var altItem = false;

                var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed =
                    new YafSyndicationFeed(
                        $"{this.GetText("PROFILE", "TOPIC")}{this.PageContext.PageTopicName} - {this.Get<BoardSettings>().PostsPerPage}",
                        feedType,
                        atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                        urlAlphaNum);

                foreach (var row in dataRows)
                {
                    var posted = Convert.ToDateTime(row["Edited"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType <long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;
                    }

                    List <SyndicationLink> attachementLinks = null;

                    // if the user doesn't have download access we simply don't show enclosure links.
                    if (this.PageContext.ForumDownloadAccess)
                    {
                        attachementLinks = this.GetMediaLinks(row["MessageID"].ToType <int>());
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["UserID"].ToType <long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        this.Get <IFormatMessage>().FormatSyndicationMessage(
                            row["Message"].ToString(), new MessageFlags(row["Flags"]), altItem, 4000),
                        null,
                        BuildLink.GetLinkNotEscaped(ForumPages.Posts, true, "m={0}&find=lastpost", row["MessageID"]),
                        $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:meid{row["MessageID"]}:{this.PageContext.PageBoardID}"
                        .Unidecode(),
                        posted,
                        feed,
                        attachementLinks);

                    // used to format feeds
                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #8
0
        /// <summary>
        /// The method creates YAF SyndicationFeed for forums in a category.
        /// </summary>
        /// <param name="feed">
        /// The YAF Syndication Feed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="categoryId">
        /// The category id.
        /// </param>
        private void GetForumFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, [NotNull] int?categoryId)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (var dt = this.GetRepository <Forum>().ListReadAsDataTable(this.PageContext.PageBoardID, this.PageContext.PageUserID, categoryId, null, false, false))
            {
                var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("DEFAULT", "FORUM"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if (row["TopicMovedID"].IsNullOrEmptyDBField() && row["LastPosted"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        if (row["LastUserID"].IsNullOrEmptyDBField() || row["LastUserID"].IsNullOrEmptyDBField())
                        {
                            break;
                        }

                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType <long>(), null, null));

                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;

                        // Alternate Link
                        // feed.Links.Add(new SyndicationLink(new Uri(BuildLink.GetLinkNotEscaped(ForumPages.topics, true))));
                    }

                    if (!row["LastUserID"].IsNullOrEmptyDBField())
                    {
                        feed.Contributors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType <long>(), null, null));
                    }

                    syndicationItems.AddSyndicationItem(
                        row["Forum"].ToString(),
                        this.HtmlEncode(row["Description"].ToString()),
                        null,
                        BuildLink.GetLinkNotEscaped(ForumPages.topics, true, "f={0}", row["ForumID"]),
                        $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:fid{row["ForumID"]}:lmid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                        .Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #9
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="lastPostIcon">
        /// The icon for last post link.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        private void GetPostLatestFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (
                var dataTopics = this.GetRepository <Topic>().RssLatestAsDataTable(
                    this.PageContext.PageBoardID,
                    this.Get <BoardSettings>().ActiveDiscussionsCount <= 50
                        ? this.Get <BoardSettings>().ActiveDiscussionsCount
                        : 50,
                    this.PageContext.PageUserID,
                    this.Get <BoardSettings>().UseStyledNicks,
                    this.Get <BoardSettings>().NoCountForumsInActiveDiscussions))
            {
                var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("ACTIVE_DISCUSSIONS"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);
                var altItem = false;
                foreach (DataRow row in dataTopics.Rows)
                {
                    // don't render moved topics
                    if (row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;
                        if (syndicationItems.Count <= 0)
                        {
                            feed.LastUpdatedTime = lastPosted + this.Get <IDateTime>().TimeOffset;
                            feed.Authors.Add(
                                SyndicationItemExtensions.NewSyndicationPerson(
                                    string.Empty,
                                    row["UserID"].ToType <long>(),
                                    row["UserName"].ToString(),
                                    row["UserDisplayName"].ToString()));
                        }

                        feed.Contributors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty,
                                row["LastUserID"].ToType <long>(),
                                row["LastUserName"].ToString(),
                                row["LastUserDisplayName"].ToString()));

                        var messageLink = BuildLink.GetLinkNotEscaped(
                            ForumPages.Posts, true, "m={0}#post{0}", row["LastMessageID"]);

                        syndicationItems.AddSyndicationItem(
                            row["Topic"].ToString(),
                            GetPostLatestContent(
                                messageLink,
                                lastPostIcon,
                                lastPostName,
                                lastPostName,
                                row["LastMessage"].ToString(),
                                !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                    ? row["LastMessageFlags"].ToType <int>()
                                    : 22,
                                altItem),
                            null,
                            BuildLink.GetLinkNotEscaped(
                                ForumPages.Posts, true, "t={0}", row["TopicID"].ToType <int>()),
                            $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:tid{row["TopicID"]}:mid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                            .Unidecode(),
                            lastPosted,
                            feed);
                    }

                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #10
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Active topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId">The category active id.</param>
        private void GetActiveFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            [NotNull] object categoryActiveId)
        {
            var syndicationItems = new List <SyndicationItem>();
            var toActDate        = DateTime.UtcNow;
            var toActText        = this.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Get <HttpRequestBase>().QueryString.Exists("txt"))
            {
                toActText =
                    this.Server.UrlDecode(
                        this.Server.HtmlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("txt")));
            }

            if (this.Get <HttpRequestBase>().QueryString.Exists("d"))
            {
                if (
                    !DateTime.TryParse(
                        this.Server.UrlDecode(
                            this.Server.HtmlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("d"))),
                        out toActDate))
                {
                    toActDate = Convert.ToDateTime(this.Get <IDateTime>().FormatDateTimeShort(DateTime.UtcNow))
                                + TimeSpan.FromDays(-31);
                    toActText = this.GetText("MYTOPICS", "LAST_MONTH");
                }
                else
                {
                    // To limit number of feeds items by timespan if we are getting an unreasonable time
                    if (toActDate < DateTime.UtcNow + TimeSpan.FromDays(-31))
                    {
                        toActDate = DateTime.UtcNow + TimeSpan.FromDays(-31);
                        toActText = this.GetText("MYTOPICS", "LAST_MONTH");
                    }
                }
            }

            var urlAlphaNum      = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);
            var feedNameAlphaNum = new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase).Replace(
                toActText, string.Empty);

            feed = new YafSyndicationFeed(
                $"{this.GetText("MYTOPICS", "ACTIVETOPICS")} - {toActText}",
                feedType,
                atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                urlAlphaNum);

            using (
                var dt =
                    this.TabledCleanUpByDate(
                        this.GetRepository <Topic>().ActiveAsDataTable(
                            this.PageContext.PageBoardID,
                            categoryActiveId.ToType <int>(),
                            this.PageContext.PageUserID,
                            toActDate,
                            DateTime.UtcNow,

                            // page index in db which is returned back  is +1 based!
                            0,

                            // set the page size here
                            20,
                            false,
                            this.Get <BoardSettings>().UseReadTrackingByDatabase),
                        "LastPosted",
                        toActDate))
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType <long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType <long>(), null, null));

                    var messageLink = BuildLink.GetLinkNotEscaped(
                        ForumPages.Posts, true, "m={0}#post{0}", row["LastMessageID"]);
                    syndicationItems.AddSyndicationItem(
                        row["Subject"].ToString(),
                        GetPostLatestContent(
                            messageLink,
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            string.Empty,
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType <int>() : 22,
                            false),
                        null,
                        messageLink,
                        $"urn:{urlAlphaNum}:ft{feedNameAlphaNum}:st{feedType}:span{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:ltid{row["LinkTopicID"]}:lmid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                        .Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #11
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Favorite topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId">The category active id.</param>
        private void GetFavoriteFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            [NotNull] object categoryActiveId)
        {
            var syndicationItems = new List <SyndicationItem>();

            DateTime toFavDate;

            var toFavText = this.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Get <HttpRequestBase>().QueryString.Exists("txt"))
            {
                toFavText =
                    this.Server.UrlDecode(
                        this.Server.HtmlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("txt")));
            }

            if (this.Get <HttpRequestBase>().QueryString.Exists("d"))
            {
                if (
                    !DateTime.TryParse(
                        this.Server.UrlDecode(
                            this.Server.HtmlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("d"))),
                        out toFavDate))
                {
                    toFavDate = PageContext.CurrentUserData.Joined ?? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2);
                    toFavText = this.GetText("MYTOPICS", "SHOW_ALL");
                }
            }
            else
            {
                toFavDate = PageContext.CurrentUserData.Joined ?? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2);
                toFavText = this.GetText("MYTOPICS", "SHOW_ALL");
            }

            using (
                var dt =
                    this.TabledCleanUpByDate(
                        this.GetRepository <FavoriteTopic>().Details(
                            categoryActiveId.ToType <int?>(),
                            this.PageContext.PageUserID,
                            toFavDate,
                            DateTime.UtcNow,

                            // page index in db is 1 based!
                            0,

                            // set the page size here
                            20,
                            false,
                            false),
                        "LastPosted",
                        toFavDate))
            {
                var urlAlphaNum      = FormatUrlForFeed(BoardInfo.ForumBaseUrl);
                var feedNameAlphaNum =
                    new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase)
                    .Replace(toFavText, string.Empty);
                feed = new YafSyndicationFeed(
                    $"{this.GetText("MYTOPICS", "FAVORITETOPICS")} - {toFavText}",
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType <long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType <long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Subject"].ToString(),
                        GetPostLatestContent(
                            BuildLink.GetLinkNotEscaped(
                                ForumPages.Posts, true, "m={0}#post{0}", row["LastMessageID"]),
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            string.Empty,
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType <int>() : 22,
                            false),
                        null,
                        BuildLink.GetLinkNotEscaped(ForumPages.Posts, true, "t={0}", row["LinkTopicID"]),
                        $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:span{feedNameAlphaNum}:ltid{row["LinkTopicID"].ToType<int>()}:lmid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                        .Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #12
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Favorite topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId"></param>
        private void GetFavoriteFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, string lastPostIcon, string lastPostName, object categoryActiveId)
        {
            var      syndicationItems = new List <SyndicationItem>();
            DateTime toFavDate        = DateTime.UtcNow;
            string   toFavText        = this.PageContext.Localization.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Request.QueryString.GetFirstOrDefault("txt") != null)
            {
                toFavText = Server.UrlDecode(Server.HtmlDecode(this.Request.QueryString.GetFirstOrDefault("txt").ToString()));
            }

            if (this.Request.QueryString.GetFirstOrDefault("d") != null)
            {
                if (!DateTime.TryParse(Server.UrlDecode(Server.HtmlDecode(this.Request.QueryString.GetFirstOrDefault("d").ToString())), out toFavDate))
                {
                    toFavDate = this.PageContext.CurrentUserData.Joined == null ? DateTime.MinValue + TimeSpan.FromDays(2) : (DateTime)this.PageContext.CurrentUserData.Joined;
                    toFavText = this.PageContext.Localization.GetText("MYTOPICS", "SHOW_ALL");
                }
            }
            else
            {
                toFavDate = this.PageContext.CurrentUserData.Joined == null ? DateTime.MinValue + TimeSpan.FromDays(2) : (DateTime)this.PageContext.CurrentUserData.Joined;
                toFavText = this.PageContext.Localization.GetText("MYTOPICS", "SHOW_ALL");
            }

            using (
                DataTable dt = DB.topic_favorite_details(
                    this.PageContext.PageBoardID,
                    this.PageContext.PageUserID,
                    toFavDate,
                    categoryActiveId,
                    false))
            {
                string urlAlphaNum      = FormatUrlForFeed(YafForumInfo.ForumBaseUrl);
                string feedNameAlphaNum = new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase).Replace(toFavText.ToString(), String.Empty);
                feed =
                    new YafSyndicationFeed(
                        "{0} - {1}".FormatWith(this.PageContext.Localization.GetText("MYTOPICS", "FAVORITETOPICS"),
                                               toFavText), feedType,
                        atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if (row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <YafDateTime>().TimeOffset;

                        if (syndicationItems.Count <= 0)
                        {
                            feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                            Convert.ToInt64(row["UserID"])));
                            feed.LastUpdatedTime = DateTime.UtcNow + this.Get <YafDateTime>().TimeOffset;
                        }

                        feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                             Convert.ToInt64(
                                                                                                 row["LastUserID"])));

                        syndicationItems.AddSyndicationItem(
                            row["Subject"].ToString(),
                            GetPostLatestContent(
                                YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}", row["LastMessageID"]),
                                lastPostIcon, lastPostName, lastPostName, String.Empty,
                                !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                    ? Convert.ToInt32(row["LastMessageFlags"])
                                    : 22, false),
                            null,
                            YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", row["LinkTopicID"]),
                            "urn:{0}:ft{1}:st{2}:span{3}:ltid{4}:lmid{5}:{6}".FormatWith(urlAlphaNum,
                                                                                         feedType,
                                                                                         atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                                                                         feedNameAlphaNum,
                                                                                         Convert.ToInt32(row["LinkTopicID"]),
                                                                                         row["LastMessageID"], PageContext.PageBoardID),
                            lastPosted,
                            feed);
                    }
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #13
0
        /// <summary>
        /// The method creates YafSyndicationFeed for forums in a category.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="categoryId">The category id.</param>
        private void GetForumFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, object categoryId)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (
                DataTable dt = DB.forum_listread(
                    this.PageContext.PageBoardID, this.PageContext.PageUserID, categoryId, null))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(this.PageContext.Localization.GetText("DEFAULT", "FORUM"), feedType, atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if ((row["TopicMovedID"].IsNullOrEmptyDBField() && row["LastPosted"].IsNullOrEmptyDBField()))
                    {
                        continue;
                    }
                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <YafDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        if (row["LastUserID"].IsNullOrEmptyDBField() || row["LastUserID"].IsNullOrEmptyDBField())
                        {
                            break;
                        }

                        feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(
                                             String.Empty,
                                             Convert.ToInt64(row["LastUserID"])));

                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <YafDateTime>().TimeOffset;

                        // Alternate Link
                        // feed.Links.Add(new SyndicationLink(new Uri(YafBuildLink.GetLinkNotEscaped(ForumPages.topics, true))));
                    }

                    if (!row["LastUserID"].IsNullOrEmptyDBField())
                    {
                        feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(
                                                  String.Empty,
                                                  Convert.ToInt64(row["LastUserID"])));
                    }

                    syndicationItems.AddSyndicationItem(
                        row["Forum"].ToString(),
                        HtmlEncode(row["Description"].ToString()),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.topics, true, "f={0}", row["ForumID"]),
                        "urn:{0}:ft{1}:st{2}:fid{3}:lmid{4}:{5}".FormatWith(urlAlphaNum,
                                                                            feedType,
                                                                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                                                            row["ForumID"],
                                                                            row["LastMessageID"], PageContext.PageBoardID),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #14
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="lastPostIcon">
        /// The icon for last post link.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        private void GetPostLatestFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName)
        {
            var syndicationItems = new List<SyndicationItem>();

            using (
                DataTable dataTopics = LegacyDb.rss_topic_latest(
                    this.PageContext.PageBoardID,
                    this.Get<YafBoardSettings>().ActiveDiscussionsCount <= 50
                        ? this.Get<YafBoardSettings>().ActiveDiscussionsCount
                        : 50,
                    this.PageContext.PageUserID,
                    this.Get<YafBoardSettings>().UseStyledNicks,
                    this.Get<YafBoardSettings>().NoCountForumsInActiveDiscussions))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("ACTIVE_DISCUSSIONS"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);
                bool altItem = false;
                foreach (DataRow row in dataTopics.Rows)
                {
                    // don't render moved topics
                    if (row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;
                        if (syndicationItems.Count <= 0)
                        {
                            feed.LastUpdatedTime = lastPosted + this.Get<IDateTime>().TimeOffset;
                            feed.Authors.Add(
                                SyndicationItemExtensions.NewSyndicationPerson(
                                    string.Empty,
                                    row["UserID"].ToType<long>(),
                                    row["UserName"].ToString(),
                                    row["UserDisplayName"].ToString()));
                        }

                        feed.Contributors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty,
                                row["LastUserID"].ToType<long>(),
                                row["LastUserName"].ToString(),
                                row["LastUserDisplayName"].ToString()));

                        string messageLink = YafBuildLink.GetLinkNotEscaped(
                            ForumPages.posts, true, "m={0}#post{0}", row["LastMessageID"]);

                        syndicationItems.AddSyndicationItem(
                            row["Topic"].ToString(),
                            GetPostLatestContent(
                                messageLink,
                                lastPostIcon,
                                lastPostName,
                                lastPostName,
                                row["LastMessage"].ToString(),
                                !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                    ? row["LastMessageFlags"].ToType<int>()
                                    : 22,
                                altItem),
                            null,
                            YafBuildLink.GetLinkNotEscaped(
                                ForumPages.posts, true, "t={0}", row["TopicID"].ToType<int>()),
                            "urn:{0}:ft{1}:st{2}:tid{3}:mid{4}:{5}".FormatWith(
                                urlAlphaNum,
                                feedType,
                                atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                row["TopicID"],
                                row["LastMessageID"],
                                this.PageContext.PageBoardID).Unidecode(),
                            lastPosted,
                            feed);
                    }

                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #15
0
        /// <summary>
        /// The method creates YafSyndicationFeed for posts.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="topicId">
        /// The TopicID
        /// </param>
        private void GetPostsFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, int topicId)
        {
            var syndicationItems = new List<SyndicationItem>();

            bool showDeleted = false;
            int userId = 0;

            if (this.Get<YafBoardSettings>().ShowDeletedMessagesToAll)
            {
                showDeleted = true;
            }

            if (!showDeleted
                &&
                ((this.Get<YafBoardSettings>().ShowDeletedMessages
                  && !this.Get<YafBoardSettings>().ShowDeletedMessagesToAll) || this.PageContext.IsAdmin
                 || this.PageContext.IsForumModerator))
            {
                userId = this.PageContext.PageUserID;
            }

            using (
                DataTable dt = LegacyDb.post_list(
                    topicId,
                    this.PageContext.PageUserID,
                    userId,
                    0,
                    showDeleted,
                    true,
                    false,
                    DateTimeHelper.SqlDbMinTime(),
                    DateTime.UtcNow,
                    DateTimeHelper.SqlDbMinTime(),
                    DateTime.UtcNow,
                    0,
                    this.Get<YafBoardSettings>().PostsPerPage,
                    2,
                    0,
                    0,
                    false,
                    -1))
            {
                // convert to linq...
                var rowList = dt.AsEnumerable();

                // last page posts
                var dataRows = rowList.Take(this.Get<YafBoardSettings>().PostsPerPage);

                var altItem = false;

                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed =
                    new YafSyndicationFeed(
                        "{0}{1} - {2}".FormatWith(
                            this.GetText("PROFILE", "TOPIC"),
                            this.PageContext.PageTopicName,
                            this.Get<YafBoardSettings>().PostsPerPage),
                        feedType,
                        atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                        urlAlphaNum);

                foreach (var row in dataRows)
                {
                    DateTime posted = Convert.ToDateTime(row["Edited"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType<long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;
                    }

                    List<SyndicationLink> attachementLinks = null;

                    // if the user doesn't have download access we simply don't show enclosure links.
                    if (this.PageContext.ForumDownloadAccess)
                    {
                        attachementLinks = this.GetMediaLinks(row["MessageID"].ToType<int>());
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["UserID"].ToType<long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        this.Get<IFormatMessage>().FormatSyndicationMessage(
                            row["Message"].ToString(), new MessageFlags(row["Flags"]), altItem, 4000),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}&find=lastpost", row["MessageID"]),
                        "urn:{0}:ft{1}:st{2}:meid{3}:{4}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            row["MessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        posted,
                        feed,
                        attachementLinks);

                    // used to format feeds
                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #16
0
        /// <summary>
        /// The method creates YAF SyndicationFeed for forums in a category.
        /// </summary>
        /// <param name="feed">
        /// The YAF Syndication Feed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="categoryId">
        /// The category id.
        /// </param>
        private void GetForumFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, [NotNull] object categoryId)
        {
            var syndicationItems = new List<SyndicationItem>();

            using (DataTable dt = LegacyDb.forum_listread(this.PageContext.PageBoardID, this.PageContext.PageUserID, categoryId, null, false, false))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("DEFAULT", "FORUM"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if (row["TopicMovedID"].IsNullOrEmptyDBField() && row["LastPosted"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        if (row["LastUserID"].IsNullOrEmptyDBField() || row["LastUserID"].IsNullOrEmptyDBField())
                        {
                            break;
                        }

                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType<long>(), null, null));

                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;

                        // Alternate Link
                        // feed.Links.Add(new SyndicationLink(new Uri(YafBuildLink.GetLinkNotEscaped(ForumPages.topics, true))));
                    }

                    if (!row["LastUserID"].IsNullOrEmptyDBField())
                    {
                        feed.Contributors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType<long>(), null, null));
                    }

                    syndicationItems.AddSyndicationItem(
                        row["Forum"].ToString(),
                        this.HtmlEncode(row["Description"].ToString()),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.topics, true, "f={0}", row["ForumID"]),
                        "urn:{0}:ft{1}:st{2}:fid{3}:lmid{4}:{5}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            row["ForumID"],
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #17
0
        /// <summary>
        /// The method creates YafSyndicationFeed for posts.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="topicId">The TopicID</param>
        private void GetPostsFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, int topicId)
        {
            var syndicationItems = new List <SyndicationItem>();

            using (
                DataTable dt = DB.post_list(
                    topicId, 0, this.PageContext.BoardSettings.ShowDeletedMessages, false))
            {
                // convert to linq...
                var rowList = dt.AsEnumerable().OrderByDescending(x => x.Field <DateTime>("Posted"));

                // see if the deleted messages need to be edited out...)
                if (this.PageContext.BoardSettings.ShowDeletedMessages && !this.PageContext.BoardSettings.ShowDeletedMessagesToAll &&
                    !this.PageContext.IsAdmin && !this.PageContext.IsForumModerator)
                {
                    // remove posts that are deleted and do not belong to this user...
                    rowList =
                        rowList.Where(x => !(x.Field <bool>("IsDeleted") && x.Field <int>("UserID") != this.PageContext.PageUserID)).OrderByDescending(y => (y.Field <DateTime>("Posted")));
                }

                // last page posts
                var dataRows = rowList.Take(PageContext.BoardSettings.PostsPerPage);

                var altItem = false;

                // load the missing message test
                this.Get <YafDBBroker>().LoadMessageText(dataRows);

                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed("{0}{1} - {2}".FormatWith(this.PageContext.Localization.GetText("PROFILE", "TOPIC"), this.PageContext.PageTopicName, PageContext.BoardSettings.PostsPerPage), feedType, atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);

                foreach (var row in dataRows)
                {
                    DateTime posted = Convert.ToDateTime(row["Edited"]) + this.Get <YafDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty, Convert.ToInt64(row["UserID"])));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <YafDateTime>().TimeOffset;
                    }

                    List <SyndicationLink> attachementLinks = null;

                    // if the user doesn't have download access we simply don't show enclosure links.
                    if (PageContext.ForumDownloadAccess)
                    {
                        attachementLinks = GetMediaLinks(row["MessageID"].ToType <int>());
                    }

                    feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty, Convert.ToInt64(row["UserID"])));

                    syndicationItems.AddSyndicationItem(
                        row["Subject"].ToString(),
                        YafFormatMessage.FormatSyndicationMessage(row["Message"].ToString(), new MessageFlags(row["Flags"]), altItem, 4000),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}", row["MessageID"]),
                        "urn:{0}:ft{1}:st{2}:meid{3}:{4}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            row["MessageID"], PageContext.PageBoardID),
                        posted,
                        feed,
                        attachementLinks);

                    // used to format feeds
                    altItem = !altItem;
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #18
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Favorite topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId">The category active id.</param>
        private void GetFavoriteFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            [NotNull] object categoryActiveId)
        {
            var syndicationItems = new List<SyndicationItem>();

            DateTime toFavDate;

            string toFavText = this.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("txt") != null)
            {
                toFavText =
                    this.Server.UrlDecode(
                        this.Server.HtmlDecode(this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("txt")));
            }

            if (this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("d") != null)
            {
                if (
                    !DateTime.TryParse(
                        this.Server.UrlDecode(
                            this.Server.HtmlDecode(this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("d"))),
                        out toFavDate))
                {
                    toFavDate = this.PageContext.CurrentUserData.Joined == null
                                    ? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2)
                                    : (DateTime)this.PageContext.CurrentUserData.Joined;
                    toFavText = this.GetText("MYTOPICS", "SHOW_ALL");
                }
            }
            else
            {
                toFavDate = this.PageContext.CurrentUserData.Joined == null
                                ? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2)
                                : (DateTime)this.PageContext.CurrentUserData.Joined;
                toFavText = this.GetText("MYTOPICS", "SHOW_ALL");
            }

            using (
                DataTable dt =
                    this.TabledCleanUpByDate(
                        this.GetRepository<FavoriteTopic>().Details(
                            categoryActiveId.ToType<int?>(),
                            this.PageContext.PageUserID,
                            toFavDate,
                            DateTime.UtcNow,
                            // page index in db is 1 based!
                            0,
                            // set the page size here
                            20,
                            false,
                            false),
                        "LastPosted",
                        toFavDate))
            {
                string urlAlphaNum = FormatUrlForFeed(YafForumInfo.ForumBaseUrl);
                string feedNameAlphaNum =
                    new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase)
                        .Replace(toFavText, string.Empty);
                feed = new YafSyndicationFeed(
                    "{0} - {1}".FormatWith(this.GetText("MYTOPICS", "FAVORITETOPICS"), toFavText),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType<long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType<long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Subject"].ToString(),
                        GetPostLatestContent(
                            YafBuildLink.GetLinkNotEscaped(
                                ForumPages.posts, true, "m={0}#post{0}", row["LastMessageID"]),
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            string.Empty,
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType<int>() : 22,
                            false),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", row["LinkTopicID"]),
                        "urn:{0}:ft{1}:st{2}:span{3}:ltid{4}:lmid{5}:{6}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            feedNameAlphaNum,
                            row["LinkTopicID"].ToType<int>(),
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #19
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Active topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId">The category active id.</param>
        private void GetActiveFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            [NotNull] object categoryActiveId)
        {
            var syndicationItems = new List<SyndicationItem>();
            DateTime toActDate = DateTime.UtcNow;
            string toActText = this.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("txt") != null)
            {
                toActText =
                    this.Server.UrlDecode(
                        this.Server.HtmlDecode(this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("txt")));
            }

            if (this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("d") != null)
            {
                if (
                    !DateTime.TryParse(
                        this.Server.UrlDecode(
                            this.Server.HtmlDecode(this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("d"))),
                        out toActDate))
                {
                    toActDate = Convert.ToDateTime(this.Get<IDateTime>().FormatDateTimeShort(DateTime.UtcNow))
                                + TimeSpan.FromDays(-31);
                    toActText = this.GetText("MYTOPICS", "LAST_MONTH");
                }
                else
                {
                    // To limit number of feeds items by timespan if we are getting an unreasonable time                
                    if (toActDate < DateTime.UtcNow + TimeSpan.FromDays(-31))
                    {
                        toActDate = DateTime.UtcNow + TimeSpan.FromDays(-31);
                        toActText = this.GetText("MYTOPICS", "LAST_MONTH");
                    }
                }
            }

            string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);
            string feedNameAlphaNum = new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase).Replace(
                toActText, string.Empty);
            feed = new YafSyndicationFeed(
                this.GetText("MYTOPICS", "ACTIVETOPICS") + " - " + toActText,
                feedType,
                atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                urlAlphaNum);

            using (
                DataTable dt =
                    this.TabledCleanUpByDate(
                        LegacyDb.topic_active(
                            this.PageContext.PageBoardID,
                            categoryActiveId,
                            this.PageContext.PageUserID,
                            toActDate,
                            DateTime.UtcNow,
                            // page index in db which is returned back  is +1 based!
                            0,
                            // set the page size here
                            20,
                            false,
                            this.Get<YafBoardSettings>().UseReadTrackingByDatabase),
                        "LastPosted",
                        toActDate))
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType<long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType<long>(), null, null));

                    string messageLink = YafBuildLink.GetLinkNotEscaped(
                        ForumPages.posts, true, "m={0}#post{0}", row["LastMessageID"]);
                    syndicationItems.AddSyndicationItem(
                        row["Subject"].ToString(),
                        GetPostLatestContent(
                            messageLink,
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            string.Empty,
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType<int>() : 22,
                            false),
                        null,
                        messageLink,
                        "urn:{0}:ft{1}:st{2}:span{3}:ltid{4}:lmid{5}:{6}".FormatWith(
                            urlAlphaNum,
                            feedNameAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            row["LinkTopicID"],
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #20
0
        /// <summary>
        /// The method creates YAF SyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">
        /// The YAF SyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="lastPostIcon">
        /// The icon for last post link.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <param name="forumId">
        /// The forum id.
        /// </param>
        private void GetTopicsFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            int forumId)
        {
            var syndicationItems = new List<SyndicationItem>();

            // vzrus changed to separate DLL specific code
            using (DataTable dt = LegacyDb.rsstopic_list(forumId, this.Get<YafBoardSettings>().TopicsFeedItemsCount))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    "{0}:{1}".FormatWith(this.GetText("DEFAULT", "FORUM"), this.PageContext.PageForumName),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType<long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;

                        // Alternate Link
                        // feed.Links.Add(new SyndicationLink(new Uri(YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true))));
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType<long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        GetPostLatestContent(
                            YafBuildLink.GetLinkNotEscaped(
                                ForumPages.posts, true, "m={0}#post{0}", row["LastMessageID"]),
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            row["LastMessage"].ToString(),
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType<int>() : 22,
                            false),
                        null,
                        YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "t={0}", row["TopicID"]),
                        "urn:{0}:ft{1}:st{2}:tid{3}:lmid{4}:{5}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            row["TopicID"],
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #21
0
        /// <summary>
        /// The method creates YAF SyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feed">
        /// The YAF SyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <param name="lastPostIcon">
        /// The icon for last post link.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <param name="forumId">
        /// The forum id.
        /// </param>
        private void GetTopicsFeed(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName,
            int forumId)
        {
            var syndicationItems = new List <SyndicationItem>();

            // vzrus changed to separate DLL specific code
            using (var dt = this.GetRepository <Topic>().RssListAsDataTable(forumId, this.Get <BoardSettings>().TopicsFeedItemsCount))
            {
                var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    $"{this.GetText("DEFAULT", "FORUM")}:{this.PageContext.PageForumName}",
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["LastUserID"].ToType <long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get <IDateTime>().TimeOffset;

                        // Alternate Link
                        // feed.Links.Add(new SyndicationLink(new Uri(BuildLink.GetLinkNotEscaped(ForumPages.Posts, true))));
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType <long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        GetPostLatestContent(
                            BuildLink.GetLinkNotEscaped(
                                ForumPages.Posts, true, "m={0}#post{0}", row["LastMessageID"]),
                            lastPostIcon,
                            lastPostName,
                            lastPostName,
                            row["LastMessage"].ToString(),
                            !row["LastMessageFlags"].IsNullOrEmptyDBField() ? row["LastMessageFlags"].ToType <int>() : 22,
                            false),
                        null,
                        BuildLink.GetLinkNotEscaped(ForumPages.Posts, true, "t={0}", row["TopicID"]),
                        $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt())}:tid{row["TopicID"]}:lmid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                        .Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #22
0
        /// <summary>
        /// The method creates YafSyndicationFeed for Active topics.
        /// </summary>
        /// <param name="feed">The YafSyndicationFeed.</param>
        /// <param name="feedType">The FeedType.</param>
        /// <param name="atomFeedByVar">The Atom feed checker.</param>
        /// <param name="lastPostIcon">The icon for last post link.</param>
        /// <param name="lastPostName">The last post name.</param>
        /// <param name="categoryActiveId"></param>
        private void GetActiveFeed(ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar, string lastPostIcon, string lastPostName, object categoryActiveId)
        {
            var      syndicationItems = new List <SyndicationItem>();
            DateTime toActDate        = DateTime.UtcNow;
            string   toActText        = this.PageContext.Localization.GetText("MYTOPICS", "LAST_MONTH");

            if (this.Request.QueryString.GetFirstOrDefault("txt") != null)
            {
                toActText = Server.UrlDecode(Server.HtmlDecode(this.Request.QueryString.GetFirstOrDefault("txt").ToString()));
            }

            if (this.Request.QueryString.GetFirstOrDefault("d") != null)
            {
                if (!DateTime.TryParse(Server.UrlDecode(Server.HtmlDecode(this.Request.QueryString.GetFirstOrDefault("d").ToString())), out toActDate))
                {
                    toActDate = Convert.ToDateTime(this.Get <YafDateTime>().FormatDateTimeShort(DateTime.UtcNow)) + TimeSpan.FromDays(-31);
                    toActText = this.PageContext.Localization.GetText("MYTOPICS", "LAST_MONTH");
                }
                else
                {
                    // To limit number of feeds items by timespan if we are getting an unreasonable time
                    if (toActDate < DateTime.UtcNow + TimeSpan.FromDays(-31))
                    {
                        toActDate = DateTime.UtcNow + TimeSpan.FromDays(-31);
                        toActText = this.PageContext.Localization.GetText("MYTOPICS", "LAST_MONTH");
                    }
                }
            }

            string urlAlphaNum      = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);
            string feedNameAlphaNum = new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase).Replace(toActText.ToString(),
                                                                                                  String.Empty);

            feed = new YafSyndicationFeed(this.PageContext.Localization.GetText("MYTOPICS", "ACTIVETOPICS") + " - " + toActText, feedType, atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(), urlAlphaNum);

            using (
                DataTable dt = DB.topic_active(
                    this.PageContext.PageBoardID,
                    this.PageContext.PageUserID,
                    toActDate,
                    categoryActiveId,
                    false))
            {
                foreach (DataRow row in dt.Rows)
                {
                    if (row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <YafDateTime>().TimeOffset;

                        if (syndicationItems.Count <= 0)
                        {
                            feed.Authors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                            Convert.ToInt64(row["UserID"])));
                            feed.LastUpdatedTime = DateTime.UtcNow + this.Get <YafDateTime>().TimeOffset;
                        }

                        feed.Contributors.Add(SyndicationItemExtensions.NewSyndicationPerson(String.Empty,
                                                                                             Convert.ToInt64(
                                                                                                 row["LastUserID"])));

                        string messageLink = YafBuildLink.GetLinkNotEscaped(ForumPages.posts, true, "m={0}#post{0}",
                                                                            row["LastMessageID"]);
                        syndicationItems.AddSyndicationItem(
                            row["Subject"].ToString(),
                            GetPostLatestContent(messageLink, lastPostIcon, lastPostName, lastPostName, String.Empty,
                                                 !row["LastMessageFlags"].IsNullOrEmptyDBField()
                                                     ? Convert.ToInt32(row["LastMessageFlags"])
                                                     : 22, false),
                            null,
                            messageLink,
                            "urn:{0}:ft{1}:st{2}:span{3}:ltid{4}:lmid{5}:{6}".FormatWith(urlAlphaNum,
                                                                                         feedNameAlphaNum,
                                                                                         feedType,
                                                                                         atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                                                                                         row["LinkTopicID"],
                                                                                         row["LastMessageID"], PageContext.PageBoardID),
                            lastPosted,
                            feed);
                    }
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #23
0
        /// <summary>
        /// The method creates YafSyndicationFeed for topic announcements.
        /// </summary>
        /// <param name="feed">
        /// The YafSyndicationFeed.
        /// </param>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        private void GetLatestAnnouncementsFeed(
            [NotNull] ref YafSyndicationFeed feed, YafRssFeeds feedType, bool atomFeedByVar)
        {
            var syndicationItems = new List<SyndicationItem>();

            using (DataTable dt = LegacyDb.topic_announcements(this.PageContext.PageBoardID, 10, this.PageContext.PageUserID))
            {
                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

                feed = new YafSyndicationFeed(
                    this.GetText("POSTMESSAGE", "ANNOUNCEMENT"),
                    feedType,
                    atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                    urlAlphaNum);

                foreach (DataRow row in dt.Rows)
                {
                    // don't render moved topics
                    if (!row["TopicMovedID"].IsNullOrEmptyDBField())
                    {
                        continue;
                    }

                    DateTime lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get<IDateTime>().TimeOffset;

                    if (syndicationItems.Count <= 0)
                    {
                        feed.Authors.Add(
                            SyndicationItemExtensions.NewSyndicationPerson(
                                string.Empty, row["UserID"].ToType<long>(), null, null));
                        feed.LastUpdatedTime = DateTime.UtcNow + this.Get<IDateTime>().TimeOffset;
                    }

                    feed.Contributors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty, row["LastUserID"].ToType<long>(), null, null));

                    syndicationItems.AddSyndicationItem(
                        row["Topic"].ToString(),
                        row["Message"].ToString(),
                        null,
                        YafBuildLink.GetLinkNotEscaped(
                            ForumPages.posts, true, "t={0}", this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("t")),
                        "urn:{0}:ft{1}:st{2}:tid{3}:lmid{4}:{5}".FormatWith(
                            urlAlphaNum,
                            feedType,
                            atomFeedByVar ? YafSyndicationFormats.Atom.ToInt() : YafSyndicationFormats.Rss.ToInt(),
                            this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("t"),
                            row["LastMessageID"],
                            this.PageContext.PageBoardID).Unidecode(),
                        lastPosted,
                        feed);
                }

                feed.Items = syndicationItems;
            }
        }
Beispiel #24
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load(object sender, EventArgs e)
        {
            // Put user code to initialize the page here
            if (!(PageContext.BoardSettings.ShowRSSLink || PageContext.BoardSettings.ShowAtomLink))
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }

            // Atom feed as variable
            bool atomFeedByVar = Request.QueryString.GetFirstOrDefault("ft") ==
                                 YafSyndicationFormats.Atom.ToInt().ToString();

            YafSyndicationFeed feed = null;
            var    syndicationItems = new List <SyndicationItem>();
            string lastPostIcon     = BaseUrlBuilder.BaseUrl + PageContext.CurrentForumPage.GetThemeContents("ICONS", "ICON_NEWEST");
            string lastPostName     = this.PageContext.Localization.GetText("DEFAULT", "GO_LAST_POST");

            YafRssFeeds feedType = YafRssFeeds.Forum;

            try
            {
                feedType = this.Request.QueryString.GetFirstOrDefault("pg").ToEnum <YafRssFeeds>(true);
            }
            catch
            {
                // default to Forum Feed.
            }

            switch (feedType)
            {
            // Latest posts feed
            case YafRssFeeds.LatestPosts:
                if (!(this.PageContext.BoardSettings.ShowActiveDiscussions && this.Get <YafPermissions>().Check(PageContext.BoardSettings.PostLatestFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                GetPostLatestFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName);
                break;

            // Latest Announcements feed
            case YafRssFeeds.LatestAnnouncements:
                if (!this.Get <YafPermissions>().Check(PageContext.BoardSettings.ForumFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                GetLatestAnnouncementsFeed(ref feed, feedType, atomFeedByVar);
                break;

            // Posts Feed
            case YafRssFeeds.Posts:
                if (!(this.PageContext.ForumReadAccess && this.Get <YafPermissions>().Check(PageContext.BoardSettings.PostsFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                if (this.Request.QueryString.GetFirstOrDefault("t") != null)
                {
                    int topicId;
                    if (int.TryParse(this.Request.QueryString.GetFirstOrDefault("t"), out topicId))
                    {
                        GetPostsFeed(ref feed, feedType, atomFeedByVar, topicId);
                    }
                }

                break;

            // Forum Feed
            case YafRssFeeds.Forum:
                if (!this.Get <YafPermissions>().Check(PageContext.BoardSettings.ForumFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                object categoryId = null;

                if (this.Request.QueryString.GetFirstOrDefault("c") != null)
                {
                    int icategoryId = 0;
                    if (int.TryParse(this.Request.QueryString.GetFirstOrDefault("c"), out icategoryId))
                    {
                        categoryId = icategoryId;
                    }
                }

                GetForumFeed(ref feed, feedType, atomFeedByVar, categoryId);
                break;

            // Topics Feed
            case YafRssFeeds.Topics:
                if (!(this.PageContext.ForumReadAccess && this.Get <YafPermissions>().Check(PageContext.BoardSettings.TopicsFeedAccess)))
                {
                    YafBuildLink.AccessDenied();
                }

                int forumId;
                if (this.Request.QueryString.GetFirstOrDefault("f") != null)
                {
                    if (int.TryParse(this.Request.QueryString.GetFirstOrDefault("f"), out forumId))
                    {
                        GetTopicsFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, forumId);
                    }
                }
                break;

            // Active Topics
            case YafRssFeeds.Active:
                if (!this.Get <YafPermissions>().Check(PageContext.BoardSettings.ActiveTopicFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }

                int    categoryActiveIntId;
                object categoryActiveId = null;
                if (this.Request.QueryString.GetFirstOrDefault("f") != null && int.TryParse(this.Request.QueryString.GetFirstOrDefault("f"), out categoryActiveIntId))
                {
                    categoryActiveId = categoryActiveIntId;
                }

                GetActiveFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, categoryActiveId);

                break;

            case YafRssFeeds.Favorite:
                if (!this.Get <YafPermissions>().Check(PageContext.BoardSettings.FavoriteTopicFeedAccess))
                {
                    YafBuildLink.AccessDenied();
                }
                int    categoryFavIntId;
                object categoryFavId = null;
                if (this.Request.QueryString.GetFirstOrDefault("f") != null && int.TryParse(this.Request.QueryString.GetFirstOrDefault("f"), out categoryFavIntId))
                {
                    categoryFavId = categoryFavIntId;
                }

                GetFavoriteFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, categoryFavId);
                break;

            default:
                YafBuildLink.AccessDenied();
                break;
            }

            // update the feed with the item list...
            // the list should be added after all other feed properties are set
            if (feed != null)
            {
                var writer = new XmlTextWriter(this.Response.OutputStream, Encoding.UTF8);
                writer.WriteStartDocument();

                // write the feed to the response writer);
                if (!atomFeedByVar)
                {
                    var rssFormatter = new Rss20FeedFormatter(feed);
                    rssFormatter.WriteTo(writer);
                    this.Response.ContentType = "application/rss+xml";
                }
                else
                {
                    var atomFormatter = new Atom10FeedFormatter(feed);
                    atomFormatter.WriteTo(writer);

                    this.Response.ContentType = "application/atom+xml";
                }

                writer.WriteEndDocument();
                writer.Close();

                this.Response.ContentEncoding = Encoding.UTF8;
                this.Response.Cache.SetCacheability(HttpCacheability.Public);

                this.Response.End();
            }
            else
            {
                YafBuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }
        }