Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Fix for Friends

  1. <?php
  2. global $user;
  3. $rtid = 1; //Relationship type ID.
  4. $max = 5; //The amount of users to show on the block.
  5.  
  6. $user_rel = db_query("
  7. SELECT u.uid
  8. FROM {users} u
  9. LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
  10. WHERE (ur.requester_id = %d OR ur.requestee_id = %d)
  11.  AND ur.approved = 1
  12.  AND ur.rtid = %d
  13.  AND u.status <> 0
  14. GROUP BY u.uid
  15. ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
  16. ", $user->uid, $user->uid, $rtid);
  17.  
  18. $user_rel_com = array();
  19. while ($value = db_fetch_array($user_rel)) {
  20.   $user_rel_com[] = $value;
  21. }
  22. //Exit if no users found.
  23. if (empty($user_rel_com)) {
  24.   return;
  25. }
  26.  
  27. foreach ($user_rel_com as $row) {
  28.   $req_req_id_list .= " OR ur.requester_id = " . $row['uid'] . " OR ur.requestee_id = " . $row['uid'];
  29.   $no_include_friends .= " AND u.uid <> ". $row['uid'];
  30. }
  31. //Trim the first " OR ".
  32. $req_req_id_list = drupal_substr($req_req_id_list, 4);
  33.  
  34. //Get all of the current user's friends' friends and order by how many times they show up in the list.
  35. $user_rel_rel = db_query("
  36. SELECT u.uid
  37. FROM {users} u
  38. LEFT JOIN {user_relationships} ur ON (u.uid = ur.requester_id OR u.uid = ur.requestee_id)
  39. WHERE (%s)
  40.  AND ur.approved = 1
  41.  AND ur.rtid = %d
  42.  AND u.uid <> %d
  43.  %s
  44.  AND u.status <> 0
  45. GROUP BY u.uid
  46. ORDER BY COUNT(ur.requester_id OR ur.requestee_id) DESC
  47. ", $req_req_id_list, $rtid, $user->uid, $no_include_friends);
  48.  
  49. $user_rel_rel_com = array();
  50. while ($value = db_fetch_array($user_rel_rel)) {
  51.   $user_rel_rel_com[] = $value['uid'];
  52. }
  53.  
  54. //Scrambles the users non-randomly.  Does not scramble the user at the bottom of the list.
  55. $z = $user_rel_rel_com;
  56. $i = 0;
  57. foreach ($user_rel_rel_com as $v) {
  58.   $r = rand(0, 1);
  59.   if ($r === 1 && $user_rel_rel_com[$i + 1]) {
  60.     $z[$i] = $user_rel_rel_com[$i + 1];
  61.     $z[$i + 1] = $v;
  62.   }
  63.   $i++;
  64. }
  65.  
  66. if(count($user_rel_rel_com) < $max) {
  67. $max = count($user_rel_rel_com);
  68. }
  69.  
  70. for ($i = 0; $i < $max; $i++) {
  71.   if ($z[$i] != $user->uid) {
  72.     $account = user_load(array('uid' => $z[$i]));
  73.     $list = theme('user_picture', $account) .' '. theme('username', $account);
  74.   }
  75. }
  76. //
  77. // Displays a list of all users including their profile images (all roles)
  78.  
  79.  
  80. $sql = 'SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u WHERE uid != 0';
  81. $sql .= tablesort_sql($header);
  82. $result = pager_query($sql, 50);
  83.  
  84.  
  85. $status = array(t('blocked'), t('active'));
  86. for ($i = 0; $i < $max; $i++) {
  87.   if ($z[$i] != $user->uid) {
  88.        $account = user_load(array('uid' => $account->uid));
  89.        if($account->picture){$account->picture = '<a href="?q=user/'.$account->uid.'"><img src="'.$account->picture.'" height="25" width="25" border="1" alt=""></a>';}
  90.          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>';}
  91.  
  92. $rows[] = array(theme('username', $account),
  93.           $account->picture,
  94.           $account->profile_membership,
  95.           $account->profile_zipcode,
  96.           $account->profile_age,
  97.           $account->profile_gender,
  98.           $account->profile_profession,
  99.           $account->access ? t('%time ago', array('%time' => format_interval(time() - $account->access))) : t('never'));
  100. }
  101.  
  102. $output = theme('table', $header, $rows);
  103. $output .= theme('pager', NULL, 50, 0);
  104. print ($output);
  105.  
  106. //Theme with CSS as appropriate.  "More" link is optional.
  107. echo '<span class="uymn">'. theme('item_list', $list) .'</span>';
  108.  
  109. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.