I needed a way to add the standard community referring links to blog posts in Community Server. I was surprised by how easy it actually was. So if you are using CommunityServer.org 2007 and want to do the same then follow these instructions.
1. create a c# project in visual studio and add this code below to a new class in the project. Fix the namespace of course.
|
using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Web; using CommunityServer.Blogs.Components; using CommunityServer.Components;
namespace SPWorks.CS.Integration { class SPWReferIt : ICSModule { private bool _syndicate = true; private bool _web = true; private DateTime _dateFilter = DateTime.MinValue; private string links = ""; public void Init(CSApplication csa, XmlNode node) { csa.PreRenderPost += new CSPostEventHandler(csa_PreRenderPost); links = node.Attributes.GetNamedItem("ReferLinks").Value; if (links == null) links = ""; links = Globals.UrlDecode(links); } private void csa_PreRenderPost(IContent content, CSPostEventArgs e) { if (e.Target == PostTarget.Web) { if (!_web) return; } else if (e.Target == PostTarget.Syndication) { if (!_syndicate) return; } if (e.ApplicationType == ApplicationType.Weblog) { WeblogPost wp = content as WeblogPost; bool includePost = (e.Target == PostTarget.Web || wp.PostDate >= _dateFilter); if (wp != null && wp.PostLevel == 1 && includePost) { string link = Globals.FullPath(BlogUrls.Instance().Post(wp)); string title = wp.Subject; if (title.Length > 150) title = title.Substring(0, 149); string[] tags = wp.Categories; string tagsstr = ""; if (tags != null) { for (int i = 0; i < tags.Length; i++) { if (tagsstr != "") tagsstr += " "; tagsstr += tags[i];
} } string tagsEncode = Globals.UrlEncode(tagsstr); string titleUrlEncode = Globals.UrlEncode(wp.Subject); string linkEncode = Globals.UrlEncode(link); string linksstr = links; if (linksstr != "") { linksstr = "\n" + linksstr.Replace("[TAGS_ENCODED]", tagsEncode).Replace("[URL_ENCODED]", linkEncode).Replace("[TITLE_ENCODED]", titleUrlEncode).Replace("[TAGS]", tagsstr ).Replace("[URL]", link).Replace("[TITLE]", title); }
wp.FormattedBody += linksstr; } } }
} } |
2. Add references to the CommunityServer blogs and components dlls to your project
3. Compile and put your dll in the bin directory of the CommunityServer web site.
4. Open the CommuntyServer.config file and make new entry for your module like so:
<add name = "SPWReferItModule" type = "SPWorks.CS.Integration.SPWReferIt,SPWorks.CS.Integration" ReferLinks="" />
5. In the step above the ReferLinks attribute is where you will put your html template for creating the links. In SHAREPOINTSearch's case we chose the follow URLs:
<a href="http://del.icio.us/post?url=[URL_ENCODED]&tags=[TAGS_ENCODED]&title=[TITLE_ENCODED]" mce_href="http://del.icio.us/post?url=[URL_ENCODED]&tags=[TAGS_ENCODED]&title=[TITLE_ENCODED]">Del.icio.us</a> | <a href="http://digg.com/submit?phase=2&url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://digg.com/submit?phase=2&url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">Digg It</a> | <a href="http://technorati.com/cosmos/search.html?url=[URL_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://technorati.com/cosmos/search.html?url=[URL_ENCODED]&tags=[TAGS_ENCODED]">Technorati</a> | <a href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=[URL_ENCODED]&Title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://blinklist.com/index.php?Action=Blink/addblink.php&url=[URL_ENCODED]&Title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">Blinklist</a> | <a href="http://furl.net/storeIt.jsp?t=[TITLE_ENCODED]&u=[URL_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://furl.net/storeIt.jsp?t=[TITLE_ENCODED]&u=[URL_ENCODED]&tags=[TAGS_ENCODED]">Furl</a> | <a href="http://reddit.com/submit?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://reddit.com/submit?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">reddit</a> | <a href="http://www.dotnetkicks.com/submit/?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]" mce_href="http://www.dotnetkicks.com/submit/?url=[URL_ENCODED]&title=[TITLE_ENCODED]&tags=[TAGS_ENCODED]">DotNetKicks</a>
NOTE: the replacement holders: [TITLE_ENCODE] [URL_ENCODE] [ TAGS_ENCODE] . these are pretty self explanatory and use these to add your own refer it links to the template. When you have the template ready. Then use http://www.albionresearch.com/misc/urlencode.php to URLEncode the whole string and paste it into the ReferLinks attribute.
THAT's it. It took me exactly 35 minutes to write and should take you 10 to use.
You can try it out on this blog post itself. See:
Del.icio.us |
Digg It |
Technorati |
Blinklist |
Furl |
reddit |
DotNetKicks