switch in Memberlist to show friends only?

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
Locked
rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

switch in Memberlist to show friends only?

Post by rcnutterz »

is it possible to add some sort of 'switch' for members to view the memberlist and see only their friends on it?

The reason i am asking is i am having a hard time getting a page where you can view your friends and see the respective custom profile field of that friend.
I have managed to get the CPF viewable in the memberlist so no if i can narrow it down to show only the members that are on that particaular members friends list it would be great.

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

further thinking on this......

is it possible to for example, make a new memberlist.php file and also include the friends database query so that the output gives what i want? so the custom memberlist page only actually displays the members that are in your friends list.

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: switch in Memberlist to show friends only?

Post by Ather »

I'm working on something, here's the result so far :p

Image
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: switch in Memberlist to show friends only?

Post by Ather »

Ok, got it working :)

Make a new file "friend.php" in root of your forum and paste the following code as its contents :

Code: Select all

<?php

//custom file to display friends that are offline/online
// by PPCW2 [ http://www.phpbb.com/community/memberlist.php?mode=viewprofile&u=978555 ]
// 29th January 2010
// part of code used from ucp.php package from phpBB

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ucp');
    
//sql to get online friends
$update_time = $config['load_online_time'] * 60;

$sql = $db->sql_build_query('SELECT_DISTINCT', array(
        'SELECT'    => 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',

        'FROM'        => array(
            USERS_TABLE        => 'u',
            ZEBRA_TABLE        => 'z'
        ),

        'LEFT_JOIN'    => array(
            array(
                'FROM'    => array(SESSIONS_TABLE => 's'),
                'ON'    => 's.session_user_id = z.zebra_id'
            )
        ),

        'WHERE'        => 'z.user_id = ' . $user->data['user_id'] . '
            AND z.friend = 1
            AND u.user_id = z.zebra_id',

        'GROUP_BY'    => 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',

        'ORDER_BY'    => 'u.username_clean ASC',
    ));

    $result = $db->sql_query($sql);

    while ($row = $db->sql_fetchrow($result))
    {
        $which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';

        $template->assign_block_vars("friends_{$which}", array(
            'USER_ID'        => $row['user_id'],

            'U_PROFILE'        => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
            'USER_COLOUR'    => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
            'USERNAME'        => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
            'USERNAME_FULL'    => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
        );
    }
    $db->sql_freeresult($result);
    
    //end of sql to get online friends

// start of code to allow Only registered users beyond this point
if (!$user->data['is_registered'])
{
    if ($user->data['is_bot'])
    {
        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
    }

    login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
}    
// end of code to allow Only registered users beyond this point
    page_header('My Friends');

    $template->set_filenames(array(
        'body' => 'friends_body.html',
    ));

    make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
    page_footer();
?>
Now make a file called "friends_body.html" in your /style/{stylename}/template folder, and paste these as its contents :

Code: Select all

    <!-- INCLUDE overall_header.html -->


	<table class="tablebg" width="100%" cellspacing="1">
	<tr>
		<th>{L_FRIENDS}</th>
	</tr>
	<tr>
		<td class="row1" align="center">
		
			<b class="genmed" style="color:green">{L_FRIENDS_ONLINE}</b>

			<ul class="nav" style="margin: 0; padding: 0; list-style-type: none; line-height: 175%;">
			<!-- BEGIN friends_online -->
				<li>{friends_online.USERNAME_FULL}
				<!-- IF S_SHOW_PM_BOX -->
					&nbsp;[ <input class="post" style="font-size: 90%;" type="submit" name="add_to[{friends_online.USER_ID}]" value="{L_ADD}" /> ]
				<!-- ENDIF -->
				</li>
			<!-- BEGINELSE -->
				<li>{L_NO_FRIENDS_ONLINE}</li>
			<!-- END friends_online -->
			</ul>

			<hr />

			<b class="genmed" style="color:red">{L_FRIENDS_OFFLINE}</b>

			<ul class="nav" style="margin: 0; padding: 0; list-style-type: none; line-height: 175%;">
			<!-- BEGIN friends_offline -->
				<li>{friends_offline.USERNAME_FULL}
				<!-- IF S_SHOW_PM_BOX -->
					&nbsp;[ <input class="post" style="font-size: 90%;" type="submit" name="add_to[{friends_offline.USER_ID}]" value="{L_ADD}" /> ]
				<!-- ENDIF -->
				</li>
			<!-- BEGINELSE -->
				<li>{L_NO_FRIENDS_OFFLINE}</li>
			<!-- END friends_offline -->
			</ul>

		</td>
	</tr>
	</table>
<br>

    <!-- INCLUDE jumpbox.html -->
    <!-- INCLUDE overall_footer.html -->
thats it, browse to {forumpath}/friend.php and it should work :)

PS, i've put the code to make the user be logged in before he can see the page, the code is commented so you can remove that if you dont want it :)
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

That is good PPCW2, however not quite what i was after ;)
Could certainly be useful though as a little module on a sidebar on my webpage (not the one in my sig, really need to get that changed).

What i am after essentially is the ability to show ONLY friends in the memberlist page (doesnt matter whether they are online or offline). has to be this page as that is the only one i have managed to get to show the custom profile fields for each user.

alternatively, do you have any ideas on how to do this:
http://www.phpbb.com/community/viewtopi ... &t=1961805

will give me the same imformation as what i am looking for really, just another way of displaying it.

Ather
Registered User
Posts: 1032
Joined: Fri May 08, 2009 9:42 am
Location: Kingdom of Bahrain
Name: Ather Akber

Re: switch in Memberlist to show friends only?

Post by Ather »

ahhh i get it now, maybe a new case in memberlist.php to show friends, some thing like : memberlist.php?mode=friends

i'll dig in to this, but some help from the seniors is appreciated :)
CPL Syed Ather Akbar
Regional Command Southwest
Camp Leatherneck, Afghanistan

My Mods/Snippets

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

PPCW2 wrote:ahhh i get it now, maybe a new case in memberlist.php to show friends, some thing like : memberlist.php?mode=friends

i'll dig in to this, but some help from the seniors is appreciated :)
Thanks, i eagerly await your brainwave :)

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

PPCW2 wrote:ahhh i get it now, maybe a new case in memberlist.php to show friends, some thing like : memberlist.php?mode=friends

i'll dig in to this, but some help from the seniors is appreciated :)
Any ideas yet? :D


User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21035
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: switch in Memberlist to show friends only?

Post by RMcGirr83 »

You can also do it by changing the $sql_where variable (would require an additional query on the zebra table).
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

RMcGirr83 wrote:You can also do it by changing the $sql_where variable (would require an additional query on the zebra table).
any chance you could develop the 'case' for me as i have not got the foggiest clue when it comes to working with queries. i only have confidence with playing around with templates to get them to look how i like etc.
i would be ever so grateful :D

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

Senky wrote:You can do it by .htaccess...
how would .htaccess give me what i am after? sorry if i sound dense ;)

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21035
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: switch in Memberlist to show friends only?

Post by RMcGirr83 »

rcnutterz wrote:
RMcGirr83 wrote:You can also do it by changing the $sql_where variable (would require an additional query on the zebra table).
any chance you could develop the 'case' for me as i have not got the foggiest clue when it comes to working with queries. i only have confidence with playing around with templates to get them to look how i like etc.
i would be ever so grateful :D
I don't know probably something like this which should remove the users from the memberlist.

OPEN

memberlist.php

FIND

Code: Select all

		// Sorting and order
BEFORE ADD

Code: Select all

		// BEGIN Ignore Foes Mod
		if (!$auth->acl_get('a_') || !$auth->acl_getf('m_'))
		{
			$sql = 	'SELECT *
				FROM ' . ZEBRA_TABLE . '
				WHERE foe <> 0 AND user_id = ' . $user->data['user_id'];
			$result = $db->sql_query($sql);
			$zebra_foes = array();
			while($row = $db->sql_fetchrow($result))
			{
				$zebra_foes[] = (int) $row['zebra_id'];
			}
			$db->sql_freeresult($result);				
			// change the sql parameters to not include foes
			if (sizeof($zebra_foes))
			{
				$zebra_foes = implode(', ', $zebra_foes);
				$sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $zebra_foes, true);
			}

		}
		// END Ignore Foes Mod
I haven't tested it though and the above will only apply if the user viewing the memberlist is not an administrator or a moderator, else foes will still be shown.
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

rcnutterz
Registered User
Posts: 97
Joined: Thu Apr 03, 2008 8:16 pm

Re: switch in Memberlist to show friends only?

Post by rcnutterz »

RMcGirr83 wrote:I don't know probably something like this which should remove the users from the memberlist.

OPEN

memberlist.php

FIND

Code: Select all

		// Sorting and order
BEFORE ADD

Code: Select all

		// BEGIN Ignore Foes Mod
		if (!$auth->acl_get('a_') || !$auth->acl_getf('m_'))
		{
			$sql = 	'SELECT *
				FROM ' . ZEBRA_TABLE . '
				WHERE foe <> 0 AND user_id = ' . $user->data['user_id'];
			$result = $db->sql_query($sql);
			$zebra_foes = array();
			while($row = $db->sql_fetchrow($result))
			{
				$zebra_foes[] = (int) $row['zebra_id'];
			}
			$db->sql_freeresult($result);				
			// change the sql parameters to not include foes
			if (sizeof($zebra_foes))
			{
				$zebra_foes = implode(', ', $zebra_foes);
				$sql_where .= ' AND ' . $db->sql_in_set('u.user_id', $zebra_foes, true);
			}

		}
		// END Ignore Foes Mod
I haven't tested it though and the above will only apply if the user viewing the memberlist is not an administrator or a moderator, else foes will still be shown.
Thanks for the quick reply,
would that only ignore people that are on your foes list? what about people that are just simply not on your friends list as well? as i am wanting the case to only show friends due the reasons set in an earlier post (quote from earlier post "The reason i am asking is i am having a hard time getting a page where you can view your friends and see the respective custom profile field of that friend.
I have managed to get the CPF viewable in the memberlist so no if i can narrow it down to show only the members that are on that particaular members friends list it would be great.")
and would it be possible to have the view the same for admin/moderators or is this toooo complex?

User avatar
RMcGirr83
Recognised Extension Developer
Posts: 21035
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr
Contact:

Re: switch in Memberlist to show friends only?

Post by RMcGirr83 »

would that only ignore people that are on your foes list?
This :)
In times of change, learners inherit the earth, while the learned find themselves beautifully equipped to deal with a world that no longer exists - Eric Hoffer
Former Modifications/Extensions Team Member | My extensions
Appreciate the extensions/mods/support then buy me a beer
All requests for support via PM will be ignored

Locked

Return to “[3.0.x] MOD Requests”