Code: Select all
function breadth_first_search($bfs_uid1, $bfs_uid2)
{
global $db;
$queue = array();
$u1_friends = array();
$scanned = array();
$node = $bfs_uid1;
$sql = "SELECT *
FROM " . FRIENDS_TABLE . "
WHERE user_a = " . $bfs_uid1;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query friends information', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$u1_friends[] = $row['user_b'];
$queue[] = $node . ',' . $row['user_b'];
}
$db->sql_freeresult($result);
if (in_array($bfs_uid2, $u1_friends)){
return $node . ',' . $bfs_uid2;
break;
}
$scanned[] = $bfs_uid1;
while(!empty($queue))
{
$node = array_shift($queue); // get the first element in array (FIFO)
$node2 = explode(',', $node); // the string is in format id1,id2,...idx we need idx so split first
if (count($node2)>10)
{
return '';
}
$last_id = array_pop($node2); // then pop the last...
if ($last_id==$bfs_uid2)
{
return $node;
}
$last_id_friends = array();
$sql = "SELECT *
FROM " . FRIENDS_TABLE . "
WHERE user_a = " . $last_id;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query friends information', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$last_id_friends[] = $row['user_b'];
if (!in_array($row['user_b'], $scanned))
{
$queue[] = $node . ',' . $row['user_b'];
}
}
$db->sql_freeresult($result);
if (in_array($bfs_uid2, $last_id_friends)){
return $node . ',' . $bfs_uid2;
break;
}
$scanned[] = $last_id;
}
}
Code: Select all
function database_union_search($uid1, $uid2)
{
global $db;
for ($x=0; $x<10 ; $x++)
{
$left_join='';
$selects="CONCAT_WS(',' ,f0.user_a ";
for ($y=1; $y<=$x ; $y++)
{
$left_join .= "LEFT JOIN " . FRIENDS_TABLE . " f$y ON f" . strval($y-1) . ".user_b = f$y.user_a ";
$selects .= ", f$y.user_a " ;
}
$selects .= ", f$x.user_b )";
// Now, $selects will be like CONCAT_WS(',' , f0.user_, f1.user_a, f2.user_a, ... , fx.user_b)
$sql = "SELECT $selects
FROM ( " . FRIENDS_TABLE . " f0
$left_join)
WHERE f0.user_a = $uid1
AND f$x.user_b = $uid2";
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query friends information', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
return $row[$selects];
}
$db->sql_freeresult($result);
}
}
Code: Select all
// The following two functions is needed to work together...
function nonrecursive_ITDDFS($uid1, $uid2){
for ($x=1 ; $x<=10 ; $x++){
$sr = $depth_limited_search($uid1, $uid2, $x);
if ($sr!='') { return $sr; }
}
}
function depth_limited_search($dfs_uid1, $dfs_uid2, $depth)
{
global $db;
$queue = array();
$u1_friends = array();
$scanned = array();
$node = $dfs_uid1;
$sql = "SELECT *
FROM " . FRIENDS_TABLE . "
WHERE user_a = " . $dfs_uid1;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query friends information', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$u1_friends[] = $row['user_b'];
$queue[] = $node . ',' . $row['user_b'];
}
$db->sql_freeresult($result);
if (in_array($dfs_uid2, $u1_friends)){
return $node . ',' . $dfs_uid2;
break;
}
$scanned[] = $dfs_uid1;
while(!empty($queue))
{
$node = array_pop($queue); // get the last element in array (LIFO)
$node2 = explode(',', $node); // the string is in format id1,id2,...idx we need idx so split first
if (count($node2)>$depth)
{
return '';
}
$last_id = array_pop($node2); // then pop the last...
if ($last_id==$dfs_uid2)
{
return $node;
}
$last_id_friends = array();
$sql = "SELECT *
FROM " . FRIENDS_TABLE . "
WHERE user_a = " . $last_id;
if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, 'Could not query friends information', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
$last_id_friends[] = $row['user_b'];
if (!in_array($row['user_b'], $scanned))
{
$queue[] = $node . ',' . $row['user_b'];
}
}
$db->sql_freeresult($result);
if (in_array($dfs_uid2, $last_id_friends)){
return $node . ',' . $dfs_uid2;
break;
}
$scanned[] = $last_id;
}
}
jbrown wrote: After EasyMOD seemed to shat all over itself a few times I finally got this installed.. Came out very nice! Thank you phpBB, EasyMOD and the Creator of Friends!! I have one problem though.. When I try to delete a friend from my friends list I encounter this error:
Warning: main(./includes/snw_delete.php): failed to open stream: No such file or directory in /var/www/html/phpBB2/friends.php on line 196
Warning: main(): Failed opening './includes/snw_delete.php' for inclusion (include_path='.:/usr/lib/php/:/usr/share/pear/') in /var/www/html/phpBB2/friends.php on line 196
jbrown wrote: I have friends installed and is working fine but when you go to a profile of a user who has me as a friend, when I click on "Add Comment" I get this error:
General Error
No Such User
Blitze wrote: If I may make a suggestion though, if at all it's not yet been implemented. Would you please add some kind of tracking system, maybe by cookies, so that when new non-member friends are invited and the email link takes them to the registration page, and should they decide to visit the site first before deciding to register, they will still be added as a friend of the member that invited them?
have friends installed and is working fine but when you go to a profile of a user who has me as a friend, when I click on "Add Comment" I get this error:
General Error
No Such User
Any suggestions?
#Notes1:
# snw_install.txt( FriendsMOD 0.1.0a ) have BUGs.
#
####
#1:COPY FILE (LINE_about_ 265)
# ADD.., 1files aren't contained.unnecessary
#
copy includes/snw_delete.php to includes/snw_invite.php
#
#2:1 backslashes are unnecessary.
# (snw_install.txt:The part of include/usercp_viewprofile.php)
#
#--LINE 930---------------------
$friends_info = sprintf($lang['Are_friends'], $profiledata['username']) . " <a href=\"friends.php?mode=comment&u=" . $profiledata['user_id'] . '\">' . $lang['Add_comment'] . '</a><br>';
# TO
$friends_info = sprintf($lang['Are_friends'], $profiledata['username']) . " <a href=\"friends.php?mode=comment&u=" . $profiledata['user_id'] . '">' . $lang['Add_comment'] . '</a><br>';
####
#Notes2:
# When you try to approve or add a friend,
Quote:
database error
DEBUG MODE
SQL Error : 1146 **** PHPBB_USERS ****
You try to change PHPBB_USERS to USERS_TABLE.
include/snw_add.php:. 4 places.
friend.php:. 3 places