DrupalBin
Submit Code
About
Recent Posts
Fix for Allow HTML in <i> node titles</i> for Drupal 6.x
Template Pre-proccessing
Testing Ubercart donation product
dave's menu screenshot
Code
Modify user profile page theme
Modify user profile page
Fix for Fix for Code
Fix for Code
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
test
theme
user
views
more tags
Home
Fix for Fix for Fix for Fix for Fix for Friends of friends code. Need up displaying user information
View
Fix
January 15, 2010 - 10:47pm — Anonymous
<?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
]
)
)
;
$rows
[
]
=
array
(
theme
(
'username'
,
$account
)
,
$account
->
profile_age
)
;
}
}
// De9ine edit
foreach
(
$rows
as
$row
)
{
print
'<span class="some-class" style="clear:both;">username: '
.
$row
[
0
]
.
' age: '
.
$row
[
1
]
.
'</span>\n'
;
}
//Theme with CSS as appropriate. "More" link is optional.
echo
'<span class="uymn">'
.
theme
(
'item_list'
,
$list
)
.
'</span>'
;
?>
display
field
FOAF
grid
profile
row
table
user
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
<?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])); $rows[] = array(theme('username', $account), $account->profile_age); } } // De9ine edit foreach($rows as $row){ print '<span class="some-class" style="clear:both;">username: '.$row[0].' age: '.$row[1].'</span>\n'; } //Theme with CSS as appropriate. "More" link is optional. echo '<span class="uymn">'. theme('item_list', $list) .'</span>'; ?>
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp
.