| 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: |
|
| 24: |
|
| 25: | $freshRead = isset($GLOBALS['xoInboxCountFresh']);
|
| 26: | $pmScripts = array('pmlite', 'readpmsg', 'viewpmsg');
|
| 27: | if (in_array(basename($_SERVER['SCRIPT_FILENAME'], '.php'), $pmScripts)) {
|
| 28: | if (!$freshRead) {
|
| 29: | unset($_SESSION['xoops_inbox_count'], $_SESSION['xoops_inbox_total'], $_SESSION['xoops_inbox_count_expire']);
|
| 30: | $GLOBALS['xoInboxCountFresh'] = true;
|
| 31: | }
|
| 32: | }
|
| 33: |
|
| 34: | $time = time();
|
| 35: | if (isset($_SESSION['xoops_inbox_count']) && (isset($_SESSION['xoops_inbox_count_expire']) && $_SESSION['xoops_inbox_count_expire'] > $time)) {
|
| 36: | $totals['assign'] = (int)$_SESSION['xoops_inbox_count'];
|
| 37: | $totals['total'] = (int)$_SESSION['xoops_inbox_total'];
|
| 38: | } else {
|
| 39: |
|
| 40: | $pm_handler = xoops_getHandler('privmessage');
|
| 41: |
|
| 42: | $xoopsPreload = XoopsPreload::getInstance();
|
| 43: | $xoopsPreload->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', array($pm_handler));
|
| 44: |
|
| 45: | $criteria = new CriteriaCompo(new Criteria('to_userid', $xoopsUser->getVar('uid')));
|
| 46: | $totals['total'] = $pm_handler->getCount($criteria);
|
| 47: |
|
| 48: | $criteria->add(new Criteria('read_msg', 0));
|
| 49: | $totals['assign'] = $pm_handler->getCount($criteria);
|
| 50: |
|
| 51: | $_SESSION['xoops_inbox_count'] = $totals['assign'];
|
| 52: | $_SESSION['xoops_inbox_total'] = $totals['total'];
|
| 53: | $_SESSION['xoops_inbox_count_expire'] = $time + 60;
|
| 54: | }
|
| 55: |
|
| 56: | $printCount = true;
|
| 57: | foreach ($totals as $key => $count) {
|
| 58: | if (!empty($params[$key])) {
|
| 59: | $smarty->assign($params[$key], $count);
|
| 60: | $printCount = false;
|
| 61: | }
|
| 62: | }
|
| 63: | if ($printCount) {
|
| 64: | echo $totals['assign'];
|
| 65: | }
|
| 66: | }
|
| 67: | |