| Conditions | 8 |
| Paths | 13 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state