/** * Avatar remove action * * Core action modified for Identicon plugin */ $user_guid = get_input('guid'); $user = get_user($user_guid); if (!$user || !$user->canEdit()) { register_error(elgg_echo('avatar:remove:fail')); forward(REFERER); } if ($user->preferIdenticon) { $user->preferIdenticon = false; // Delete all identicons from diskspace $icon_sizes = elgg_get_config('icon_sizes'); $seed = identicon_seed($user); foreach ($icon_sizes as $name => $size_info) { $file = new ElggFile(); $file->owner_guid = $user_guid; $file->setFilename("identicon/{$seed}/{$name}.jpg"); $file->delete(); } // Remove icon unset($user->icontime); } else { // Delete all icons from diskspace $icon_sizes = elgg_get_config('icon_sizes'); foreach ($icon_sizes as $name => $size_info) { $file = new ElggFile(); $file->owner_guid = $user_guid; $file->setFilename("profile/{$user_guid}{$name}.jpg");
/** * 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; }
$group = get_entity($group_guid); if (!$group instanceof ElggGroup) { header("HTTP/1.1 404 Not Found"); exit; } // If is the same ETag, content didn't changed. $etag = $group->icontime . $group_guid; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { header("HTTP/1.1 304 Not Modified"); exit; } $size = strtolower(elgg_extract('size', $vars)); if (!in_array($size, array('large', 'medium', 'small', 'tiny', 'master'))) { $size = "medium"; } $seed = identicon_seed($group); $filehandler = new ElggFile(); $filehandler->owner_guid = $group->owner_guid; $filehandler->setFilename("identicon/" . $seed . '/' . $size . ".jpg"); $success = false; if ($filehandler->open("read")) { if ($contents = $filehandler->read($filehandler->getSize())) { $success = true; } } if (!$success) { $contents = elgg_view("groups/default{$size}.gif"); header("Content-type: image/gif"); } else { header("Content-type: image/jpeg"); }