<script runat="server" type="text/C#">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//SEO Stuff
CSContext cscontext = CSContext.Current;
// If we're in a forum Thread, add the description of the first post in the thread as
// the Meta Description, and keywords of that post as Meta Keywords
if (cscontext.ThreadID > 0 && cscontext.ApplicationType == ApplicationType.Forum)
{
CommunityServer.Discussions.Components.Thread t = CommunityServer.Discussions.Controls.ForumControlUtility.Instance().GetCurrentThread(this);
if (t != null)
{
Head.AddMetaDescription(t.ForceExcerpt, cscontext.Context);
if (t.Categories != null)
{
Head.AddMetaKeywords(String.Concat(t.Categories), cscontext.Context);
}
}
}
// If we have a specific post, add the post excerpt as the Meta Description
// and if the post has any tags, add those as Meta Keywords
else if (cscontext.PostID > 0 || !String.IsNullOrEmpty(cscontext.PostName))
{
Post p = CSControlUtility.Instance().GetCurrentPost(this.Page);
if (p != null)
{
Head.AddMetaDescription(p.ForceExcerpt, cscontext.Context);
if (p.Categories != null)
{
Head.AddMetaKeywords(String.Concat(p.Categories), cscontext.Context);
}
}
}
//If we don't have a post, do we have a Section
else if (cscontext.SectionID > 0)
{
Section section = CSControlUtility.Instance().GetCurrentSection(this.Page);
//Add Section Description as Meta Description
Head.AddMetaDescription(section.Description, cscontext.Context);
}
// Are we in a Section Group, add the group description as the Meta Description
//N.b. Groups as in Forum Groups, Blog Groups as opposed to Hubs
else if (cscontext.GroupID > 0)
{
CommunityServer.Components.Group group = CSControlUtility.Instance().GetCurrentGroup(this.Page);
if (group != null && !String.IsNullOrEmpty(group.Description))
Head.AddMetaDescription(Formatter.RemoveHtml(group.Description, 250), cscontext.Context);
}
// If we're on a user profile page, put the User Bio as the Meta Description
else if (!string.IsNullOrEmpty(cscontext.UserName) || cscontext.UserID > 0)
{
User u = CSControlUtility.Instance().GetCurrentUser(this);
if (u != null && !String.IsNullOrEmpty(u.Profile.Bio))
Head.AddMetaDescription(Formatter.RemoveHtml(u.Profile.Bio, 250), cscontext.Context);
}
// If we are on a Tags page, add tags as Meta Keywords
// We might be on a tags page in a specific section, so don't use ELSE on if statement
if (cscontext.Tags != null)
{
Head.AddMetaKeywords(String.Concat(cscontext.Tags), cscontext.Context);
}
}
</script>