1: <?php
2:
3: function smarty_function_xoInboxCount($params, &$smarty)
4: {
5: $xoops = Xoops::getInstance();
6:
7: if (!$xoops->isUser()) {
8: return;
9: }
10: $time = time();
11: if (isset($_SESSION['xoops_inbox_count']) && @$_SESSION['xoops_inbox_count_expire'] > $time) {
12: $count = (int)($_SESSION['xoops_inbox_count']);
13: } else {
14: $pm_handler = $xoops->getHandlerPrivateMessage();
15:
16: $xoops->events()->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler));
17:
18: $criteria = new CriteriaCompo(new Criteria('read_msg', 0));
19: $criteria->add(new Criteria('to_userid', $xoops->user->getVar('uid')));
20: $count = (int)($pm_handler->getCount($criteria));
21: $_SESSION['xoops_inbox_count'] = $count;
22: $_SESSION['xoops_inbox_count_expire'] = $time + 60;
23: }
24: if (!@empty($params['assign'])) {
25: $smarty->assign($params['assign'], $count);
26: } else {
27: echo $count;
28: }
29: }
30: