Making Community Server BIGGER
My aim is to make Community Server bigger than Dozing Dogs by, hmmmm, I'd like to say Sept 1st (my 1 year anniversary at Telligent) but that's probably too optimistic. How about November 1st.
I'm talking about my tags of course.
Not surprisingly, my Dozing Dogs tag is winning by over 50 extra entries today; I've been babbling away about DD since I started building the product and the business back on Day 1 in August 2004.
In many ways, I'm back to square one, just like two years ago.
Although I'm in my 11th month here, I only started using CS about a month ago. That probably makes me more of a newbie than you!
Luckily I'm old enough not to mind looking stupid, so of course I'll post all my mistakes and silly questions right here. Occasionally someone will come along that will make use of them, and at the same time make me feel smug about not being the biggest n00b on the block. Maybe.
So let me pick one thing out of the hat that I did recently, so you can all tell me how there was an easy, built-in way to do it already. But first, I have to make an admission.
I run ads on this site, and lucky for youme, in my feed too.
Just be grateful they don't ask me to make them blink. Because I would you know.
So, how do I do that? No, remember I don't know about the easy way to do it. I gave the CS Team a break and stopped asking questions thay day (I bet they didn't even notice. I tell you, they are so ungrateful sometimes; if they only knew the questions I could ask)
So, I wrote a CSModule. Grand sounding, ain't it? It's huge, it is. Well, truth be told, actually it isn't:
public class CMSTokensModule : ICSModule
{
public void Init(CSApplication csa, XmlNode node)
{
csa.PreRenderPost +=new CSPostEventHandler(csa_PreRenderPost);
}
private void csa_PreRenderPost(IContent content, CSPostEventArgs e)
{
foreach (TextPart tp in e.TextParts)
if (tp.Name == "include")
content.FormattedBody = tp.Replace(content.FormattedBody, IncludeContent(tp.Value.Trim()));
}
private static string IncludeContent(string token)
{
// try loading post first
BlogThreadQuery query = new BlogThreadQuery();
query.SectionID = 4; // HACK: yes, this is very naughty
query.PostName = token;
query.ReturnFullThread = false;
PostSet ps = WeblogPosts.GetPosts(query,true);
if (ps != null && ps.HasResults)
{
Post p = (Post)ps.Posts[0];
return p.FormattedBody;
}
// TODO: try loading article
return string.Empty;
}
}
and there it is. Build and drop that in the bin folder, add this line into the CSModules part of CommunityServer.config:
<add name = "CMSTokens" type = "JamesShaw.CS.Modules.CMSTokensModule, JamesShaw.CS.Modules.CMSTokens" />
Now, whenever I write [include:blogad] in my post it gets replaced at pre-render time with the contents of my blog article called "blogad". Doing it at pre-render means that I can change it at any time, and it affects all posts when they are next rendered. I don't want to simply replace my include token with my ad once and store it in Post.FormattedBody.
Easy, huh?
ASP.NET 3.5 Web Hosting: 3 Months FREE + FREE Setup - CLICK HERE!