This little class generates the icons that you see at the bottom of blogs and forums and such similar to this at my blog:
I wanted to make it available to all of my sites, make it expandable and configurable - particularly my retail sites where I want folks to bookmark the products that they like. So here is what I came up with. Attached to this post is a .tar.gz file as well as a .zip file with all the icons references in the class. You'll want to copy and paste it because it's probably cut off in your browser's view.
<?php
class bookmarkRenderer
{
protected $siteMasters = array();
public $completes = array();
public $graphicsRoot;
public $icons = array();
public $names = array();
public $tags = array();
public $urls = array();
public $prototype;
function __construct()
{
$this->graphicsRoot = '/graphics';
$this->urlPrototype = <<<PHP
$this->urls[] = '%%insertionURL%%';
$this->icons[] = <img src=\"\$bmIcon\" border=\"0\" title=\"Add \'\$theTitle\' to \$bmName\" alt=\"Add \'\$theTitle\' to \$bmName\" />
PHP;
$this->prototype = '$this->completes[$bmName] = "<a class=\"$theClass\" onclick=\"window.open(this.href, \'_blank\', \'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no\'); return false;\" href=\"%%insertionURL%%\" title=\"Add \'$theTitle\' to $bmName\"><img src=\"$bmIcon\" border=\"0\" title=\"Add \'$theTitle\' to $bmName\" alt=\"Add \'$theTitle\' to $bmName\" /></a>";';
$ptr = -1;
$ptr++;
$this->siteMasters[$ptr]['name'] = 'De.licio.us';
$this->siteMasters[$ptr]['icon'] = 'delicious.png';
$this->siteMasters[$ptr]['url'] = 'http://del.icio.us/post?url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Digg';
$this->siteMasters[$ptr]['icon'] = 'digg.png';
$this->siteMasters[$ptr]['url'] = 'http://digg.com/submit?phase=2&url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Furl';
$this->siteMasters[$ptr]['icon'] = 'furl.png';
$this->siteMasters[$ptr]['url'] = 'http://furl.net/storeIt.jsp?t=$urlTitle&u=$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'BlinkList';
$this->siteMasters[$ptr]['icon'] = 'blinklist.png';
$this->siteMasters[$ptr]['url'] = 'http://blinklist.com/index.php?Action=Blink/addblink.php&Name=$urlTitle&Description=$urlTitle&Url=$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Reddit';
$this->siteMasters[$ptr]['icon'] = 'reddit.png';
$this->siteMasters[$ptr]['url'] = 'http://reddit.com/submit?url=$theURL&title= $urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'FeedMeLinks';
$this->siteMasters[$ptr]['icon'] = 'feedmelinks.png';
$this->siteMasters[$ptr]['url'] = 'http://feedmelinks.com/categorize?from=toolbar&op=submit&name=$urlTitle&url=$theURL&version=0.7';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Technorati';
$this->siteMasters[$ptr]['icon'] = 'technorati.png';
$this->siteMasters[$ptr]['url'] = 'http://www.technorati.com/faves?add=$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Yahoo MyWeb';
$this->siteMasters[$ptr]['icon'] = 'yahoo_myweb.png';
$this->siteMasters[$ptr]['url'] = 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u=$theURL&t=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'NewsVine';
$this->siteMasters[$ptr]['icon'] = 'newsvine.png';
$this->siteMasters[$ptr]['url'] = 'http://www.newsvine.com/_wine/save?u=$theURL&h=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Socializer';
$this->siteMasters[$ptr]['icon'] = 'socializer.png';
$this->siteMasters[$ptr]['url'] = 'http://ekstreme.com/socializer/?url=$theURL&title= $urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Ma.gnolia';
$this->siteMasters[$ptr]['icon'] = 'magnolia.png';
$this->siteMasters[$ptr]['url'] = 'http://ma.gnolia.com/bookmarklet/add?url=$theURL&title=$urlTitle&description=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Stumble Upon';
$this->siteMasters[$ptr]['icon'] = 'stumbleupon.png';
$this->siteMasters[$ptr]['url'] = 'http://www.stumbleupon.com/refer.php?url=$theURL&title= $urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Google Bookmarks';
$this->siteMasters[$ptr]['icon'] = 'google.png';
$this->siteMasters[$ptr]['url'] = 'http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'RawSugar';
$this->siteMasters[$ptr]['icon'] = 'rawsugar.png';
$this->siteMasters[$ptr]['url'] = 'http://www.rawsugar.com/tagger/?turl=$theURL&tttl=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Squidoo';
$this->siteMasters[$ptr]['icon'] = 'squidoo.png';
$this->siteMasters[$ptr]['url'] = 'http://www.squidoo.com/lensmaster/bookmark?$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Spurl';
$this->siteMasters[$ptr]['icon'] = 'spurl.png';
$this->siteMasters[$ptr]['url'] = 'http://www.spurl.net/spurl.php?url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Blinkbits';
$this->siteMasters[$ptr]['icon'] = 'blinkbits.png';
$this->siteMasters[$ptr]['url'] = 'http://blinkbits.com/bookmarklets/save.php?v=1&source_url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Netvouz';
$this->siteMasters[$ptr]['icon'] = 'netvouz.png';
$this->siteMasters[$ptr]['url'] = 'http://netvouz.com/action/submitBookmark?url=$theURL&title= $urlTitle&popup=no';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Rojo';
$this->siteMasters[$ptr]['icon'] = 'rojo.png';
$this->siteMasters[$ptr]['url'] = 'http://www.rojo.com/add-subscription/?resource=$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'BlogMarks';
$this->siteMasters[$ptr]['icon'] = 'blogmarks.png';
$this->siteMasters[$ptr]['url'] = 'http://blogmarks.net/my/new.php?mini=1&simple=1&url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Shadows';
$this->siteMasters[$ptr]['icon'] = 'shadows.png';
$this->siteMasters[$ptr]['url'] = 'http://www.shadows.com/shadows.aspx?url=$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Simpy';
$this->siteMasters[$ptr]['icon'] = 'simpy.png';
$this->siteMasters[$ptr]['url'] = 'http://www.simpy.com/simpy/LinkAdd.do?href=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Co.mments';
$this->siteMasters[$ptr]['icon'] = 'comments.png';
$this->siteMasters[$ptr]['url'] = 'http://co.mments.com/track?url=$theURL&title=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Scuttle';
$this->siteMasters[$ptr]['icon'] = 'scuttle.png';
$this->siteMasters[$ptr]['url'] = 'http://www.scuttle.org/bookmarks.php/maxpower?action=add&address=$theURL&title=$urlTitle&description=$urlTitle';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Bloglines';
$this->siteMasters[$ptr]['icon'] = 'bloglines.png';
$this->siteMasters[$ptr]['url'] = 'http://www.bloglines.com/sub/$theURL';
$ptr++;
$this->siteMasters[$ptr]['name'] = 'Tailrank';
$this->siteMasters[$ptr]['icon'] = 'tailrank.png';
$this->siteMasters[$ptr]['url'] = 'http://tailrank.com/share/?title=$urlTitle&link_href=$theURL';
}
function build($theClass, $theTitle, $theURL)
{
$theURL = urlencode($theURL);
$urlTitle = urlencode($theTitle);
$this->clearArrays();
foreach($this->siteMasters as $site)
{
$bmName = $site['name'];
$bmIcon = "{$this->graphicsRoot}/{$site['icon']}";
$workStr = str_replace('%%insertionURL%%', $site['url'], $this->prototype);
eval($workStr);
}
ksort($this->completes);
}
function clear()
{
$this->aClass = '';;
$this->title = '';
$this->target = '';
$this->tags = array();
}
protected function clearArrays()
{
$this->names = array();
$this->icons = array();
$this->urls = array();
$this->completes = array();
}
function count() { return count($this->completes) + 1; }
}
?>
It is important to note that this class only creates the href and image HTML for each bookmark service – you must wrap it in the actual presentation. For example, this is similar to what you see on my blog:
<?php
require_once("/www/sites/lib/classes/class.bookmarks.php");
$obj = new bookmarkRenderer();
$obj->build('THECLASS', 'Breast Cancer Awareness Gifts', 'http://www.beauxties.com/');
$max = floor($obj->count() / 2);
$row2 = false;
$current = 0;
$output[] = '<table cellpadding="0" cellspacing="0" border="0">';
$output[] = '<tr><td align="center" nowrap>';
foreach($obj->completes as $row)
{
if (($current >= $max) and (!$row2))
{
$output[] = '</td></tr>';
$output[] = '<tr><td align="center" nowrap>';
$row2 = true;
}
$output[] = $row;
$current++;
}
$output[] = '</td></tr></table>';
echo implode(chr(10), $output), "\n\n";
?>
Once you have executed $obj->build() you can also reference them one-by-one, even by name if you wish with something like:
$someHTML = $obj->completes[‘De.licio.us’];
Have fun!
/p