This snippet of code is for module developers. It will display all users names and avatars in a list.
Because of the way DF outputs userinfo whenever you try to display an avatar it will actually display your own instead of the actual member you want it to. This method gets around the owninfo stuff and outputs the avatars that belong to each member.
Though I did develop my own method the small bit of avatar image code was taken from the DF_Arcade module because it's better than my method.
It would be nice to see a core function created that addresses all of this stuff into one easy to use function such as get_own_avatar($avatar) or get_user_avatar($user_id). Obviously from what you see now you have to do a lot of coding yourself to get things separated for the correct output.
Code:
global $prefix, $db, $MAIN_CFG;
$sql = "
SELECT user_id, username, user_avatar, user_avatar_type
FROM ".$prefix."_users
ORDER BY username";
$result = $db->sql_query($sql);
$avatar_path = $MAIN_CFG['avatar']['path'];
$avatar_gallery = $MAIN_CFG['avatar']['gallery_path'];
OpenTable();
echo "<table border='0' cellpadding='2' cellspacing='2'>";
echo "<tr><td nowrap='nowrap'>Avatar</td><td nowrap='nowrap'>Username</td></tr>";
while(list($user_id, $username, $user_avatar, $user_avatar_type) = $db->sql_fetchrow($result)){
echo "<tr><td nowrap='nowrap'>";
if ($user_avatar_type == '') {
$avatar = 'images/avatars/gallery/blank.gif';
} else if ($user_avatar_type == 1) {
$avatar = "$avatar_path/$user_avatar";
} else if ($user_avatar_type == 2) {
$avatar = $user_avatar;
} else if ($user_avatar_type == 3) {
$avatar = "$avatar_gallery/$user_avatar";
} else {
$avatar = 'images/avatars/gallery/blank.gif';
}
echo "<img src='".$avatar."' alt='".$user_avatar."' /></td><td nowrap='nowrap'>".$username."</td></tr>";
}
echo "</table>";
CloseTable();