3
I asked a simular question a while back. Here is the response:
global $xoopsUser;
if (is_object($xoopsUser)) {
$pm_handler =& xoops_gethandler('privmessage');
$criteria = new CriteriaCompo(new Criteria('read_msg', 0));
$criteria->add(new Criteria('to_userid', $xoopsUser->getVar('uid')));
$msgs = $pm_handler->getCount($criteria);
}
$xoops_url = XOOPS_URL;
if ($msgs > 0) {
echo "
";
}
How does this work? Here's a brief explanation.
First you need to determine if there's new private messages for the logged user. This won't work for anonymous users, since all the code is wrapped in an if statement that precludes it.
One line instantiates the private message handler. Then we create a mixed criteria that includes the actual user id and as far as I can see, the existence of non-read messages.
Then we assign to a variable the result of counting the non-read messages sent to the user. If this variable is larger than zero, that is, if there are non-read private messages addressed to the user, then we echo to the screen the table containing the count and the link to the private message page.
A couple of extra notes:
1) Don't include the opening and closing tags for PHP. They are already included.
2. Don't try to use Smarty variables. All blocks are rendered through a template that already exists, so you can only use general variables, as in the example above.
I hope this works.