Mutual Friends Mod

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Ideas Centre
User avatar
keith10456
Registered User
Posts: 2315
Joined: Thu Feb 24, 2005 6:55 pm
Contact:

Mutual Friends Mod

Post by keith10456 »

I was thinking a "Mutual Friends" mod would be great for phpBB... One similar to the feature on Facebook.

More or less, the mod would query your Friends, compare them to the Friends of your Friends, then let you know which Friends are on their Friends' list but not on yours... These would be your Mutual Friends.

This is a great way of building camaraderie and activity among your members.

The difficult part (outside of writing the code of course) would be how/where to implement it on the phpBB board.

I was thinking maybe it could be placed on the memberlist.php file/page... Located above or below the "Find A Member" area (that shows A, B, C, D, etc.)

Maybe the Mutual Friends portion could show something like Your Mutual Friends - Click the avatar to add them as a Friend... displaying the avatar of 3 or so members (MF's).

Thoughts? Opinions?
User avatar
NicMason.com
Registered User
Posts: 53
Joined: Mon Nov 14, 2005 1:03 pm
Location: Melbourne, Australia
Contact:

Re: Mutual Friends Mod

Post by NicMason.com »

Hi Keith,

I've made something similar which you can see here (mutual friends are at the bottom of the profile page): http://arts.org.au/forum/memberlist.php ... rofile&u=2

I can post more details later... Bit busy right now! :)

Cheers,

Nic

PS: Perhaps you can help with this one: http://www.phpbb.com/community/viewtopi ... &t=1707675
User avatar
keith10456
Registered User
Posts: 2315
Joined: Thu Feb 24, 2005 6:55 pm
Contact:

Re: Mutual Friends Mod

Post by keith10456 »

NicMason.com wrote:Hi Keith,

I've made something similar which you can see here (mutual friends are at the bottom of the profile page): http://arts.org.au/forum/memberlist.php ... rofile&u=2

I can post more details later... Bit busy right now! :)

Cheers,

Nic

PS: Perhaps you can help with this one: http://www.phpbb.com/community/viewtopi ... &t=1707675
At the bottom of the page, is that "Mutual Friends" or simply "Friends".

In reference to the 2nd link... I wouldn't have a clue as to how to go about adding a link to the "Contact" section of the profile page :?
User avatar
NicMason.com
Registered User
Posts: 53
Joined: Mon Nov 14, 2005 1:03 pm
Location: Melbourne, Australia
Contact:

Re: Mutual Friends Mod

Post by NicMason.com »

Hi Keith,

Sorry, I misunderstood your definition of mutual friends... But this code is very close. You'll just need to read through it and add a few more database calls and conditional statements.

What this does is to only display "mutual" friends in the sense that BOTH parties have added each other as a friend.

I don't have time to add the facebook definition of mutual friends code to it right now, and if you can't code it I sure someone on this forum can... I'll probably add it within the next month or so.

This code will also display the friends in the order that they last logged in, with the most recent first.

NB: If you have your forum VISUALLY integrated inside another software (such as a CMS) this probably won't work because the URLs will be different.

You'll need to save the block of code (at bottom) as a php file such as "whatever.php" and add it here:

YourSite.com/forum/whatever.php

(Don't forget to add your database username, password, and hostname in the code.)


Also, you may want to add the "whatever.php" file to the "deny" list in your .htaccess file to prevent prying eyes, as it contains your host password, as follows:

Code: Select all

<Files "whatever.php">
Order Allow,Deny
Deny from All
</Files>

Then, in memberlist_view.html near the bottom just before </form> you'll need to add:

<!-- INCLUDEPHP whatever.php -->


Finally in your ACP check "Allow PHP" in >>General >>Security.

I realise this is not quite what you're looking for but it's at least halfway there.

Hopefully you can work out the rest, and if so please post it here! :D

Code: Select all

<?php

/**
* This copyright notice must remain in place 
* under the terms of the GNU Lesser General Public License.
* 
* @version $Id: Mutual Friends in PHPBB3 Profile 2009-02-08 09:47:00Z Nic Mason $
* ===================================================
* @author
* Name: Nic Mason ~ NicMason.com ~ ARTS.org.au
* Url: http://nicmason.com ~ http://arts.org.au
* ===================================================
* @copyright Copyright (C) 2008 NicMason.com (http://nicmason.com). All rights reserved.
* @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
* You can use, redistribute this file and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
* 
* This copyright notice must remain in place 
* under the terms of the GNU Lesser General Public License.
*/

function curPageURL2() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

$url = curPageURL2();

$mystring = $url;
$findme   = '&u=';
$pos = strpos($mystring, $findme);
$uidpos = $pos+3;
$uid_inter = substr($mystring, $uidpos);

for($i=0; $i<strlen($uid_inter); $i++){
	if(!is_numeric(substr($uid_inter, $i, 1))){
		$uid = substr($uid_inter, 0, $i);
		break;
		}
	else{
		$uid = $uid_inter;
	}
}


$username = "--------- YOUR DATABASE USERNAME ---------";					// CHANGE THIS!!!
$password = "--------- YOUR DATABASE PASSWORD ---------";					// CHANGE THIS!!!
$hostname = "--------- YOUR HOSTNAME (usually: localhost) ---------";		// CHANGE THIS!!!


												// INITALISE THE ARRAY:
$ufriends_ids = array(0 => 0);					// Define the array  &  Set 0th Key to Zero 0
unset($ufriends_ids[0]);							// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$ufriends_ids = array_values($ufriends_ids);		// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

												// INITALISE THE ARRAY:
$ffriends_ids = array(0 => 0);					// Define the array  &  Set 0th Key to Zero 0
unset($ffriends_ids[0]);							// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$ffriends_ids = array_values($ffriends_ids);		// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

												// INITALISE THE ARRAY:
$friends_ids = array(0 => 0);					// Define the array  &  Set 0th Key to Zero 0
unset($friends_ids[0]);							// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$friends_ids = array_values($friends_ids);		// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)


$dbh = mysql_connect($hostname, $username, $password) 
	or die("Unable to connect to MySQL");

$selected = mysql_select_db("arts_pb3",$dbh) 
	or die("Could not select arts_pb3");

$result = mysql_query("select zebra_id from phpbb_zebra WHERE user_id=$uid AND friend='1'");
$result2 = mysql_query("select user_id from phpbb_zebra WHERE zebra_id=$uid AND friend='1'");

$i=0;
$j=0;

$unum1=mysql_num_fields($result);
$fnum1=mysql_num_fields($result2);
$unum2=mysql_num_rows($result);
$fnum2=mysql_num_rows($result2);


while ($row = mysql_fetch_row($result))
{
	for ($i=0; $i<$unum1; $i++)
	{
		$ufriends_ids[] = $row[$i];
	}
}



$i=0;
$j=0;

while ($row = mysql_fetch_row($result2))
{
	for ($i=0; $i<$fnum1; $i++)
	{
		$ffriends_ids[] = $row[$i];
	}

}



$i=0;
$j=0;

for ($i=0; $i<$unum2; $i++)
{
	for ($j=0; $j<$fnum2; $j++)
	{
		if (($ufriends_ids[$i] == $ffriends_ids[$j]) && ($ufriends_ids[$i] != NULL))
		{
			$friends_ids[] = $ufriends_ids[$i];



		}
	}
}



$i=0;
$j=0;

$profile_name = '';

$result = mysql_query("select username from phpbb_users WHERE user_id=$uid");

while ($row = mysql_fetch_row($result)) {
	for ($i=0; $i<mysql_num_fields($result); $i++) {
	$profile_name = "$row[$i]";
	}
}



$havefriends = 0;
$fid = 0;
$numfriends=count($friends_ids);


												// INITALISE THE ARRAY:
$lastvisit = array(0 => 0);						// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($lastvisit[0]);							// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$lastvisit = array_values($lastvisit);			// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

$fid = $friends_ids[0];


$i=0;
$j=0;

for ($i=0; $i<$numfriends; $i++) {
	$fid = $friends_ids[$i];
	
	$result = mysql_query("select user_lastvisit from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);

	$lastvisit[] = $row[0];
}


array_multisort($lastvisit, $friends_ids);




															// INITALISE THE ARRAY:
$fusername = array(0 => 0);									// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($fusername[0]);										// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$fusername = array_values($fusername);						// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

															// INITALISE THE ARRAY:
$fuser_avatar = array(0 => 0);								// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($fuser_avatar[0]);									// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$fuser_avatar = array_values($fuser_avatar);				// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

															// INITALISE THE ARRAY:
$fuser_avatar_type = array(0 => 0);							// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($fuser_avatar_type[0]);								// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$fuser_avatar_type = array_values($fuser_avatar_type);		// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

															// INITALISE THE ARRAY:
$fuser_avatar_width = array(0 => 0);						// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($fuser_avatar_width[0]);								// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$fuser_avatar_width = array_values($fuser_avatar_width);	// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)

															// INITALISE THE ARRAY:
$fuser_avatar_height = array(0 => 0);						// Define the USER_ID + LAST_LOGIN array  &  Set 0th Key to Zero 0
unset($fuser_avatar_height[0]);								// Delete the Value for the 0th Key (ie: Remove the Zero from the array.)
$fuser_avatar_height = array_values($fuser_avatar_height);	// Start the array from the 0th Key again (ie: The next value inserted into the array will be assigned to the 0th Key.)


$fid = $friends_ids[0];


$i=0;
$j=0;

for ($i=0; $i<$numfriends; $i++) {
	$fid = $friends_ids[$i];
	
	$result = mysql_query("select username from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);
	$fusername[] = $row[0];
	
	$result = mysql_query("select user_avatar from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);
	$fuser_avatar[] = $row[0];
	
	$result = mysql_query("select user_avatar_type from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);
	$fuser_avatar_type[] = $row[0];
	
	$result = mysql_query("select user_avatar_width from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);
	$fuser_avatar_width[] = $row[0];
	
	$result = mysql_query("select user_avatar_height from phpbb_users WHERE user_id=$fid");
	$row = mysql_fetch_row($result);
	$fuser_avatar_height[] = $row[0];
}


mysql_close($dbh);

if (array_key_exists(0, $friends_ids)) {
	$havefriends=1;
}
else  {
    $havefriends=0;
}
?>


<div class="panel bg2" <?php if ($havefriends == 0) {echo 'style="display:none"';} ?>>
	<div class="inner">
		<span class="corners-top"><span></span></span>
		<div class="column1">

			<h3>FRIENDS OF <?php echo $profile_name; ?></h3>

			<h3b>&nbsp;<br /></h3b>


			<div style="text-align:left; display:none">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td width="60px" style="padding:0px 10px 10px 0px"><a href="http://www.username.com"><img src="http://saintkilda.com.au/forum/download/file.php?avatar=2_1231567126.gif" alt="Username" width="100" height="57" border="0" longdesc="Username Long" /></a></td>
					<td style="text-align:left; padding:10px 10px 10px 0px"><a href="http://username.com" target="_top">Username</a></td>
				  </tr>
				  <tr>
					<td width="60px" style="padding:0px 10px 10px 0px"><a href="http://www.username.com"><img src="http://saintkilda.com.au/forum/images/avatars/no_avatar.png" alt="Username" width="100" height="57" border="0" longdesc="Username Long" /></a></td>
					<td style="text-align:left; padding:10px 10px 10px 0px; font-size:12px"><a href="http://username.com" target="_top">Username</a></td>
				  </tr>
				</table>
			</div>

			<div style="text-align:left">
				<table width="100%" border="0" cellspacing="0" cellpadding="0">
				  
					<?php
					
						$fav_size_new=50;
						
						$dav_width=100;
						$dav_height=57;
						
						if (array_key_exists(0, $friends_ids)) {
							$havefriends=1;
							$fno_avatar="http://saintkilda.com.au/forum/images/avatars/no_avatar.png";
							
							$i=0;
							$j=0;
							
							for ($j=(count($friends_ids)-1); $j>=0; $j--) {
							
								$fav_width=intval($fuser_avatar_width[$j]);
								$fav_height=intval($fuser_avatar_height[$j]);
								
								if (($fav_width=='') || ($fav_width==NULL) || ($fav_width=='0') || ($fav_width==0))
									{
									$fav_width=$dav_width;
									$fav_height=$dav_height;
									}
								
								if (($fav_width > $fav_size_new) || ($fav_height > $fav_size_new)) {
								
									if ($fav_width >= $fav_height) {
										$fav_width_new=$fav_size_new;
										$fav_height_new=($fav_height*($fav_size_new/$fav_width));
									}
									else {
										$fav_width_new=($fav_width*($fav_size_new/$fav_height));
										$fav_height_new=$fav_size_new;
									}
								}
								
								
								if (($dav_width > $fav_size_new) || ($dav_height > $fav_size_new)) {
								
									if ($dav_width >= $dav_height) {
										$dav_width_new=$fav_size_new;
										$dav_height_new=($dav_height*($fav_size_new/$fav_width));
									}
									else {
										$dav_width_new=($dav_width*($fav_size_new/$dav_height));
										$dav_height_new=$fav_size_new;
									}
								}
								
								if (array_key_exists(0, $friends_ids)) {
							
									echo '<tr>';
										echo '<td width="60px" style="padding:0px 10px 10px 0px">';
											echo '<a href="../../../../../forum/memberlist.php?mode=viewprofile&u='.$friends_ids[$j].'">';
											
												if ($fuser_avatar_type[$j]!=='0') {
													echo '<img src="../../../../../forum/download/file.php?avatar='.$fuser_avatar[$j].'"';
													echo 'alt="'.$fusername[$j].'" width="'.$fav_width_new.'" height="'.$fav_height_new.'" border="0"/>';
												}
												else {
													echo '<img src="../../../../../forum/images/avatars/no_avatar.png"';
													echo 'alt="'.$fusername[$j].'" width="'.$dav_width_new.'" height="'.$dav_height_new.'" border="0"/>';
												}
		
											echo '</a>';
										echo '</td>';
										echo '<td style="text-align:left; padding:0px 10px 10px 0px">';
											echo '<a href="../../../../../forum/memberlist.php?mode=viewprofile&u='.$friends_ids[$j].'">'.$fusername[$j].'</a>';
										echo '</td>';
									echo '</tr>';
									
								}
							}
						}
						
					?>
					
				</table>
			</div>

		</div>
		<span class="corners-bottom"><span></span></span>
	</div>
</div>
User avatar
keith10456
Registered User
Posts: 2315
Joined: Thu Feb 24, 2005 6:55 pm
Contact:

Re: Mutual Friends Mod

Post by keith10456 »

Thanks for the post. Unfortunately I couldn't write php or phpbb code to save my life.

However, hopefully someone else can utilize the code you provided.
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: Mutual Friends Mod

Post by Peter77sx »

Bump, ....... this would be a nifty feature to have. :ugeek:
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: Mutual Friends Mod

Post by Peter77sx »

So I got the code above to work, but it's asking for

Could not select arts_pb3

Code: Select all

$selected = mysql_select_db("arts_pb3",$dbh) 
   or die("Could not select arts_pb3");
There's gotta be an easier way?
superj707
Registered User
Posts: 1136
Joined: Thu Feb 26, 2009 12:20 am

Re: Mutual Friends Mod

Post by superj707 »

bump
Peter77sx
Registered User
Posts: 3260
Joined: Wed Nov 09, 2005 2:51 pm

Re: Mutual Friends Mod

Post by Peter77sx »

Summer bump.
superj707
Registered User
Posts: 1136
Joined: Thu Feb 26, 2009 12:20 am

Re: Mutual Friends Mod

Post by superj707 »

thanks ... I have been waiting so long for this. Perhaps this will get some attention again. We never got it working. anybody feel like helping? PLEEEEEASE
Lastpost
Registered User
Posts: 74
Joined: Thu Feb 04, 2010 7:09 am

Re: Mutual Friends Mod

Post by Lastpost »

I was looking for the same thing:
http://www.phpbb.com/community/viewtopi ... &t=2095381

Still hoping ... :lol:
trickoff
Registered User
Posts: 513
Joined: Mon Jan 07, 2008 12:23 am

Re: Mutual Friends Mod

Post by trickoff »

thumbs up for this!
cathay123
Registered User
Posts: 2
Joined: Wed Jun 30, 2010 3:13 am

Re: Mutual Friends Mod

Post by cathay123 »

summer Bump, this would be a nifty feature to have.
Lastpost
Registered User
Posts: 74
Joined: Thu Feb 04, 2010 7:09 am

Re: Mutual Friends Mod

Post by Lastpost »

Another bumb for help. ;)
Skinny Vinny
Registered User
Posts: 230
Joined: Tue Dec 01, 2009 7:10 pm

Re: Mutual Friends Mod

Post by Skinny Vinny »

I will build this, but not tonight.
It's part of a larger mod i have been slowly working on.
This is, imho, a must have feature going forward in the oh-so-social web.
It would be more appropriately called a 'suggested friends' mod.

The bad news is that mine will be using memcached, so it won't be for everybody. A version could be scripted for db caching in a custom table, but I really hate doing that. If you run something like this without caching, I suggest it's hidden away in ucp or something. Somewhere that doesn't get a lot of traffic unless they're intentionally using it.

So I guess I'm just helping bump this for anyone that wants to build a more globally compatible version :)
Locked

Return to “[3.0.x] MOD Requests”