Adding refer (digg, technorati ..) links to Community Server blogs

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
Published Saturday, September 15, 2007 1:56 PM by notorioustech

Comments

# Community Server Byte for September 19, 2007

blog bits Rich Mercer with a very informative post on extending Community Server email services. Example

Thursday, September 20, 2007 12:15 AM by Dave Burke

# Community Server Byte for September 19, 2007

blog bits Rich Mercer with a very informative post on extending Community Server email services. Example

Thursday, September 20, 2007 1:03 AM by Community Blogs

# A new Link Share control for Community Server 2007

A new Link Share control for Community Server 2007 with source from Christopher Evan. BookmarkIt!

Thursday, September 20, 2007 8:53 PM by Dave Burke's Community Server Bits

# re: Adding refer (digg, technorati ..) links to Community Server blogs

sharepointsearch.com/.../2349.ashx

I have attached to the original post a quick build of the dll so you don't have to go through steps 1-3, just unzip it into your CS bin directory and start at step 4:

Note:

<add name = "SPWReferItModule" type = "SPWorks.CS.Integration.SPWReferIt,SPWorks.CS.Integration" ReferLinks="" />

will become :

<add name = "SPWReferItModule" type = "SPWorks.CS.Freeware.SPWReferIt,SPWorks.CS.Freeware" ReferLinks="" />

Monday, September 24, 2007 12:30 PM by notorioustech

# Add digg, del.ico.us & other referrers to CS 2007

This is a tasty little snack that allows you to easily add referrer tags to your Community Server posts

Wednesday, December 05, 2007 11:18 PM by TechEd

# Adding Social Bookmarking to Community Server 2007

Adding Social Bookmarking to Community Server 2007 Community Server is the platform that powers rich

Thursday, February 07, 2008 1:05 PM by mystyleit

# communtyserver org

Pingback from  communtyserver org

Monday, July 14, 2008 7:26 AM by communtyserver org