Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 02:32:44 PM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155539 Posts in 21712 Topics by 7737 Members
Latest Member: deanmacullam
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Snippet: Display members online  (Read 1667 times)
MoSaG

Offline Offline

Posts: 12


« on: August 27, 2010, 05:51:03 PM »

My first snippet (and first module for WB in any way) - and I am not a pro-php-developer Wink

The reason for it was to learn, how to write code for WB modules.

It displays all usernames of logged-in users in an unordered list.

Put
Code:
<?php MembersOnline(); ?>
to your template, thats all.

Optional Parameters:
  • (1) seconds of timeout
  • (2) custom headline
  • (3) selection of display: username or display_name
  • (4) custom 'no users online' message

i.e.
Code:
<?php MembersOnline('600''users online''username''-'); ?>

default is
Code:
<?php MembersOnline('300''Active users in last 5 min''display_name''0 users online'); ?>


You can modify the appereance by editing the frontend.htt of the snippet.

Hope it is bugfree, please report any errors, suggestions or security issues, 'will try to fix them.

Perhaps there are useful additions like a linked username where you can directly email the user ... or something like that. But this is my first try and I need more learning Wink

Sorry for my english ...

Updated to 0.1.1: added support for a custom timeout; simply add seconds for timeout in the brackets
Updated to 0.1.2: added support for a custom headline, add headline in quotes and separated from seconds to the brackets
Updated to 0.1.3: added support for custom selection of username or display_name, add 'username' or 'display_name' as third parameter
Updated to 0.1.4: added custom message if no users are online, add i.e. 'no users online' as fourth parameter
« Last Edit: August 30, 2010, 06:47:35 PM by MoSaG » Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #1 on: August 27, 2010, 06:06:48 PM »

hi,

welcome to wb community Smiley the snippet sounds great, i am looking forward to test it

cheers
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #2 on: August 27, 2010, 06:45:55 PM »

Hi,

I did a quick review of your code..

What happens if I am online, but idle for 6 min ? I want be displayed..right Smiley
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
MoSaG

Offline Offline

Posts: 12


« Reply #3 on: August 27, 2010, 08:27:49 PM »

5 Minutes is the default timeout, if you are idle 6 mins you will be kicked off the list. The next time you surf on a page (and still be logged in to the system), you're status will be updated to online again. I think, that's ok, no realtime updates at the moment ...
Do you think an option "show me always on, as long as I am not logged off" makes sense? (this could be one of the possible additions, a user may change the online status, the timeout, or "I want to be invisible" Wink )
On line 21 in inlcude.php you can set a higher timeout limit. Perhaps I learn in a few days how I get an admintool to run, where you can enter the timeout. Meanwhile you have to change it by hand in the snippet. Thanks for testing!
« Last Edit: August 27, 2010, 08:38:59 PM by MoSaG » Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #4 on: August 27, 2010, 09:24:14 PM »

For example if you are hanging on forum, and you dont surf, you are still displayed as online.. Smiley

It is not my intention to increase/decrease timeout , just to point that even when you are loged in & not surfing, you are still online, but idle Smiley

Perhaps more precise would be: "Active users in last 5 min: <list>"

And, regarding timeout, since this is a function, you can easily increase the timeout:
Code:
function MembersOnline ($custom_timeout) {

global $database;
$timestamp = time();
if ($custom_timeout = null) { $my_timeout = "300"; } else { $my_timeout = $custom_timeout;}
$timeout = $timestamp - $custom_timeout;
....
the rest of code stays as is
}
example:
<?php MembersOnline(600); ?> => timeout 10 min
<?php MembersOnline(); ?>       => timeout 5 min


cheers

Edit: by the way I am not a pro-coder myself, and I am still learning..   so dont be afraid and keep your head up Smiley Smiley
« Last Edit: August 27, 2010, 09:26:38 PM by crnogorac081 » Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
MoSaG

Offline Offline

Posts: 12


« Reply #5 on: August 28, 2010, 09:32:22 AM »

Perhaps more precise would be: "Active users in last 5 min: <list>"
And, regarding timeout, since this is a function, you can easily increase the timeout:

added support for a custom timeout and a custom headline. Perhaps I update it later to a multilanguage version ...
Logged
iradj

Offline Offline

Posts: 261



« Reply #6 on: August 30, 2010, 11:07:22 AM »

Hi,
I want to show display_name and not user name. What should I do?

BR Iradj
Logged
MoSaG

Offline Offline

Posts: 12


« Reply #7 on: August 30, 2010, 12:20:19 PM »

I want to show display_name and not user name. What should I do?

Hi,
if you want to show display_name instead of username change line 56 in include.php from
Code:
   $username = $database->get_one("SELECT username FROM ".TABLE_PREFIX."users WHERE user_id = '".$row['user_id']."'");
to
Code:
   $username = $database->get_one("SELECT display_name FROM ".TABLE_PREFIX."users WHERE user_id = '".$row['user_id']."'");

Have not tested, but should work ... tested, it works and thanks for this, because it makes more sense to display the display_name than the username! I'll change this on the snippet soon.
« Last Edit: August 30, 2010, 12:23:13 PM by MoSaG » Logged
iradj

Offline Offline

Posts: 261



« Reply #8 on: August 30, 2010, 12:39:40 PM »

Thanks, it works. Can you write me why I always get one sized line.
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #9 on: August 30, 2010, 12:43:42 PM »

Hello,

this is a very nice snippet.

I suggest to use another parameter to have a choice between username || display_name, like:

MembersOnline ($seconds = 300, $headline = 'Active users in last 5 min', $show='username');
Makes more sense to me than a hardcoded solution.

BTW, there is another Snippet from User Ruud E. which creates a list of visitors who are not logged in.
Maybe it was a good idea to merge both, or extend this one to have a list of logged in users and a Number print of those not logged in?

Regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
MoSaG

Offline Offline

Posts: 12


« Reply #10 on: August 30, 2010, 02:19:58 PM »

Thanks, it works. Can you write me why I always get one sized line.
Sorry don't understand, do you mean the blank line (only the bullet) under your name?
Perhaps you give me the link to your website so I can view it in action?
Logged
MoSaG

Offline Offline

Posts: 12


« Reply #11 on: August 30, 2010, 02:44:47 PM »

this is a very nice snippet.

I suggest to use another parameter to have a choice between username || display_name, like:

I've added this.

BTW, there is another Snippet from User Ruud E. which creates a list of visitors who are not logged in.

Yes I know, my snippet based on Ruuds snippet - after I understand how Ruuds snippet worked, I have to remove many lines and code nearly from scratch, because his way is completly different.

Maybe it was a good idea to merge both, or extend this one to have a list of logged in users and a Number print of those not logged in?

I don't know if I can just (legaly) copy Ruuds code to my snippet ... but you are right, it is a good idea to show not logged in users too ... I'll think about it, how to solve this.
Logged
iradj

Offline Offline

Posts: 261



« Reply #12 on: August 30, 2010, 02:51:19 PM »

Thanks, it works. Can you write me why I always get one sized line.
Sorry don't understand, do you mean the blank line (only the bullet) under your name?
Perhaps you give me the link to your website so I can view it in action?

Yes exactly what I mean.  URL is www.evgberg.de
Logged
MoSaG

Offline Offline

Posts: 12


« Reply #13 on: August 30, 2010, 03:23:59 PM »

Yes exactly what I mean.  URL is www.evgberg.de

can't reproduce it, but perhaps this helps to you:

at first try to clear caches and relogg, if this does'nt help, empty database table '..._mod_members_onl ine', if this also has no effect try to change line 58 from:
Code:
$tpl->set_var(array("USERNAME" => $username));
to:
Code:
if ($username) { $tpl->set_var(array("USERNAME" => $username)); }

Hope some/one of this tips will help.

EDIT: perhaps the new 0.1.4 version will solve the problem, the snippet has stored users that are not logged in with id 0 so they are always on - this will be checked now and only id higher than 0 will be stored to the members_online table, in addition there is now a custom message available if no user is online, see the updated version in 1st message.
« Last Edit: August 30, 2010, 04:13:04 PM by MoSaG » Logged
iradj

Offline Offline

Posts: 261



« Reply #14 on: August 30, 2010, 04:56:25 PM »

Thank you. Everything works great.
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!