The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 06:37:08 AM

Login with username, password and session length


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

Posts: 10096



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 306 times.)
* bm_icons.zip (45.62 KB - downloaded 282 times.)
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


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
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



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

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
dink
Expert
****
Offline Offline

Posts: 349


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
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


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

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

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #10 on: October 21, 2007, 07:01:15 PM »

Thanks Smiley
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #11 on: October 21, 2007, 07:10:51 PM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
dink
Expert
****
Offline Offline

Posts: 349


View Profile
« Reply #12 on: October 21, 2007, 10:24:59 PM »

 Ditto

<<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.
« Last Edit: October 21, 2007, 10:55:37 PM by dink » Logged

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

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #13 on: October 21, 2007, 11:05:01 PM »

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

I could eat a bowl of Alphabet Soup and shit a better argument than that.
dink
Expert
****
Offline Offline

Posts: 349


View Profile
« Reply #14 on: October 22, 2007, 10:20:51 AM »

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

 
« Last Edit: October 22, 2007, 10:25:02 AM by dink » Logged

[quote Nutballs]
the universe has a giant fist, and its got enough whoop ass for everyone.
[/quote]
Pages: [1] 2
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!