Display a list of buddies snippet
PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Description
This php snippet displays a list of buddies and links to their profiles to users who have View Buddy List permissions.
Dependencies: profile.module. Buddylist.module
Usage
- For use in your user profile page override
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
<?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', 5);
if ($buddies = buddylist_get_buddies($user->uid)) {
foreach(array_keys($buddies) as $buddy) {
$account = user_load(array('uid' => $buddy));
$listbuddies[] = $account;
$i++;
if ($i > $cnt) {
break;
}
}
$output .= t('Buddies');
$output .= theme('user_list', $listbuddies);
$output .= '<br />';
if (count($buddies) > variable_get('buddylist_prof_buddies', 5)) {
$output .= '<div class="more-link">' . l(t('more'), 'buddylist', array('title' => t('View more.'))) . '</div>';
}
$sql = 'SELECT b.uid, u.name FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC';
$result = db_query_range($sql, $user->uid, 0, $cnt);
while ($row = db_fetch_object($result)) {
$listbuddiesof[$row->uid] = $row;
}
$output .= t('Buddies of');
if ($listbuddiesof) {
$output .= theme('user_list', $listbuddiesof);
}
if (count($sql) > variable_get('buddylist_prof_buddies', 5)) {
$output .= '<div class="more-link">'. l(t('more'), 'buddylist/'. $user->uid .'/buddiesof', array('title' => t('View more.'))) .'</div>';
}
print $output;
}
}
?>Alternate with images
<div class="friends">
<div id="profileBuddylist">
<div class="picContainer">
<?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', 5);
if ($buddies = buddylist_get_buddies($user->uid)) {
foreach(array_keys($buddies) as $buddy) {
$account = user_load(array('uid' => $buddy));
$output .=theme('user_picture', $account);
$listbuddies[] = $account;
$i++;
if ($i > $cnt) {
break;
}
}
$output .= '</div>'. theme('user_list', $listbuddies);
if (count($buddies) > variable_get('buddylist_prof_buddies', 5)) {
$output .= '<div class="more-link">' . l(t('more'), 'buddylist', array('title' => t('View more.'))) . '</div>';
}
print $output;
}
}
?>Then there is the css to make it look nice.
#profileBuddylist img{float:left; margin-right:10px;}
.picContainer{width:745px; height:87px;}
#profileBuddylist li{float:left; width:100px;margin-right:10px;text-align: center;}Drupal 4.6
<?php
if (user_access('view buddy lists')) {
// if thisuser has friends, show friends
$cnt = variable_get('buddylist_prof_buddies', 5);
if ($buddies = buddylist_get_buddies($user->uid)) {
foreach($buddies as $buddy) {
$listbuddies[] = format_name($buddy);
$i++;
if ($i > $cnt) {
break;
}
}
$output .= form_item(t('Buddies'), theme('item_list', $listbuddies));
print $output;
}
}
?>
Want to take this even further using CSS?
Ok,
I like this snippet. it works nice. But I wanted a leeeeeetle more out of it.
On my website, Upon registration, the maximum size image people can have is 76px wide by 76px high.
I have created a background for the user image which is 86px wide by 86px high.
This background image has a slight border & a drop shadow, and is rounded.
What is best to do, is create your 86px image, then drag & drop a test image which is 76x76px into the center, so when you design your background, you can get the look spot on..
I have named this: userpic_bg.png & placed it in my selected template "images" folder.
I then went and reduced the size of this to 46px wide by 46px high and called it userpic_bg_small.png
and also added that to my templates images folder.
Now, every time I see the user image, I want the background to show, so in your template "style.css", add:
(note, there is already a ".picture", please modify this to look as below)
.picture {
background: url(images/userpic_bg.png) left top no-repeat;
float: right;
clear: right;
width: 86px;
height: 86px;
padding: 5px;
}
/* Custom User profile */
.picContainer{width:100%; height:87px;}
#profileBuddylist li{float:left; width:100px;margin-right:10px;text-align: center;}
#profileBuddylist img {width:36px; height:36px;}
div#profileBuddylist .picture {
background: url(images/userpic_bg_small.png) left top no-repeat;
float: right;
clear: right;
width: 36px;
height: 36px;
padding: 5px;
}
This will push the image right, and add a background. (make sure you have a default image for those who haven't created one yet!)
In my user_profile.tpl.php I added:
<h3>My Buddies</h3>
<div class="friends">
<div id="profileBuddylist">
<div class="picContainer">
<?php
if ( user_access('view buddy lists') || user_access('administer users') ) {
// if thisuser has friends, show friends
$output = '<div>';
$i = 0;
$cnt = variable_get('buddylist_prof_buddies', 5);
if ($buddies = buddylist_get_buddies($user->uid)) {
foreach(array_keys($buddies) as $buddy) {
$account = user_load(array('uid' => $buddy));
$output .=theme('user_picture', $account);
$listbuddies[] = $account;
$i++;
if ($i > $cnt) {
break;
}
}
$output .= '</div>'. theme('user_list', $listbuddies);
if (count($buddies) > variable_get('buddylist_prof_buddies', 5)) {
$output .= '<div class="more-link">' . l(t('more'), 'buddylist', array('title' => t('View more.'))) . '</div>';
}
print $output;
}
}
?></div></div></div>
Note, this is a cleanup, as the one above does not have the correct amount of closing divs..
Now, if all went well, you should have a smaller version of the user icon.
Hope that helps someone....