|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Xoops\Core\Kernel\Criteria; |
|
|
|
|
|
|
4
|
|
|
use Xoops\Core\Kernel\CriteriaCompo; |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* xoInboxCount lets templates access private message inbox statistics for the current user |
|
8
|
|
|
* |
|
9
|
|
|
* Example: {xoInboxCount assign='unread_count' total='inbox_total'} |
|
10
|
|
|
* |
|
11
|
|
|
* Both assign and total parameters are optional. If neither is specified the unread count is displayed. |
|
12
|
|
|
* - assign = variable name to assign with the current unread message count |
|
13
|
|
|
* - total = variable name to assign with the current inbox total |
|
14
|
|
|
* |
|
15
|
|
|
* @param array $params parameters |
|
16
|
|
|
* @param Smarty_Internal_Template $smarty template |
|
17
|
|
|
* @return null |
|
18
|
|
|
*/ |
|
19
|
|
|
function smarty_function_xoInboxCount($params, Smarty_Internal_Template $smarty) |
|
20
|
|
|
{ |
|
21
|
|
|
$assign = 'assign'; |
|
22
|
|
|
$total = 'total'; |
|
23
|
|
|
$inbox_count = 'xoops_inbox_count'; |
|
24
|
|
|
$inbox_total = 'xoops_inbox_total'; |
|
25
|
|
|
$inbox_expire = 'xoops_inbox_count_expire'; |
|
26
|
|
|
|
|
27
|
|
|
$xoops = Xoops::getInstance(); |
|
28
|
|
|
$session = $xoops->session(); |
|
29
|
|
|
|
|
30
|
|
|
if (!$xoops->isUser()) { |
|
31
|
|
|
return; |
|
32
|
|
|
} |
|
33
|
|
|
$time = time(); |
|
34
|
|
|
if ($session->has($inbox_count) |
|
35
|
|
|
&& $session->has($inbox_expire) |
|
36
|
|
|
&& $session->get($inbox_expire) > $time |
|
37
|
|
|
) { |
|
38
|
|
|
$totals[$assign] = (int)$session->get($inbox_count); |
|
|
|
|
|
|
39
|
|
|
$totals[$total] = (int)$session->get($inbox_total); |
|
40
|
|
|
} else { |
|
41
|
|
|
$pmHandler = $xoops->getHandlerPrivateMessage(); |
|
42
|
|
|
$eventArgs = [$pmHandler]; |
|
43
|
|
|
|
|
44
|
|
|
$xoops->events()->triggerEvent('core.class.smarty.xoops_plugins.xoinboxcount', $eventArgs); |
|
45
|
|
|
$pmHandler = $eventArgs[0]; |
|
46
|
|
|
|
|
47
|
|
|
$criteria = new CriteriaCompo(new Criteria('to_userid', $xoops->user->getVar('uid'))); |
|
|
|
|
|
|
48
|
|
|
$totals[$total] = $pmHandler->getCount($criteria); |
|
49
|
|
|
|
|
50
|
|
|
$criteria->add(new Criteria('read_msg', 0)); |
|
51
|
|
|
$totals[$assign] = $pmHandler->getCount($criteria); |
|
52
|
|
|
|
|
53
|
|
|
$session->set($inbox_count, $totals[$assign]); |
|
54
|
|
|
$session->set($inbox_total, $totals[$total]); |
|
55
|
|
|
$session->set($inbox_expire, $time + 60); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$printCount = true; |
|
59
|
|
|
foreach ($totals as $key => $count) { |
|
60
|
|
|
if (!empty($params[$key])) { |
|
61
|
|
|
$smarty->assign($params[$key], $count); |
|
62
|
|
|
$printCount = false; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
if ($printCount) { |
|
66
|
|
|
echo $totals['assign']; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: