Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Forums / Cotonti / Extensions / Support / User API documentation?

#1 2012-11-30 18:52

Hey guys, I'm writing a notifications module which I am hoping will work similar to Facebook's system.

Currently, notifications are stored in the database and it has a very simple system to show notifications, similar to when you get a new private message.

I have a notification JS script to "pop up" the notification. I would like to know how I can get these to pop up if the user is logged in, or to wait for the user to log in before it springs into action. I was looking for some more information on the user API as I was thinking maybe I can do this with cookies?

Thanks in advance.


#2 2012-11-30 19:33

What you need is just the current user object which is $usr / {PHP.usr} depending on whether you are in PHP or TPL. It has some commonly used properties which are set in system/common.php lines 322-336:

$usr['id'] = (int) $row['user_id'];
$usr['name'] = $row['user_name'];
$usr['maingrp'] = $row['user_maingrp'];
$usr['lastvisit'] = $row['user_lastvisit'];
$usr['lastlog'] = $row['user_lastlog'];
$usr['timezone'] = cot_timezone_offset($row['user_timezone'], true);
$usr['timezonename'] = $row['user_timezone'];
$usr['theme'] = ($cfg['forcedefaulttheme']) ? $cfg['defaulttheme'] : $row['user_theme'];
$usr['scheme'] = $row['user_scheme'];
$usr['lang'] = ($cfg['forcedefaultlang']) ? $cfg['defaultlang'] : $row['user_lang'];
$usr['newpm'] = $row['user_newpm'];
$usr['auth'] = unserialize($row['user_auth']);
$usr['adminaccess'] = cot_auth('admin', 'any', 'R');
$usr['level'] = $cot_groups[$usr['maingrp']]['level'];
$usr['profile'] = $row;

What you need to check to know whether the user is logged in or not is this:

if ($usr['id'] > 0)
	// User is logged in
	// This is a guest

There are actually more fields available for users than listed above. All fields present in `cot_users` table (including extrafields) are available via $usr['profile'] array. For example, here is how you can get the avatar image path:



May the Source be with you!
#3 2012-11-30 19:37

Thank you Trustmaster,

That code (for checking if user is logged in) I dont think would work for what I am trying to do as I need it to wait for specific user to login before it pops up. For example, say you were registered on my site and I sent you a friend request while you were offline, I would like the notification to pop up as soon as you logged in next. Is that possible?


Added 2 days later:

Maybe hooking into the header would be an option?

This post was edited by lukgoh (2012-12-02 16:05, 8 years ago)
#4 2012-12-02 16:11

Maybe hooking into the header would be an option?

To pass the status to JavaScript? Yes, have a look at search.header.php for example.

May the Source be with you!
#5 2012-12-02 16:50

Siena never ceases to amaze me. Thank you very much, this just made my module awesome.

#6 2012-12-02 17:08
#36382 lukgoh:

this just made my module awesome.

starting to get curious.. :)


#7 2012-12-02 17:17

Kingsley, Im getting super excited about BB! Thanks to the help from Trustmaster it now notifies the user (when logged in) if they have new member applications, clan challenges and anything else I want, like new messages, etc. Looks awesome. You have the link if you want to see for yourself. Feel free to create new accounts so you can test everything if you want!

Added 4 hours later:

I have been reading this: but it wasn't very clear to me how to display messages when you use cot_redirect() function.

What I am actually trying to achieve is to fire up some js after it has redirected but I would also like to know about  message display on redirect. 


Added 34 minutes later:

After spending a while googling the issue its obvious that you can't refresh and modify the page at the same time. This leaves me thinking maybe using $_GET is the only solution?

This post was edited by lukgoh (2012-12-02 21:34, 8 years ago)
#8 2012-12-03 06:44

Messages use sessions to store values. So they will be displayed after redirect if they haven't been displayed yet.

May the Source be with you!