/** * This makes sure that the image is present (builds it if it isn't) and then * displays it. */ function identicon_check($entity) { //make sure the image functions are available before trying to make avatars if (function_exists("imagecreatetruecolor")) { // entity is group, user or something else? if ($entity instanceof ElggGroup) { $file = new ElggFile(); $file->owner_guid = $entity->owner_guid; $seed = identicon_seed($entity); $file->setFilename('identicon/' . $seed . '/master.jpg'); $file->setMimeType('image/jpeg'); if (!$file->exists()) { if (identicon_build_group($seed, $file)) { return true; } else { // there was some error building the icon return false; } } else { // file's already there return true; } } else { if ($entity instanceof ElggUser) { $file = new ElggFile(); $file->owner_guid = $entity->getGUID(); $seed = identicon_seed($entity); $file->setFilename('identicon/' . $seed . '/master.jpg'); $file->setMimeType('image/jpeg'); if (!$file->exists()) { if (identicon_build($seed, $file)) { return true; } else { // there was some error building the icon return false; } } else { // file's already there return true; } } else { // neither group nor user return false; } } } // we can't build the icon return false; }
function identicon_get_avatar($avatar, $id_or_email, $size, $default) { global $identicon; if (!isset($identicon)) { return $avatar; } $email = ''; if (is_numeric($id_or_email)) { $id = (int) $id_or_email; $user = get_userdata($id); if ($user) { $email = $user->user_email; } } elseif (is_object($id_or_email)) { if (!empty($id_or_email->user_id)) { $id = (int) $id_or_email->user_id; $user = get_userdata($id); if ($user) { $email = $user->user_email; } } elseif (!empty($id_or_email->comment_author_email)) { $email = $id_or_email->comment_author_email; } } else { $email = $id_or_email; } if (!$avatar) { return identicon_build($email, '', '', true, $size); } if (!$identicon->identicon_options['gravatar']) { $identiconurl = identicon_build($email, '', false); $newavatar = preg_replace('@src=(["\'])http://[^"\']+["\']@', 'src=\\1' . $identiconurl . '\\1', $avatar); $avatar = $newavatar; } elseif ($identicon->identicon_options['gravatar'] == 1) { $identiconurl = identicon_build($email, '', false, '', true, true, $size, false); if (strpos($avatar, 'default=http://') !== false) { $newavatar = preg_replace('@default=http://[^&\'"]+([&\'"])@', 'default=' . urlencode($identiconurl) . '\\1', $avatar); } else { $newavatar = preg_replace('@(src=(["\'])http://[^?]+\\?)@', '\\1default=' . urlencode($identiconurl) . '&', $avatar); } $avatar = $newavatar; } return $avatar; }