Example #1
0
        /// <summary>
        /// 获得论坛最新的20个主题的Rss描述
        /// </summary>
        /// <param name="ttl">TTL数值</param>
        /// <returns>Rss描述</returns>
        public static string GetRssXml(int ttl)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string rssContent = cache.RetrieveObject("/Forum/RSS/Index") as string;

            if (rssContent == null)
            {
                UserGroupInfo guestinfo = UserGroups.GetUserGroupInfo(7);
                StringBuilder forumlist = new StringBuilder();//允许访问的板块Id列表

                foreach (ForumInfo f in Forums.GetForumList())
                {
                    //当前版块允许rss订阅
                    if (f.Allowrss == 1)
                    {
                        //板块有权限设置信息时
                        if (!Utils.StrIsNullOrEmpty(f.Viewperm))
                        {
                            if (Utils.InArray("7", f.Viewperm, ","))
                                forumlist.AppendFormat(",{0}", f.Fid);
                        }
                        else
                        {
                            if (guestinfo.Allowvisit == 1)
                                forumlist.AppendFormat(",{0}", f.Fid);
                        }
                    }

                    //if (f.Allowrss == 0)
                    //    forumlist.AppendFormat(",{0}", f.Fid);
                    //else
                    //{
                    //    //板块权限设置为空,按照用户组权限走,RSS仅检查游客权限
                    //    if (Utils.StrIsNullOrEmpty(f.Viewperm))
                    //    {
                    //        if (guestinfo.Allowvisit == 0)
                    //            forumlist.AppendFormat(",{0}", f.Fid);
                    //    }
                    //    else
                    //    {
                    //        if (!Utils.InArray("7", f.Viewperm, ","))
                    //            forumlist.AppendFormat(",{0}", f.Fid);
                    //    }
                    //}
                }
                rssContent = Discuz.Data.Feeds.BuildRssOutput(ttl, forumlist.ToString().Trim(','), "");

                //声明新的缓存策略接口
                Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
                ics.TimeOut = ttl * 60;
                cache.LoadCacheStrategy(ics);
                cache.AddObject("/Forum/RSS/Index", rssContent);
                cache.LoadDefaultCacheStrategy();
            }
            return rssContent;
        }
Example #2
0
        /// <summary>
        /// 获得在线用户总数量
        /// </summary>
        /// <returns>用户数量</returns>
        public static int GetOnlineAllUserCount()
        {
            int onlineUserCountCacheMinute = GeneralConfigs.GetConfig().OnlineUserCountCacheMinute;
            if (onlineUserCountCacheMinute == 0)
                return Discuz.Data.OnlineUsers.GetOnlineAllUserCount();

            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            int onlineAllUserCount = TypeConverter.ObjectToInt(cache.RetrieveObject("/Forum/OnlineUserCount"));
            if (onlineAllUserCount != 0)
                return onlineAllUserCount;

            onlineAllUserCount = Discuz.Data.OnlineUsers.GetOnlineAllUserCount();
            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = onlineUserCountCacheMinute * 60;
            cache.LoadCacheStrategy(ics);
            cache.AddObject("/Forum/OnlineUserCount", onlineAllUserCount);
            cache.LoadDefaultCacheStrategy();
            return onlineAllUserCount;
        }
Example #3
0
        /// <summary>
        /// 获得日志的RSS
        /// </summary>
        /// <param name="ttl">Time To Live</param>
        /// <param name="uid">用户id</param>
        /// <returns></returns>
        public static string GetBlogAggRss(int ttl)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            string str = cache.RetrieveObject("/SPACE/RSS/Index") as string;
            if (str != null)
            {
                return str;
            }

            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + BaseConfigs.GetForumPath.ToLower();
            DataTable dt = Data.DbProvider.GetInstance().GetWebSiteAggSpacePostsList(20, 1);
            if (dt == null || dt.Rows.Count < 1)
            {
                return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified blog not found</Rss>\r\n";
            }
            StringBuilder rssBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
            rssBuilder.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            rssBuilder.Append("<rss version=\"2.0\">\r\n");
            rssBuilder.Append("  <channel>\r\n");
            rssBuilder.Append("    <title>");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append(" - ");
            rssBuilder.Append("最新空间日志");
            rssBuilder.Append("</title>\r\n");
            rssBuilder.Append("    <link>");
            rssBuilder.Append(forumurl);
            rssBuilder.Append("spaceindex.aspx");
            rssBuilder.Append("</link>\r\n");
            rssBuilder.AppendFormat("    <description>Latest {0} blogs</description>\r\n", dt.Rows.Count);
            rssBuilder.Append("    <copyright>Copyright (c) ");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append("</copyright>\r\n");
            rssBuilder.Append("    <generator>");
            rssBuilder.Append("Discuz!NT");
            rssBuilder.Append("</generator>\r\n");
            rssBuilder.Append("    <pubDate>");
            rssBuilder.Append(DateTime.Now.ToString("r"));
            rssBuilder.Append("</pubDate>\r\n");
            rssBuilder.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());
            foreach (DataRow dr in dt.Rows)
            {
                rssBuilder.Append("    <item>\r\n");
                rssBuilder.Append("      <title>");
                rssBuilder.Append(Utils.HtmlEncode(dr["title"].ToString().Trim()));
                rssBuilder.Append("</title>\r\n");
                rssBuilder.Append("      <description><![CDATA[");
                rssBuilder.Append(Utils.HtmlEncode(Utils.GetSubString(Utils.RemoveHtml(dr["content"].ToString()), 200, "......")));
                rssBuilder.Append("]]></description>\r\n");
                rssBuilder.Append("      <link>");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append("space/viewspacepost.aspx?postid=");
                rssBuilder.Append(dr["postid"].ToString());
                rssBuilder.Append("</link>\r\n");
                rssBuilder.Append("      <category>");
                rssBuilder.Append(Utils.HtmlEncode(dr["category"].ToString()));
                rssBuilder.Append("</category>\r\n");
                rssBuilder.Append("      <author>");
                rssBuilder.Append(Utils.HtmlEncode(dr["author"].ToString().Trim()));
                rssBuilder.Append("</author>\r\n");
                rssBuilder.Append("      <pubDate>");
                rssBuilder.Append(Utils.HtmlEncode(Convert.ToDateTime(dr["postdatetime"]).ToString("r").Trim()));
                rssBuilder.Append("</pubDate>\r\n");
                rssBuilder.Append("    </item>\r\n");
            }
            rssBuilder.Append("  </channel>\r\n");
            rssBuilder.Append("</rss>");

            cache.AddObject("/SPACE/RSS/Index", rssBuilder.ToString());
            cache.LoadDefaultCacheStrategy();

            return rssBuilder.ToString();
        }
Example #4
0
        /// <summary>
        /// 获得指定用户日志的RSS
        /// </summary>
        /// <param name="ttl">Time To Live</param>
        /// <param name="uid">用户id</param>
        /// <returns></returns>
        public static string GetBlogRss(int ttl, int uid)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            string str = cache.RetrieveObject("/SPACE/RSS/Blog" + uid) as string;
            if (str != null)
                return str;

            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + BaseConfigs.GetForumPath.ToLower();
            ShortUserInfo user = Users.GetShortUserInfo(uid);
            if (user == null || user.Uid < 1 || user.Uid != uid)
            {
                return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified user not found</Rss>\r\n";
            }
            SpacePostInfo[] posts = BlogProvider.GetSpacepostsInfo(Space.Data.DbProvider.GetInstance().SpacePostsList(20, 1, uid, 1));
            if (posts == null || posts.Length < 1)
            {
                return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified user's blog is not found</Rss>\r\n";
            }
            StringBuilder rssBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
            rssBuilder.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            rssBuilder.Append("<rss version=\"2.0\">\r\n");
            rssBuilder.Append("  <channel>\r\n");
            rssBuilder.Append("    <title>");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append(" - ");
            rssBuilder.Append(user.Username);
            rssBuilder.Append("的个人空间");
            rssBuilder.Append("</title>\r\n");
            rssBuilder.Append("    <link>");
            rssBuilder.Append(forumurl);
            rssBuilder.Append("space/?uid=");
            rssBuilder.Append(uid.ToString());
            rssBuilder.Append("</link>\r\n");
            rssBuilder.AppendFormat("    <description>Latest {0} blogs</description>\r\n", posts.Length);
            rssBuilder.Append("    <copyright>Copyright (c) ");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append("</copyright>\r\n");
            rssBuilder.Append("    <generator>");
            rssBuilder.Append("Discuz!NT");
            rssBuilder.Append("</generator>\r\n");
            rssBuilder.Append("    <pubDate>");
            rssBuilder.Append(DateTime.Now.ToString("r"));
            rssBuilder.Append("</pubDate>\r\n");
            rssBuilder.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());
            foreach (SpacePostInfo post in posts)
            {
                rssBuilder.Append("    <item>\r\n");
                rssBuilder.Append("      <title>");
                rssBuilder.Append(Utils.HtmlEncode(post.Title.ToString().Trim()));
                rssBuilder.Append("</title>\r\n");
                rssBuilder.Append("      <description><![CDATA[");
                rssBuilder.Append(Utils.HtmlEncode(Utils.GetSubString(Utils.RemoveHtml(post.Content), 200, "......")));
                rssBuilder.Append("]]></description>\r\n");
                rssBuilder.Append("      <link>");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append("space/viewspacepost.aspx?postid=");
                rssBuilder.Append(post.Postid.ToString());
                rssBuilder.Append("</link>\r\n");
                rssBuilder.Append("      <category>");
                rssBuilder.Append(Utils.HtmlEncode(post.Category));
                rssBuilder.Append("</category>\r\n");
                rssBuilder.Append("      <author>");
                rssBuilder.Append(Utils.HtmlEncode(post.Author.ToString().Trim()));
                rssBuilder.Append("</author>\r\n");
                rssBuilder.Append("      <pubDate>");
                rssBuilder.Append(Utils.HtmlEncode(post.Postdatetime.ToString("r").Trim()));
                rssBuilder.Append("</pubDate>\r\n");
                rssBuilder.Append("    </item>\r\n");
            }
            rssBuilder.Append("  </channel>\r\n");
            rssBuilder.Append("</rss>");

            cache.AddObject("/SPACE/RSS/Blog" + uid, rssBuilder.ToString());
            cache.LoadDefaultCacheStrategy();

            return rssBuilder.ToString();
        }
Example #5
0
		/// <summary>
		/// 获得论坛最新的20个主题的Rss描述
		/// </summary>
		/// <param name="ttl">TTL数值</param>
		/// <returns>Rss描述</returns>
		public static string GetRssXml(int ttl)
		{
		
			Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

			string str = cache.RetrieveObject("/RSS/Index") as string;
			if (str != null)
			{
				return str;
			}
			ForumInfo[] forumlist = Forums.GetForumList();
			UserGroupInfo guestinfo = UserGroups.GetUserGroupInfo(7);
			StringBuilder sbforumlist = new StringBuilder();//不允许游客访问的板块Id列表
			StringBuilder sbRss = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");

			foreach (ForumInfo f in forumlist)
			{
				if (f.Allowrss == 0)
				{
					sbforumlist.AppendFormat(",{0}", f.Fid);
				}
				else
				{
					if (f.Viewperm == null || f.Viewperm == string.Empty)
					{
						//板块权限设置为空,按照用户组权限走,RSS仅检查游客权限
						if (guestinfo.Allowvisit == 0)
						{
							sbforumlist.AppendFormat(",{0}", f.Fid);
						}
					}
					else
					{
						if (!Utils.InArray("7", f.Viewperm, ","))
						{
							sbforumlist.AppendFormat(",{0}", f.Fid);
						}
					}
				}
			}

			if (sbforumlist.Length > 0)
				sbforumlist.Remove(0,1);
            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + ("/").ToLower();		
            	
			sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
			sbRss.Append("<rss version=\"2.0\">\r\n");
			sbRss.Append("  <channel>\r\n");
			sbRss.Append("    <title>");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
			sbRss.Append("</title>\r\n");
			sbRss.Append("    <link>");
			sbRss.Append(forumurl);
			sbRss.Append("</link>\r\n");
			sbRss.Append("    <description>Latest 20 threads</description>\r\n");
			sbRss.Append("    <copyright>Copyright (c) ");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
			sbRss.Append("</copyright>\r\n");
			sbRss.Append("    <generator>");
			sbRss.Append("Discuz!NT");
			sbRss.Append("</generator>\r\n");
			sbRss.Append("    <pubDate>");
			//sbRss.Append(DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"));
			sbRss.Append(DateTime.Now.ToString("r"));
			sbRss.Append("</pubDate>\r\n");
			sbRss.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());


            //声明新的缓存策略接口
            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            IDataReader reader = DatabaseProvider.GetInstance().GetNewTopics(sbforumlist.ToString());
			
			if (reader != null)
			{
				while (reader.Read())
				{
					sbRss.Append("    <item>\r\n");
					sbRss.Append("      <title>");
					sbRss.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
					sbRss.Append("</title>\r\n");
					sbRss.Append("    <description><![CDATA[");
					if (reader["message"].ToString().IndexOf("[hide]") > -1)
						sbRss.Append("***内容隐藏***");
					else
						sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(UBB.ClearUBB(reader["message"].ToString()), 200, "......")));
					sbRss.Append("]]></description>\r\n");
					sbRss.Append("      <link>");
					sbRss.Append(Utils.HtmlEncode(forumurl));

                    if (config.Aspxrewrite == 1)
                    {
                        sbRss.Append("showtopic-");
                        sbRss.Append(reader["tid"].ToString());
                        sbRss.Append(config.Extname);
                    }
                    else 
                    {
                        sbRss.Append("showtopic.aspx?topicid=");
                        sbRss.Append(reader["tid"].ToString());
                    }
                    
					sbRss.Append("</link>\r\n");
					sbRss.Append("      <category>");
					sbRss.Append(Utils.HtmlEncode(reader["name"].ToString().Trim()));
					sbRss.Append("</category>\r\n");
					sbRss.Append("      <author>");
					sbRss.Append(Utils.HtmlEncode(reader["poster"].ToString().Trim()));
					sbRss.Append("</author>\r\n");
					sbRss.Append("      <pubDate>");
					sbRss.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim()));
					sbRss.Append("</pubDate>\r\n");
					sbRss.Append("    </item>\r\n");
				}
				reader.Close();
			}
			else
			{
				sbRss.Length = 0;
				sbRss.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
				sbRss.Append("<Rss>Error</Rss>\r\n");
				cache.AddObject("/RSS/Index", sbRss.ToString());
				cache.LoadDefaultCacheStrategy();
				return sbRss.ToString();
			}
			

			sbRss.Append("  </channel>\r\n");
			sbRss.Append("</rss>");

			cache.AddObject("/RSS/Index", sbRss.ToString());
			cache.LoadDefaultCacheStrategy();
		
			return sbRss.ToString();
		}
Example #6
0
		/// <summary>
		/// 获得指定版块最新的20个主题的Rss描述
		/// </summary>
		/// <param name="ttl">TTL数值</param>
		/// <param name="fid">版块id</param>
		/// <returns>Rss描述</returns>
		public static string GetForumRssXml(int ttl, int fid)
		{
			Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

			string str = cache.RetrieveObject("/RSS/Forum" + fid) as string;
			if(str != null)
			{
				return str;
			}

            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + ("/").ToLower();//GeneralConfigs.GetConfig().Forumurl;
            //if (!forumurl.EndsWith("/"))
            //{
            //    forumurl = forumurl + "/";
            //}
			ForumInfo forum = Forums.GetForumInfo(fid);
			if (forum == null)
			{
				
				return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified forum not found</Rss>\r\n";
			}

			if (forum.Viewperm == null || forum.Viewperm == string.Empty)
			{
				//板块权限设置为空,按照用户组权限走,RSS仅检查游客权限
				UserGroupInfo guestinfo = UserGroups.GetUserGroupInfo(7);
				if (guestinfo.Allowvisit == 0)
				{
					return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n";
				}
			}
			else
			{
				if (!Utils.InArray("7", forum.Viewperm, ","))
				{
					return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n";
				}
				
			}
			StringBuilder sbRss = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
			sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
			sbRss.Append("<rss version=\"2.0\">\r\n");
			sbRss.Append("  <channel>\r\n");
			sbRss.Append("    <title>");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
			sbRss.Append(" - ");
			sbRss.Append(Utils.HtmlEncode(forum.Name));
			sbRss.Append("</title>\r\n");
			sbRss.Append("    <link>");
			sbRss.Append(forumurl);

            if (config.Aspxrewrite == 1)
            {
                sbRss.Append("showforum-");
                sbRss.Append(fid.ToString());
                sbRss.Append(config.Extname);
            }
            else
            {
                sbRss.Append("showforum.aspx?forumid=");
                sbRss.Append(fid.ToString());
            }

			sbRss.Append("</link>\r\n");
			sbRss.Append("    <description>Latest 20 threads</description>\r\n");
			sbRss.Append("    <copyright>Copyright (c) ");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
			sbRss.Append("</copyright>\r\n");
			sbRss.Append("    <generator>");
			sbRss.Append("Discuz!NT");
			sbRss.Append("</generator>\r\n");
			sbRss.Append("    <pubDate>");
			//sbRss.Append(DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"));
			sbRss.Append(DateTime.Now.ToString("r"));
			sbRss.Append("</pubDate>\r\n");
			sbRss.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());

            IDataReader reader = DatabaseProvider.GetInstance().GetForumNewTopics(fid);
			if (reader != null)
			{
				while (reader.Read())
				{
					sbRss.Append("    <item>\r\n");
					sbRss.Append("      <title>");
					sbRss.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
					sbRss.Append("</title>\r\n");
                    sbRss.Append("      <description><![CDATA[");
					if (reader["message"].ToString().IndexOf("[hide]") > -1)
						sbRss.Append("***内容隐藏***");
					else
						sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(UBB.ClearUBB(reader["message"].ToString()), 200, "......")));
					sbRss.Append("]]></description>\r\n");
					sbRss.Append("      <link>");
					sbRss.Append(Utils.HtmlEncode(forumurl));

                    if (config.Aspxrewrite == 1)
                    {
                        sbRss.Append("showtopic-");
                        sbRss.Append(reader["tid"].ToString());
                        sbRss.Append(config.Extname);
                    }
                    else
                    {
                        sbRss.Append("showtopic.aspx?topicid=");
                        sbRss.Append(reader["tid"].ToString());
                    }

					sbRss.Append("</link>\r\n");
					sbRss.Append("      <category>");
					sbRss.Append(Utils.HtmlEncode(forum.Name));
					sbRss.Append("</category>\r\n");
					sbRss.Append("      <author>");
					sbRss.Append(Utils.HtmlEncode(reader["poster"].ToString().Trim()));
					sbRss.Append("</author>\r\n");
					sbRss.Append("      <pubDate>");
					sbRss.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim()));
					sbRss.Append("</pubDate>\r\n");
					sbRss.Append("    </item>\r\n");
				}
				reader.Close();
			}
			sbRss.Append("  </channel>\r\n");
			sbRss.Append("</rss>");


            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);
			cache.AddObject("/RSS/Forum" + fid, sbRss.ToString());
			cache.LoadDefaultCacheStrategy();
		
			return sbRss.ToString();
		}
Example #7
0
        /// <summary>
        /// 获得指定版块最新的20个主题的Rss描述
        /// </summary>
        /// <param name="ttl">TTL数值</param>
        /// <param name="fid">版块id</param>
        /// <returns>Rss描述</returns>
        public static string GetForumRssXml(int ttl, int fid)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();
            string rssContent = cache.RetrieveObject("/Forum/RSS/Forum" + fid) as string;

            if (rssContent == null)
            {
                ForumInfo forum = Forums.GetForumInfo(fid);
                if (forum == null)
                    return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified forum not found</Rss>\r\n";

                //板块d有权限设置,按照用户组权限走,RSS仅检查游客权限
                if (!Utils.StrIsNullOrEmpty(forum.Viewperm) && !Utils.InArray("7", forum.Viewperm, ","))
                    return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n";
                else if (UserGroups.GetUserGroupInfo(7).Allowvisit == 0)
                    return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n";

                rssContent = Discuz.Data.Feeds.BuildRssOutput(ttl, fid.ToString(), forum.Name);
                Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
                ics.TimeOut = ttl * 60;
                cache.LoadCacheStrategy(ics);
                cache.AddObject("/Forum/RSS/Forum" + fid, rssContent);
                cache.LoadDefaultCacheStrategy();
            }
            return rssContent;
        }
Example #8
0
        /// <summary>
        /// 获得图片的RSS
        /// </summary>
        /// <param name="ttl">Time To Live</param>
        /// <returns></returns>
        public static string GetPhotoRss(int ttl)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            string str = cache.RetrieveObject("/PHOTO/RSS/Index") as string;
            if (str != null)
                return str;

            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + BaseConfigs.GetForumPath.ToLower();
            IDataReader reader = DbProvider.GetInstance().GetFocusPhotoList(2, 20, 100);
            if (reader == null)
                return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified photos not found</Rss>\r\n";

            StringBuilder rssBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
            rssBuilder.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            rssBuilder.Append("<rss version=\"2.0\">\r\n");
            rssBuilder.Append("  <channel>\r\n");
            rssBuilder.Append("    <title>");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append(" - ");
            rssBuilder.Append("最新照片");
            rssBuilder.Append("</title>\r\n");
            rssBuilder.Append("    <link>");
            rssBuilder.Append(forumurl);
            rssBuilder.Append("spaceindex.aspx");
            rssBuilder.Append("</link>\r\n");
            rssBuilder.AppendFormat("    <description>Latest 20 photos</description>\r\n");
            rssBuilder.Append("    <copyright>Copyright (c) ");
            rssBuilder.Append(Utils.HtmlEncode(GeneralConfigs.GetConfig().Forumtitle));
            rssBuilder.Append("</copyright>\r\n");
            rssBuilder.Append("    <generator>");
            rssBuilder.Append("Discuz!NT");
            rssBuilder.Append("</generator>\r\n");
            rssBuilder.Append("    <pubDate>");
            rssBuilder.Append(DateTime.Now.ToString("r"));
            rssBuilder.Append("</pubDate>\r\n");
            rssBuilder.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());
            while (reader.Read())
            {
                rssBuilder.Append("    <item>\r\n");
                rssBuilder.Append("      <title>");
                rssBuilder.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
                rssBuilder.Append("</title>\r\n");
                rssBuilder.Append("      <description><![CDATA[<img src=\"");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append(reader["filename"].ToString().Trim());
                rssBuilder.Append("\"/>]]></description>\r\n");
                rssBuilder.Append("      <link>");
                rssBuilder.Append(Utils.HtmlEncode(forumurl));
                rssBuilder.Append("showphoto.aspx?photoid=");
                rssBuilder.Append(reader["photoid"].ToString());
                rssBuilder.Append("</link>\r\n");
                rssBuilder.Append("      <category>");
                rssBuilder.Append("</category>\r\n");
                rssBuilder.Append("      <author>");
                rssBuilder.Append(Utils.HtmlEncode(reader["username"].ToString().Trim()));
                rssBuilder.Append("</author>\r\n");
                rssBuilder.Append("      <pubDate>");
                rssBuilder.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdate"]).ToString("r").Trim()));
                rssBuilder.Append("</pubDate>\r\n");
                rssBuilder.Append("    </item>\r\n");
            }
            reader.Close();
            rssBuilder.Append("  </channel>\r\n");
            rssBuilder.Append("</rss>");

            cache.AddObject("/PHOTO/RSS/Index", rssBuilder.ToString());
            cache.LoadDefaultCacheStrategy();

            return rssBuilder.ToString();
        }
Example #9
0
        /// <summary>
        /// 获得论坛最新的20个主题的Rss描述
        /// </summary>
        /// <param name="ttl">TTL数值</param>
        /// <returns>Rss描述</returns>
        public static string GetRssXml(int ttl)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            string str = cache.RetrieveObject("/RSS/Index") as string;

            if (str != null)
            {
                return(str);
            }
            ForumInfo[]   forumlist   = Forums.GetForumList();
            UserGroupInfo guestinfo   = UserGroups.GetUserGroupInfo(7);
            StringBuilder sbforumlist = new StringBuilder();            //不允许游客访问的板块Id列表
            StringBuilder sbRss       = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");

            foreach (ForumInfo f in forumlist)
            {
                if (f.Allowrss == 0)
                {
                    sbforumlist.AppendFormat(",{0}", f.Fid);
                }
                else
                {
                    if (f.Viewperm == null || f.Viewperm == string.Empty)
                    {
                        //板块权限设置为空,按照用户组权限走,RSS仅检查游客权限
                        if (guestinfo.Allowvisit == 0)
                        {
                            sbforumlist.AppendFormat(",{0}", f.Fid);
                        }
                    }
                    else
                    {
                        if (!Utils.InArray("7", f.Viewperm, ","))
                        {
                            sbforumlist.AppendFormat(",{0}", f.Fid);
                        }
                    }
                }
            }

            if (sbforumlist.Length > 0)
            {
                sbforumlist.Remove(0, 1);
            }
            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + ("/").ToLower();

            sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            sbRss.Append("<rss version=\"2.0\">\r\n");
            sbRss.Append("  <channel>\r\n");
            sbRss.Append("    <title>");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
            sbRss.Append("</title>\r\n");
            sbRss.Append("    <link>");
            sbRss.Append(forumurl);
            sbRss.Append("</link>\r\n");
            sbRss.Append("    <description>Latest 20 threads</description>\r\n");
            sbRss.Append("    <copyright>Copyright (c) ");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
            sbRss.Append("</copyright>\r\n");
            sbRss.Append("    <generator>");
            sbRss.Append("Discuz!NT");
            sbRss.Append("</generator>\r\n");
            sbRss.Append("    <pubDate>");
            //sbRss.Append(DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"));
            sbRss.Append(DateTime.Now.ToString("r"));
            sbRss.Append("</pubDate>\r\n");
            sbRss.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());


            //声明新的缓存策略接口
            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);

            IDataReader reader = DatabaseProvider.GetInstance().GetNewTopics(sbforumlist.ToString());

            if (reader != null)
            {
                while (reader.Read())
                {
                    sbRss.Append("    <item>\r\n");
                    sbRss.Append("      <title>");
                    sbRss.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
                    sbRss.Append("</title>\r\n");
                    sbRss.Append("    <description><![CDATA[");
                    if (reader["message"].ToString().IndexOf("[hide]") > -1)
                    {
                        sbRss.Append("***内容隐藏***");
                    }
                    else
                    {
                        sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(UBB.ClearUBB(reader["message"].ToString()), 200, "......")));
                    }
                    sbRss.Append("]]></description>\r\n");
                    sbRss.Append("      <link>");
                    sbRss.Append(Utils.HtmlEncode(forumurl));

                    if (config.Aspxrewrite == 1)
                    {
                        sbRss.Append("showtopic-");
                        sbRss.Append(reader["tid"].ToString());
                        sbRss.Append(config.Extname);
                    }
                    else
                    {
                        sbRss.Append("showtopic.aspx?topicid=");
                        sbRss.Append(reader["tid"].ToString());
                    }

                    sbRss.Append("</link>\r\n");
                    sbRss.Append("      <category>");
                    sbRss.Append(Utils.HtmlEncode(reader["name"].ToString().Trim()));
                    sbRss.Append("</category>\r\n");
                    sbRss.Append("      <author>");
                    sbRss.Append(Utils.HtmlEncode(reader["poster"].ToString().Trim()));
                    sbRss.Append("</author>\r\n");
                    sbRss.Append("      <pubDate>");
                    sbRss.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim()));
                    sbRss.Append("</pubDate>\r\n");
                    sbRss.Append("    </item>\r\n");
                }
                reader.Close();
            }
            else
            {
                sbRss.Length = 0;
                sbRss.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
                sbRss.Append("<Rss>Error</Rss>\r\n");
                cache.AddObject("/RSS/Index", sbRss.ToString());
                cache.LoadDefaultCacheStrategy();
                return(sbRss.ToString());
            }


            sbRss.Append("  </channel>\r\n");
            sbRss.Append("</rss>");

            cache.AddObject("/RSS/Index", sbRss.ToString());
            cache.LoadDefaultCacheStrategy();

            return(sbRss.ToString());
        }
Example #10
0
        /// <summary>
        /// 获得指定版块最新的20个主题的Rss描述
        /// </summary>
        /// <param name="ttl">TTL数值</param>
        /// <param name="fid">版块id</param>
        /// <returns>Rss描述</returns>
        public static string GetForumRssXml(int ttl, int fid)
        {
            Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService();

            string str = cache.RetrieveObject("/RSS/Forum" + fid) as string;

            if (str != null)
            {
                return(str);
            }

            string forumurl = "http://" + DNTRequest.GetCurrentFullHost() + ("/").ToLower();//GeneralConfigs.GetConfig().Forumurl;
            //if (!forumurl.EndsWith("/"))
            //{
            //    forumurl = forumurl + "/";
            //}
            ForumInfo forum = Forums.GetForumInfo(fid);

            if (forum == null)
            {
                return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Specified forum not found</Rss>\r\n");
            }

            if (forum.Viewperm == null || forum.Viewperm == string.Empty)
            {
                //板块权限设置为空,按照用户组权限走,RSS仅检查游客权限
                UserGroupInfo guestinfo = UserGroups.GetUserGroupInfo(7);
                if (guestinfo.Allowvisit == 0)
                {
                    return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n");
                }
            }
            else
            {
                if (!Utils.InArray("7", forum.Viewperm, ","))
                {
                    return("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<Rss>Guest Denied</Rss>\r\n");
                }
            }
            StringBuilder sbRss = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");

            sbRss.Append("<?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\" media=\"screen\"?>\r\n");
            sbRss.Append("<rss version=\"2.0\">\r\n");
            sbRss.Append("  <channel>\r\n");
            sbRss.Append("    <title>");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
            sbRss.Append(" - ");
            sbRss.Append(Utils.HtmlEncode(forum.Name));
            sbRss.Append("</title>\r\n");
            sbRss.Append("    <link>");
            sbRss.Append(forumurl);

            if (config.Aspxrewrite == 1)
            {
                sbRss.Append("showforum-");
                sbRss.Append(fid.ToString());
                sbRss.Append(config.Extname);
            }
            else
            {
                sbRss.Append("showforum.aspx?forumid=");
                sbRss.Append(fid.ToString());
            }

            sbRss.Append("</link>\r\n");
            sbRss.Append("    <description>Latest 20 threads</description>\r\n");
            sbRss.Append("    <copyright>Copyright (c) ");
            sbRss.Append(Utils.HtmlEncode(config.Forumtitle));
            sbRss.Append("</copyright>\r\n");
            sbRss.Append("    <generator>");
            sbRss.Append("Discuz!NT");
            sbRss.Append("</generator>\r\n");
            sbRss.Append("    <pubDate>");
            //sbRss.Append(DateTime.Now.ToUniversalTime().ToString("ddd, dd MMM yyyy HH':'mm':'ss 'GMT'"));
            sbRss.Append(DateTime.Now.ToString("r"));
            sbRss.Append("</pubDate>\r\n");
            sbRss.AppendFormat("    <ttl>{0}</ttl>\r\n", ttl.ToString());

            IDataReader reader = DatabaseProvider.GetInstance().GetForumNewTopics(fid);

            if (reader != null)
            {
                while (reader.Read())
                {
                    sbRss.Append("    <item>\r\n");
                    sbRss.Append("      <title>");
                    sbRss.Append(Utils.HtmlEncode(reader["title"].ToString().Trim()));
                    sbRss.Append("</title>\r\n");
                    sbRss.Append("      <description><![CDATA[");
                    if (reader["message"].ToString().IndexOf("[hide]") > -1)
                    {
                        sbRss.Append("***内容隐藏***");
                    }
                    else
                    {
                        sbRss.Append(Utils.HtmlEncode(Utils.GetSubString(UBB.ClearUBB(reader["message"].ToString()), 200, "......")));
                    }
                    sbRss.Append("]]></description>\r\n");
                    sbRss.Append("      <link>");
                    sbRss.Append(Utils.HtmlEncode(forumurl));

                    if (config.Aspxrewrite == 1)
                    {
                        sbRss.Append("showtopic-");
                        sbRss.Append(reader["tid"].ToString());
                        sbRss.Append(config.Extname);
                    }
                    else
                    {
                        sbRss.Append("showtopic.aspx?topicid=");
                        sbRss.Append(reader["tid"].ToString());
                    }

                    sbRss.Append("</link>\r\n");
                    sbRss.Append("      <category>");
                    sbRss.Append(Utils.HtmlEncode(forum.Name));
                    sbRss.Append("</category>\r\n");
                    sbRss.Append("      <author>");
                    sbRss.Append(Utils.HtmlEncode(reader["poster"].ToString().Trim()));
                    sbRss.Append("</author>\r\n");
                    sbRss.Append("      <pubDate>");
                    sbRss.Append(Utils.HtmlEncode(Convert.ToDateTime(reader["postdatetime"]).ToString("r").Trim()));
                    sbRss.Append("</pubDate>\r\n");
                    sbRss.Append("    </item>\r\n");
                }
                reader.Close();
            }
            sbRss.Append("  </channel>\r\n");
            sbRss.Append("</rss>");


            Discuz.Cache.ICacheStrategy ics = new RssCacheStrategy();
            ics.TimeOut = ttl;
            cache.LoadCacheStrategy(ics);
            cache.AddObject("/RSS/Forum" + fid, sbRss.ToString());
            cache.LoadDefaultCacheStrategy();

            return(sbRss.ToString());
        }