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
        public ActionResult BreakfastsAndSides(int id)
        {
            int             page              = id / 4;
            int             index             = id % 4;
            var             latestMealsItems2 = _rssProvider2.GetLatest(page);
            SyndicationItem model             = latestMealsItems2.ElementAt(index);

            model = SyndicationItemExtensions.FormatText(model);
            return(View(model));
        }
        /// <summary>
        /// The method creates YAF SyndicationFeed for forums in a category.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="categoryId">
        /// The category id.
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetForumFeed([NotNull] RssFeeds feedType, [CanBeNull] int?categoryId)
        {
            var syndicationItems = new List <SyndicationItem>();

            var forums = this.GetRepository <Forum>().ListRead(
                BoardContext.Current.PageBoardID,
                BoardContext.Current.PageUserID,
                categoryId,
                null,
                false);

            var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

            var feed = new FeedItem(this.Get <ILocalization>().GetText("DEFAULT", "FORUM"), feedType, urlAlphaNum);

            forums.Where(x => x.LastPosted.HasValue && !x.TopicMovedID.HasValue).ForEach(
                forum =>
            {
                var lastPosted = forum.LastPosted.Value + this.Get <IDateTimeService>().TimeOffset;

                if (syndicationItems.Count <= 0)
                {
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty,
                            forum.LastUserID.Value,
                            null,
                            null));

                    feed.LastUpdatedTime = System.DateTime.UtcNow + this.Get <IDateTimeService>().TimeOffset;
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(
                        string.Empty,
                        forum.LastUserID.Value,
                        null,
                        null));

                syndicationItems.AddSyndicationItem(
                    forum.Forum,
                    forum.Description,
                    null,
                    this.Get <LinkBuilder>().GetLink(ForumPages.Topics, true, "f={0}&name={1}", forum.ForumID, forum.Forum),
                    $@"urn:{urlAlphaNum}:ft{feedType}:
                              fid{forum.ForumID}:lmid{forum.LastMessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);
            });

            feed.Items = syndicationItems;

            return(feed);
        }
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>
        /// <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 #6
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;
            }
        }
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 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 #9
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 #10
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 #11
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 #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">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;
            }
        }
        /// <summary>
        /// The method creates SyndicationFeed for topics in a forum.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <param name="forumId">
        /// The forum id.
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetTopicsFeed([NotNull] RssFeeds feedType, [NotNull] string lastPostName, [NotNull] int forumId)
        {
            var syndicationItems = new List <SyndicationItem>();

            var topics = this.GetRepository <Topic>().RssList(
                forumId,
                BoardContext.Current.PageUserID,
                BoardContext.Current.BoardSettings.TopicsFeedItemsCount);

            var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

            var feed = new FeedItem(
                $"{this.Get<ILocalization>().GetText("DEFAULT", "FORUM")}:{BoardContext.Current.PageForumName}",
                feedType,
                urlAlphaNum);

            topics.ForEach(
                topic =>
            {
                var lastPosted = (System.DateTime)topic.LastPosted + this.Get <IDateTimeService>().TimeOffset;

                if (syndicationItems.Count <= 0)
                {
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty,
                            (int)topic.LastUserID,
                            null,
                            null));
                    feed.LastUpdatedTime = System.DateTime.UtcNow + this.Get <IDateTimeService>().TimeOffset;
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(
                        string.Empty,
                        (int)topic.LastUserID,
                        null,
                        null));

                var postLink = this.Get <LinkBuilder>().GetLink(
                    ForumPages.Posts,
                    true,
                    "m={0}&name={1}#post{0}",
                    (int)topic.LastMessageID,
                    (string)topic.Topic);

                var content = this.GetPostLatestContent(
                    postLink,
                    lastPostName,
                    (string)topic.LastMessage,
                    (int)topic.LastMessageFlags,
                    false);

                syndicationItems.AddSyndicationItem(
                    (string)topic.Topic,
                    content,
                    null,
                    postLink,
                    $"urn:{urlAlphaNum}:ft{feedType}:tid{topic.TopicID}:lmid{topic.LastMessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);
            });

            feed.Items = syndicationItems;

            return(feed);
        }
Beispiel #14
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;
            }
        }
        /// <summary>
        /// The method creates Syndication Feed for topics in a forum.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetPostLatestFeed([NotNull] RssFeeds feedType, [NotNull] string lastPostName)
        {
            var syndicationItems = new List <SyndicationItem>();

            var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

            var feed = new FeedItem(this.Get <ILocalization>().GetText("ACTIVE_DISCUSSIONS"), feedType, urlAlphaNum);

            var topics = this.GetRepository <Topic>().RssLatest(
                BoardContext.Current.PageBoardID,
                BoardContext.Current.BoardSettings.ActiveDiscussionsCount <= 50
                    ? BoardContext.Current.BoardSettings.ActiveDiscussionsCount
                    : 50,
                BoardContext.Current.PageUserID);

            var altItem = false;

            topics.ForEach(
                topic =>
            {
                var lastPosted = topic.Item2.LastPosted.Value + this.Get <IDateTimeService>().TimeOffset;
                if (syndicationItems.Count <= 0)
                {
                    feed.LastUpdatedTime = lastPosted + this.Get <IDateTimeService>().TimeOffset;
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(
                            string.Empty,
                            topic.Item2.UserID,
                            topic.Item2.UserName,
                            topic.Item2.UserDisplayName));
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(
                        string.Empty,
                        topic.Item2.LastUserID.Value,
                        topic.Item2.LastUserName,
                        topic.Item2.LastUserDisplayName));

                var messageLink = this.Get <LinkBuilder>().GetLink(
                    ForumPages.Posts,
                    true,
                    "m={0}&name={1}#post{0}",
                    topic.Item2.LastMessageID,
                    topic.Item2.TopicName);

                syndicationItems.AddSyndicationItem(
                    topic.Item2.TopicName,
                    this.GetPostLatestContent(
                        messageLink,
                        lastPostName,
                        topic.Item1.MessageText,
                        topic.Item2.LastMessageFlags ?? 22,
                        altItem),
                    null,
                    this.Get <LinkBuilder>().GetLink(
                        ForumPages.Posts,
                        true,
                        "t={0}&name={1}",
                        topic.Item2.ID,
                        topic.Item2.TopicName),
                    $"urn:{urlAlphaNum}:ft{feedType}:tid{topic.Item2.ID}:mid{topic.Item2.LastMessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);

                altItem = !altItem;

                feed.Items = syndicationItems;
            });

            return(feed);
        }
        /// <summary>
        /// The method creates the SyndicationFeed for posts.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="topicId">
        /// The TopicID
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetPostsFeed([NotNull] RssFeeds feedType, [NotNull] int topicId)
        {
            var syndicationItems = new List <SyndicationItem>();

            var showDeleted = false;
            var userId      = 0;

            if (BoardContext.Current.BoardSettings.ShowDeletedMessagesToAll)
            {
                showDeleted = true;
            }

            if (!showDeleted &&
                (BoardContext.Current.BoardSettings.ShowDeletedMessages &&
                 !BoardContext.Current.BoardSettings.ShowDeletedMessagesToAll || BoardContext.Current.IsAdmin ||
                 BoardContext.Current.IsForumModerator))
            {
                userId = BoardContext.Current.PageUserID;
            }

            var posts = this.GetRepository <Message>().PostListPaged(
                topicId,
                BoardContext.Current.PageUserID,
                userId,
                false,
                showDeleted,
                DateTimeHelper.SqlDbMinTime(),
                System.DateTime.UtcNow,
                0,
                BoardContext.Current.BoardSettings.PostsPerPage,
                -1);

            var altItem = false;

            var urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

            var feed = new FeedItem(
                $"{this.Get<ILocalization>().GetText("PROFILE", "TOPIC")}{BoardContext.Current.PageTopicName} - {BoardContext.Current.BoardSettings.PostsPerPage}",
                feedType,
                urlAlphaNum);

            posts.ForEach(
                row =>
            {
                var posted = row.Edited + this.Get <IDateTimeService>().TimeOffset;

                if (syndicationItems.Count <= 0)
                {
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(string.Empty, row.UserID, null, null));
                    feed.LastUpdatedTime = System.DateTime.UtcNow + this.Get <IDateTimeService>().TimeOffset;
                }

                List <SyndicationLink> attachmentLinks = null;

                // if the user doesn't have download access we simply don't show enclosure links.
                if (BoardContext.Current.ForumDownloadAccess)
                {
                    attachmentLinks = this.GetMediaLinks(row.MessageID);
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(string.Empty, row.UserID, null, null));

                syndicationItems.AddSyndicationItem(
                    row.Topic,
                    this.Get <IFormatMessage>().FormatSyndicationMessage(
                        row.Message,
                        new MessageFlags(row.Flags),
                        altItem,
                        4000),
                    null,
                    this.Get <LinkBuilder>().GetLink(
                        ForumPages.Posts,
                        true,
                        "m={0}&name={1}&find=lastpost",
                        row.MessageID,
                        row.Topic),
                    $"urn:{urlAlphaNum}:ft{feedType}:meid{row.MessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    posted,
                    feed,
                    attachmentLinks);

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

            feed.Items = syndicationItems;

            return(feed);
        }
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;
            }
        }
        /// <summary>
        /// method the SyndicationFeed for Favorite topics.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetFavoriteFeed([NotNull] RssFeeds feedType, [NotNull] string lastPostName)
        {
            var syndicationItems = new List <SyndicationItem>();

            System.DateTime toFavDate;

            var toFavText = this.Get <ILocalization>().GetText("MYTOPICS", "LAST_MONTH");

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

            if (this.Get <HttpRequestBase>().QueryString.Exists("d"))
            {
                if (!System.DateTime.TryParse(
                        HttpUtility.UrlDecode(
                            HttpUtility.HtmlDecode(this.Get <HttpRequestBase>().QueryString.GetFirstOrDefault("d"))),
                        out toFavDate))
                {
                    toFavDate = BoardContext.Current.User.Joined /*
                                                                  * ?? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2)*/;
                    toFavText = this.Get <ILocalization>().GetText("MYTOPICS", "SHOW_ALL");
                }
            }
            else
            {
                toFavDate = BoardContext.Current.User
                            .Joined /* ?? DateTimeHelper.SqlDbMinTime() + TimeSpan.FromDays(2)*/;
                toFavText = this.Get <ILocalization>().GetText("MYTOPICS", "SHOW_ALL");
            }

            var list = this.GetRepository <Types.Models.FavoriteTopic>().ListPaged(
                BoardContext.Current.PageUserID,
                toFavDate,
                System.DateTime.UtcNow,
                0,  // page index in db is 1 based!
                20, // set the page size here
                false);

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

            var feed = new FeedItem(
                $"{this.Get<ILocalization>().GetText("MYTOPICS", "FAVORITETOPICS")} - {toFavText}",
                feedType,
                urlAlphaNum);

            list.ForEach(
                t =>
            {
                var lastPosted = t.LastPosted.Value + this.Get <IDateTimeService>().TimeOffset;

                if (syndicationItems.Count <= 0)
                {
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(string.Empty, t.UserID, null, null));
                    feed.LastUpdatedTime = System.DateTime.UtcNow + this.Get <IDateTimeService>().TimeOffset;
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(string.Empty, t.LastUserID.Value, null, null));

                syndicationItems.AddSyndicationItem(
                    t.Subject,
                    this.GetPostLatestContent(
                        this.Get <LinkBuilder>().GetLink(ForumPages.Posts, true, "m={0}#post{0}", t.LastMessageID, t.Subject),
                        lastPostName,
                        lastPostName,
                        t.LastMessageFlags ?? 22,
                        false),
                    null,
                    this.Get <LinkBuilder>().GetLink(ForumPages.Posts, true, "t={0}&name={1}", t.LinkTopicID, t.Subject),
                    $"urn:{urlAlphaNum}:ft{feedType}:span{feedNameAlphaNum}:ltid{t.LinkTopicID}:lmid{t.LastMessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);
            });

            feed.Items = syndicationItems;

            return(feed);
        }
        /// <summary>
        /// The method creates SyndicationFeed for Active topics.
        /// </summary>
        /// <param name="feedType">
        /// The FeedType.
        /// </param>
        /// <param name="lastPostName">
        /// The last post name.
        /// </param>
        /// <returns>
        /// The <see cref="FeedItem"/>.
        /// </returns>
        public FeedItem GetActiveFeed([NotNull] RssFeeds feedType, [NotNull] string lastPostName)
        {
            var syndicationItems = new List <SyndicationItem>();
            var toActDate        = System.DateTime.UtcNow;
            var toActText        = this.Get <ILocalization>().GetText("MYTOPICS", "LAST_MONTH");

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

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

            var urlAlphaNum      = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);
            var feedNameAlphaNum = new Regex(@"[^A-Za-z0-9]", RegexOptions.IgnoreCase).Replace(toActText, string.Empty);
            var feed             = new FeedItem(
                $"{this.Get<ILocalization>().GetText("MYTOPICS", "ACTIVETOPICS")} - {toActText}",
                feedType,
                urlAlphaNum);

            var topics = this.GetRepository <Topic>().ListActivePaged(
                BoardContext.Current.PageUserID,
                toActDate,
                System.DateTime.UtcNow,
                0,  // page index in db which is returned back  is +1 based!
                20, // set the page size here
                this.Get <BoardSettings>().UseReadTrackingByDatabase);

            topics.Where(t => t.TopicMovedID.HasValue).ForEach(
                t =>
            {
                var lastPosted = t.LastPosted.Value + this.Get <IDateTimeService>().TimeOffset;

                if (syndicationItems.Count <= 0)
                {
                    feed.Authors.Add(
                        SyndicationItemExtensions.NewSyndicationPerson(string.Empty, t.UserID, null, null));
                    feed.LastUpdatedTime = System.DateTime.UtcNow + this.Get <IDateTimeService>().TimeOffset;
                }

                feed.Contributors.Add(
                    SyndicationItemExtensions.NewSyndicationPerson(string.Empty, t.LastUserID.Value, null, null));

                var messageLink = this.Get <LinkBuilder>().GetLink(
                    ForumPages.Posts,
                    true,
                    "m={0}&name={1}#post{0}",
                    t.LastMessageID,
                    t.Subject);

                syndicationItems.AddSyndicationItem(
                    t.Subject,
                    this.GetPostLatestContent(
                        messageLink,
                        lastPostName,
                        lastPostName,
                        t.LastMessageFlags ?? 22,
                        false),
                    null,
                    messageLink,
                    $"urn:{urlAlphaNum}:ft{feedNameAlphaNum}:st{feedType}:ltid{t.LinkTopicID}:lmid{t.LastMessageID}:{BoardContext.Current.PageBoardID}"
                    .Unidecode(),
                    lastPosted,
                    feed);
            });

            feed.Items = syndicationItems;

            return(feed);
        }
Beispiel #20
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 #21
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;
            }
        }