温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:SpaceBuilder v1.0正式版源码
当前文件:
SpaceBuiderV10Source/BlogControls/Views/EntryView.cs,打开代码结构图
SpaceBuiderV10Source/BlogControls/Views/EntryView.cs,打开代码结构图1//------------------------------------------------------------------------------ 2
// <copyright company="Tunynet"> 3
// Copyright (c) Tunynet Network Technology Co., Ltd. All rights reserved. 4
// </copyright> 5
//------------------------------------------------------------------------------ 6
7
using SpaceBuilder.Blogs.Components; 8
using SpaceBuilder.Components; 9
using System.Web.UI.WebControls; 10
using System; 11
using SpaceBuilder.Controls; 12
using TunyNet.Utils; 13
using SpaceBuilder.Posts.Components; 14
using SpaceBuilder.Configuration; 15
using SpaceBuilder.Controls.Utils; 16
using System.Web.UI.HtmlControls; 17
using SpaceBuilder.Posts.Permissions; 18
namespace SpaceBuilder.Blogs.Controls 19
{ 20
/// <summary> 21
/// Summary description for EntryView. 22
/// </summary> 23
public class EntryView : WeblogThemedControl 24
{ 25
private HyperLink entryTitle = null; 26
private Literal blogPostType; 27
private Literal entryBody = null; 28
//private DownloadAttachmentLink downloadAttachmentLink; 29
30
private Literal tags; 31
private Literal entryDesc = null; 32
private HyperLink authorLink = null; 33
//private RatingImageButton ratings = null; 34
private RatingButton ratingButton = null; 35
36
private ModalLink commendToMyClubButton; 37
private HyperLink editLink = null; 38
//private HtmlContainerControl editBlock; 39
40
private ModalLink commendItemButton; 41
42
private StatusMessage statusMessage; 43
private StatusMessage blogThreadStatusMessage; 44
45
private EntryComments comments = null; 46
private CommentForm commentForm = null; 47
48
private HtmlGenericControl entryViewBlock; 49
50
SBContext wlContext = SBContext.Current; 51
52
protected override void AttachChildControls() 53
{ 54
entryTitle = FindControl("EntryTitle") as HyperLink; 55
blogPostType = FindControl("BlogPostType") as Literal; 56
57
entryBody = FindControl("EntryBody") as Literal; 58
59
tags = FindControl("Tags") as Literal; 60
entryDesc = FindControl("EntryDesc") as Literal; 61
authorLink = FindControl("AuthorLink") as HyperLink; 62
//ratings = FindControl("Ratings") as RatingImageButton; 63
ratingButton = FindControl("RatingButton") as RatingButton; 64
65
commendToMyClubButton = FindControl("CommendToMyClubButton") as ModalLink; 66
editLink = FindControl("EditLink") as HyperLink; 67
//editBlock = FindControl("EditBlock") as HtmlContainerControl; 68
69
commendItemButton = FindControl("CommendItemButton") as ModalLink; 70
71
statusMessage = FindControl("StatusMessage") as StatusMessage; 72
blogThreadStatusMessage = FindControl("BlogThreadStatusMessage") as StatusMessage; 73
74
comments = FindControl("Comments") as EntryComments; 75
commentForm = FindControl("CommentForm") as CommentForm; 76
entryViewBlock = FindControl("EntryViewBlock") as HtmlGenericControl; 77
//Bind(); 78
} 79
80
protected override void OnLoad(EventArgs e) 81
{ 82
EnsureChildControls(); 83
base.OnLoad(e); 84
Bind(); 85
if (!Page.IsPostBack) 86
{ 87
博客文章及博客的计数 91
92
TrackbackMarkUp tb = new TrackbackMarkUp(); 93
tb.Title = CurrentPost.Subject; 94
tb.PermaLink = BlogUrls.Instance().ShowPost(CurrentPost, CurrentWeblog); 95
tb.PingUrl = BlogUrls.Instance().TrackbackPingUrl(CurrentPost.PostID); 96
this.Controls.Add(tb); 97
} 98
} 99
100
private void Bind() 101
{ 102
this.CurrentPost = BlogPosts.GetThread(wlContext.PostID, false, true, false); 103
if (this.CurrentPost == null) 104
{ 105
throw new SBException(SBExceptionType.ResourceNotFound, string.Format("Blog {0} is not found!",wlContext.PostID)); 106
} 107
if (IsUserDomainOwner || this.CurrentPost.IsPublic || wlContext.User.IsBlogAdministrator) 108
{ 109
if (CurrentPost != null) 110
{ 111
//make sure we only render posts where they are supposed to be 112
if (CurrentPost.SectionID == CurrentWeblog.SectionID && CurrentPost.PostDate < DateTime.Now) 113
{ 114
//entryTitle.Text =StringUtils.Trim(CurrentPost.Subject,30); 115
entryTitle.Text = CurrentPost.Subject; 116
entryTitle.ToolTip = CurrentPost.Subject; 117
entryTitle.NavigateUrl = BlogUrls.Instance().ShowPost(CurrentPost, CurrentWeblog); 118
119
if (blogPostType != null) 120
{ 121
switch (CurrentPost.BlogPostType) 122
{ 123
case BlogPostType.Post: 124
blogPostType.Text += "[原创]"; 125
break; 126
case BlogPostType.Article: 127
blogPostType.Text += "[转帖]"; 128
break; 129
} 130
} 131
132
entryBody.Text = CurrentPost.Body; 133
134
if (tags != null) 135
{ 136
if (this.CurrentPost.Tags.Count > 0) 137
{ 138
tags.Text = "标签:"; 139
foreach (UserTag tag in CurrentPost.Tags) 140
{ 141
tags.Text += string.Format("<a href='{0}' title='该用户在此标签下还有{1}篇文章'>{2}</a> ", GlobalUrls.Instance().ShowBlogPostsByTag(CurrentDomainUser.UserName, tag.TagName), tag.ItemCount, tag.TagName); 142
} 143
} 144
} 145
146
if (IsUserDomainOwner && !this.CurrentPost.IsPublic) 147
{ 148
Image notPublicImage = FindControl("NotPublicImage") as Image; 149
if (notPublicImage != null) 150
{ 151
notPublicImage.Visible = true; 152
notPublicImage.ToolTip = "此文章未公开"; 153
} 154
} 155
156
entryDesc.Text = string.Format("发布于" + " {0}", CurrentPost.PostDate.ToString("f")); 157
158
HyperLink commentsLink = FindControl("CommentsLink") as HyperLink; 159
HyperLink doCommnentHyperLink = FindControl("DoCommentHyperLink") as HyperLink; 160
Literal doCommentLiteral = FindControl("DoCommentLiteral") as Literal; 161
if (commentsLink != null) 162
{ 163
//if ((CurrentWeblog.EnableComments && !CurrentPost.IsLocked) || CurrentPost.ReplyCount > 0) 164
if (CurrentWeblog.EnableComments && CurrentPost.ReplyCount >= 0) 165
{ 166
commentsLink.Text = string.Format("评论({0})", CurrentPost.ReplyCount); //string.Format(ResourceManager.GetString("Weblog_EntryList_Comments"), CurrentPost.ReplyCount); 167
commentsLink.NavigateUrl = BlogUrls.Instance().ShowPost(CurrentPost, CurrentWeblog) + "#comments"; 168
169
if (!CurrentPost.IsLocked) 170
{ 171
if (doCommnentHyperLink != null) 172
{ 173
doCommnentHyperLink.NavigateUrl = BlogUrls.Instance().ShowPost(CurrentPost, CurrentWeblog) + "#comment"; 174
doCommnentHyperLink.Visible = true; 175
} 176
} 177
else 178
{ 179
//commentsLink.Text = string.Format("评论关闭(已有{0}评论)", CurrentPost.ReplyCount); 180
if (doCommentLiteral != null) 181
{ 182
doCommentLiteral.Visible = true; 183
} 184
} 185
} 186
else 187
{ 188
commentsLink.Visible = false; 189
commentsLink.EnableViewState = false; 190
} 191
} 192
193
Literal totalViews = FindControl("TotalViews") as Literal; 194
if (totalViews != null) 195
totalViews.Text = string.Format("点击({0})", CurrentPost.HitTimes); 196
197
if (CurrentPost.EnableRatings) 198
{ 199
ratingButton.Visible = true; 200
ratingButton.TotalRatings = CurrentPost.TotalRatings; 201
ratingButton.RatingSum = CurrentPost.RatingSum; 202
ratingButton.ThreadID = CurrentPost.ThreadID; 203
ratingButton.ApplicationType = ApplicationType.Blog; 204
//ratingButton.Rating = CurrentPost.ThreadRating; 205
} 206
else 207
{ 208
ratingButton.Visible = false; 209
ratingButton.EnableViewState = false; 210
} 211
212
if (authorLink != null) 213
{ 214
authorLink.Text = CurrentPost.Author; 215
authorLink.NavigateUrl = UserUrls.Instance().UserChannelHome(CurrentPost.UserID, UserDomainMenuType.Profile); 216
} 217
} 218
else 219
{ 220
Context.Response.StatusCode = 404; 221
Context.Response.SuppressContent = true; 222
Context.Response.End(); 223
} 224
} 225
226
if (comments != null) 227
{ 228
comments.PostID = wlContext.PostID; 229
230
if (this.CurrentPost != null) 231
{ 232
BlogThread we = this.CurrentPost; 233
234
if (CurrentWeblog.EnableComments && !we.IsLocked) 235
{ 236
commentForm.DataSource = we; 237
commentForm.DataBind(); 238
} 239
else 240
{ 241
commentForm.Visible = false; 242
commentForm.EnableViewState = false; 243
} 244
245
this.SetPageTitle(we.Subject); 246
247
Referral r = new Referral(); 248
r.SectionID = we.SectionID; 249
r.PostID = we.PostID; 250
Referrals.AddToQueue(Context, CurrentWeblog.ReferralFilter, r); 251
} 252
} 253
254
if (CurrentPost != null) 255
{ 256
bool enableComments = CurrentWeblog.EnableNewComments(CurrentUser); 257
258
if (SBContext.Current.User.IsAnonymous || !CurrentPost.IsPublic || !SBConfiguration.Instance().EnableClub) 259
{ 260
commendToMyClubButton.Visible = false; 261
commendToMyClubButton.EnableViewState = false; 262
} 263
else 264
commendToMyClubButton.Url = ChannelUrls.Instance().CommendPostToClub(ApplicationType.Blog, CurrentPost.PostID); 265
266
if (Permissions.ValidatePermissions(this.CurrentWeblog, Permission.Post, this.CurrentUser)) 267
{ 268
editLink.NavigateUrl = BlogUrls.Instance().PostEditor(this.CurrentWeblog.ApplicationKey, CurrentPost.PostID); 269
editLink.Text = ResourceManager.GetString("Edit"); 270
editLink.ToolTip = "修改该文章"; 271
editLink.Visible = true; 272
} 273
else 274
{ 275
editLink.Visible = false; 276
editLink.EnableViewState = false; 277
//editBlock.Visible = false; 278
} 279
280
if (CurrentPost.IsPublic && CurrentUser.IsBlogAdministrator) 281
{ 282
commendItemButton.Visible = true; 283
commendItemButton.Url = GlobalUrls.Instance().CreateCommendedItem(CommendType.BlogPost, CurrentPost.PostID); 284
} 285
} 286
else 287
{ 288
this.Controls.Clear(); 289
this.Visible = false; 290
this.EnableViewState = false; 291
} 292
293
//commentForm.Bind(); 294
}




