showtopics.aspx
上传用户:wenllgg125
上传日期:2020-04-09
资源大小:7277k
文件大小:10k
源码类别:

SCSI/ASPI

开发平台:

Others

  1. <%@ Page Language="C#" AutoEventWireup="true" Inherits="Discuz.Web.UI.ShowTopicsPage" %>
  2. <%@ Import Namespace="Discuz.Forum" %>
  3. <%@ Import Namespace="Discuz.Common" %>
  4. <%@ Import Namespace="Discuz.Common.Generic" %>
  5. <%@ Import Namespace="System.Web.UI.WebControls" %>
  6. <%@ Import Namespace="System.Data" %>
  7. <%@ Import Namespace="Discuz.Entity" %>
  8. <script runat="server">
  9.     
  10.     /*  模板代码开始 在此调整样式 请注意备份.
  11. {0}代表帖子ID, 
  12. {1}代表标题, 
  13. {2}代表帖子所属论坛ID, 
  14. {3}代表帖子所属论坛名称 , 
  15. {4}代表帖子未截字的完整标题,双引号用"表示,建议使用单引号 , 
  16. {5}代表图片缩*unicef略图路径(从根路径开始输出,设置type参数为1(正方形)或2(原比例)或onlyimg参数为1时有效),
  17. {6}代表当前Space完整Url,
  18. {7}代表当前Space日志完整Url,
  19. {8}代表当前相册完整Url,
  20. {9}代表当前版块的Url重写名称
  21. {10}代表当前帖子的Url
  22.     {11}代表站点根地址
  23.     {12}代表主题分类
  24. */
  25.     public string[] Templates = {
  26. /*模板0 奇数行模板*/ "<p>[<a href="{11}{9}" title="{4}">{3}</a>]{12} <a href="{11}{10}" title="{4}">{1}</a></p>",
  27. /*模板1 奇数行模板*/ "<li>·<a href="{11}{10}" title="{4}">{1}</a></li>",
  28. /*模板2 奇数行图片调用模板*/ "<img src="{5}" title="{4}" />",
  29. /*模板3 奇数行个人空间模板*/ "<a href="{6}" title="{4}">{1}</a>",
  30. /*模板4 奇数行个人日志模板*/ "<a href="{7}" title="{4}">{1}</a>",
  31. /*模板5 奇数行相册模板*/ "<a href="{8}" title="{4}">{1}</a>",
  32. /*模板6 奇数行推荐日志模板*/ "<li>·<a href="{7}" title="{4}">{1}</a></li>"
  33. };
  34.     public string[] AlternatingTemplates = {
  35. /*模板0 偶数行模板*/ "<p style="background-color: #ffffcc;">[<a href="{11}{9}" title="{4}">{3}</a>]{12} <a href="{11}{10}" title="{4}">{1}</a></p>",
  36. /*模板1 偶数行模板*/ "<li>·<a href="{11}{10}" title="{4}"><b>{1}</b></a></li>",
  37. /*模板2 偶数行图片调用模板*/ "<img src="{5}" title="{4}" />",
  38. /*模板3 偶数行个人空间模板*/ "<a href="{6}" title="{4}">{1}</a>",
  39. /*模板4 偶数行个人日志模板*/ "<a href="{7}" title="{4}">{1}</a>",
  40. /*模板5 偶数行相册模板*/ "<a href="{8}" title="{4}">{1}</a>",
  41. /*模板6 偶数行推荐日志模板*/ "<li>·<a href="{7}" title="{4}">{1}</a></li>"
  42. };
  43.     public string TypeNameTemplate = "<a href="{2}showforum.aspx?forumid={3}&typeid={1}">[{0}]</a>";
  44.     /*在主题有主题分类的情况下,分类名称的显示样式模板 */
  45.     public string AggregationTemplate ="<li><span><a href="{11}{9}" target="_blank">[{3}]</a></span><a href="{11}{10}" target="_blank" title="{4}">{1}</a></li>";
  46.     /* 模板代码结束 */
  47.     override protected void OnInit(EventArgs e)
  48.     {
  49.         int count = DNTRequest.GetQueryInt("count", 10);
  50.         int views = DNTRequest.GetQueryInt("views", -1);
  51.         int fid = DNTRequest.GetQueryInt("fid", 0);
  52.         int tType = DNTRequest.GetQueryInt("time", 0);
  53.         int oType = DNTRequest.GetQueryInt("order", 0);
  54.         bool isDigest = DNTRequest.GetQueryInt("digest", 0) == 1;
  55.         int mid = DNTRequest.GetQueryInt("template", 0);
  56.         int cachetime = DNTRequest.GetQueryInt("cachetime", 20);
  57.         bool onlyimg = DNTRequest.GetQueryInt("onlyimg", 0) == 1;
  58.         string agg = DNTRequest.GetQueryString("agg");
  59.         string typeIdList = DNTRequest.GetQueryString("typeidlist");
  60.         try
  61.         {
  62.             if (Request.QueryString["encoding"] != null)
  63.                 Response.ContentEncoding = System.Text.Encoding.GetEncoding(Request.QueryString["encoding"]);
  64.             string template = Templates[mid];
  65.             string alternatingTemplate = AlternatingTemplates[mid];
  66.             TopicTimeType timeType = ConvertTimeType(tType);
  67.             TopicOrderType orderType = ConvertOrderType(oType);
  68.             /*  
  69.             Focuss.GetTopicList(count, views, fid, timetype, ordertype, isdigest, timespan, onlyimg)方法说明
  70.             <summary>
  71.             获得帖子列表
  72.             </summary>
  73.             <param name="count">最大数量</param>
  74.             <param name="views">最小浏览量, -1为不限制</param>
  75.             <param name="fid">板块ID,0为全部板块</param>
  76.             <param name="timetype">期限类型,1为一天(TopicTimeType.Day)、2为一周(TopicTimeType.Week)、3为一月(TopicTimeType.Month)、0为不限制(TopicTimeType.All)</param>
  77.             <param name="ordertype">排序类型(倒序): 0为id(TopicOrderType.ID)、1为访问量倒序(TopicOrderType.Views)、2为最后回复排序(TopicOrderType.LastPost)、3为最新主题(PostDateTime)、5为回复数(Replies)、6为评分数</param>
  78.             <param name="isdigest">是否精华</param>
  79.             <param name="timespan">缓存时间</param>
  80.             <param name="onlyimg">是否只为图片</param>
  81.             <param name="agg">空间,日志或相册调用:1为更新的个人空间;2推荐的个人空间;3最新日志;4推荐日志;5推荐相册。</param>
  82.             <returns></returns>
  83.             */
  84.             switch (agg)
  85.             {
  86.                 case "1":
  87.                 case "updatedspace":
  88.                     OutPutUpdatedSpaces(template, alternatingTemplate);
  89.                     break;
  90.                 case "2":
  91.                 case "recommendedspace":
  92.                     OutPutRecommendedSpaces(template, alternatingTemplate);
  93.                     break;
  94.                 case "3":
  95.                 case "newspacepost":
  96.                     OutPutNewSpacePosts(template, alternatingTemplate);
  97.                     break;
  98.                 case "4":
  99.                 case "recommendedspacepost":
  100.                     OutPutRecommendedSpacePosts(template, alternatingTemplate);
  101.                     break;
  102.                 case "5":
  103.                 case "recommendedalbum":
  104.                     OutPutRecommendedAlbum(template, alternatingTemplate);
  105.                     break;
  106.                 default:
  107.                     DataTable dt = Focuses.GetTopicList(count, views, fid, typeIdList, timeType, orderType, isDigest, cachetime, onlyimg);
  108.                     OutPut(dt, template, alternatingTemplate);
  109.                     break;
  110.             }
  111.         }
  112.         catch
  113.         {
  114.             Response.Write("document.write('参数错误,请检查!');");
  115.         }
  116.         finally
  117.         {
  118.             Response.End();
  119.         }
  120.         base.OnInit(e);
  121.     }
  122.     private void OutPut(DataTable dt, string template, string alternatingTemplate)
  123.     {
  124.         string result = "";
  125.         int length = DNTRequest.GetQueryInt("length", -1);
  126.         int contentType = DNTRequest.GetQueryInt("type", 0);
  127.         int imgMaxSize = DNTRequest.GetQueryInt("imgsize", 80);
  128.         bool onlyimg = DNTRequest.GetQueryInt("onlyimg", 0) == 1;
  129.         SortedList<int, string> topicTypeList = Caches.GetTopicTypeArray();
  130.         int aggregation = DNTRequest.GetQueryInt("aggregation", 0);
  131.         int i = 0;
  132.         foreach (DataRow dr in dt.Rows)
  133.         {
  134.             int tid = Utils.StrToInt(dr["tid"], 0);
  135.             ForumInfo forum = Forums.GetForumInfo(Convert.ToInt32(dr["fid"]));
  136.             string title = dr["title"].ToString().Trim();
  137.             string thumbnail = "";
  138.             string topicTypeName;
  139.             topicTypeList.TryGetValue(TypeConverter.ObjectToInt(dr["typeid"]), out topicTypeName);
  140.             if (!string.IsNullOrEmpty(topicTypeName))
  141.                 topicTypeName = string.Format(TypeNameTemplate, topicTypeName, dr["typeid"].ToString(), rootUrl, dr["fid"].ToString());
  142.             if (contentType == 1 || contentType == 2 || onlyimg)
  143.             {
  144.                 thumbnail = Attachments.GetThumbnailByTid(tid, imgMaxSize, ConvertThumbnailType(contentType));
  145.             }
  146.             if (aggregation == 0)
  147.             result += string.Format((i % 2 == 0 ? template : alternatingTemplate), dr["tid"].ToString(), (length == -1 ? title : Utils.GetUnicodeSubString(title, length, "")), forum.Fid, forum.Name, title, thumbnail, "", "", "", Urls.ShowForumAspxRewrite(forum.Fid, 0, forum.Rewritename), Urls.ShowTopicAspxRewrite(tid, 0), rootUrl, topicTypeName);
  148.             else
  149.             result += string.Format(AggregationTemplate, dr["tid"].ToString(), (length == -1 ? title : Utils.GetUnicodeSubString(title, length, "")), forum.Fid, forum.Name, title, thumbnail, "", "", "", Urls.ShowForumAspxRewrite(forum.Fid, 0, forum.Rewritename), Urls.ShowTopicAspxRewrite(tid, 0), rootUrl, topicTypeName);
  150.    
  151.             i++;
  152.         }
  153.         Response.Write("document.write('" + result.Replace("'", "\'") + "');");
  154.     }
  155.     private TopicOrderType ConvertOrderType(int t)
  156.     {
  157.         switch (t)
  158.         {
  159.             case (int)TopicOrderType.Views:
  160.                 return TopicOrderType.Views;
  161.             case (int)TopicOrderType.LastPost:
  162.                 return TopicOrderType.LastPost;
  163.             case (int)TopicOrderType.PostDateTime:
  164.                 return TopicOrderType.PostDateTime;
  165.             case (int)TopicOrderType.Replies:
  166.                 return TopicOrderType.Replies;
  167.             case (int)TopicOrderType.Rate:
  168.                 return TopicOrderType.Rate;
  169.             default: return TopicOrderType.ID;
  170.         }
  171.     }
  172.     private ThumbnailType ConvertThumbnailType(int t)
  173.     {
  174.         switch (t)
  175.         {
  176.             case (int)ThumbnailType.Square:
  177.                 return ThumbnailType.Square;
  178.             case (int)ThumbnailType.Thumbnail:
  179.                 return ThumbnailType.Thumbnail;
  180.             default: return ThumbnailType.Square;
  181.         }
  182.     }
  183.     private TopicTimeType ConvertTimeType(int t)
  184.     {
  185.         return (TopicTimeType)(Enum.Parse(typeof(TopicTimeType), t.ToString()));
  186.     }
  187. </script>