Beispiel #1
0
        /// <summary>
        /// The method creates SyndicationFeed for topic announcements.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="atomFeedByVar">
        /// The Atom feed checker.
        /// </param>
        /// <returns>
        /// The <see cref="YafSyndicationFeed"/>.
        /// </returns>
        private YafSyndicationFeed GetLatestAnnouncementsFeed(RssFeeds feedType, bool atomFeedByVar)
        {
            var syndicationItems = new List <SyndicationItem>();

            var dt = this.GetRepository <Topic>().AnnouncementsAsDataTable(
                this.PageContext.PageBoardID,
                10,
                this.PageContext.PageUserID);
            var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

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

            dt.Rows.Cast <DataRow>().Where(row => !row["TopicMovedID"].IsNullOrEmptyDBField()).ForEach(
                row =>
            {
                var lastPosted = Convert.ToDateTime(row["LastPosted"]) + this.Get <IDateTime>().TimeOffset;

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

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

                syndicationItems.AddSyndicationItem(
                    row["Topic"].ToString(),
                    row["Message"].ToString(),
                    null,
                    BuildLink.GetLink(
                        ForumPages.Posts,
                        true,
                        "t={0}&name={1}",
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t"),
                        row["Topic"].ToString()),
                    $"urn:{urlAlphaNum}:ft{feedType}:st{(atomFeedByVar ? SyndicationFormats.Atom.ToInt() : SyndicationFormats.Rss.ToInt())}:tid{this.Get<HttpRequestBase>().QueryString.GetFirstOrDefault("t")}:lmid{row["LastMessageID"]}:{this.PageContext.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);
            });

            feed.Items = syndicationItems;

            return(feed);
        }
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>
        /// 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;
            }
        }
 /// <summary>
 /// The add syndication item.
 /// </summary>
 /// <param name="currentList">
 /// The current list.
 /// </param>
 /// <param name="title">
 /// The title.
 /// </param>
 /// <param name="content">
 /// The content.
 /// </param>
 /// <param name="summary">
 /// The summary.
 /// </param>
 /// <param name="link">
 /// The alternate link.
 /// </param>
 /// <param name="id">
 /// The id.
 /// </param>
 /// <param name="posted">
 /// The posted.
 /// </param>
 /// <param name="feed">
 /// The feed.
 /// </param>
 public static void AddSyndicationItem(
     this List <SyndicationItem> currentList,
     string title,
     string content,
     string summary,
     string link,
     string id,
     DateTime posted,
     YafSyndicationFeed feed)
 {
     AddSyndicationItem(currentList, title, content, summary, link, id, posted, feed, null);
 }
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>
        /// The add syndication item.
        /// </summary>
        /// <param name="currentList">
        /// The current list.
        /// </param>
        /// <param name="title">
        /// The title.
        /// </param>
        /// <param name="content">
        /// The content.
        /// </param>
        /// <param name="summary">
        /// The summary.
        /// </param>
        /// <param name="link">
        /// The alternate link.
        /// </param>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="posted">
        /// The posted.
        /// </param>
        /// <param name="feed">
        /// The feed.
        /// </param>
        /// <param name="links">
        /// The links.
        /// </param>
        public static void AddSyndicationItem(
            this List <SyndicationItem> currentList,
            string title,
            string content,
            string summary,
            string link,
            string id,
            DateTime posted,
            YafSyndicationFeed feed,
            List <SyndicationLink> links)
        {
            var si = new SyndicationItem(
                BoardContext.Current.Get <IBadWordReplace>().Replace(title),
                new TextSyndicationContent(
                    BoardContext.Current.Get <IBadWordReplace>().Replace(content),
                    TextSyndicationContentKind.Html),
                new Uri(link),
                id,
                new DateTimeOffset(posted))
            {
                PublishDate = new DateTimeOffset(posted)
            };

            links?.ForEach(syndicationLink => si.Links.Add(syndicationLink));

            si.Authors.Add(
                new SyndicationPerson(string.Empty, feed.Contributors[feed.Contributors.Count - 1].Name, string.Empty));
            si.SourceFeed = feed;
            if (summary.IsNotSet())
            {
                si.Summary = new TextSyndicationContent(
                    BoardContext.Current.Get <IBadWordReplace>().Replace(content),
                    TextSyndicationContentKind.Html);
            }
            else
            {
                si.Summary = new TextSyndicationContent(
                    BoardContext.Current.Get <IBadWordReplace>().Replace(summary),
                    TextSyndicationContentKind.Html);
            }

            currentList.Add(si);
        }
Beispiel #7
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 #8
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 #9
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 #10
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 #11
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 #12
0
        /// <summary>
        /// The page_ load.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void Page_Load([NotNull] object sender, [NotNull] EventArgs e)
        {
            // Put user code to initialize the page here
            if (!(this.Get <BoardSettings>().ShowRSSLink || this.Get <BoardSettings>().ShowAtomLink))
            {
                BuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }

            // Atom feed as variable
            var atomFeedByVar = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("ft")
                                == YafSyndicationFormats.Atom.ToInt().ToString();

            YafSyndicationFeed feed = null;

            // var syndicationItems = new List<SyndicationItem>();
            var lastPostIcon = string.Empty;
            var lastPostName = this.GetText("DEFAULT", "GO_LAST_POST");

            YafRssFeeds feedType;

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

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

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

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

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

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

                if (this.Get <HttpRequestBase>().QueryString.Exists("t"))
                {
                    if (int.TryParse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("t"), out var topicId))
                    {
                        this.GetPostsFeed(ref feed, feedType, atomFeedByVar, topicId);
                    }
                }

                break;

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

                int?categoryId = null;

                if (this.Get <HttpRequestBase>().QueryString.Exists("c"))
                {
                    categoryId = this.Get <HttpRequestBase>().QueryString.GetFirstOrDefaultAsInt("c");
                }

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

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

                if (this.Get <HttpRequestBase>().QueryString.Exists("f"))
                {
                    if (int.TryParse(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out var forumId))
                    {
                        this.GetTopicsFeed(ref feed, feedType, atomFeedByVar, lastPostIcon, lastPostName, forumId);
                    }
                }

                break;

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

                object categoryActiveId = null;
                if (this.Get <HttpRequestBase>().QueryString.Exists("f")
                    &&
                    int.TryParse(
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out var categoryActiveIntId))
                {
                    categoryActiveId = categoryActiveIntId;
                }

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

                break;

            case YafRssFeeds.Favorite:
                if (!this.Get <IPermissions>().Check(this.Get <BoardSettings>().FavoriteTopicFeedAccess))
                {
                    BuildLink.AccessDenied();
                }

                object categoryFavId = null;
                if (this.Get <HttpRequestBase>().QueryString.Exists("f")
                    &&
                    int.TryParse(
                        this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("f"), out var categoryFavIntId))
                {
                    categoryFavId = categoryFavIntId;
                }

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

            default:
                BuildLink.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.Get <HttpResponseBase>().OutputStream, Encoding.UTF8);
                writer.WriteStartDocument();

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

                    this.Get <HttpResponseBase>().ContentType = "application/atom+xml";
                }

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

                this.Get <HttpResponseBase>().ContentEncoding = Encoding.UTF8;
                this.Get <HttpResponseBase>().Cache.SetCacheability(HttpCacheability.Public);

                this.Get <HttpResponseBase>().End();
            }
            else
            {
                BuildLink.RedirectInfoPage(InfoMessage.AccessDenied);
            }
        }
Beispiel #13
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 #14
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 #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(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 #16
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 #17
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;
            }
        }