Like my work? If you're looking for a Bracknell Web Design Agency then drop us a line at 'Nine Four' and we can hook up for a chat.

ExpressionEngine Plug-in: Member Online? Tuesday July 8, 2008

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’ 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’ 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. :)

Posted in: ExpressionEngine

 
Play online poker at Full Tilt Poker and PokerStars. The best online poker rooms still open to US players. welike-Poker.com provides unbiased and critical online poker room reviews.
  1. Drew

    Jul 8, 12:36 PM

    Hooray for plugins! Just taking a quick look at the source (admittedly I’ve not written any EE plugins myself, so I may be failing to appreciate some subtleties) it looks like you could tighten up those two database queries a bit.

    Could you not perform the test in one hit by joining across the two tables, something like:

    SELECT count(exp_online_users.*) FROM exp_online_users, exp_members WHERE exp_online_users.member_id=exp_members.member_id AND exp_members.username = ‘someusername’;

    You’d either get a result of 1 or 0.
  2. Nathan Pitman

    Jul 8, 02:30 PM

    @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. :)
  3. Ingmar

    Jul 8, 02:34 PM

    My I suggest:

    bq. SELECT COUNT (*) FROM exp_online_users
    RIGHT JOIN exp_members USING (member_id)
    WHERE screen_name = “My Screenname”
  4. Nathan Pitman

    Jul 8, 03:42 PM

    @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? :)
  5. Drew

    Jul 8, 05:23 PM

    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.
  6. Nathan Pitman

    Jul 8, 07:49 PM

    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.
Leave your comments
name:
email: Gravatar enabled.
http://
Format your message with Textile.
Remember

related

recently

The 10 most recent articles.