See the buddies for user whose profile is being watched

leanazulyoro - August 28, 2008 - 03:22
Project:Avatar Blocks
Version:5.x-1.2
Component:User interface
Category:feature request
Priority:normal
Assigned:Unassigned
Status:postponed
Description

Hi, i'm not sure if this can be done, i'd like to have a "my buddies" avatar block for each user in his/her profile page, but the current buddies block only show the buddies for the currently logged in user. Can you think a workaround?, at least take it in count for next version. It may be a checkbox in the block configurations: "show avatars for user whose profile is being viewed".

#1

roopletheme - August 28, 2008 - 08:23

Duplicate of this request. I won't be doing this any time soon, but I'll keep it in mind for a future release.

#2

roopletheme - September 9, 2008 - 13:07
Status:active» postponed

#3

walker2238 - October 6, 2008 - 23:25

Not to sure how good this is but regardless if you are still interested in a quick fix this is what I use... Keep in mind this is a very dirty fix and is placed directly into my page-user.tpl

<?php
//////////////////////////////////////////////////////////////////////////
// Buddylist starts (block) shows who has added you to their buddylist
//////////////////////////////////////////////////////////////////////////
 
global $user;

  if (empty(
$uid)) {
   
$uid = $user->uid;
  }
 
// Check that the uid is valid, not the anonymous user, and the user exists
 
if (!(is_numeric($uid) && ($uid > 0) && $thisuser = user_load(array('uid' => $uid)))) {
   
drupal_not_found();
    exit();
  }

 
$viewing_own_account = ($user->uid == $uid);
 
 
buddylist_setmsg_received($thisuser);

 
$buddies_per_page = 10;

   
$sql_fav = "SELECT DISTINCT(b.buddy), u.access FROM {buddylist} b INNER JOIN {users} u ON b.buddy = u.uid WHERE b.uid = %d ORDER BY u.access DESC";

   
$sql_fan = "SELECT DISTINCT(u.uid) as buddy, u.access FROM {buddylist} b INNER JOIN {users} u ON b.uid = u.uid WHERE b.buddy = %d ORDER BY u.access DESC";

 
$result_fav = pager_query($sql_fav, $buddies_per_page, 0 , NULL, $uid);
 
$result_fan = pager_query($sql_fan, $buddies_per_page, 0 , NULL, $uid);

 
$online_interval = time() - variable_get('user_block_seconds_online', 180);

 
$buddies_fav = array();
  while (
$account = db_fetch_object($result_fav)) {
   
$online = $account->access > $online_interval;
   
$buddies_fav[] = array('uid' => $account->buddy, 'online' => $online);
  }
 
$buddies_fan = array();
  while (
$account = db_fetch_object($result_fan)) {
   
$online = $account->access > $online_interval;
   
$buddies_fan[] = array('uid' => $account->buddy, 'online' => $online);
  }

// Prints out favorites block
if (!empty($buddies_fav)) {
$user_fans = '<div class="my-favorites">' . '<p class="favs">Favorites</p>' . theme('buddylisting', $thisuser, $buddies_fav, $buddies_per_page);
$user_fans .= '</div>';
if (
count($buddies_fav) > 9 && arg(0) == 'user' && $user->uid == arg(1)) {
$user_fans .= '<a class="fans-fav" href="/my-favorites">View all favorites</a>';
}
print
$user_fans;
}

// Prints out fan block
if (!empty($buddies_fan)) {
$user_favs = '<div class="my-favorites">' . '<p class="fans">Fans</p>' . theme('buddylisting', $thisuser, $buddies_fan, $buddies_per_page);
$user_favs .= '</div>';
if (
count($buddies_fan) > 9 && arg(0) == 'user' && $user->uid == arg(1)) {
$user_favs .= '<a class="fans-fav" href="/my-fans/' . $user->uid . '/fans">View all fans</a>';
}
print
$user_favs;
}
?>

#4

j3frea - October 11, 2008 - 10:56

I also wanted to do this, I am using the Advanced Profile module and so I'm using panels. For the buddylist panel, I stole the avatar code and then checked out the buddylist code to see how it fetches the buddies... This is the code that I am now using for a "Custom PHP content" pane:

<?php
$imagecache_preset
= variable_get('avatar_blocks_bl_icpreset''');
$default_picture = variable_get('user_picture_default''');
$display_count = variable_get('avatar_blocks_bl_count'10);

if (!
is_numeric($display_count))
{
 
$display_count = 10;
}

$buddy_ids = array_keys(buddylist_get_buddies(arg(1)));
if (
count($buddy_ids))
{
 
$buddy_ids_str = '('. implode(',', $buddy_ids). ')';
  if (
variable_get('avatar_blocks_bl_display_noavatar', 1))
  {
   
$sql = 'SELECT uid,name,picture FROM {users} WHERE uid > 0 AND access > 0 AND uid IN '.$buddy_ids_str.' ORDER BY created DESC';
  }
  else
  {
   
$sql = 'SELECT uid,name,picture FROM {users} WHERE uid > 0 AND access > 0 AND uid IN '.$buddy_ids_str.' AND picture <> "" ORDER BY created DESC';
  }
 
$my_buddylist_list = db_query_range($sql, $buddy_ids_str, 0, $display_count);

 
$buddies = array();
  while (
$next_buddy = db_fetch_object($my_buddylist_list))
  {
   
$buddies[] = $next_buddy;
  }
 
$output = theme_avatar_blocks_block($buddies, $imagecache_preset);
}

$block->content = $output;
?>

I don't know whether the first three lines are doing anything useful because they might need to be in the avatar_blocks context.

The important thing to note is

<?php
$buddy_ids
= array_keys(buddylist_get_buddies(arg(1)));
?>

arg(1) takes the second argument from the url (I'm also using clean urls - I don't know whether that affects it either). So, for my user profile I have "http://website/user/1" - arg(0) returns "user" and arg(1) returns "1"

I hope that all made sense

 
 

Drupal is a registered trademark of Dries Buytaert.