show logged in authors / smarty question

Creating and modifying plugins.
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

show logged in authors / smarty question

Post by Linus »

Hey there,
I'm looking for a sidebar plugin which shows the currently logged authors.
It seems that there's no such plugin available yet..

Furthermore I've got a question regarding the index.tpl file.
I want to hide the sidebar on a subpage ([subpage]=forum here). Therefore I need to know how smarty can check for the opened url.

Thanks in advance
Greetings Andi
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I don't know about a "currently logged in" plugin. If we've got one, Garvin will direct you to it as soon as he sees this post.

You could use the Sidebar Hider event plugin to hide the sidebar.

If you really want to modify your Smarty, I don't think we keep the current page around. Bulletproof addresses that by setting {$currpage} in its config.inc.php:

Code: Select all

$serendipity['smarty']->assign(array('currpage'=> "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
You could put the same thing in your template's config.inc.php, creating it if necessary.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: show logged in authors / smarty question

Post by garvinhicking »

Hi!
I'm looking for a sidebar plugin which shows the currently logged authors.
There is no functionality for that because Serendipity does not keep track of logged in authors.

You can use the "Active visitors" plugin though and patch it to add another DB table row with which you indicate if a visitor is an author or not...? :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

@ dil err judebert:
Thanks a lot - i figured it out ;)
@ garvin
Damn I knew that would be your answer - I've already looked over the db yesterday searching for a loggedIn field or something like that...
Maybe I will patch the plugin if I got time...
Kind regards
Andi
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Hi Garvin,
now I got time ;)
But I'm not sure what plugin the "Active visitors" is neither how to determine if a visitor is an author...

I looked over the code and this is what I think how I could implement it:
Create a new function which saves the authorid and a bool if logged in db. Add a call to it in the login and logout function of config.inc to store the actual state of the author.
Add a new SidebarItem printing the authornames which are logged into s9y...

This is just how I would do it - but I would not change s9ys core functions if there is another way to do this....
Kind regards
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!
Linus wrote:Hi Garvin,
now I got time ;)
But I'm not sure what plugin the "Active visitors" is neither how to determine if a visitor is an author...
I believe serendipity_plugin_statistics (bundled with s9y) does that. I think this one already stores the information in a DB, so you'd just need to add that boolean flag?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Okay I already thought that this is the plugin you suggested to patch and yes it already stores it's data in the visitors table...

But how can I determine who is logged in and who is only a visitor?
Do I have to modify the login & logout functions or is there another way to get the information?

Instead of storing a boolean flag I'm planning to store the authorid.
I could easily fetch the rows from the visitors table which got the authorid set and get the realnames to display them in the sidebar...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!
But how can I determine who is logged in and who is only a visitor?
Do I have to modify the login & logout functions or is there another way to get the information?
You can use the serendipity_authorLoggedIn() PHP function, it returns true if a user is logged in.

The author id is containde in $serendipity['authorid'].

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Sorry maybe I'm a bit dumb today but I don't understand what your talking about...
I want to display ALL users which are currently logged in on the sidebar..
You can use the serendipity_authorLoggedIn() PHP function, it returns true if a user is logged in.
I think you mean serendipity_userLoggedIn().
I can't use this function imho because I can't supply an argument.
Doing something like fetchUsers() and then a loop:

Code: Select all

foreach user { 
   if(serendipity_userLoggedIn()) {
      print authorname...
    }
}
won't work or am I wrong?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

You need two things:

1. The code that inserts the current authorid in your DB table. This is done through serendipity_userloggedin() and $serendipity['authorid']

2. To display the list of logged in users, you need your own custom DB query that evalutes the table you filled in 1.)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Hi Garvin
1. The code that inserts the current authorid in your DB table. This is done through serendipity_userloggedin() and $serendipity['authorid']
Mmh i ran into problems putting db_queries into serendipity_userLoggedIn() function.
Thats the function:

Code: Select all

function serendipity_userLoggedIn() {
    if ($_SESSION['serendipityAuthedUser'] === true && IS_installed) {
        return true;
    } else {
        return false;
    }
}
First I added global $serendipity to access the authorid. Putting simple db_queries (to insert and delete) in the if and else statement isn't working...

So I tried to find another place to put the code in which I found in the loginform plugin. I've put a line for inserting the authorid in db before serendipity_login() and to delete the authorid from db before serendipity_logout().
Well it´s working if the user logs in and out via the loginform.
But if a user is inactive and gets disconnected without logging out he is certainly shown as online.
2. To display the list of logged in users, you need your own custom DB query that evalutes the table you filled in 1.)
I got this part already working - simply copied userprofiles_birthdays and edited it to get a new sidebox...
Regards,
Andi
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Don't modify core code, you can do it all in your plugin. First check for if user_loggedIn() and then issue a db query within your plugin to update the DB table accordingly.
But if a user is inactive and gets disconnected without logging out he is certainly shown as online.
sure, that's the same with anonymous visitors. You can only show a list of authors who "have logged in over the last past 5 minutes" or so.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Hi Garv!
Well I got it working at the moment without any changes to the core.
I`ve created a new table with only on field (authorid).
Everytime a user logs in/out with the sidebarplugin I insert/delete the authorid in the table. I put that code in the serendipity_event_loginform.php.
As I mentioned before I copied serendipity_plugin_userprofiles_birthday changed it to display the realnames from the currently logged authors.

I know that this is _very_ dirty (and yes I feel ashamed) but it´s working and I got no further motiviation right now, to write it the way it should be.

I`ll see how it behaves...

Anyway thanks a lot
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Hm. I personally never log out of my s9y installations, how will you track if an author really is logged out?

You should at least save a timestamp together with the authorid, and then purge old DB entries that are older than X minutes/hours to eradicate this.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Linus
Regular
Posts: 66
Joined: Mon Mar 06, 2006 1:59 pm
Location: Mannheim
Contact:

Post by Linus »

Thank you Garvin,
I did what you told me. When a user logs in I save the time.
The user will be removed from the list after 600sec. I change the color (green,yellow,red) of an image every 200 sec to indicate how much time is left. Furthermore I added a button that the user can manually update his state...
The result looks like this:
Image
Regards Andi
Post Reply