Community & Support

Block that displays user avatars

Hi people,

I'm searching for a custom block that will display the last e.g 20 pictures[avatars] resized. So the block will display 20 user pictures, resized to, let's say, 40x40.

That's the only thing I want. I searched for some custom snippets but none of them did my work. Also the avatar gallery module could not resize the pictures, I don't know why.

I think that this is quite a "simple" php work. I tried coding it myself but my php knowledge is far smaller compared to most of you in here.

Any help greatly appreciated. :)

Comments

Until now I came up with

Until now I came up with this :

<div align=justify>
<?php
$limit
= 20;
$default_picture = variable_get('user_picture_default', '');
$result = db_query_range('SELECT uid, name, picture FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, $limit);
while (
$account = db_fetch_object($result)) {
  if (
$account->picture){
   
$output .= '<img src="/'.$account->picture.'" alt = "avatar" width="36" height="36" />';
  } else if ((!
$account->picture) AND ($default_picture)){
   
$output .= '<img src="'.$default_picture.'" alt = "avatar" width="36" height="36" />';
  }
}

return
$output;
?>

</div>

The only thing that is missing, is that I want a link to user profiles in every picture and quite a better formatting. Something like with 4 rows and 5 columns..

Does anyone know anything about this?

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://tus.ath.cx

You're on the right track

We do something similar. In our case, only users with valid avatars make the cut. Note the use of divs to tie the image and the username link together. CSS is used to handle the layout; the avatar class is declared as inline, so it flows. We're linking the images to the user page, but not linking the usernames.

Another version of this code selected from users who were active this week. I just noticed our programmer forgot that clause. :-)

<?php
        $sql
= "SELECT u.uid, u.name, u.picture FROM {users} u WHERE picture!='' ORDER BY RAND() LIMIT 6";
       
$result = db_query($sql);

        while(
$user_data = db_fetch_object($result)) {
           
// truncate long usernames
           
$name = $user_data->name;
            if (
strlen($name) > 9) {
               
$name = substr($name, 0, 8) . "...";
                }
            print
"<div class=\"avatar\">\n";
            print
"    <a href=\"/user/$user_data->uid\"><img src=\"$user_data->picture\" \></a><br />\n";
            print
"$name\n";
            print
"</div>\n";
        }
   
?>

Thanks for the reply. I'm

Thanks for the reply. I'm still trying to figure out, though, how to link to user profiles using my php code. It simply doesn't work if i add your <a> tag.

Any help please?

edit : I tried now with this line :

$output .= '<a href="' . $root . url("user/" . $uid) . '"><img src="'.$default_picture.'" alt = "avatar" width="36" height="36" /></a>';

and it does give me a valid but not correct link. It gives me a http://www.site.gr/user/ link, without the uid.

Help... :(

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://tus.ath.cx

Anyone?

Anyone?

edit : OK I've found it.

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://simpledesigns.hopto.org - simple designs

http://www.dobro.gr - Online community for Greek students in Bulgaria
http://tus.ath.cx

What exactly...

What exactly did you do to get it to work?

It's driving me crazy!

Latte/

this worked great

One correction,

print " uid\">Only local images are allowed.picture\" \>
\n";

should be

print " uid\">Only local images are allowed.picture\" />
\n";

This is the code that worked

This is the code that worked for me:

<?php
        $sql
= "SELECT u.uid, u.name, u.picture FROM {users} u WHERE picture!='' ORDER BY RAND() LIMIT 6";
       
$result = db_query($sql);

        while(
$user_data = db_fetch_object($result)) {
           
// truncate long usernames
           
$name = $user_data->name;
            if (
strlen($name) > 9) {
               
$name = substr($name, 0, 8) . "...";
                }
       
$output = "<div class='avatar'>";
$output .="<a href='" . url("user/" . $uid) . $user_data->uid ."'>";
$output .="<img src='". $user_data->picture . "'/></a><br>";
$output .= $name;
$output .= "</div>";
echo
$output;
        }
  
?>

i know this post is long ago.

i know this post is long ago. but i just want to share it here and get advice from the php gurus here. i do this to get my user's avatars to lay in a block, limit by 20 latest members with picture uploaded only.

i used realname module.

if there's a reason for this code to be better, i would like to hear your advice. cheers!

<?php
$limit
= 20;
$result = db_query_range('SELECT uid, name, picture FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, $limit);
while (
$account = db_fetch_object($result))
  {
    if (
$account->picture)
      {
       
$realname = theme('username', $account, array('plain' => TRUE));
       
$output .= '<a href="' . url("user/" . $uid) . $account->uid .'"><img src="/sites/default/files/imagecache/your_preset_name/'.$account->picture.'" title="'. $realname .'" alt="'. $realname .'"></a>';
      }
    else if (!
$account->picture) { $output .= ''; }
  }
return
$output;
?>
nobody click here