perkiset

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&Applauseescription=$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'] = &'

;Net

 vouz';
$this->siteMasters[$ptr]['icon'] = &'

;net

 vouz.png';
$this->siteMasters[$ptr]['url'] = 'http:/

/net

 vouz.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.

asp

 x?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), " ";

?>


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

nutballs

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.

perkiset

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...

nutballs

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.

dink

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?

nutballs

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

www.bookerbox.com

perkiset

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.

dink

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.

nutballs

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.

dink

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.

nutballs

Thanks Applause

perkiset

quote author=nutballs link=topic=575.msg3822#msg3822 date=1193006019

Im going to spam the bookmarking services at some point, once I feel its solid enough.


Let us all know here so that we can assist in the effort. Well done NBs

dink

Applause

<<edit>>
There was a series of heavy-duty thunder boomers coming thru my place this evening, so I was a little late with the blog post.  (I shut this baby down and pull the plug when the electricity flows downhill.)  The deed has been done.

nutballs

thanks guys. I actually am going to ask for some opinions once I finish. There are currently 2-3 features I am going to add, but they will be optional and the BookerBox will always work with just the original code since technically everything is optional (or will be when I am done).

I also just switched over to a wordpress blog as the support structure. I realized that would work great, since I could post any time I add a new feature, people could comment, and basically it could act as a general communication system.

i gotta have my wife make a logo for me...

i have found a few issues that I need to figure out.
specifically, Styles. I want to override and clear any styles that come from the hosting site. I have noticed a problem which you can see on BrainDonkey.com when you mou

seo

 ver the icons, they get underlines. Its because the host site (braindonkey) has that style in the style sheet for hover. the problem is, you cant declare hover 'inline', only in the head style declaration, or a separate style sheet.
Any hints?
My though was to write my own styles to the head, dynamically, the same way I write the BookerBox, but that started getting over my head a bit.

dink

Man, I don't have a clue about the styles issue.

<>I don't see underlines, but the icons tend to jump
a little when I mou

seo

 ver.  FF2.07

edit:  they don't jump around on my site.  They jump
around on braindonkey. 

Advice == This is very likely to go viral on you.
Gird your loins.  Get cache plugin for WP, host
the site stylesheet on a different server.

I know you aren't ready for the big time, but it
could start before you know it.

Applause

perkiset

Don't understand the issue with styles... since you are all

javascript

 , you'll need to add a little something to the page, but it's pretty trivial..

* Create a string version of the styles you want to use - have that be a variable in your dynamic JS.
* In the JS code, append a new DIV to the HTML page ie., get the body tag, append a DIV node to it and hang on to the reference.
* do a <newDivNode>.innerHTML = <the String Representation of your style sheet> - poof, your styles are available.
* Create the HTML for your buttons, calling out the styles that you just added.

I think that's about it if I'm reading you right...

nutballs

thanks for the encouragement Dink. i took your advice and installed wp-cache.
I actually am on a HUGE hosting platform, with the ability to scale almost infinitely, plus I have some pull with rackspace if it went viral and needed a big premium pipe in under an hour. I am going to install a very lightweight template onto wordpress as well to reduce excess bandwidth. plus im sure i could bribe perk Applause

Perk
im gonna call.

perkiset

Okeydokey.

nutballs

thanks to Perks advice, i have fixed a bunch of issues that popped up after testing it in assorted other places. its all good now, baring some CSS issues which may crop up but I will now be able to defeat those issues.

Also, i had an epiphany...
I am going to add something to this thing that might actually push it over the edge, making it rock.
more to come...

now where did i leave those extra 12 hours a day?

perkiset

quote author=nutballs link=topic=575.msg3856#msg3856 date=1193194052

thanks to Perks advice, i have fixed a bunch of issues that popped up after testing it in assorted other places. its all good now, baring some CSS issues which may crop up but I will now be able to defeat those issues.


You r 2 kind... I was just rambling when you found that missing semi-colon and there was much rejoicing Applause Applause Applause

nutballs

nah, i meant the suggestions.

removing the A href and instead doing an onclick on the image, reduced the code by a few bytes.

I als changed how the page is called to be adsense-like. like you suggested. it makes the call smaller as a result. plus it is more idiot proof now. basically I have the client JS call a translator page, which then assembles everything to the way it is needed for the final page call. basically you end up with 2 calls, but ease of use increases.
basically, you call a JS, which writes a newly formatted JS call to your page, which again calls back to my server. This is to handle the passing of parameters into the querystring, so

PHP

  can get its hands on it.

perkiset

sounds spot on man... nice work. I love the concept and look. Twas a great idea.

nutballs

ah just you wait and see what I have up my sleeve...

matthewk

Just registered.
Thanks for this perk I'm using it now.


Perkiset's Place Home   Politics @ Perkiset's