1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: function smarty_function_xoInboxCount($params, &$smarty)
17: {
18: global $xoopsUser;
19:
20: if (!isset($xoopsUser) || !is_object($xoopsUser)) {
21: return null;
22: }
23: $time = time();
24: if (isset($_SESSION['xoops_inbox_count']) && @$_SESSION['xoops_inbox_count_expire'] > $time) {
25: $totals['assign'] = (int)$_SESSION['xoops_inbox_count'];
26: $totals['total'] = (int)$_SESSION['xoops_inbox_total'];
27: } else {
28: $pm_handler = xoops_getHandler('privmessage');
29:
30: $xoopsPreload = XoopsPreload::getInstance();
31: $xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler));
32:
33: $criteria = new CriteriaCompo(new Criteria('to_userid', $xoopsUser->getVar('uid')));
34: $totals['total'] = $pm_handler->getCount($criteria);
35:
36: $criteria->add(new Criteria('read_msg', 0));
37: $totals['assign'] = $pm_handler->getCount($criteria);
38:
39: $_SESSION['xoops_inbox_count'] = $totals['assign'];
40: $_SESSION['xoops_inbox_total'] = $totals['total'];
41: $_SESSION['xoops_inbox_count_expire'] = $time + 60;
42: }
43:
44: $printCount = true;
45: foreach ($totals as $key => $count) {
46: if (!empty($params[$key])) {
47: $smarty->assign($params[$key], $count);
48: $printCount = false;
49: }
50: }
51: if ($printCount) {
52: echo $totals['assign'];
53: }
54: }
55: