function avatars_remove_user_files($user) { global $globals; if ($globals['Amazon_S3_media_bucket']) { Media::rm("avatars/{$user}-*"); } if ($globals['Amazon_S3_local_cache'] || !$globals['Amazon_S3_media_bucket']) { $subdir = @get_avatars_dir() . '/' . get_cache_dir_chain($user); if ($subdir && ($handle = @opendir($subdir))) { while (false !== ($file = readdir($handle))) { if (preg_match("/^{$user}-/", $file)) { @unlink($subdir . '/' . $file); } } closedir($handle); } } }
function avatar_get_from_db($user, $size = 0) { global $db, $globals; $img = $db->get_var("select avatar_image from avatars where avatar_id={$user}"); if (!strlen($img) > 0) { return false; } $subdir = get_avatars_dir() . '/' . intval($user / $globals['avatars_files_per_dir']); $file_base = $subdir . '/' . $user; @mkdir(get_avatars_dir()); @mkdir($subdir); if (!is_writable($subdir)) { return false; } file_put_contents($file_base . '-80.jpg', $img); if ($size > 0 && $size != 80 && in_array($size, $globals['avatars_allowed_sizes'])) { avatar_resize("{$file_base}-80.jpg", "{$file_base}-{$size}.jpg", $size); return file_get_contents("{$file_base}-{$size}.jpg"); } return $img; }