<?php
global $user;
$rtid = 1; //Relationship type ID.
$max = 5; //The amount of users to show on the block.
$user_rel = db_query("
SELECT u.uid
FROM {users} u
LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
WHERE (ur.requester_id = %d OR ur.requestee_id = %d)
AND ur.approved = 1
AND ur.rtid = %d
AND u.status <> 0
GROUP BY u.uid
ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
", $user->uid, $user->uid, $rtid);
$user_rel_com = array();
while ($value = db_fetch_array($user_rel)) {
$user_rel_com[] = $value;
}
//Exit if no users found.
if (empty($user_rel_com)) {
return;
}
foreach ($user_rel_com as $row) {
$req_req_id_list .= " OR ur.requester_id = " . $row['uid'] . " OR ur.requestee_id = " . $row['uid'];
$no_include_friends .= " AND u.uid <> ". $row['uid'];
}
//Trim the first " OR ".
$req_req_id_list = drupal_substr($req_req_id_list, 4);
//Get all of the current user's friends' friends and order by how many times they show up in the list.
$user_rel_rel = db_query("
SELECT u.uid
FROM {users} u
LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
WHERE (%s)
AND ur.approved = 1
AND ur.rtid = %d
AND u.uid <> %d
%s
AND u.status <> 0
GROUP BY u.uid
ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
", $req_req_id_list, $rtid, $user->uid, $no_include_friends);
$user_rel_rel_com = array();
while ($value = db_fetch_array($user_rel_rel)) {
$user_rel_rel_com[] = $value['uid'];
}
//Scrambles the users non-randomly. Does not scramble the user at the bottom of the list.
$z = $user_rel_rel_com;
$i = 0;
foreach ($user_rel_rel_com as $v) {
$r = rand(0, 1);
if ($r === 1 && $user_rel_rel_com[$i + 1]) {
$z[$i] = $user_rel_rel_com[$i + 1];
$z[$i + 1] = $v;
}
$i++;
}
if(count($user_rel_rel_com) < $max) {
$max = count($user_rel_rel_com);
}
for ($i = 0; $i < $max; $i++) {
if ($z[$i] != $user->uid) {
$account = user_load(array('uid' => $z[$i]));
$list = theme('user_picture', $account) .' '. theme('username', $account);
}
}
/////
// Displays a list of all users including their profile images (all roles)
$sql = 'SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u WHERE uid != 0';
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);
$status = array(t('blocked'), t('active'));
for ($i = 0; $i < $max; $i++) {
if ($z[$i] != $user->uid) {
$account = user_load(array('uid' => $account->uid));
if($account->picture){$account->picture = '<a href="?q=user/'.$account->uid.'"><img src="'.$account->picture.'" height="25" width="25" border="1" alt=""></a>';}
else{$account->picture = '<a href="?q=user/'.$account->uid.'"><img src="../assets/images/default-user-sm.gif" height="25" width="25" border="1" alt=""></a>';}
$rows[] = array(theme('username', $account),
$account->picture,
$account->profile_membership,
$account->profile_zipcode,
$account->profile_age,
$account->profile_gender,
$account->profile_profession,
$account->access ? t('%time ago', array('%time' => format_interval(time() - $account->access))) : t('never'));
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0);
print ($output);
/////
//Theme with CSS as appropriate. "More" link is optional.
echo '<span class="uymn">'. theme('item_list', $list) .'</span>';
?>