1
//------------------------------------------------------------------------------
2
// <copyright company="Tunynet">
3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved.
4
// </copyright>
5
//------------------------------------------------------------------------------
6
7
using System;
8
using System.Collections.Generic;
9
using System.Text;
10
using System.Web.UI.WebControls;
11
using SpaceBuilder.Utils;
12
using SpaceBuilder.Clubs.Components;
13
using SpaceBuilder.Components;
14
using SpaceBuilder.Blogs.Components;
15
using System.Web.UI;
16
using SpaceBuilder.Posts.Components;
17
using SpaceBuilder.Controls;
18
using TunyNet.Data.Utils;
19
using TunyNet.Utils;
20
using System.Web.UI.HtmlControls;
21
22
namespace SpaceBuilder.Blogs.Controls
23
...{
24
public class CommendedBlogThreadListRepeater : Repeater
25
...{
26
SBContext wlContext = SBContext.Current;
27
private PagingDataSet<CommendedPost> pds = null;
28
/**//// <summary>
29
/// 当前Repeater绑定的数据源,用于向外传出
30
/// </summary>
31
public PagingDataSet<CommendedPost> Entities
32
...{
33
get ...{ return pds; }
34
}
35
protected override void OnInit(EventArgs e)
36
...{
37
base.OnInit(e);
38
this.EnableViewState = false;
39
}
40
public void Bind()
41
...{
42
this.ItemDataBound += new RepeaterItemEventHandler(CommendedPostsRepeater_ItemDataBound);
43
44
this.CurrentClub = SpaceBuilder.Clubs.Components.Clubs.GetClub(SBContext.Current.ClubDomainName);
45
if (CurrentClub == null)
46
return;
47
48
if (OnlyShowMyBlogs && SBContext.Current.User.IsAnonymous)
49
...{
50
this.Visible = false;
51
return;
52
}
53
54
CommendedPostQuery query = new CommendedPostQuery();
55
query.ClubID = CurrentClub.ClubID;
56
query.ApplicationType = ApplicationType.Blog;
57
58
if (OnlyShowMyBlogs)
59
query.CommenderUserID = SBContext.Current.User.UserID;
60
61
query.IncludeTags = false;
62
query.PageSize = this.DisplayItemCount;
63
query.IgnorePaging = this.ignorePaging;
64
query.SortBy = this.SortBy;
65
query.SortOrder = this.SortOrder;
66
query.PageIndex = this.pageIndex;
67
68
pds = CommendedPosts.GetCommendedPosts(query);
69
if (pds.Records.Count > 0)
70
...{
71
this.DataSource = this.pds.Records;
72
this.DataBind();
73
}
74
else
75
...{
76
this.DataSource = null;
77
this.DataBind();
78
}
79
}
80
81
82
protected override void OnLoad(EventArgs e)
83
...{
84
base.OnLoad(e);
85
if (this.Page.IsPostBack == false)
86
...{
87
this.Bind();
88
}
89
}
90
91
protected override void Render(HtmlTextWriter writer)
92
...{
93
if (this.pds != null && this.pds.Records.Count > 0)
94
base.Render(writer);
95
}
96
97
事件#region 事件
98
99
protected void CommendedPostsRepeater_ItemDataBound(object Sender, RepeaterItemEventArgs e)
100
...{
101
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
102
...{
103
CommendedPost cp = (CommendedPost)e.Item.DataItem;
104
if (cp != null)
105
...{
106
//如果是私有那么这一条不显示(暂时)——yangmj
107
BlogThread post = BlogPosts.GetThread(cp.PostID, true);
108
if (post == null)
109
...{
110
HtmlContainerControl blogThreadLi = e.Item.FindControl("BlogThreadLi") as HtmlContainerControl;
111
if (blogThreadLi != null)
112
...{
113
blogThreadLi.Visible = false;
114
}
115
return;
116
}
117
118
119
HyperLink subject = e.Item.FindControl("Subject") as HyperLink;
120
if (subject != null)
121
...{
122
subject.Text = StringUtils.Trim(cp.Subject, this.DisplayLength);
123
if (post.BlogPostType == BlogPostType.Article)
124
subject.Text += "[转帖]";
125
else if (post.BlogPostType == BlogPostType.Post)
126
subject.Text += "[原创]";
127
subject.ToolTip = cp.Subject;
128
subject.NavigateUrl = BlogUrls.Instance().ShowPost(post);
129
subject.Attributes["target"] = "_blank";
130
}
131
132
RatingButton ratingButton = e.Item.FindControl("RatingButton") as RatingButton;
133
if (ratingButton != null)
134
...{
135
if (post.EnableRatings)
136
...{
137
ratingButton.Visible = true;
138
ratingButton.TotalRatings = post.TotalRatings;
139
ratingButton.RatingSum = post.RatingSum;
140
ratingButton.ThreadID = post.ThreadID;
141
ratingButton.ApplicationType = ApplicationType.Blog;
142
}
143
else
144
...{
145
ratingButton.Visible = false;
146
}
147
}
148
149
HyperLink author = e.Item.FindControl("Author") as HyperLink;
150
if (author != null)
151
...{
152
author.Text = StringUtils.Trim(cp.Author, 20);
153
author.ToolTip = "查看 " + cp.Author + " 的空间";
154
author.NavigateUrl = UserUrls.Instance().UserChannelHome(cp.AuthorUserID, UserDomainMenuType.Profile);
155
author.Attributes["target"] = "_blank";
156
}
157
158
Literal postDate = e.Item.FindControl("PostDate") as Literal;
159
if (postDate != null)
160
postDate.Text = Formatter.FormatDate(post.PostDate);
161
162
163
Literal body = e.Item.FindControl("Body") as Literal;
164
if (body != null)
165
...{
166
if (post.HasExcerpt)
167
body.Text = post.Excerpt;
168
else
169
body.Text = HtmlUtils.TrimHtml(post.Body, 250);
170
}
171
172
HyperLink readMore = e.Item.FindControl("ReadMoreLink") as HyperLink;
173
if (readMore != null)
174
...{
175
readMore.Visible = true;
176
readMore.NavigateUrl = BlogUrls.Instance().ShowPost(post);
177
readMore.Text = "[阅读全文]";
178
}
179
180
HyperLink comments = e.Item.FindControl("Comments") as HyperLink;
181
if (comments != null)
182
...{
183
comments.NavigateUrl = BlogUrls.Instance().ShowPost(post) + "#comments";
184
}
185
186
Literal replies = e.Item.FindControl("Replies") as Literal;
187
if (replies != null)
188
replies.Text = post.ReplyCount.ToString();
189
190
Literal totalViews = e.Item.FindControl("TotalViews") as Literal;
191
if (totalViews != null)
192
totalViews.Text = post.HitTimes.ToString();
193
194
//Literal tagNames = e.Item.FindControl("TagNames") as Literal;
195
//if (tagNames != null && post.Tags.Count > 0)
196
//{
197
// foreach (ClubTag tag in cp.Tags)
198
// {
199
// tagNames.Text += tag.TagName + ",";
200
// }
201
// if (tagNames.Text.Length > 0)
202
// tagNames.Text = tagNames.Text.TrimEnd(new char[] { ',' });
203
//}
204
205
HyperLink commender = e.Item.FindControl("Commender") as HyperLink;
206
if (commender != null)
207
...{
208
commender.Text = StringUtils.Trim(cp.Commender, 20);
209
commender.ToolTip = "查看 " + cp.Author + " 的空间";
210
commender.NavigateUrl = UserUrls.Instance().UserChannelHome(cp.CommenderUserID, UserDomainMenuType.Profile);
211
commender.Attributes["target"] = "_blank";
212
}
213
214
Literal commendedDate = e.Item.FindControl("CommendedDate") as Literal;
215
if (commendedDate != null)
216
commendedDate.Text = Formatter.FormatDate(cp.CommendedDate);
217
218
}
219
}
220
else if (e.Item.ItemType == ListItemType.Footer)
221
...{
222
HyperLink more = e.Item.FindControl("More") as HyperLink;
223
if (more != null)
224
...{
225
more.Visible = true;
226
if (OnlyShowMyBlogs)
227
more.NavigateUrl = ClubUrls.Instance().MyBlogList(CurrentClub.DomainName);
228
else
229
more.NavigateUrl = ClubUrls.Instance().BlogHome(CurrentClub.DomainName);
230
}
231
}
232
}
233
234
#endregion
235
236
237
属性#region 属性
238
239
private SpaceBuilder.Clubs.Components.Club currentClub = null;
240
public SpaceBuilder.Clubs.Components.Club CurrentClub
241
...{
242
get ...{ return this.currentClub; }
243
set ...{ this.currentClub = value; }
244
}
245
246
/**//// <summary>
247
/// blog标题需要显示的长度
248
/// </summary>
249
private int displayLength = 6;
250
public int DisplayLength
251
...{
252
get ...{ return displayLength; }
253
set ...{ displayLength = value; }
254
}
255
256
private bool onlyShowMyBlogs = false;
257
public bool OnlyShowMyBlogs
258
...{
259
get ...{ return onlyShowMyBlogs; }
260
set ...{ onlyShowMyBlogs = value; }
261
}
262
263
private int pageIndex;
264
public int PageIndex
265
...{
266
get ...{ return pageIndex; }
267
set ...{ pageIndex = value; }
268
}
269
270
private bool ignorePaging = false;
271
public bool IgnorePaging
272
...{
273
get ...{ return ignorePaging; }
274
set ...{ ignorePaging = value; }
275
}
276
277
278
279
private bool isUseURLPara =