Show online status in memberlist

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)
Scam Warning
User avatar
TrumpX
Registered User
Posts: 93
Joined: Tue Nov 16, 2010 2:45 pm
Location: Online

Show online status in memberlist

Post by TrumpX »

How to add the online status of a user to the memberlist ?
What changes have to be made in memberlist.php ?
vortexhlp
Registered User
Posts: 195
Joined: Fri Jan 09, 2009 7:51 pm

Re: Show online status in memberlist

Post by vortexhlp »

What do you mean by memberlist? the functions file of memberlist can fetch the online status of an individual (or any info about that person).

Code: Select all

<!-- IF S_ONLINE -->Online!<!-- ELSE -->Offline<!-- ENDIF -->
pretty simple :P
User avatar
TrumpX
Registered User
Posts: 93
Joined: Tue Nov 16, 2010 2:45 pm
Location: Online

Re: Show online status in memberlist

Post by TrumpX »

Thanks for your reply, but it wasn't that easy...

This code in memberlist_body.html works for users with "u_viewonline" rights only (admin for example)

Code: Select all

<!-- IF memberrow.S_ONLINE -->Online!<!-- ELSE -->Offline<!-- ENDIF -->
At least for me it does...


I believe there is a bug in memberlist.php:

Code: Select all

if ($config['load_onlinetrack'])
	{
		$update_time = $config['load_online_time'] * 60;
		$online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false;
	}
	else
	{
		$online = false;
	}
I had to change the code and add "|| $data['user_allow_viewonline']"

Code: Select all

if ($config['load_onlinetrack'])
	{
		$update_time = $config['load_online_time'] * 60;
		$online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $data['user_allow_viewonline'] || $auth->acl_get('u_viewonline'))) ? true : false;
	}
	else
	{
		$online = false;
	}
Now it works for all users
vortexhlp
Registered User
Posts: 195
Joined: Fri Jan 09, 2009 7:51 pm

Re: Show online status in memberlist

Post by vortexhlp »

Oh i see, the friend system isn't completed I think? Hmm... Then how would I go about adding online/offline statuses for friends in memberlist_view.html?
User avatar
TrumpX
Registered User
Posts: 93
Joined: Tue Nov 16, 2010 2:45 pm
Location: Online

Re: Show online status in memberlist

Post by TrumpX »

vortexhlp wrote:Oh i see, the friend system isn't completed I think? Hmm... Then how would I go about adding online/offline statuses for friends in memberlist_view.html?
In memberlist_view.html online/offline status is getting displayed for all users by default.
If you want online/offline status be visible to friends only..

open memberlist php and find

Code: Select all

// Get user...
		$sql = 'SELECT *
			FROM ' . USERS_TABLE . '
			WHERE ' . (($username) ? "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "user_id = $user_id");
		$result = $db->sql_query($sql);
		$member = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);
replace with

Code: Select all

// Get user...
		$sql = 'SELECT u.*, z.friend, z.foe
				FROM ' . USERS_TABLE . ' u LEFT JOIN ' . ZEBRA_TABLE . ' z
				ON z.user_id = u.user_id AND z.zebra_id = ' . $user->data['user_id'] . '
				WHERE ' . (($username) ? "u.username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'" : "u.user_id = $user_id");
		$result = $db->sql_query($sql);
		$member = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

next find

Code: Select all

// Dump it out to the template
	return array(

on a new line add

Code: Select all

'S_FRIEND'			=>	($data['friend']) ? true : false,
'S_FOE'			=>	($data['foe']) ? true : false,

in memberlist_view.html replace every occurrence of:

Code: Select all

<!-- IF S_ONLINE -->
with

Code: Select all

<!-- IF S_ONLINE and S_FRIEND -->

I hope that I understood your question correctly.
My memberlist.php is heavy modified and may differ from yours but this should work in theory :D
vortexhlp
Registered User
Posts: 195
Joined: Fri Jan 09, 2009 7:51 pm

Re: Show online status in memberlist

Post by vortexhlp »

Well basically I'm trying to convert memberlist_view into the center attention of a uhh well kind of like facebook's wall. So when you go there you see the person's friends, his or her blogs, etc... It does display all of the user's friends but it doesn't display who's online and who's offline, just all of the above in one go. Unfortunately the friendsystem as far as I can see doesn't have a condition of 'S_ONLINE' for example.

Here's what I'm trying to achieve:
[ONLINE]
FRIENDNAME1 FRIENDNAME2 FRIENDNAME3

------------------------------------------------------

[OFFLINE]
FRIENDNAME4 FRIENDNAME5 FRIENDNAME6

It should be viewed by everyone who visits the profile, so this isn't a "these are my friends, and I'm the only one who can see this", but rather a "these are my friends and everyone can see them". Your previous post was very insightful and I appreciate it but it isn't doing what I need it to do :)
User avatar
TrumpX
Registered User
Posts: 93
Joined: Tue Nov 16, 2010 2:45 pm
Location: Online

Re: Show online status in memberlist

Post by TrumpX »

Here is a function to check the online status of a user:

Code: Select all

function is_user_online($user_id)
{
    global $db, $config, $auth;
    
    if($config['load_onlinetrack'])
    {
        $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
            FROM ' . SESSIONS_TABLE . '
            WHERE session_user_id = '.$db->sql_escape($user_id);
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($sql);
    
        $session_time = (isset($row['session_time'])) ? $row['session_time'] : 0;
        $session_viewonline = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
    
        $allow_viewonline = ($session_viewonline || $auth->acl_get('u_viewonline')) ? true : false;
    
        $update_time = $config['load_online_time'] * 60;
        $online = ((time() - $update_time < $session_time) && ($allow_viewonline)) ? true : false;
    
        return $online;
    }
    
    return false;
}
You could call this function for every friend
and then assign S_ONLINE yourself

Return to “[3.0.x] MOD Requests”