1<?php 2 3/** 4 * xoInboxCount lets templates access private message inbox statistics for the current user 5 * 6 * Example: <{xoInboxCount assign='unread_count' total='inbox_total'}> 7 * 8 * Both assign and total parameters are optional. If neither is specified the unread count is displayed. 9 * - assign = variable name to assign with the current unread message count 10 * - total = variable name to assign with the current inbox total 11 * 12 * @param $params 13 * @param $smarty 14 * @return null 15 */ 16function 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