Aug 18

Social Bookmarking PHP Library

Posted by Jaimie Sirovich on Aug. 18th, 2006. 5 comments — voice your opinion.

BECOME AN EGGHEAD. SUBSCRIBE TO OUR RSS FEED OR FOLLOW US ON TWITTER!

Learn to be as nerdy as we are by never missing our latest blog entries. Receive great tips, tricks, and ideas on improving your web site every day! Subscribe via our RSS Feed, follow us, or use the chicklets in the sidebar for more options.
X

Many of us use social bookmarking sites — del.icio.us, digg, reddit, etc.  They're pretty useful, and also great sources of organic traffic.  There are plenty of plugins for blogging applications that place icons on a page to ease its bookmarking.  For example, the one I use for this WordPress blog is  called "Sociable."

But that's for WordPress.  I wanted to experiment with social bookmarking on some of the custom sites I develop, so I developed a little class that will work for any web application.  I took the icons and referenced the list of sites from Sociable, so kudos to Peter Harkins for putting all that stuff together.  Here it is:

<?

// +———————————————————————-+
// | SocialBookmarking                                                    |
// | Displays links for various social bookmarking services               |
// +———————————————————————-+
// | Copyright (c) 2005 Jaimie Sirovich                                   |
// +———————————————————————-+
// | Author: Jaimie Sirovich <jsirovic@gmail.com>                         |
// | Icons taken from WordPress Plugin Sociable by Peter Harkins          |
// | (http://push.cx)                                                     |
// +———————————————————————-+

class SocialBookmarking
{
    var 
$_link;
    var 
$_title;
    var 
$_site_name;
    
    var 
$_templates = array(
    
        
'blinkbits' => array(
            
'icon' => 'blinkbits.png',
            
'url' => 'http://www.blinkbits.com/bookmarklets/save.php?v=1&source_url={LINK}&title={TITLE}&body={TITLE}',
        ),
    
        
'BlinkList' => array(
            
'icon' => 'blinklist.png',
            
'url' => 'http://www.blinklist.com/index.php?Action=Blink/addblink.php&Description=&Url={LINK}&Title={TITLE}',
        ),
    
        
'blogmarks' => array(
            
'icon' => 'blogmarks.png',
            
'url' => 'http://blogmarks.net/my/new.php?mini=1&simple=1&url={LINK}&title={TITLE}',
        ),
    
        
'co.mments' => array(
            
'icon' => 'co.mments.gif',
            
'url' => 'http://co.mments.com/track?url={LINK}&title={TITLE}',
        ),
    
        
'connotea' => array(
            
'icon' => 'connotea.png',
            
'url' => 'http://www.connotea.org/addpopup?continue=confirm&uri={LINK}&title={TITLE}',
        ),
    
        
'del.icio.us' => array(
            
'icon' => 'delicious.png',
            
'url' => 'http://del.icio.us/post?url={LINK}&title={TITLE}',
        ),
    
        
'De.lirio.us' => array(
            
'icon' => 'delirious.png',
            
'url' => 'http://de.lirio.us/rubric/post?uri={LINK};title={TITLE};when_done=go_back',
        ),
    
        
'digg' => array(
            
'icon' => 'digg.png',
            
'url' => 'http://digg.com/submit?phase=2&url={LINK}&title={TITLE}',
        ),
    
        
'Fark' => array(
            
'icon' => 'fark.png',
            
'url' => 'http://cgi.fark.com/cgi/fark/edit.pl?new_url={LINK}&new_comment={TITLE}&new_comment={SITENAME}&linktype=Misc',
        ),
    
        
'feedmelinks' => array(
            
'icon' => 'feedmelinks.png',
            
'url' => 'http://feedmelinks.com/categorize?from=toolbar&op=submit&url={LINK}&name={TITLE}',
        ),
    
        
'Furl' => array(
            
'icon' => 'furl.png',
            
'url' => 'http://www.furl.net/storeIt.jsp?u={LINK}&t={TITLE}',
        ),
    
        
'LinkaGoGo' => array(
            
'icon' => 'linkagogo.png',
            
'url' => 'http://www.linkagogo.com/go/AddNoPopup?url={LINK}&title={TITLE}',
        ),
    
        
'Ma.gnolia' => array(
            
'icon' => 'magnolia.png',
            
'url' => 'http://ma.gnolia.com/beta/bookmarklet/add?url={LINK}&title={TITLE}&description={TITLE}',
        ),
    
        
'NewsVine' => array(
            
'icon' => 'newsvine.png',
            
'url' => 'http://www.newsvine.com/_tools/seed&save?u={LINK}&h={TITLE}',
        ),
    
        
'Netvouz' => array(
            
'icon' => 'netvouz.png',
            
'url' => 'http://www.netvouz.com/action/submitBookmark?url={LINK}&title={TITLE}&description={TITLE}',
        ),
    
        
'RawSugar' => array(
            
'icon' => 'rawsugar.png',
            
'url' => 'http://www.rawsugar.com/tagger/?turl={LINK}&tttl=TITTLE',
        ),
        
        
'Reddit' => array(
            
'icon' => 'reddit.png',
            
'url' => 'http://reddit.com/submit?url={LINK}&title={TITLE}',
        ),
    
        
'scuttle' => array(
            
'icon' => 'scuttle.png',
            
'url' => 'http://www.scuttle.org/bookmarks.php/maxpower?action=add&address={LINK}&title={TITLE}&description={TITLE}',
        ),
    
        
'Shadows' => array(
            
'icon' => 'shadows.png',
            
'url' => 'http://www.shadows.com/features/tcr.htm?url={LINK}&title={TITLE}',
        ),
    
        
'Simpy' => array(
            
'icon' => 'simpy.png',
            
'url' => 'http://www.simpy.com/simpy/LinkAdd.do?href={LINK}&title={TITLE}',
        ),
    
        
'Smarking' => array(
            
'icon' => 'smarking.png',
            
'url' => 'http://smarking.com/editbookmark/?url={LINK}&description={TITLE}',
        ),
    
        
'Spurl' => array(
            
'icon' => 'spurl.png',
            
'url' => 'http://www.spurl.net/spurl.php?url={LINK}&title={TITLE}',
        ),
    
        
'TailRank' => array(
            
'icon' => 'tailrank.png',
            
'url' => 'http://tailrank.com/share/?text=&link_href={LINK}&title={TITLE}',
        ),
    
        
'Wists' => array(
            
'icon' => 'wists.png',
            
'url' => 'http://wists.com/r.php?c=&r={LINK}&title={TITLE}',
        ),
    
        
'YahooMyWeb' => array(
            
'icon' => 'yahoomyweb.png',
            
'url' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u={LINK}&={TITLE}',
        )
    
    );
    
    function 
SocialBookmarking($link$title$site_name)
    {
        
$this->_link $link;
        
$this->_title $title;
        
$this->_site_name $site_name;
    }

    function getHTML($sites = array('del.icio.us''digg''Furl''Reddit''YahooMyWeb'))
    {
        
        
$tmp "<ul class=\"social_bookmarking\">";
        
        foreach(
$sites as $s) {
            
            if (
$_site_info $this->_templates[$s]) {
    
                
$tmp .= "<li class=\"social_bookmarking\">";
        
                
$url str_replace(array('{LINK}''{TITLE}''{SITENAME}'), array(urlencode($this->_link), urlencode($this->_title), urlencode($this->_site_name)), $_site_info['url']); 

                $tmp .= "<a rel=\"nofollow\" href=\"$url\" title=\"$s\">";
                
$tmp .= "<img src=\"/social_bookmarking_icons/{$_site_info['icon']}\" alt=\"$s\" class=\"social_bookmarking\" />";
                
$tmp .= "</a></li>";
            
            }
                        
        }
        
        
$tmp .= "</ul>";
        
        return 
$tmp;
        
    }

}

?>

You'll need to place these icons in the directory "/social_bookmarking_icons" on your web server.  You may also want to set up styles for the elements of class "social_bookmarking."

To use it, simply create a class by calling the constructor with parameters link, title, and site name.  Then make a call to "getHTML()."  Now you're done!

Tell an amigo:
  • Sphinn
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook



Related posts:
Adding Social Bookmarking Icons To News Feeds If you're using a newsreader, you may notice that I...
Patched Sociable Code To Enable Feed Icons I said I would release this if enough people asked. ...
RSS Made Even Simpler Syndication isn't only for blogs; it can be used for...
Simple Cloak PHP Library Tell an amigo: ...
Reddit for WordPress Plugin This is a terribly simple but useful WordPress plugin that...




"5 Wise Comments Banged Out Somewhere On The Internet ..."


rxbbx

thnx, usefull indeed.

Martin Edelius

Thanks a lot for this one, saved me the time to reinvent the wheel so to speak. :)

Shimshon Young

Jamie, that was great! Thanks a bunch.

I added it to my blog at http://www.iris.org.il/blog/ — this is a Serendipity blog and uses smarties so it was a bit trickier to integrate it. For anyone who needs help getting around the smarties see this page which makes it easy: http://www.s9y.org/11.html#A32

One more thing: there is a tiny bug in the Yahoo part:

'YahooMyWeb' => array(
'icon' => 'yahoomyweb.png',
'url' => 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u={LINK}&={TITLE}',
)

That should say "&t={TITLE}" .

abdulla

Social bookmarking websites like del.icio.us already have huge databases of links and tags. Since there is already a del.icio.us plugin for Firefox, it shouldn't be too hard to implement something like it to fetch data on the bookmark and give suggestions based on what others have already tagged the bookmark with.
———–
Abdulla

Social Bookmarking

rxbbx dev » Social Bookmarking

[...] - Social Bookmarking PHP Library [...]



Care To Bang On The Keys ... ?

BECOME AN EGGHEAD. SUBSCRIBE TO OUR RSS FEED!

Learn to be as nerdy as we are by never missing our latest blog entries. Receive great tips, tricks, and ideas on improving your web site every day! Subscribe via our RSS Feed or use the chicklets in the sidebar.