PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Discuz/Discuz.Web/UI/ShowTopicsPage.cs

#
C# | 151 lines | 128 code | 20 blank | 3 comment | 23 complexity | ab1513e62239b40d2b8cf92e5e4daa85 MD5 | raw file
  1. using System.Data;
  2. using Discuz.Common;
  3. using Discuz.Forum;
  4. using Discuz.Entity;
  5. using System.Text;
  6. using Discuz.Aggregation;
  7. #if NET1
  8. #else
  9. using Discuz.Common.Generic;
  10. using Discuz.Plugin.Space;
  11. using Discuz.Plugin.Album;
  12. #endif
  13. namespace Discuz.Web.UI
  14. {
  15. /// <summary>
  16. /// RSS页面类
  17. /// </summary>
  18. public class ShowTopicsPage : PageBase
  19. {
  20. SpacePluginBase spb = SpacePluginProvider.GetInstance();
  21. AlbumPluginBase apb = AlbumPluginProvider.GetInstance();
  22. int length = DNTRequest.GetQueryInt("length", -1);
  23. int count = DNTRequest.GetQueryInt("count", 10);
  24. int cachetime = DNTRequest.GetQueryInt("cachetime", 20);
  25. string rooturl = "http://" + DNTRequest.GetCurrentFullHost() + Discuz.Config.BaseConfigs.GetForumPath;
  26. string spacerooturl = "http://" + DNTRequest.GetCurrentFullHost() + Discuz.Config.BaseConfigs.GetForumPath + "space/";
  27. protected void OutPutUpdatedSpaces(string template, string alternatingTemplate)
  28. {
  29. if (spb == null)
  30. {
  31. Response.Write("document.write('未安装空间插件');");
  32. return;
  33. }
  34. StringBuilder result = new StringBuilder();
  35. DataTable dt = Focuses.GetUpdatedSpaces(count, cachetime);
  36. int i = 0;
  37. string title = "";
  38. foreach (DataRow dr in dt.Rows)
  39. {
  40. title = dr["spacetitle"].ToString().Trim();
  41. result.AppendFormat((i%2 == 0 ? template : alternatingTemplate), string.Empty, (length == -1 ? title : Utils.GetSubString(title, length, "")), string.Empty, string.Empty, title, string.Empty, spacerooturl + "?uid=" + dr["userid"].ToString());
  42. i++;
  43. }
  44. Response.Write("document.write('" + result.ToString().Replace("'", "\\'") + "');");
  45. }
  46. protected void OutPutRecommendedSpaces(string template, string alternatingTemplate)
  47. {
  48. if (spb == null)
  49. {
  50. Response.Write("document.write('未安装空间插件');");
  51. return;
  52. }
  53. SpaceConfigInfoExt[] spaces = AggregationFacade.SpaceAggregation.GetSpaceListFromFile("Website");
  54. StringBuilder result = new StringBuilder();
  55. int i = 0;
  56. foreach (SpaceConfigInfoExt space in spaces)
  57. {
  58. if (i >= count)
  59. break;
  60. result.AppendFormat((i % 2 == 0 ? template : alternatingTemplate), string.Empty, (length == -1 ? space.Spacetitle : Utils.GetSubString(space.Spacetitle, length, "")), string.Empty, string.Empty, space.Spacetitle, string.Empty, spacerooturl + "?uid=" + space.Userid.ToString());
  61. i++;
  62. }
  63. Response.Write("document.write('" + result.ToString().Replace("'", "\\'") + "');");
  64. }
  65. protected void OutPutNewSpacePosts(string template, string alternatingTemplate)
  66. {
  67. if (spb == null)
  68. {
  69. Response.Write("document.write('未安装空间插件');");
  70. return;
  71. }
  72. StringBuilder result = new StringBuilder();
  73. DataTable dt = Focuses.GetNewSpacePosts(count, cachetime);
  74. int i = 0;
  75. string title = "";
  76. foreach (DataRow dr in dt.Rows)
  77. {
  78. title = dr["title"].ToString().Trim();
  79. result.AppendFormat((i % 2 == 0 ? template : alternatingTemplate), string.Empty, (length == -1 ? title : Utils.GetSubString(title, length, "")), string.Empty, string.Empty, title, string.Empty, spacerooturl + "?uid=" + dr["uid"].ToString(), spacerooturl + "viewspacepost.aspx?postid=" + dr["postid"].ToString());
  80. i++;
  81. }
  82. Response.Write("document.write('" + result.ToString().Replace("'", "\\'") + "');");
  83. }
  84. protected void OutPutRecommendedSpacePosts(string template, string alternatingTemplate)
  85. {
  86. if (spb == null)
  87. {
  88. Response.Write("document.write('未安装空间插件');");
  89. return;
  90. }
  91. StringBuilder result = new StringBuilder();
  92. SpaceShortPostInfo[] posts = AggregationFacade.SpaceAggregation.GetSpacePostList("Website");
  93. int i = 0;
  94. string title = "";
  95. foreach (SpaceShortPostInfo post in posts)
  96. {
  97. if (i > count)
  98. break;
  99. title = post.Title;
  100. result.AppendFormat((i % 2 == 0 ? template : alternatingTemplate), string.Empty, (length == -1 ? title : Utils.GetSubString(title, length, "")), string.Empty, string.Empty, title, string.Empty, spacerooturl + "?uid=" + post.Uid.ToString(), spacerooturl + "viewspacepost.aspx?postid=" + post.Postid.ToString());
  101. i++;
  102. }
  103. Response.Write("document.write('" + result.ToString().Replace("'", "\\'") + "');");
  104. }
  105. protected void OutPutRecommendedAlbum(string template, string alternatingTemplate)
  106. {
  107. if (apb == null)
  108. {
  109. Response.Write("document.write('未安装相册插件');");
  110. return;
  111. }
  112. StringBuilder result = new StringBuilder();
  113. #if NET1
  114. AlbumInfoCollection albums = AggregationFacade.AlbumAggregation.GetRecommandAlbumList("Website");
  115. #else
  116. List<AlbumInfo> albums = AggregationFacade.AlbumAggregation.GetRecommandAlbumList("Website");
  117. #endif
  118. int i = 0;
  119. string title = "";
  120. foreach (AlbumInfo album in albums)
  121. {
  122. if (i > count)
  123. break;
  124. title = album.Title;
  125. result.AppendFormat((i % 2 == 0 ? template : alternatingTemplate), string.Empty, (length == -1 ? title : Utils.GetSubString(title, length, "")), string.Empty, string.Empty, title, string.Empty, spacerooturl + "?uid=" + album.Userid.ToString(), string.Empty, rooturl + "showalbum.aspx?albumid=" + album.Albumid.ToString());
  126. i++;
  127. }
  128. Response.Write("document.write('" + result.ToString().Replace("'", "\\'") + "');");
  129. }
  130. }
  131. }