$g_gravatar_folder = $g_image_path.'gravatars/'; $g_gravatar_cache = $g_gravatar_folder.'cache/'; $g_gravatar_default = 'default.gif'; function gravatar($email,$size=80) { global $g_gravatar_folder; global $g_gravatar_cache; global $g_gravatar_default; $gravatar_id = md5($email); $class = array('logo'); // default, vcard logo if(is_file($_SERVER['DOCUMENT_ROOT'].$g_gravatar_cache.$gravatar_id)) { // ace, it's cached, serve it from here then $gravatar_path = $g_gravatar_cache; } else { // grab it from the site $fetch_gravatar_url = 'http://www.gravatar.com/avatar.php?gravatar_id='.$gravatar_id.'&size='.$size; list($width,$height) = getimagesize($fetch_gravatar_url); // if the height/width doesn't match the size, the image isn't there if($width==$size && height==$size) { // the file exists, so we cache it $fetch_gravatar_url_text = file_get_contents($fetch_gravatar_url); $file_open = fopen($_SERVER['DOCUMENT_ROOT'].$g_gravatar_cache.$gravatar_id, 'x'); fwrite($file_open, $fetch_gravatar_url_text); fclose($file_open); $gravatar_path = $gravatar_path_cache; } else { // no file, show the default one. $gravatar_path = $g_gravatar_folder; $gravatar_id = $g_gravatar_default; $class = ''; // no point setting the vcard logo } } return displayImage($gravatar_id,'gravatar','normal',$gravatar_path,'','','',$class); }