The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. July 02, 2009, 10:34:52 PM

Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: Social Bookmark Icons PHP class - any site, any page  (Read 1793 times)
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 6011



View Profile
« on: October 19, 2007, 03:07:00 PM »

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.

Code:
<?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:

Code:
<?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:

Code:
$someHTML = $obj->completes[‘De.licio.us’];

Have fun!

/p

* bm_icons.tar.gz (41.1 KB - downloaded 62 times.)
* bm_icons.zip (45.62 KB - downloaded 62 times.)
Logged

Don't make me... Get off my lawn.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3990


View Profile
« Reply #1 on: October 20, 2007, 05:44:50 PM »

ironically, i too have been making a solution for this, but i might be aiming a bit higher in the re-use arena.

I built a solution with a JS that you just copy paste into any webpage. It then pulls the assorted bookmarking icons and links and builds a grid for you. My thought was that it would stay up to date, without the site owner worrying about it. It also can be restricted to the specific bookmarking services they want listed.

it will add new bookmark icons as new services are added.
it will update URLs for bookmarking.
its styleable. though I cant figure out how to override "hover" styles from the client site.

you know where to find it if you want to see it.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 6011



View Profile
« Reply #2 on: October 20, 2007, 05:51:36 PM »

Oooooh I like it... didn't think about doing it dynamically at the client. That'd just solve a world of issues. Configurable by the user and, if you drop a cookie, it'd stay that way without having the site developer do squat.

Lotsa dynamic client side HTML there... think I might play with that idea as well and we could come up with a final or something if you're in the mood...
Logged

Don't make me... Get off my lawn.
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3990


View Profile
« Reply #3 on: October 20, 2007, 06:59:23 PM »

The only reason to not do a cookie is if it was to be on multiple blogs owned by different people.

the cookie would be for the the bookmarking widget domain. So if you had it, but only had 3 services listed, and I had all of them, there would be a discrepancy. The only other way would be to check if the client domain matches, if not, build a new box.

that would reduce server load a bit.

my other thing was originally I was pulling the Favicon from each site, so I wouldnt have to host the icons, but that doesnt work since a few of the services dont have favicons... Plus if they ever blocked remote access, that would be an issue as well.
Logged
dink
Expert
****
Offline Offline

Posts: 332


View Profile
« Reply #4 on: October 20, 2007, 07:46:47 PM »

Quote
you know where to find it if you want to see it.

I must have lost the map.  Or, maybe I didn't have one in the
first place.

Can you give me a search phrase for Google?
Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3990


View Profile
« Reply #5 on: October 20, 2007, 08:49:25 PM »

i don't know why I didnt just post it.

www.bookerbox.com
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 6011



View Profile
« Reply #6 on: October 21, 2007, 10:42:58 AM »

You were just being polite, certainly. But It's hot enough you should have this link here as well:

http://www.braindonkey.com/2007/10/20/bookerbox-one-box-for-every-bookmark/

Well done NBs, looks *really* good.
Logged

Don't make me... Get off my lawn.
dink
Expert
****
Offline Offline

Posts: 332


View Profile
« Reply #7 on: October 21, 2007, 01:13:38 PM »

Many thanks to both of you.

Cool little scipt, NB's.  I shall endeavor to get it up.

I think this deserves a blog post too.  With your permission
of course.

Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
nutballs
Administrator
Lifer
*****
Online Online

Posts: 3990


View Profile
« Reply #8 on: October 21, 2007, 03:33:39 PM »

have at it. i am going to make the site "prettier" but haven't gotten that far. sooner or later I'll have some stats of usage, but for now, its just a dumb bookmarker.

and thanks perk, i appreciate the links. Im going to spam the bookmarking services at some point, once I feel its solid enough.
Logged
dink
Expert
****
Offline Offline

Posts: 332


View Profile
« Reply #9 on: October 21, 2007, 05:01:59 PM »

I had it live within a few minutes of posting above.  If you
watch your stats you already knew that, tho.

Had to adjust the col width a little, but it's a snap.  Even
without the widgets thingamabob.

Sweet lil ap.  Thanks.
Logged