Пример #1
0
    /// <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>
    public static void AddSyndicationItem(
      this List<SyndicationItem> currentList, string title, string content, string summary,string link, string id, DateTime posted, YafSyndicationFeed feed, List<SyndicationLink> mlinks)
    {
      var si = new SyndicationItem(
        YafContext.Current.Get<IBadWordReplace>().Replace(title),
        new TextSyndicationContent(YafContext.Current.Get<IBadWordReplace>().Replace(content),TextSyndicationContentKind.Html),
        // Alternate Link
        new Uri(link),
        id,
        new DateTimeOffset(posted)) {PublishDate = new DateTimeOffset(posted)};
      if (mlinks != null)
      {

        foreach (var syndicationLink in mlinks)
        {
          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(YafContext.Current.Get<IBadWordReplace>().Replace(content),
          TextSyndicationContentKind.Html);
      }
      else
      {
        si.Summary = new TextSyndicationContent(YafContext.Current.Get<IBadWordReplace>().Replace(summary),
          TextSyndicationContentKind.Html);  
      }

      

      currentList.Add(si);
    }
Пример #2
0
 /// <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);
 }
Пример #3
0
        /// <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(
                YafContext.Current.Get <IBadWordReplace>().Replace(title),
                new TextSyndicationContent(
                    YafContext.Current.Get <IBadWordReplace>().Replace(content),
                    TextSyndicationContentKind.Html),

                // Alternate Link
                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(
                    YafContext.Current.Get <IBadWordReplace>().Replace(content),
                    TextSyndicationContentKind.Html);
            }
            else
            {
                si.Summary = new TextSyndicationContent(
                    YafContext.Current.Get <IBadWordReplace>().Replace(summary),
                    TextSyndicationContentKind.Html);
            }

            currentList.Add(si);
        }
Пример #4
0
 /// <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>
 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);
 }
Пример #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(
            [NotNull] ref YafSyndicationFeed feed,
            YafRssFeeds feedType,
            bool atomFeedByVar,
            [NotNull] string lastPostIcon,
            [NotNull] string lastPostName)
        {
            var syndicationItems = new List<SyndicationItem>();

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

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

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

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

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

                    altItem = !altItem;
                }

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

            bool showDeleted = false;
            int userId = 0;

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

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

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

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

                var altItem = false;

                string urlAlphaNum = FormatUrlForFeed(BaseUrlBuilder.BaseUrl);

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

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

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

                    List<SyndicationLink> attachementLinks = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            DateTime toFavDate;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                feed.Items = syndicationItems;
            }
        }