function get_avatar($nick) { global $known_pic_types; $dir = "avatars/"; $avatar_dir = $dir . $nick . "/"; if (!is_dir($avatar_dir)) { // lolwat no avatar dir, try default dir get_default_avatar($nick); return; } $avatars = scandir($avatar_dir); shuffle($avatars); // Avatars list contains '.' and '..' if (count($avatars) === 2) { // lolwat empty avatar dir, try default dir get_default_avatar($nick); return; } foreach ($avatars as $avatar) { if (in_array(substr($avatar, -3), $known_pic_types)) { echo $avatar_dir . $avatar; return; } } }
function user_get_avatar($user_id, $user_level, $user_avatar, $user_avatar_type, $user_allow_avatar, $path_prefix = '', $max_width = 0) { global $config; $user_avatar_path = ''; $user_avatar_link = ''; $user_avatar_dim = ''; if ($user_avatar_type && $user_id != ANONYMOUS && $user_allow_avatar) { switch ($user_avatar_type) { case USER_AVATAR_UPLOAD: $user_avatar_path = $config['allow_avatar_upload'] ? $path_prefix . $config['avatar_path'] . '/' . $user_avatar : ''; break; case USER_AVATAR_REMOTE: $user_avatar_path = $user_avatar; if ($user_level != ADMIN) { // Set this to false if you want to force height as well $force_width_only = true; $avatar_width = $config['avatar_max_width']; $avatar_height = $config['avatar_max_height']; if (!empty($config['allow_avatar_remote'])) { $user_avatar_dim = ' width="' . $avatar_width . '"' . ($force_width_only ? '' : ' height="' . $avatar_height . '"'); $user_avatar_path = $user_avatar; } else { $user_avatar_path = ''; } } break; case USER_AVATAR_GALLERY: $user_avatar_path = $config['allow_avatar_local'] ? $path_prefix . $config['avatar_gallery_path'] . '/' . $user_avatar : ''; break; case USER_GRAVATAR: $user_avatar_path = $config['enable_gravatars'] ? get_gravatar($user_avatar) : ''; break; case USER_AVATAR_GENERATOR: $user_avatar_path = $config['allow_avatar_generator'] ? $user_avatar : ''; break; default: $user_avatar_path = ''; } } if (empty($user_avatar_path)) { $user_avatar_path = get_default_avatar($user_id, $path_prefix); } if (!empty($max_width)) { $max_width = (int) $max_width; if ($max_width > 10 && $max_width < 240) { $user_avatar_dim = ' style="width: ' . $max_width . 'px; max-width: ' . $max_width . 'px;"'; } } $avatar_class = $max_width > 10 && $max_width < 40 ? '' : ' class="avatar"'; $user_avatar_link = !empty($user_avatar_path) ? '<img src="' . $user_avatar_path . '" alt="avatar"' . $avatar_class . $user_avatar_dim . ' />' : ' '; return $user_avatar_link; }