It's been a while since I contributed to the CS Queensryche Series. This post picks up where SiteUrls - The Needle Lies ends, discussing the splendid process of Url creation in Community Server, specifically the Comment Permalink Url.
I realized recently that my DBVT skins (based on the CS default skins) do not contain a Name anchor for permalinks to individual comments. Other themes like Gertrude have them, and I'll be adding them to Skin DBVT soon. Urls to individual comments are important, I think. But that got me thinking about the process of creating Comment Permalinks, and happened to coincide with the fact that for fun I was looking into a glitch with Blog Comment Urls generated in the User Profile Recent Posts list reported recently in Community Server Forums.
So we're going to look at how Comment Urls are generated in the User Profile Recent Posts list to get the Url Formatting Revolution started. CS.Components.SearchBarrel.WeblogBarrelItem formats the retrieved search results for recent user weblog posts. We can populate the basics from IndexPost (used with SearchBarrel), but need to pass the WeblogPost.BlogPostType and .ParentID properties to create the Url.
COMMUNITYSERVER.COMPONENTS.SEARCHBARREL.WEBLOGBARRELITEM
public override void Format(IndexPost post)
{
WeblogPost wp = new WeblogPost();
wp.PostID = post.PostID;
wp.Name = post.Name;
wp.UserTime = post.PostDate;
wp.SectionID = post.SectionID;
// DBVT Modified - Obtain the post's BlogPostType and ParentID to format blog comment
WeblogPost _wp = WeblogPosts.GetWeblogEntry(wp.SectionID, wp.PostID);
wp.BlogPostType = _wp.BlogPostType;
wp.ParentID = _wp.ParentID;
// END
// DBVT Modified - Create comment URL
if (wp.BlogPostType == BlogPostType.Comment)
post.Url = BlogUrls.Instance().Post(wp, wp.Weblog, _wp);
else
post.Url = BlogUrls.Instance().Post(wp);
post.ApplicationUrl = BlogUrls.Instance().Home;
}
Now for some of that sweet CS Url formatting action. Notice we're calling an overloaded method of Post(). It String.Formats() the Name Anchor from the results of Post(WeblogPost, Weblog) and the comment (or child) postID.
COMMUNITYSERVER.BLOGS.COMPONENTS.BLOGURLS
public virtual string Post(WeblogPost parent, Weblog weblog, WeblogPost child)
{
return string.Format("{0}#{1}",Post(parent,weblog),child.PostID);
}
public virtual string Post(WeblogPost post, Weblog weblog)
{
.......
// DBVT Modified to create Comment URL. Using post.ParentID in URL
else if (post.BlogPostType == BlogPostType.Comment)
{
return FormatUrl("weblogpostId", weblog.ApplicationKey, post.UserTime.Year,
post.UserTime.Month.ToString("00"), post.UserTime.Day.ToString("00"), post.ParentID);
}
// END
else
{
......
}
}
Now we'll let the FormatUrl() method take us home to momma. This ApplicationUrls.FormatUrl() method works in conjunction with the SiteUrlsData provider, which if you recall from The Needle Lies, reads in all of the SiteUrls.config path syntax information, passing a NameValueCollection of parameter values and our Url "name" value, which is "weblogpostId," and constructs the url.
parameters
{Dimensions:[5]}
[0]: "henry"
[1]: 2006
[2]: "09"
[3]: "13"
[4]: 2
COMMUNITYSERVER.COMPONENTS.APPLICATIONURLS
protected string FormatUrl(string name, params object[] parameters)
{
return Globals.GetSiteUrls().UrlData.FormatUrl(name, parameters);
}
COMMUNITYSERVER.COMPONENTS.SITEURLSDATA
public virtual string FormatUrl(string name, params object[] parameters)
{
if(parameters == null)
return this.Paths[name];
else
return string.Format(Paths[name],parameters);
}
/// <summary>
/// Property Paths (NameValueCollection)
/// </summary>
public NameValueCollection Paths
{
get { return this._paths; }
}
Community Server Url Formatting Revolution Calling.
More on the CS Queensryche Series when able. Today's episode theme song: Revolution Calling.
[Queensryche]