How do i display a list of images/avatars from my Buddylist?
jorisx - February 16, 2006 - 23:26
How do i display a list of images/avatars from my Buddylist?
I've seen a display random avatar list in the phpsnippets http://drupal.org/node/29246 but I'm not that good in php to convert and show a list of my buddies pictures/avatars...

Same request and situation
I'm interested in the same result, did you had success?
I was trying as well to change that snippet, but I'm facing problems with the query and the output.
Did you get this working?
Also would like to display a picture next to the name in buddylist on user profile. Please post code if you got it working. Thanks!
My ugly hack to get avatar with the buddy list
Ok, I got it somewhat, I say upfront: "don't try this at home". I'm messing with an important module. I don't know when else it is called and I've tried to pre-fix any problems by adding an $avatar variable, but I have no idea if that would fix anything.
Oh, and this is the first time I'm trying to hack something in Drupal. You have been warned.
You would have to change the url (makingthesite.com is mine :).
<?php
function theme_user_list($users, $title = NULL, $avatar = 'true')
{
if (!empty($users))
{
foreach ($users as $user)
{
//CODE BY JULIUS, TRYING TO GET THE PICTURE WITH THE NAME
// I've added the $avatar variable, so that if I don't want it with the name, I should be able
// To remove the picture of the avatar by giving the theme_user_list function the third variable of 'false';
// I'm not an expert coder, but it seems to me that should work.
$avatar_image ="";
if ($avatar != 'false')
{
foreach ($user as $key => $value)
{
if($key == 'picture')
{
$avatar_url = $value;
}
}
// If there is no picture in the profile, don't add the image (the <BR> would mess things a little)
if($avatar_url == true)
{
$avatar_image = "<IMG widtdh='50' height='50' border='1' SRC='http://www.makingthesite.com/drupal_test/".$avatar_url."'><BR>";
}
}
$items[] = $avatar_image.theme('username', $user);
// END CODE BY JULIUS
}
}
return theme('item_list', $items, $title);
}
?>
Now I think it's really 'not done' to mess with the user.module. But I found out that what you see in the list of users is in that items[] thingy.
Also this foreach I do, will probably really make your site slow. It's far from perfect, but I'm getting there.
Also I have been playing around with the buddylist module. And now I'm not sure if that had any part in making this work. So if it doesn't work.. well, then it doesn't.
There is nothing else on the forum, I thought that my ugly hack would at least give someone a starting point.
It only works for the 'my buddylist' block as far as I can tell, so not on all the buddystuff. So far as I can tell I haven't broken anything with this hack.
Found a cool way to print buddy's picture on profiles!
Ok i never have ever posted anything like this because I just never felt i could code. Recently ive been doing alot of work with php in general and drupal, I find that drupal is very very simple and can easily be tooken apart. The follow is code from my user_profile.tpl.php page at www.indacut.com . a site i made for me and friends to have as a "myspace". Im still working on it!
******************************************************
<div class="friends">
<div class="Buddylist">
<table width="300" border="0" cellspacing="0" cellpadding="2">
<tr><p align="right"><font class="buddiestext">Connects</font></p>
<?php
if ( user_access('view buddy lists') || user_access('administer users') ) {
// if thisuser has friends, show friends
$output = '';
$i = 0;
$cnt = variable_get('buddylist_prof_buddies', 8);
if ($buddies = buddylist_get_buddies($user->uid)) {
foreach(array_keys($buddies) as $buddy) {
$account = user_load(array('uid' => $buddy));
$listbuddies[] = $account;
?>
<td><img border="1" height="65" width="65" src="http://indacut.com/drupal/<? print $account->picture?>"></tr></td>
<?
$i++;
if ($i > $cnt) {
$output .= '<div class="more-link">' . l(t('view all connects'), 'buddylist', array('title' => t('View more.'))) . '</div>';
break;
}
}
print $output;
}
}
?>
</table></div>
*************************************************
Notice: !!!!!
<td><img border="1" height="65" width="65" src="http://indacut.com/drupal/<? print $account->picture?>"></tr></td> !!!!!!it is placed right after listbuddies and is told to print the location of the buddy's picture for every buddy that is listed. works for me. and you can control the height and width of the image by simply using the hieght and width property of the command.
visit http://www.indacut.com and register real quick, then take a look at the profiles for an example.
hope this helps!
Doesn't work...
I've tried using this the same way in user_profile.tpl.php but it doesn't work. I have changed the location to my site address to the pictures. It does show an image placemark briefly but then dissapears. Any help?
Steve Blaze
Admin
NWiLive.com
Adding a profile link
This code works great for showing the buddypics... is there any way to get the pics to link to the profile of the buddy pictured? I can't seem to figure out how to do it.
many thanks for any ideas, and again, great snippet.
this may help
This may help, though you'll probably have to edit some of my hardcoding:
http://drupal.org/node/83665
Look at the new buddylist
Look at the new buddylist pictures snippet for 4.7: http://drupal.org/node/97060
Easiest Way to Add Users' Pictures in Buddylist
Hi all,
The easiest way is to add the following code in your template.php file under your theme. If you don't have one, you can just create one using notepad or any text editor.
The code:
function phptemplate_buddylist($buddies) {
if (!empty($buddies)) {
foreach ($buddies as $user) {
$items[] = theme('user_picture', $user) . theme('username', $user);
}
}
return theme('item_list', $items, $title);
}
It is short and sweet. I use this code in my Hand Cell Phone - Mobile Phones Users Social Networking site. It works!