Part of the EllisLab Network
pMachine Pro has been replaced by ExpressionEngine, our full featured web publishing solution. Please consider upgrading.
You can download pMachine Pro here: Download pMachine Pro  |  Download Language Packs
   
 
How To Insert Gravatar in Comments Pages PM PRO 2.4 ? 
Posted: 11 September 2005 10:40 PM   [ Ignore ]  
Summer Student
Total Posts:  1
Joined  2005-02-15

guyz.. any suggestions for adding the gravatar to Comments Page ?  (example : http://www.greendezire.com/)
please help.. Thanks!

Profile
 
 
Posted: 30 January 2006 04:48 AM   [ Ignore ]   [ # 1 ]  
Summer Student
Total Posts:  1
Joined  2005-12-22

I recommend using your own avatar system… Like http://www.webnicht.com/comments.php?id=91_0_1_0_C Gravatar seems to be very often not working… If your hosting the avatars yourself, the avatars will be available when your site is… wink

Profile
 
 
Posted: 25 February 2006 08:03 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  4
Joined  2006-02-25

I’ve just written a simple hack to make Gravatars work on pMachine

the instructions can be found here

I’m going to look into caching the gravatars locally so they will mostly work even when gravatars.com is down

------------------------------------------------
I’ve got local caching working, but I’m not sure what hapens if it requests an update and the sites down, its a little hard to test when the sites working smile

in its current state its pretty easy to impliment and hopefully my instructions make enough sense that you dont have to be a php developer to follow them

Profile
 
 
Posted: 13 April 2006 02:14 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  2
Joined  2006-01-19

Sorry, doesn’t seem to work smoothly for me.  I keep getting some strange characters after my none.gif link which renders the gravatar as a broken image link e.g. /pMachine/gravatarcache/none.gifc743c71810bd8f932f5c62e8ad0f7c98

Plus confirmed gravatar users don’t get their proper gravatars displayed.  Instead, they were also routed to the none.gif link (with the strange characters at the back).

Profile
 
 
Posted: 13 April 2006 02:46 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  2
Joined  2006-01-19

It works when I discard the cache functionalities:

function GetGravatar($email)
//function to return the gravatar required
{
$gravatar_url="http://www.gravatar.com/avatar.php?gravatar_id=";
$gravatar_id=md5($email);

$gravatar = “$gravatar_url$gravatar_id”;
return $gravatar;

}

Profile
 
 
Posted: 13 April 2006 04:56 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  4
Joined  2006-02-25

cheers for the feedback, I’ll have a look at the cache code to see whats going wrong, it looks like its appending the gravatar id onto the none image, even though its supposed to be one or the other

Profile
 
 
Posted: 17 April 2006 01:35 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Total Posts:  4
Joined  2006-02-25

Ok I’ve fixed the code, the mistake was I appended the gravatar id onto the address of the image, and I dont think the cache worked anyway so you were right to take it out smile

if you replace all the functions that were added to display the gravatar with the ones bellow then it’ll all start working how its supposed to
it checks the cache for an existing gravatar, if its not found or has expired the it is requested from gravatar.com, if its not found at gravatar.com or the site cant be reached the none image is used unless theres a cached copy.

function wp_gravatar_info($md5 = ‘’) {

if (’’ == $md5) { return false; }

$r = array();

$foo = @file("http://www.gravatar.com/info/md5/$md5");

if (! $foo) return false;

array_shift($foo); // strip leading <xml ...> declaration

array_shift($foo); // strip opening <gravatar>

array_pop($foo); // strip closing <gravatar>

foreach ($foo as $bar) {

$matched = array();

preg_match_all("/([^<>])+/", $bar, $matched);

$r[$matched[0][1]] = $matched[0][2];

}

return $r;

}

function Download_Gravatar($id, $local, $remote)

{

// we don’t know about this gravatar yet, let’s look for it

$response = wp_gravatar_info($id);

if (’200’ == $response)

{

// it’s not an error, so let’s make a local copy

if ( (is_writeable($local)) && (ini_get(’allow_url_fopen’)) )

{

$cached = copy ($remote.$id, $local.$id.".TMP");

if (! $cached)

{

// looks like the copy failed, delete the TMP

unlink($local.$id.".TMP");

return 0;

} else

{

// we copied successfully

rename($local.$id.".TMP", $local.$id);

return 1;

}

}

} else {

return 0;

}

}

function Gravitar_Cached($id, $local, $remote)

{

$cachetime="34200";

if(file_exists($local.$id))

//if the file exists on the server

{

//check its date

$now=time();

$ftime=filemtime($local.$id);

//echo “boo”.filectime($remote.$id);

if($now-$ftime>$cachetime)

//if the time difference is more then the cache time then get a newer copy

{

//download it

Download_Gravatar($id, $local, $remote);

}

return 1;

}else

{

//download it its new

return Download_Gravatar($id, $local, $remote);

}

}

function GetGravatar($email)

//function to return the gravitar requiered

{

$gravatar_url="http://www.gravatar.com/avatar.php?gravatar_id=";

$gravatar_id=md5($email);

$gravatar_local=$_SERVER[’DOCUMENT_ROOT’] . “/pMachine/gravatarcache/”;

$gravatar_local_url=$_SERVER[’SERVER_ROOT’] . “/pMachine/gravatarcache/”;

$gravatar_none=$_SERVER[’SERVER_ROOT’] . “/pMachine/gravatarcache/none.gif”;

if(Gravitar_Cached($gravatar_id, $gravatar_local, $gravatar_url))

{

$gravatar_path=$gravatar_local_url.$gravatar_id;

$gravatar = “$gravatar_path”;

}else

{

$gravatar_path=$gravatar_none;

$gravatar = “<a href=’http://www.gravatar.com’ target=’_blank’ title=’Get your own gravatar from www.gravatar.com’>$gravatar_path</a>”;

}

return $gravatar;

}

hopefully that’ll do the trick, its all working on my site now so it should be fine for anyone else wink
good luck smile

Profile
 
 
Posted: 12 July 2007 03:24 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  4
Joined  2006-02-25

had a bit of a reorganisation and moved to wordpress so wont be developing this any further

but my page with the final code on can now be found at

http://shuttworld.co.uk/2006/02/27/enabling-gravatars-on-pmachine-pro.html

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 233, on December 18, 2007 12:04 AM
Total Registered Members: 60971 Total Logged-in Users: 0
Total Topics: 73683 Total Anonymous Users: 0
Total Replies: 397485 Total Guests: 39
Total Posts: 471168    
Members ( View Memberlist )
Active Members: