Exemplo n.º 1
0
        /// <summary>
        /// 获得帖子列表
        /// </summary>
        /// <param name="count">数量</param>
        /// <param name="views">最小浏览量</param>
        /// <param name="fid">板块ID</param>
        /// <param name="timetype">期限类型,一天、一周、一月、不限制</param>
        /// <param name="ordertype">排序类型,时间倒序、浏览量倒序、最后回复倒序</param>
        /// <param name="isdigest">是否精华</param>
        /// <param name="cachetime">缓存的有效期(单位:分钟)</param>
        /// <returns></returns>
        public static DataTable GetTopicList(ForumHotItemInfo forumHotItemInfo)
        {
            //防止恶意行为
            forumHotItemInfo.Cachetimeout  = forumHotItemInfo.Cachetimeout == 0 ? 1 : forumHotItemInfo.Cachetimeout;
            forumHotItemInfo.Dataitemcount = forumHotItemInfo.Dataitemcount > 50 ? 50 : (forumHotItemInfo.Dataitemcount < 1 ? 1 : forumHotItemInfo.Dataitemcount);

            DataTable dt = new DataTable();

            if (forumHotItemInfo.Cachetimeout > 0)
            {
                dt = DNTCache.GetCacheService().RetrieveObject("/Forum/ForumHostList-" + forumHotItemInfo.Id) as DataTable;
            }

            if (dt == null)
            {
                //如果版块idlist设置为空,则默认读取所有可见板块的idlist
                string forumList      = string.IsNullOrEmpty(forumHotItemInfo.Forumlist) ? Forums.GetVisibleForum() : forumHotItemInfo.Forumlist;
                string orderFieldName = Focuses.GetFieldName((TopicOrderType)Enum.Parse(typeof(TopicOrderType), forumHotItemInfo.Sorttype));

                dt = Discuz.Data.Topics.GetTopicList(forumHotItemInfo.Dataitemcount, -1, 0, "",
                                                     Focuses.GetStartDate((TopicTimeType)Enum.Parse(typeof(TopicTimeType), forumHotItemInfo.Datatimetype)),
                                                     orderFieldName, forumList, orderFieldName == "digest", false);

                if (forumHotItemInfo.Cachetimeout > 0)
                {
                    DNTCache.GetCacheService().AddObject("/Forum/ForumHostList-" + forumHotItemInfo.Id, dt, forumHotItemInfo.Cachetimeout);
                }
            }
            return(dt);
        }
Exemplo n.º 2
0
        /// <summary>获取帖子列表,带缓存</summary>
        /// <param name="inf"></param>
        /// <returns></returns>
        public static EntityList <Topic> GetTopicList(ForumHotItemInfo inf)
        {
            if (inf.Cachetimeout < 60)
            {
                inf.Cachetimeout = 60;
            }
            if (inf.Dataitemcount > 50)
            {
                inf.Dataitemcount = 50;
            }
            else if (inf.Dataitemcount < 1)
            {
                inf.Dataitemcount = 1;
            }

            var list = XCache.Current.RetrieveObject("/Forum/ForumHostList-" + inf.Id) as EntityList <Topic>;

            if (list == null)
            {
                string visibleFidList = string.IsNullOrEmpty(inf.Forumlist) ? Forums.GetVisibleForum() : inf.Forumlist;
                //string fieldName = Focuses.GetFieldName((TopicOrderType)Enum.Parse(typeof(TopicOrderType), inf.Sorttype));
                var type = Focuses.GetStartDate((TopicTimeType)Enum.Parse(typeof(TopicTimeType), inf.Datatimetype));
                list = Topic.GetFocusTopicList(inf.Dataitemcount, -1, 0, "", type, inf.Sorttype, visibleFidList, inf.Sorttype == "digest", false);
                if (inf.Cachetimeout > 0)
                {
                    XCache.Add("/Forum/ForumHostList-" + inf.Id, list, inf.Cachetimeout);
                }
            }
            return(list);
        }
Exemplo n.º 3
0
        public static string HotImagesArray(ForumHotItemInfo fi)
        {
            //string format = "<li><a href=\"{0}\" target=\"_blank\"><img src=\"{1}\" alt=\"{2}\"/></a></li>";
            //string format2 = "<a href=\"#\" rel=\"{0}\">{0}</a>";
            var sb   = new StringBuilder();
            var sb2  = new StringBuilder();
            var thum = (BaseConfigs.GetForumPath + "cache/rotatethumbnail/").EnsureDirectory();

            //string fidlist = string.IsNullOrEmpty(fi.Forumlist) ? Forums.GetVisibleForum() : fi.Forumlist;
            var fidlist = fi.Forumlist;

            if (fidlist.IsNullOrWhiteSpace())
            {
                fidlist = Forums.GetVisibleForum();
            }
            int num = 1;
            // 热点图片
            var list = ForumHots.HotImages(fi.Dataitemcount, fi.Cachetimeout, fi.Sorttype, fi.Id, fidlist, fi.Enabled);

            foreach (var att in list)
            {
                //int topicid = att["tid"].ToInt();
                string filename = (att.FileName + "").Trim();
                string title    = (att.Title + "").Trim();
                title = Utils.JsonCharFilter(title).Replace("'", "\\'");

                string format = "<li><a href=\"{0}\" target=\"_blank\"><img src=\"{1}\" alt=\"{2}\"/></a></li>";
                if (!att.IsLocal)
                {
                    ForumHots.DeleteCacheImageFile();
                    var file = Path.GetFileName(filename);
                    Thumbnail.MakeRemoteThumbnailImage(filename, thum.CombinePath("r_" + file), 360, 240);
                    sb.AppendFormat(format, Urls.ShowTopicAspxRewrite(att.Tid, 0), "cache/rotatethumbnail/r_" + file, title);
                }
                else
                {
                    string file    = att.FullFileName.Replace('\\', '/').Trim();
                    string str     = "cache/rotatethumbnail/r_" + Utils.GetFilename(file);
                    var    newFile = Utils.GetMapPath(BaseConfigs.GetForumPath + str);
                    if (!File.Exists(newFile) && File.Exists(file))
                    {
                        ForumHots.DeleteCacheImageFile();
                        Thumbnail.MakeThumbnailImage(file, newFile, 360, 240);
                    }
                    sb.AppendFormat(format, Urls.ShowTopicAspxRewrite(att.Tid, 0), str, title);
                }
                sb2.AppendFormat("<a href=\"#\" rel=\"{0}\">{0}</a>", num);
                num++;
            }
            return("<div class=\"image_reel\"><ul>" + sb.ToString() + "</ul></div><div class=\"paging\"><span></span>" + sb2.ToString() + "</div>");
        }
Exemplo n.º 4
0
        /// <summary>
        /// 转换热门图片为数组
        /// </summary>
        /// <param name="topNumber">获取的数量</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="cachetime">缓存时间</param>
        /// <returns></returns>
        public static string HotImagesArray(ForumHotItemInfo forumHotItemInfo)
        {
            string        imagesItemTemplate = "<li><a href=\"{0}\" target=\"_blank\"><img src=\"{1}\" alt=\"{2}\"/></a></li>";
            string        imagesPageTemplate = "<a href=\"#\" rel=\"{0}\">{0}</a>";
            StringBuilder hotImagesLi        = new StringBuilder();
            StringBuilder hotImagePage       = new StringBuilder();

            //如果没有缩略图目录,则去生成
            if (!Directory.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/")))
            {
                Utils.CreateDir(Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/"));
            }

            //如果版块idlist设置为空,则默认读取所有可见板块的idlist
            string forumList = string.IsNullOrEmpty(forumHotItemInfo.Forumlist) ? Forums.GetVisibleForum() : forumHotItemInfo.Forumlist;
            int    i         = 1;

            foreach (DataRow dr in HotImages(forumHotItemInfo.Dataitemcount, forumHotItemInfo.Cachetimeout, forumHotItemInfo.Sorttype, forumHotItemInfo.Id, forumList, forumHotItemInfo.Enabled).Rows)
            {
                int    tid      = TypeConverter.ObjectToInt(dr["tid"]);
                string fileName = dr["filename"].ToString().Trim();
                string title    = dr["title"].ToString().Trim();

                title = Utils.JsonCharFilter(title).Replace("'", "\\'");

                if (fileName.StartsWith("http://"))
                {
                    DeleteCacheImageFile();
                    Thumbnail.MakeRemoteThumbnailImage(fileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/r_" + Utils.GetFilename(fileName)), 360, 240);
                    hotImagesLi.AppendFormat(imagesItemTemplate, Urls.ShowTopicAspxRewrite(tid, 0), "cache/rotatethumbnail/r_" + Utils.GetFilename(fileName), title);
                }
                else
                {
                    //图片文件名称
                    string fullFileName = BaseConfigs.GetForumPath + "upload/" + fileName.Replace('\\', '/').Trim();
                    //图片缩略后的名称
                    string thumbnailFileName = "cache/rotatethumbnail/r_" + Utils.GetFilename(fullFileName);

                    if (!File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + thumbnailFileName)) && File.Exists(Utils.GetMapPath(fullFileName)))
                    {
                        DeleteCacheImageFile();
                        Thumbnail.MakeThumbnailImage(Utils.GetMapPath(fullFileName), Utils.GetMapPath(BaseConfigs.GetForumPath + thumbnailFileName), 360, 240);
                    }
                    hotImagesLi.AppendFormat(imagesItemTemplate, Urls.ShowTopicAspxRewrite(tid, 0), "cache/rotatethumbnail/r_" + Utils.GetFilename(fullFileName), title);
                }
                hotImagePage.AppendFormat(imagesPageTemplate, i);
                i++;
            }

            return("<div class=\"image_reel\"><ul>" + hotImagesLi.ToString() + "</ul></div><div class=\"paging\"><span></span>" + hotImagePage.ToString() + "</div>");
        }
Exemplo n.º 5
0
        /// <summary>
        /// 转换热门图片为数组
        /// </summary>
        /// <param name="topNumber">获取的数量</param>
        /// <param name="orderBy">排序方式</param>
        /// <param name="cachetime">缓存时间</param>
        /// <returns></returns>
        public static string HotImagesArray(ForumHotItemInfo forumHotItemInfo)
        {
            string        imagesItemTemplate = "title:\"{0}\",img:\"{1}\",url:\"{2}\"";
            StringBuilder hotImagesArray     = new StringBuilder();

            //如果没有缩略图目录,则去生成
            if (!Directory.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/")))
            {
                Utils.CreateDir(Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/"));
            }

            //如果版块idlist设置为空,则默认读取所有可见板块的idlist
            string forumList = string.IsNullOrEmpty(forumHotItemInfo.Forumlist) ? Forums.GetVisibleForum() : forumHotItemInfo.Forumlist;

            foreach (DataRow dr in HotImages(forumHotItemInfo.Dataitemcount, forumHotItemInfo.Cachetimeout, forumHotItemInfo.Sorttype, forumHotItemInfo.Id, forumList, forumHotItemInfo.Enabled).Rows)
            {
                int    tid      = TypeConverter.ObjectToInt(dr["tid"]);
                string fileName = dr["filename"].ToString().Trim();
                string title    = dr["title"].ToString().Trim();

                title = Utils.JsonCharFilter(title).Replace("'", "\\'");

                if (fileName.StartsWith("http://"))
                {
                    DeleteCacheImageFile();
                    Thumbnail.MakeRemoteThumbnailImage(fileName, Utils.GetMapPath(BaseConfigs.GetForumPath + "cache/rotatethumbnail/r_" + Utils.GetFilename(fileName)), 360, 240);
                    hotImagesArray.Append("{");
                    hotImagesArray.AppendFormat(imagesItemTemplate, title, "cache/rotatethumbnail/r_" + Utils.GetFilename(fileName), Urls.ShowTopicAspxRewrite(tid, 0));
                    hotImagesArray.Append("},");
                    continue;
                }
                //图片文件名称
                string fullFileName = BaseConfigs.GetForumPath + "upload/" + fileName.Replace('\\', '/').Trim();
                //图片缩略后的名称
                string thumbnailFileName = "cache/rotatethumbnail/r_" + Utils.GetFilename(fullFileName);

                if (!File.Exists(Utils.GetMapPath(BaseConfigs.GetForumPath + thumbnailFileName)) && File.Exists(Utils.GetMapPath(fullFileName)))
                {
                    DeleteCacheImageFile();
                    Thumbnail.MakeThumbnailImage(Utils.GetMapPath(fullFileName), Utils.GetMapPath(BaseConfigs.GetForumPath + thumbnailFileName), 360, 240);
                }
                hotImagesArray.Append("{");
                hotImagesArray.AppendFormat(imagesItemTemplate, title, "cache/rotatethumbnail/r_" + Utils.GetFilename(fullFileName), Urls.ShowTopicAspxRewrite(tid, 0));
                hotImagesArray.Append("},");
            }

            return("[" + hotImagesArray.ToString().TrimEnd(',') + "]");
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (action)
            {
            case "setenabled":
                forumHotConfigInfo.Enable = DNTRequest.GetInt("enabled", 0) == 1;
                ForumHotConfigs.SaveConfig(forumHotConfigInfo);
                Response.Redirect("forum_forumhot.aspx");
                break;

            case "edit":
                forumHotItem = forumHotConfigInfo.ForumHotCollection[id - 1];
                break;

            case "editsave":
                //数据来源版块设定范围
                string forumlist = DNTRequest.GetString("forumlist");
                //显示版块名称长度限制
                int forumLength = DNTRequest.GetInt("forumnamelength", 0);
                //显示主题标题长度限制
                int titleLength = DNTRequest.GetInt("topictitlelength", 0);
                //数据来源时间设定范围
                string dataTimeType = DNTRequest.GetString("datatimetype");
                //热点信息类型
                string dataType = DNTRequest.GetString("datatype");
                //热点信息排序类型
                string sortType = DNTRequest.GetString("sorttype");
                //热点信息名称
                string forumHotName = DNTRequest.GetString("forumhotitemname");
                //是否启用
                int enabled = DNTRequest.GetInt("itemenabled", 0);
                //读取最大数据条数
                int dataCount = DNTRequest.GetInt("datacount", 0);
                //数据缓存时间
                int cacheTimeOut = DNTRequest.GetInt("cachetime", 0);

                //限制enabled值在0-1之间
                enabled = enabled < 0 ? 0 : (enabled > 1 ? 1 : enabled);

                cacheTimeOut = cacheTimeOut < 0 ? 1 : cacheTimeOut;


                switch (dataType)
                {
                case "topics":
                    forumLength = forumLength < 0 ? 0 : forumLength;
                    titleLength = titleLength < 0 ? 0 : titleLength;
                    break;

                case "forums":
                    forumlist    = string.Empty;
                    dataTimeType = string.Empty;
                    forumLength  = forumLength < 0 ? 0 : forumLength;
                    titleLength  = 0;
                    break;

                case "users":
                    forumlist   = string.Empty;
                    forumLength = 0;
                    titleLength = 0;
                    //如果此时sortType=posts,另外给它赋值为dataTimeType的值供前台方法调用
                    sortType = sortType == "posts" ? dataTimeType : sortType;
                    break;

                case "pictures":
                    titleLength = titleLength < 0 ? 0 : titleLength;
                    forumLength = 0;
                    break;
                }
                forumHotConfigInfo.ForumHotCollection[id - 1].Name             = forumHotName;
                forumHotConfigInfo.ForumHotCollection[id - 1].Enabled          = enabled;
                forumHotConfigInfo.ForumHotCollection[id - 1].Datatype         = dataType;
                forumHotConfigInfo.ForumHotCollection[id - 1].Sorttype         = sortType;
                forumHotConfigInfo.ForumHotCollection[id - 1].Forumlist        = forumlist;
                forumHotConfigInfo.ForumHotCollection[id - 1].Dataitemcount    = dataCount;
                forumHotConfigInfo.ForumHotCollection[id - 1].Datatimetype     = dataTimeType;
                forumHotConfigInfo.ForumHotCollection[id - 1].Cachetimeout     = cacheTimeOut;
                forumHotConfigInfo.ForumHotCollection[id - 1].Forumnamelength  = forumLength;
                forumHotConfigInfo.ForumHotCollection[id - 1].Topictitlelength = titleLength;

                ForumHotConfigs.SaveConfig(forumHotConfigInfo);
                DNTCache.GetCacheService().RemoveObject("/Forum/ForumHot");
                DNTCache.GetCacheService().RemoveObject("/Forum/ForumHostList-" + id);
                DNTCache.GetCacheService().RemoveObject("/Aggregation/HotForumList" + id);
                DNTCache.GetCacheService().RemoveObject("/Aggregation/Users_" + id + "List");
                DNTCache.GetCacheService().RemoveObject("/Aggregation/HotImages_" + id + "List");
                Response.Redirect("forum_forumhot.aspx");
                break;
            }
        }
Exemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            action = DNTRequest.GetString("action");
            if (action != null)
            {
                var cfg = ForumHotConfigInfo.Current;

                if (action == "setenabled")
                {
                    cfg.Enable = (DNTRequest.GetInt("enabled", 0) == 1);

                    //ForumHotConfigs.SaveConfig(cfg);
                    cfg.Save();
                    base.Response.Redirect("forum_forumhot.aspx");
                    return;
                }
                if (action == "edit")
                {
                    this.forumHotItem = cfg.ForumHotCollection[this.id - 1];
                    return;
                }
                if (action != "editsave")
                {
                    return;
                }

                string forumlist        = Request["forumlist"];
                int    forumnamelength  = DNTRequest.GetInt("forumnamelength", 0);
                int    topictitlelength = DNTRequest.GetInt("topictitlelength", 0);
                forumnamelength  = ((forumnamelength < 0) ? 0 : forumnamelength);
                topictitlelength = ((topictitlelength < 0) ? 0 : topictitlelength);
                string datatimetype     = Request["datatimetype"];
                string datatype         = Request["datatype"];
                string sorttype         = Request["sorttype"];
                string forumhotitemname = Request["forumhotitemname"];
                int    itemenabled      = DNTRequest.GetInt("itemenabled", 0);
                int    datacount        = DNTRequest.GetInt("datacount", 0);
                int    cachetime        = DNTRequest.GetInt("cachetime", 0);
                itemenabled = ((itemenabled < 0) ? 0 : ((itemenabled > 1) ? 1 : itemenabled));
                cachetime   = ((cachetime < 0) ? 1 : cachetime);

                switch (datatype)
                {
                case "topics":
                    //forumlist = string.Empty;
                    //datatimetype = string.Empty;
                    //topictitlelength = 0;
                    break;

                case "forums":
                    break;

                case "users":
                    //forumlist = string.Empty;
                    //forumnamelength = 0;
                    //topictitlelength = 0;
                    sorttype = ((sorttype == "posts") ? datatimetype : sorttype);
                    break;

                case "pictures":
                    //forumnamelength = 0;
                    break;

                default:
                    break;
                }
                var hot = cfg.ForumHotCollection[this.id - 1];
                hot.Name             = forumhotitemname;
                hot.Enabled          = itemenabled;
                hot.Datatype         = datatype;
                hot.Sorttype         = sorttype;
                hot.Forumlist        = forumlist;
                hot.Dataitemcount    = datacount;
                hot.Datatimetype     = datatimetype;
                hot.Cachetimeout     = cachetime;
                hot.Forumnamelength  = forumnamelength;
                hot.Topictitlelength = topictitlelength;
                cfg.Save();

                XCache.Remove("/Forum/ForumHostList-" + this.id);
                XCache.Remove("/Aggregation/HotForumList" + this.id);
                XCache.Remove("/Aggregation/Users_" + this.id + "List");
                XCache.Remove("/Aggregation/HotImages_" + this.id + "List");
                base.Response.Redirect("forum_forumhot.aspx");
            }
        }