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