Nathan Pitmanhello, my name is
nathan pitman.

ExpressionEngine Plug-in: Member Online? Jul 08. 086

Whilst working on the Wired In website I came up against a little problem. I wanted to be ale to show if a specific user was online or offline, much like you would on a social networking site. However although there are tags to return a list of online users within ExpressionEngine, you cannot pass this a specific username with a view to returning a true/false response.

So, after poking around a few plug-ins which queried the DB for values (specifically the ‘“Member Info”:http://expressionengine.com/downloads/details/member_info/’ plug-in) I decided to launch in and write my first plug-in to do the job for me.

The plug-in is called ‘Member Online?‘ and it accepts a ‘username’ for which it will then simply return a true or false value. Using the optional ‘return’ parameter you can specify the values you would like returned in place of true or false.

So, typical usage would be as follows:

{exp:np_memberonline username="{username}" return="Online,Offline"}

You could either use this to simply write a string out into the page, as I am, or use it to change the class of a page element to highlight online users perhaps.

Download: pi.np_memberonline.php.zip

At the moment I’m using this alongside the Solspace ‘“User Module”:http://www.solspace.com/software/detail/user/’ to build the community aspects of the Wired In website so I’ve only developed it so far as required to meet those requirements. If you have any further ideas as to how the plug-in could be developed do let me know. :)

@Drew: Didn’t quite work out of the box like that but after a bit of fiddling I got it working with one query pretty much as you suggested. Thanks for the suggestion! That’s now included in the current release. :)

Posted by Nathan Pitman  on  07/08  at  11:35 AM

My I suggest:

bq. SELECT COUNT (*) FROM exp_online_users

RIGHT JOIN exp_members USING (member_id)

WHERE screen_name = “My Screenname”

Posted by  on  07/08  at  11:35 AM

@Ingmar: Thanks for the suggestion but in the scenario I have I need to return the online status of any user from a username, not the screen name. Or did I miss something? :)

Posted by Nathan Pitman  on  07/08  at  11:35 AM

Oh dear – have I started a ‘suggest some SQL’ war?

I’m afraid I rather obsess over the performance and robustness of every line of code. It’s something of an affliction and isn’t always healthy or necessary. It does put me on edge though when you see in the sidebar of someone’s blog that the page was built using 30+ queries. Databases are much harder to scale up than web servers, so it pays to treat them as sacred.

Posted by Drew  on  07/08  at  11:35 AM

I totally agree and I think it’s an area where I would like to ‘gen’ up a lot, but at the end of the day I have to accept that I’m not a ‘full on’ developer and I’m not sure I ever will be, more of an in between hybrid, slowing down the web, one extraneous query at a time. ;P

In all seriousness though, I don’t think there’s anything wrong with your affliction, I have the same problem when it comes to design, every minute detail has to be perfect.

Posted by Nathan Pitman  on  07/08  at  11:35 AM

Speak your mind

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?

Submit the word you see below: